Merge "Add (corrected) usb power sink handling" into nyc-mr1-dev

This commit is contained in:
Philip P. Moltmann
2016-08-04 20:08:32 +00:00
committed by Android (Google) Code Review

View File

@@ -49,6 +49,7 @@ import android.util.Pair;
import android.util.Slog; import android.util.Slog;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.server.FgThread; import com.android.server.FgThread;
@@ -320,6 +321,7 @@ public class UsbDeviceManager {
private boolean mConnected; private boolean mConnected;
private boolean mHostConnected; private boolean mHostConnected;
private boolean mSourcePower; private boolean mSourcePower;
private boolean mSinkPower;
private boolean mConfigured; private boolean mConfigured;
private boolean mUsbDataUnlocked; private boolean mUsbDataUnlocked;
private String mCurrentFunctions; private String mCurrentFunctions;
@@ -401,7 +403,18 @@ public class UsbDeviceManager {
public void updateHostState(UsbPort port, UsbPortStatus status) { public void updateHostState(UsbPort port, UsbPortStatus status) {
boolean hostConnected = status.getCurrentDataRole() == UsbPort.DATA_ROLE_HOST; boolean hostConnected = status.getCurrentDataRole() == UsbPort.DATA_ROLE_HOST;
boolean sourcePower = status.getCurrentPowerRole() == UsbPort.POWER_ROLE_SOURCE; boolean sourcePower = status.getCurrentPowerRole() == UsbPort.POWER_ROLE_SOURCE;
obtainMessage(MSG_UPDATE_HOST_STATE, hostConnected ? 1 :0, sourcePower ? 1 :0).sendToTarget(); boolean sinkPower = status.getCurrentPowerRole() == UsbPort.POWER_ROLE_SINK;
if (DEBUG) {
Slog.i(TAG, "updateHostState " + port + " status=" + status);
}
SomeArgs args = SomeArgs.obtain();
args.argi1 = hostConnected ? 1 :0;
args.argi2 = sourcePower ? 1 :0;
args.argi3 = sinkPower ? 1 :0;
obtainMessage(MSG_UPDATE_HOST_STATE, args).sendToTarget();
} }
private boolean waitForState(String state) { private boolean waitForState(String state) {
@@ -718,8 +731,11 @@ public class UsbDeviceManager {
} }
break; break;
case MSG_UPDATE_HOST_STATE: case MSG_UPDATE_HOST_STATE:
mHostConnected = (msg.arg1 == 1); SomeArgs args = (SomeArgs) msg.obj;
mSourcePower = (msg.arg2 == 1); mHostConnected = (args.argi1 == 1);
mSourcePower = (args.argi2 == 1);
mSinkPower = (args.argi3 == 1);
args.recycle();
updateUsbNotification(); updateUsbNotification();
if (mBootCompleted) { if (mBootCompleted) {
updateUsbStateBroadcastIfNeeded(); updateUsbStateBroadcastIfNeeded();
@@ -809,6 +825,8 @@ 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) {
id = com.android.internal.R.string.usb_charging_notification_title;
} }
if (id != mUsbNotificationId) { if (id != mUsbNotificationId) {
// clear notification if title needs changing // clear notification if title needs changing
@@ -908,6 +926,9 @@ public class UsbDeviceManager {
pw.println(" mConfigured: " + mConfigured); pw.println(" mConfigured: " + mConfigured);
pw.println(" mUsbDataUnlocked: " + mUsbDataUnlocked); pw.println(" mUsbDataUnlocked: " + mUsbDataUnlocked);
pw.println(" mCurrentAccessory: " + mCurrentAccessory); pw.println(" mCurrentAccessory: " + mCurrentAccessory);
pw.println(" mHostConnected: " + mHostConnected);
pw.println(" mSourcePower: " + mSourcePower);
pw.println(" mSinkPower: " + mSinkPower);
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());