diff options
| author | 2017-07-18 17:29:10 -0700 | |
|---|---|---|
| committer | 2017-07-18 17:44:47 -0700 | |
| commit | 5e79cbb2913c28ca6d79001ddaa0c8cec78b3eed (patch) | |
| tree | 020d1347f0e7bce78df7f8a367a7b2fb215a4b89 /services/usb/java | |
| parent | f99ac67bdb19c96eedc9ce274ded306e9f658371 (diff) | |
Always reevaluate whether to show the notification for USB_DEVICE_* intents
The decision whether to show or hide the "Usb supplying power.."
notification is based on two different broadcasts
1. USB_DEVICE_ATTACHED/DETACHED
2. USB_PORT_CHANGED
Depending on how long the port takes to enumerate, the required
intents might arrive in different order. Previously, it was assumed
that the ATTACHED broadcast would arrive before the PORT_CHANGED
broadcast and the code was aggressive to reduce the number of
times the decision to display/hide the notification is made.
This might cause the notification to be displayed in some instances
when it is not supposed to be displayed. This CL makes the usb service
to always reevaluate whenever USB_DEVICE_ATTACHED/DETACHED is
received.
Also, adding logs to print whenever the notification in enqueued/
dequeued.
Bug: 63785369
Test: Verified that the notification is displayed when connecting
to another pixel device and hidden when mouse or headset is
connected.
Change-Id: I30650a2d9923d01a1fce4b9450e65ec7f4e6557b
Diffstat (limited to 'services/usb/java')
| -rw-r--r-- | services/usb/java/com/android/server/usb/UsbDeviceManager.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index b0fefc494037..c696b509b4b8 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -956,11 +956,6 @@ public class UsbDeviceManager { Slog.i(TAG, "HOST_STATE connected:" + connected); } - if ((mHideUsbNotification && connected) - || (!mHideUsbNotification && !connected)) { - break; - } - mHideUsbNotification = false; while (devices.hasNext()) { Map.Entry pair = (Map.Entry) devices.next(); @@ -1061,12 +1056,22 @@ public class UsbDeviceManager { private void updateUsbNotification(boolean force) { if (mNotificationManager == null || !mUseUsbNotification - || ("0".equals(SystemProperties.get("persist.charging.notify"))) - // Dont show the notification when connected to a USB peripheral - // and the link does not support PR_SWAP and DR_SWAP - || (mHideUsbNotification && !mSupportsAllCombinations)) { + || ("0".equals(SystemProperties.get("persist.charging.notify")))) { return; } + + // Dont show the notification when connected to a USB peripheral + // and the link does not support PR_SWAP and DR_SWAP + if (mHideUsbNotification && !mSupportsAllCombinations) { + if (mUsbNotificationId != 0) { + mNotificationManager.cancelAsUser(null, mUsbNotificationId, + UserHandle.ALL); + mUsbNotificationId = 0; + Slog.d(TAG, "Clear notification"); + } + return; + } + int id = 0; int titleRes = 0; Resources r = mContext.getResources(); @@ -1117,6 +1122,7 @@ public class UsbDeviceManager { if (mUsbNotificationId != 0) { mNotificationManager.cancelAsUser(null, mUsbNotificationId, UserHandle.ALL); + Slog.d(TAG, "Clear notification"); mUsbNotificationId = 0; } if (id != 0) { @@ -1173,6 +1179,7 @@ public class UsbDeviceManager { mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL); + Slog.d(TAG, "push notification:" + title); mUsbNotificationId = id; } } |