diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 610190ea0e234..2fc893e9c06a9 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -494,6 +494,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser // current USB state private boolean mHostConnected; private boolean mUsbAccessoryConnected; + private boolean mInHostModeWithNoAccessoryConnected; private boolean mSourcePower; private boolean mSinkPower; private boolean mConfigured; @@ -947,6 +948,17 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser mSupportsAllCombinations = false; } + if (mHostConnected) { + if (!mUsbAccessoryConnected) { + mInHostModeWithNoAccessoryConnected = true; + } else { + mInHostModeWithNoAccessoryConnected = false; + } + } else { + // if not in host mode, reset value to false + mInHostModeWithNoAccessoryConnected = false; + } + mAudioAccessorySupported = port.isModeSupported(MODE_AUDIO_ACCESSORY); args.recycle(); @@ -971,6 +983,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser Slog.i(TAG, "HOST_STATE connected:" + mUsbAccessoryConnected); } + if (!devices.hasNext()) { + mInHostModeWithNoAccessoryConnected = true; + } else { + mInHostModeWithNoAccessoryConnected = false; + } + mHideUsbNotification = false; while (devices.hasNext()) { Map.Entry pair = (Map.Entry) devices.next(); @@ -1171,7 +1189,8 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser // 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 ((mHideUsbNotification || mInHostModeWithNoAccessoryConnected) + && !mSupportsAllCombinations) { if (mUsbNotificationId != 0) { mNotificationManager.cancelAsUser(null, mUsbNotificationId, UserHandle.ALL);