Merge changes from topic 'pixel-c' into nyc-mr2-dev
am: dee514fae3
Change-Id: I4038d1fbd429fcedc4a379d764b5ef5c59dcce1d
This commit is contained in:
committed by
android-build-merger
commit
fa207eb889
@@ -32,6 +32,7 @@ import android.hardware.usb.UsbAccessory;
|
|||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.hardware.usb.UsbPort;
|
import android.hardware.usb.UsbPort;
|
||||||
import android.hardware.usb.UsbPortStatus;
|
import android.hardware.usb.UsbPortStatus;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.FileUtils;
|
import android.os.FileUtils;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -111,6 +112,7 @@ public class UsbDeviceManager {
|
|||||||
private static final int MSG_USER_SWITCHED = 5;
|
private static final int MSG_USER_SWITCHED = 5;
|
||||||
private static final int MSG_UPDATE_USER_RESTRICTIONS = 6;
|
private static final int MSG_UPDATE_USER_RESTRICTIONS = 6;
|
||||||
private static final int MSG_UPDATE_HOST_STATE = 7;
|
private static final int MSG_UPDATE_HOST_STATE = 7;
|
||||||
|
private static final int MSG_UPDATE_CHARGING_STATE = 9;
|
||||||
|
|
||||||
private static final int AUDIO_MODE_SOURCE = 1;
|
private static final int AUDIO_MODE_SOURCE = 1;
|
||||||
|
|
||||||
@@ -192,6 +194,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) {
|
public UsbDeviceManager(Context context, UsbAlsaManager alsaManager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mUsbAlsaManager = alsaManager;
|
mUsbAlsaManager = alsaManager;
|
||||||
@@ -216,6 +227,8 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
mContext.registerReceiver(mHostReceiver,
|
mContext.registerReceiver(mHostReceiver,
|
||||||
new IntentFilter(UsbManager.ACTION_USB_PORT_CHANGED));
|
new IntentFilter(UsbManager.ACTION_USB_PORT_CHANGED));
|
||||||
|
mContext.registerReceiver(mChargingReceiver,
|
||||||
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UsbSettingsManager getCurrentSettings() {
|
private UsbSettingsManager getCurrentSettings() {
|
||||||
@@ -330,6 +343,7 @@ public class UsbDeviceManager {
|
|||||||
private int mUsbNotificationId;
|
private int mUsbNotificationId;
|
||||||
private boolean mAdbNotificationShown;
|
private boolean mAdbNotificationShown;
|
||||||
private int mCurrentUser = UserHandle.USER_NULL;
|
private int mCurrentUser = UserHandle.USER_NULL;
|
||||||
|
private boolean mUsbCharging;
|
||||||
|
|
||||||
public UsbHandler(Looper looper) {
|
public UsbHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -428,7 +442,10 @@ public class UsbDeviceManager {
|
|||||||
args.argi2 = sourcePower ? 1 :0;
|
args.argi2 = sourcePower ? 1 :0;
|
||||||
args.argi3 = sinkPower ? 1 :0;
|
args.argi3 = sinkPower ? 1 :0;
|
||||||
|
|
||||||
obtainMessage(MSG_UPDATE_HOST_STATE, args).sendToTarget();
|
removeMessages(MSG_UPDATE_HOST_STATE);
|
||||||
|
Message msg = obtainMessage(MSG_UPDATE_HOST_STATE, args);
|
||||||
|
// debounce rapid transitions of connect/disconnect on type-c ports
|
||||||
|
sendMessageDelayed(msg, UPDATE_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean waitForState(String state) {
|
private boolean waitForState(String state) {
|
||||||
@@ -731,6 +748,7 @@ public class UsbDeviceManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
|
SomeArgs args;
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_UPDATE_STATE:
|
case MSG_UPDATE_STATE:
|
||||||
mConnected = (msg.arg1 == 1);
|
mConnected = (msg.arg1 == 1);
|
||||||
@@ -754,7 +772,7 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_HOST_STATE:
|
case MSG_UPDATE_HOST_STATE:
|
||||||
SomeArgs args = (SomeArgs) msg.obj;
|
args = (SomeArgs) msg.obj;
|
||||||
mHostConnected = (args.argi1 == 1);
|
mHostConnected = (args.argi1 == 1);
|
||||||
mSourcePower = (args.argi2 == 1);
|
mSourcePower = (args.argi2 == 1);
|
||||||
mSinkPower = (args.argi3 == 1);
|
mSinkPower = (args.argi3 == 1);
|
||||||
@@ -766,6 +784,10 @@ public class UsbDeviceManager {
|
|||||||
mPendingBootBroadcast = true;
|
mPendingBootBroadcast = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MSG_UPDATE_CHARGING_STATE:
|
||||||
|
mUsbCharging = (msg.arg1 == 1);
|
||||||
|
updateUsbNotification();
|
||||||
|
break;
|
||||||
case MSG_ENABLE_ADB:
|
case MSG_ENABLE_ADB:
|
||||||
setAdbEnabled(msg.arg1 == 1);
|
setAdbEnabled(msg.arg1 == 1);
|
||||||
break;
|
break;
|
||||||
@@ -850,7 +872,7 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
} else if (mSourcePower) {
|
} else if (mSourcePower) {
|
||||||
id = com.android.internal.R.string.usb_supplying_notification_title;
|
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;
|
id = com.android.internal.R.string.usb_charging_notification_title;
|
||||||
}
|
}
|
||||||
if (id != mUsbNotificationId) {
|
if (id != mUsbNotificationId) {
|
||||||
@@ -954,6 +976,7 @@ public class UsbDeviceManager {
|
|||||||
pw.println(" mHostConnected: " + mHostConnected);
|
pw.println(" mHostConnected: " + mHostConnected);
|
||||||
pw.println(" mSourcePower: " + mSourcePower);
|
pw.println(" mSourcePower: " + mSourcePower);
|
||||||
pw.println(" mSinkPower: " + mSinkPower);
|
pw.println(" mSinkPower: " + mSinkPower);
|
||||||
|
pw.println(" mUsbCharging: " + mUsbCharging);
|
||||||
try {
|
try {
|
||||||
pw.println(" Kernel state: "
|
pw.println(" Kernel state: "
|
||||||
+ FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
|
+ FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
|
||||||
|
|||||||
Reference in New Issue
Block a user