summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r--core/java/android/hardware/Usb.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/core/java/android/hardware/Usb.java b/core/java/android/hardware/Usb.java
index 57271d4..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
@@ -55,6 +59,24 @@ public class Usb {
public static final String ACTION_USB_STATE =
"android.hardware.action.USB_STATE";
+ /**
+ * Broadcast Action: A broadcast for USB camera attached event.
+ *
+ * This intent is sent when a USB device supporting PTP is attached to the host USB bus.
+ * The intent's data contains a Uri for the device in the MTP provider.
+ */
+ public static final String ACTION_USB_CAMERA_ATTACHED =
+ "android.hardware.action.USB_CAMERA_ATTACHED";
+
+ /**
+ * Broadcast Action: A broadcast for USB camera detached event.
+ *
+ * This intent is sent when a USB device supporting PTP is detached from the host USB bus.
+ * The intent's data contains a Uri for the device in the MTP provider.
+ */
+ public static final String ACTION_USB_CAMERA_DETACHED =
+ "android.hardware.action.USB_CAMERA_DETACHED";
+
/**
* Boolean extra indicating whether USB is connected or disconnected.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast.
@@ -96,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;
+ }
+ }
}