From 2424262814fc4e99c3c8d4e88e96f36fed0ea68e Mon Sep 17 00:00:00 2001 From: Ray Chi Date: Mon, 14 Feb 2022 11:50:14 +0800 Subject: [PATCH] Fix handling usb notification after pr_swap complete After the device (USB host) finished the pr_swap and the power role is changed from Source to Sink, the notification should be updated with different messages. However, the notification may be ignored since the charger type is not USB. Users may get confused when the notification is gone. If the peripheral device is still connected, UsbDeviceManager should push new notification. Bug: 212189038 Test: notification is updated Change-Id: I772c8c06a1e3a8770d0bf132c5e8fdf313bb2685 --- .../usb/java/com/android/server/usb/UsbDeviceManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 8cb0909def5d..21f789f4e735 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -492,6 +492,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser // current USB state private boolean mHostConnected; + private boolean mUsbAccessoryConnected; private boolean mSourcePower; private boolean mSinkPower; private boolean mConfigured; @@ -961,10 +962,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser break; case MSG_UPDATE_HOST_STATE: Iterator devices = (Iterator) msg.obj; - boolean connected = (msg.arg1 == 1); + mUsbAccessoryConnected = (msg.arg1 == 1); if (DEBUG) { - Slog.i(TAG, "HOST_STATE connected:" + connected); + Slog.i(TAG, "HOST_STATE connected:" + mUsbAccessoryConnected); } mHideUsbNotification = false; @@ -1218,7 +1219,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser } else if (mSourcePower) { titleRes = com.android.internal.R.string.usb_supplying_notification_title; id = SystemMessage.NOTE_USB_SUPPLYING; - } else if (mHostConnected && mSinkPower && mUsbCharging) { + } else if (mHostConnected && mSinkPower && (mUsbCharging || mUsbAccessoryConnected)) { titleRes = com.android.internal.R.string.usb_charging_notification_title; id = SystemMessage.NOTE_USB_CHARGING; }