diff options
| author | Mike Lockwood <lockwood@android.com> | 2010-08-31 13:46:35 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-31 13:46:35 -0700 |
| commit | 6ed727e39e945a512cd870e3136dd47927242020 (patch) | |
| tree | 17050d41496b769b377c201ef011285064a3299f /core | |
| parent | f827a0cf1d42e3f69050c2888221e901d7f80330 (diff) | |
| parent | 08bff3b9d4c0a66c3aaac45db68207d08276fd38 (diff) | |
| download | frameworks_base-6ed727e39e945a512cd870e3136dd47927242020.zip frameworks_base-6ed727e39e945a512cd870e3136dd47927242020.tar.gz frameworks_base-6ed727e39e945a512cd870e3136dd47927242020.tar.bz2 | |
Merge "USB: Add functions for querying if a USB function is supported and enabled."
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/hardware/Usb.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/java/android/hardware/Usb.java b/core/java/android/hardware/Usb.java index 1028f9f..ebb8296 100644 --- a/core/java/android/hardware/Usb.java +++ b/core/java/android/hardware/Usb.java @@ -17,6 +17,10 @@ package android.hardware; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + /** * Class for accessing USB state information. * @hide @@ -114,4 +118,30 @@ public class Usb { * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast */ public static final String USB_FUNCTION_DISABLED = "disabled"; + + private static File getFunctionEnableFile(String function) { + return new File("/sys/class/usb_composite/" + function + "/enable"); + } + + /** + * Returns true if the specified USB function is supported by the kernel. + * Note that a USB function maybe supported but disabled. + */ + public static boolean isFunctionSupported(String function) { + return getFunctionEnableFile(function).exists(); + } + + /** + * Returns true if the specified USB function is currently enabled. + */ + public static boolean isFunctionEnabled(String function) { + try { + FileInputStream stream = new FileInputStream(getFunctionEnableFile(function)); + boolean enabled = (stream.read() == '1'); + stream.close(); + return enabled; + } catch (IOException e) { + return false; + } + } } |
