Fix handling usb dialog for wall chargers.
UsbPort.POWER_ROLE_SINK is orthogonal to the type of the charger attached. POWER_ROLE_SINK would be the case for AC charging and USB charging. Therefore query BatteryManager for the charger type. Cherry-pick: https://android-review.googlesource.com/#/c/338265/ Bug: 34972898 Test: Charging notification should not show for pixel-c chargers. Change-Id: I8dddcd7727b6af973bd173d2c6e325aa4be2ca3a
This commit is contained in:
committed by
Badhri Jagan Sridharan
parent
a2f8f4970e
commit
843aba7745
@@ -33,6 +33,7 @@ import android.hardware.usb.UsbAccessory;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.FileUtils;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -122,6 +123,7 @@ public class UsbDeviceManager {
|
||||
private static final int MSG_UPDATE_USER_RESTRICTIONS = 6;
|
||||
private static final int MSG_UPDATE_HOST_STATE = 7;
|
||||
private static final int MSG_ACCESSORY_MODE_ENTER_TIMEOUT = 8;
|
||||
private static final int MSG_UPDATE_CHARGING_STATE = 9;
|
||||
|
||||
private static final int AUDIO_MODE_SOURCE = 1;
|
||||
|
||||
@@ -203,6 +205,15 @@ public class UsbDeviceManager {
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mChargingReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
boolean usbCharging = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
mHandler.sendMessage(MSG_UPDATE_CHARGING_STATE, usbCharging);
|
||||
}
|
||||
};
|
||||
|
||||
public UsbDeviceManager(Context context, UsbAlsaManager alsaManager,
|
||||
UsbSettingsManager settingsManager) {
|
||||
mContext = context;
|
||||
@@ -229,6 +240,8 @@ public class UsbDeviceManager {
|
||||
}
|
||||
mContext.registerReceiver(mHostReceiver,
|
||||
new IntentFilter(UsbManager.ACTION_USB_PORT_CHANGED));
|
||||
mContext.registerReceiver(mChargingReceiver,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
}
|
||||
|
||||
private UsbProfileGroupSettingsManager getCurrentSettings() {
|
||||
@@ -358,6 +371,7 @@ public class UsbDeviceManager {
|
||||
private int mUsbNotificationId;
|
||||
private boolean mAdbNotificationShown;
|
||||
private int mCurrentUser = UserHandle.USER_NULL;
|
||||
private boolean mUsbCharging;
|
||||
|
||||
public UsbHandler(Looper looper) {
|
||||
super(looper);
|
||||
@@ -799,6 +813,10 @@ public class UsbDeviceManager {
|
||||
mPendingBootBroadcast = true;
|
||||
}
|
||||
break;
|
||||
case MSG_UPDATE_CHARGING_STATE:
|
||||
mUsbCharging = (msg.arg1 == 1);
|
||||
updateUsbNotification();
|
||||
break;
|
||||
case MSG_ENABLE_ADB:
|
||||
setAdbEnabled(msg.arg1 == 1);
|
||||
break;
|
||||
@@ -892,7 +910,7 @@ public class UsbDeviceManager {
|
||||
}
|
||||
} else if (mSourcePower) {
|
||||
id = com.android.internal.R.string.usb_supplying_notification_title;
|
||||
} else if (mHostConnected && mSinkPower) {
|
||||
} else if (mHostConnected && mSinkPower && mUsbCharging) {
|
||||
id = com.android.internal.R.string.usb_charging_notification_title;
|
||||
}
|
||||
if (id != mUsbNotificationId) {
|
||||
@@ -998,6 +1016,7 @@ public class UsbDeviceManager {
|
||||
pw.println(" mHostConnected: " + mHostConnected);
|
||||
pw.println(" mSourcePower: " + mSourcePower);
|
||||
pw.println(" mSinkPower: " + mSinkPower);
|
||||
pw.println(" mUsbCharging: " + mUsbCharging);
|
||||
try {
|
||||
pw.println(" Kernel state: "
|
||||
+ FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
|
||||
|
||||
Reference in New Issue
Block a user