diff options
author | Mike Lockwood <lockwood@android.com> | 2010-08-31 13:27:05 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-08-31 13:27:05 -0400 |
commit | 08bff3b9d4c0a66c3aaac45db68207d08276fd38 (patch) | |
tree | ae0fbd79e4d65ce97783e441dd7cf916dc05144c | |
parent | 9846bc6a9bbcc1282791faf60718384fff12233e (diff) | |
download | frameworks_base-08bff3b9d4c0a66c3aaac45db68207d08276fd38.zip frameworks_base-08bff3b9d4c0a66c3aaac45db68207d08276fd38.tar.gz frameworks_base-08bff3b9d4c0a66c3aaac45db68207d08276fd38.tar.bz2 |
USB: Add functions for querying if a USB function is supported and enabled.
Change-Id: I5fc24960e1e01c27e892acc2e76c12ddf8c654cb
Signed-off-by: Mike Lockwood <lockwood@android.com>
-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; + } + } } |