From 0be6800b0feba50fa2c1be7852ee2eb02c38afc0 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Tue, 3 May 2016 13:35:15 -0700 Subject: [PATCH] Fix notifications for USB PD enabled devices The devices with USB PD support can have the data role and the power role of their USB-C port reversed. Ensure the title of the notification and the content of the USB selection dialog is correct in this case. Testing done on Ryu with the following accessories: - legacy A-C cable - USB-C charger (5X) - USB-PD charger (Zinger) - Pixel 2 (in both roles) - Type-C Macbook (in both roles) - Nexus 5X (in both roles) - Apple AV HDMI accessory - LG USB-C screen/dock - Honeybuns dock Bug: 28310685 Bug: 24137353 Change-Id: Id7f358c40d8714fae68ca98a7eb067f62f18b0af --- .../com/android/server/usb/UsbDeviceManager.java | 15 ++++++++++++--- 1 file changed, 12 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 08cbcf764a4ed..df9242dc0aa12 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -319,6 +319,7 @@ public class UsbDeviceManager { // current USB state private boolean mConnected; private boolean mHostConnected; + private boolean mSourcePower; private boolean mConfigured; private boolean mUsbDataUnlocked; private String mCurrentFunctions; @@ -399,7 +400,8 @@ public class UsbDeviceManager { public void updateHostState(UsbPort port, UsbPortStatus status) { boolean hostConnected = status.getCurrentDataRole() == UsbPort.DATA_ROLE_HOST; - obtainMessage(MSG_UPDATE_HOST_STATE, hostConnected ? 1 :0, 0).sendToTarget(); + boolean sourcePower = status.getCurrentPowerRole() == UsbPort.POWER_ROLE_SOURCE; + obtainMessage(MSG_UPDATE_HOST_STATE, hostConnected ? 1 :0, sourcePower ? 1 :0).sendToTarget(); } private boolean waitForState(String state) { @@ -717,6 +719,7 @@ public class UsbDeviceManager { break; case MSG_UPDATE_HOST_STATE: mHostConnected = (msg.arg1 == 1); + mSourcePower = (msg.arg2 == 1); updateUsbNotification(); if (mBootCompleted) { updateUsbStateBroadcastIfNeeded(); @@ -782,7 +785,11 @@ public class UsbDeviceManager { Resources r = mContext.getResources(); if (mConnected) { if (!mUsbDataUnlocked) { - id = com.android.internal.R.string.usb_charging_notification_title; + if (mSourcePower) { + id = com.android.internal.R.string.usb_supplying_notification_title; + } else { + id = com.android.internal.R.string.usb_charging_notification_title; + } } else if (UsbManager.containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) { id = com.android.internal.R.string.usb_mtp_notification_title; @@ -795,10 +802,12 @@ public class UsbDeviceManager { } else if (UsbManager.containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) { id = com.android.internal.R.string.usb_accessory_notification_title; + } else if (mSourcePower) { + id = com.android.internal.R.string.usb_supplying_notification_title; } else { id = com.android.internal.R.string.usb_charging_notification_title; } - } else if (mHostConnected) { + } else if (mSourcePower) { id = com.android.internal.R.string.usb_supplying_notification_title; } if (id != mUsbNotificationId) {