usb: Don't show the notification when no USB device is connected
Currently, the "Charging connected device via USB" notification appears and then disappears when a USB device is disconnected. The notification should not appear when no USB device is connected. This CL prevents this. Also prevents the notification from showing up when a mouse is connected. Bug: 234548453 Test: Peripheral mode, host mode, and Power/Data role swap Signed-off-by: Jimmy Hu <hhhuuu@google.com> Change-Id: Ie4c67c639d8633361e5a3675502283cae4e35bd9
This commit is contained in:
@@ -508,6 +508,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
|
|||||||
// current USB state
|
// current USB state
|
||||||
private boolean mHostConnected;
|
private boolean mHostConnected;
|
||||||
private boolean mUsbAccessoryConnected;
|
private boolean mUsbAccessoryConnected;
|
||||||
|
private boolean mInHostModeWithNoAccessoryConnected;
|
||||||
private boolean mSourcePower;
|
private boolean mSourcePower;
|
||||||
private boolean mSinkPower;
|
private boolean mSinkPower;
|
||||||
private boolean mConfigured;
|
private boolean mConfigured;
|
||||||
@@ -959,6 +960,17 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
|
|||||||
mSupportsAllCombinations = false;
|
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);
|
mAudioAccessorySupported = port.isModeSupported(MODE_AUDIO_ACCESSORY);
|
||||||
|
|
||||||
args.recycle();
|
args.recycle();
|
||||||
@@ -983,6 +995,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
|
|||||||
Slog.i(TAG, "HOST_STATE connected:" + mUsbAccessoryConnected);
|
Slog.i(TAG, "HOST_STATE connected:" + mUsbAccessoryConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!devices.hasNext()) {
|
||||||
|
mInHostModeWithNoAccessoryConnected = true;
|
||||||
|
} else {
|
||||||
|
mInHostModeWithNoAccessoryConnected = false;
|
||||||
|
}
|
||||||
|
|
||||||
mHideUsbNotification = false;
|
mHideUsbNotification = false;
|
||||||
while (devices.hasNext()) {
|
while (devices.hasNext()) {
|
||||||
Map.Entry pair = (Map.Entry) devices.next();
|
Map.Entry pair = (Map.Entry) devices.next();
|
||||||
@@ -1192,7 +1210,8 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
|
|||||||
|
|
||||||
// Dont show the notification when connected to a USB peripheral
|
// Dont show the notification when connected to a USB peripheral
|
||||||
// and the link does not support PR_SWAP and DR_SWAP
|
// and the link does not support PR_SWAP and DR_SWAP
|
||||||
if (mHideUsbNotification && !mSupportsAllCombinations) {
|
if ((mHideUsbNotification || mInHostModeWithNoAccessoryConnected)
|
||||||
|
&& !mSupportsAllCombinations) {
|
||||||
if (mUsbNotificationId != 0) {
|
if (mUsbNotificationId != 0) {
|
||||||
mNotificationManager.cancelAsUser(null, mUsbNotificationId,
|
mNotificationManager.cancelAsUser(null, mUsbNotificationId,
|
||||||
UserHandle.ALL);
|
UserHandle.ALL);
|
||||||
|
|||||||
Reference in New Issue
Block a user