diff options
Diffstat (limited to 'services/usb/java/com')
| -rw-r--r-- | services/usb/java/com/android/server/usb/UsbDeviceManager.java | 52 | ||||
| -rw-r--r-- | services/usb/java/com/android/server/usb/UsbSettingsManager.java | 2 |
2 files changed, 43 insertions, 11 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 769ee46..29a1809 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -322,7 +322,7 @@ public class UsbDeviceManager { private boolean mCurrentFunctionsApplied; private UsbAccessory mCurrentAccessory; private int mUsbNotificationId; - private boolean mAdbNotificationShown; + private int mAdbNotificationId; private int mCurrentUser = UserHandle.USER_NULL; public UsbHandler(Looper looper) { @@ -348,6 +348,20 @@ public class UsbDeviceManager { Settings.Global.getUriFor(Settings.Global.ADB_ENABLED), false, new AdbSettingsObserver()); + ContentObserver adbNotificationObserver = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + updateAdbNotification(); + } + }; + + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), + false, adbNotificationObserver); + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.ADB_NOTIFY), + false, adbNotificationObserver); + // Watch for USB configuration changes mUEventObserver.startObserving(USB_STATE_MATCH); mUEventObserver.startObserving(ACCESSORY_START_MATCH); @@ -792,15 +806,35 @@ public class UsbDeviceManager { private void updateAdbNotification() { if (mNotificationManager == null) return; - final int id = com.android.internal.R.string.adb_active_notification_title; - if (mAdbEnabled && mConnected) { - if ("0".equals(SystemProperties.get("persist.adb.notify"))) return; + final int id; + boolean usbAdbActive = mAdbEnabled && mConnected; + boolean netAdbActive = mAdbEnabled && + Settings.Secure.getInt(mContentResolver, Settings.Secure.ADB_PORT, -1) > 0; + boolean hideNotification = "0".equals(SystemProperties.get("persist.adb.notify")) + || Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ADB_NOTIFY, 1) == 0; + + if (hideNotification) { + id = 0; + } else if (usbAdbActive && netAdbActive) { + id = com.android.internal.R.string.adb_both_active_notification_title; + } else if (usbAdbActive) { + id = com.android.internal.R.string.adb_active_notification_title; + } else if (netAdbActive) { + id = com.android.internal.R.string.adb_net_active_notification_title; + } else { + id = 0; + } - if (!mAdbNotificationShown) { + if (id != mAdbNotificationId) { + if (mAdbNotificationId != 0) { + mNotificationManager.cancelAsUser(null, mAdbNotificationId, UserHandle.ALL); + } + if (id != 0) { Resources r = mContext.getResources(); CharSequence title = r.getText(id); CharSequence message = r.getText( - com.android.internal.R.string.adb_active_notification_message); + com.android.internal.R.string.adb_active_generic_notification_message); Intent intent = Intent.makeRestartActivityTask( new ComponentName("com.android.settings", @@ -822,13 +856,11 @@ public class UsbDeviceManager { .setContentIntent(pi) .setVisibility(Notification.VISIBILITY_PUBLIC) .build(); - mAdbNotificationShown = true; + mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL); } - } else if (mAdbNotificationShown) { - mAdbNotificationShown = false; - mNotificationManager.cancelAsUser(null, id, UserHandle.ALL); + mAdbNotificationId = id; } } diff --git a/services/usb/java/com/android/server/usb/UsbSettingsManager.java b/services/usb/java/com/android/server/usb/UsbSettingsManager.java index 2cf42f0..674952c 100644 --- a/services/usb/java/com/android/server/usb/UsbSettingsManager.java +++ b/services/usb/java/com/android/server/usb/UsbSettingsManager.java @@ -739,7 +739,7 @@ class UsbSettingsManager { } // Send broadcast to running activity with registered intent - mUserContext.sendBroadcast(intent); + mUserContext.sendBroadcastAsUser(intent, UserHandle.ALL); // Start activity with registered intent resolveActivity(intent, matches, defaultPackage, device, null); |
