Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a13e3779 authored by Khoa Hong's avatar Khoa Hong
Browse files

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
parent cc179ce3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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