From a13e37793f52acf56f1106cd7db8157e7c13ad76 Mon Sep 17 00:00:00 2001 From: Khoa Hong Date: Wed, 31 Aug 2022 16:49:07 +0800 Subject: [PATCH] Show charging notification when device is being charged via USB, with USB data disabled. Bug: 239184431 Test: Use TestDPC to enroll device and disable USB data, then verify that the behavior of charging notifications is identical to another phone with USB data enabled: - Notification shows up when connecting to laptop, another phone before/after power swap. - Notification does not show up when connecting to a wall charger. Change-Id: I016f65dcdd478d3429efe871bf99aee2f1653c45 --- .../com/android/server/usb/UsbDeviceManager.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 9562c1a5bcf98..e90a376e90f87 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -514,6 +514,8 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser private boolean mConfigured; private boolean mAudioAccessoryConnected; private boolean mAudioAccessorySupported; + private boolean mConnectedToDataDisabledPort; + private int mPowerBrickConnectionStatus; private UsbAccessory mCurrentAccessory; private int mUsbNotificationId; @@ -952,12 +954,19 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser && status.isRoleCombinationSupported(POWER_ROLE_SOURCE, DATA_ROLE_DEVICE) && status.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_DEVICE); + + boolean usbDataDisabled = + status.getUsbDataStatus() != UsbPortStatus.DATA_STATUS_ENABLED; + mConnectedToDataDisabledPort = status.isConnected() && usbDataDisabled; + mPowerBrickConnectionStatus = status.getPowerBrickConnectionStatus(); } else { mHostConnected = false; mSourcePower = false; mSinkPower = false; mAudioAccessoryConnected = false; mSupportsAllCombinations = false; + mConnectedToDataDisabledPort = false; + mPowerBrickConnectionStatus = UsbPortStatus.POWER_BRICK_STATUS_UNKNOWN; } if (mHostConnected) { @@ -1265,6 +1274,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser } else if (mHostConnected && mSinkPower && (mUsbCharging || mUsbAccessoryConnected)) { titleRes = com.android.internal.R.string.usb_charging_notification_title; id = SystemMessage.NOTE_USB_CHARGING; + } else if (mSinkPower && mConnectedToDataDisabledPort + && mPowerBrickConnectionStatus != UsbPortStatus.POWER_BRICK_STATUS_CONNECTED) { + // Show charging notification when USB Data is disabled on the port, and not + // connected to a wall charger. + titleRes = com.android.internal.R.string.usb_charging_notification_title; + id = SystemMessage.NOTE_USB_CHARGING; } if (id != mUsbNotificationId || force) { // clear notification if title needs changing