diff options
Diffstat (limited to 'services/java/com/android/server/UsbObserver.java')
-rw-r--r-- | services/java/com/android/server/UsbObserver.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/services/java/com/android/server/UsbObserver.java b/services/java/com/android/server/UsbObserver.java index d08fe9b..546e5f8 100644 --- a/services/java/com/android/server/UsbObserver.java +++ b/services/java/com/android/server/UsbObserver.java @@ -24,6 +24,7 @@ import android.net.Uri; import android.os.Handler; import android.os.Message; import android.os.UEventObserver; +import android.provider.Mtp; import android.provider.Settings; import android.util.Log; import android.util.Slog; @@ -147,8 +148,43 @@ class UsbObserver extends UEventObserver { } } + private native void monitorUsbHostBus(); + + // called from JNI in monitorUsbHostBus() + private void usbCameraAdded(int deviceID) { + Intent intent = new Intent(Usb.ACTION_USB_CAMERA_ATTACHED, + Mtp.Device.getContentUri(deviceID)); + Log.d(TAG, "usbCameraAdded, sending " + intent); + mContext.sendBroadcast(intent); + } + + // called from JNI in monitorUsbHostBus() + private void usbCameraRemoved(int deviceID) { + Intent intent = new Intent(Usb.ACTION_USB_CAMERA_DETACHED, + Mtp.Device.getContentUri(deviceID)); + Log.d(TAG, "usbCameraRemoved, sending " + intent); + mContext.sendBroadcast(intent); + } + + private void initHostSupport() { + // Create a thread to call into native code to wait for USB host events. + // This thread will call us back on usbCameraAdded and usbCameraRemoved. + Runnable runnable = new Runnable() { + public void run() { + monitorUsbHostBus(); + } + }; + new Thread(null, runnable, "UsbObserver host thread").start(); + } + void systemReady() { synchronized (this) { + if (mContext.getResources().getBoolean( + com.android.internal.R.bool.config_hasUsbHostSupport)) { + // start monitoring for connected USB devices + initHostSupport(); + } + update(); mSystemReady = true; } |