summaryrefslogtreecommitdiffstats
path: root/services/usb
diff options
context:
space:
mode:
Diffstat (limited to 'services/usb')
-rw-r--r--services/usb/java/com/android/server/usb/UsbDeviceManager.java105
1 files changed, 64 insertions, 41 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 2beb669..7a2f1a3 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -305,7 +305,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) {
@@ -330,14 +330,20 @@ public class UsbDeviceManager {
mContentResolver.registerContentObserver(
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, new ContentObserver(null) {
- public void onChange(boolean selfChange) {
- updateAdbNotification();
- }
- }
- );
+ false, adbNotificationObserver);
// Watch for USB configuration changes
mUEventObserver.startObserving(USB_STATE_MATCH);
@@ -775,44 +781,61 @@ public class UsbDeviceManager {
private void updateAdbNotification() {
if (mNotificationManager == null) return;
- final int id = com.android.internal.R.string.adb_active_notification_title;
+ 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 (mAdbEnabled && mConnected && !mAdbNotificationShown && !hideNotification) {
- Resources r = mContext.getResources();
- CharSequence title = r.getText(id);
- CharSequence message = r.getText(
- com.android.internal.R.string.adb_active_notification_message);
-
- Intent intent = Intent.makeRestartActivityTask(
- new ComponentName("com.android.settings",
- "com.android.settings.DevelopmentSettings"));
- PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
- intent, 0, null, UserHandle.CURRENT);
-
- Notification notification = new Notification.Builder(mContext)
- .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
- .setWhen(0)
- .setOngoing(true)
- .setTicker(title)
- .setDefaults(0) // please be quiet
- .setPriority(Notification.PRIORITY_LOW)
- .setColor(mContext.getColor(
- com.android.internal.R.color.system_notification_accent_color))
- .setContentTitle(title)
- .setContentText(message)
- .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);
+ 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 (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_generic_notification_message);
+
+ Intent intent = Intent.makeRestartActivityTask(
+ new ComponentName("com.android.settings",
+ "com.android.settings.DevelopmentSettings"));
+ PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
+ intent, 0, null, UserHandle.CURRENT);
+
+ Notification notification = new Notification.Builder(mContext)
+ .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
+ .setWhen(0)
+ .setOngoing(true)
+ .setTicker(title)
+ .setDefaults(0) // please be quiet
+ .setPriority(Notification.PRIORITY_LOW)
+ .setColor(mContext.getColor(
+ com.android.internal.R.color.system_notification_accent_color))
+ .setContentTitle(title)
+ .setContentText(message)
+ .setContentIntent(pi)
+ .setVisibility(Notification.VISIBILITY_PUBLIC)
+ .build();
+
+ mNotificationManager.notifyAsUser(null, id, notification,
+ UserHandle.ALL);
+ }
+ mAdbNotificationId = id;
}
}