Loading core/java/android/hardware/Usb.java +30 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; } } } Loading
core/java/android/hardware/Usb.java +30 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; } } }