diff options
author | Mike Lockwood <lockwood@android.com> | 2011-06-17 12:21:39 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-06-17 19:49:05 -0400 |
commit | 5787a2d5b4e5bd60087eb7fbb13c97c7d0ba113e (patch) | |
tree | 0e6b497309b9aa41d8821a160e0ccbb4447b91bf /services | |
parent | ecedfdc7794048cd539e3df92b641a18a05acdf7 (diff) | |
download | frameworks_base-5787a2d5b4e5bd60087eb7fbb13c97c7d0ba113e.zip frameworks_base-5787a2d5b4e5bd60087eb7fbb13c97c7d0ba113e.tar.gz frameworks_base-5787a2d5b4e5bd60087eb7fbb13c97c7d0ba113e.tar.bz2 |
USB connected notification and temporary USB options dialog
This change adds a notification when USB is connected.
Selecting the notification brings up a dialog to allow switching between
MTP and PTP modes, and also allows mounting a CD image for installing AFT.
The UI design is not final - this is a temporary implementation of the UI.
Change-Id: Idd678537aba595fd4cb183ea755bf437f372d826
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/usb/UsbDeviceManager.java | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java index e03f9a0..b7f9d5c 100644 --- a/services/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/java/com/android/server/usb/UsbDeviceManager.java @@ -95,11 +95,17 @@ public class UsbDeviceManager { private NotificationManager mNotificationManager; private final boolean mHasUsbAccessory; - // for adb connected notifications + // for USB connected notification + private boolean mUsbNotificationShown; + private boolean mUseUsbNotification; + private Notification mUsbNotification; + + // for adb connected notification private boolean mAdbNotificationShown; private Notification mAdbNotification; private boolean mAdbEnabled; + private class AdbSettingsObserver extends ContentObserver { public AdbSettingsObserver() { super(null); @@ -112,6 +118,50 @@ public class UsbDeviceManager { } } + private void updateUsbNotification(boolean connected) { + if (mNotificationManager == null || !mUseUsbNotification) return; + if (connected) { + if (!mUsbNotificationShown) { + Resources r = mContext.getResources(); + CharSequence title = r.getText( + com.android.internal.R.string.usb_preferences_notification_title); + CharSequence message = r.getText( + com.android.internal.R.string.usb_preferece_notification_message); + + if (mUsbNotification == null) { + mUsbNotification = new Notification(); + mUsbNotification.icon = com.android.internal.R.drawable.stat_sys_data_usb; + mUsbNotification.when = 0; + mUsbNotification.flags = Notification.FLAG_ONGOING_EVENT; + mUsbNotification.tickerText = title; + mUsbNotification.defaults = 0; // please be quiet + mUsbNotification.sound = null; + mUsbNotification.vibrate = null; + } + + Intent intent = new Intent(); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | + Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intent.setClassName("com.android.systemui", + "com.android.systemui.usb.UsbPreferenceActivity"); + PendingIntent pi = PendingIntent.getActivity(mContext, 0, + intent, 0); + + mUsbNotification.setLatestEventInfo(mContext, title, message, pi); + + mUsbNotificationShown = true; + mNotificationManager.notify( + com.android.internal.R.string.usb_preferences_notification_title, + mUsbNotification); + } + + } else if (mUsbNotificationShown) { + mUsbNotificationShown = false; + mNotificationManager.cancel( + com.android.internal.R.string.usb_preferences_notification_title); + } + } + private void updateAdbNotification(boolean adbEnabled) { if (mNotificationManager == null) return; if (adbEnabled) { @@ -205,6 +255,17 @@ public class UsbDeviceManager { mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + // We do not show the USB notification if the primary volume supports mass storage. + // The legacy mass storage UI will be used instead. + boolean massStorageSupported = false; + StorageManager storageManager = (StorageManager) + mContext.getSystemService(Context.STORAGE_SERVICE); + StorageVolume[] volumes = storageManager.getVolumeList(); + if (volumes.length > 0) { + massStorageSupported = volumes[0].allowMassStorage(); + } + mUseUsbNotification = !massStorageSupported; + // make sure the ADB_ENABLED setting value matches the current state Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED, mAdbEnabled ? 1 : 0); @@ -448,6 +509,7 @@ public class UsbDeviceManager { case MSG_UPDATE_STATE: mConnected = (msg.arg1 == 1); mConfigured = (msg.arg2 == 1); + updateUsbNotification(mConnected); updateAdbNotification(mAdbEnabled && mConnected); if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) { @@ -481,6 +543,7 @@ public class UsbDeviceManager { mDefaultFunctions = function; break; case MSG_SYSTEM_READY: + updateUsbNotification(mConnected); updateAdbNotification(mAdbEnabled && mConnected); updateUsbState(); if (mCurrentAccessory != null && mDeferAccessoryAttached) { |