Merge "Update UsbService to V1_1 usb hal"
This commit is contained in:
committed by
Android (Google) Code Review
commit
ece721f8cd
@@ -587,6 +587,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
android.hardware.thermal-V1.0-java-constants \
|
||||
android.hardware.tv.input-V1.0-java-constants \
|
||||
android.hardware.usb-V1.0-java-constants \
|
||||
android.hardware.usb-V1.1-java-constants \
|
||||
android.hardware.vibrator-V1.0-java-constants \
|
||||
|
||||
# Loaded with System.loadLibrary by android.view.textclassifier
|
||||
|
||||
@@ -64,6 +64,18 @@ public final class UsbPort implements Parcelable {
|
||||
*/
|
||||
public static final int MODE_DUAL = Constants.PortMode.DRP;
|
||||
|
||||
/**
|
||||
* Mode bit: This USB port can support USB Type-C Audio accessory.
|
||||
*/
|
||||
public static final int MODE_AUDIO_ACCESSORY =
|
||||
android.hardware.usb.V1_1.Constants.PortMode_1_1.AUDIO_ACCESSORY;
|
||||
|
||||
/**
|
||||
* Mode bit: This USB port can support USB Type-C debug accessory.
|
||||
*/
|
||||
public static final int MODE_DEBUG_ACCESSORY =
|
||||
android.hardware.usb.V1_1.Constants.PortMode_1_1.DEBUG_ACCESSORY;
|
||||
|
||||
/**
|
||||
* Power role: This USB port does not have a power role.
|
||||
*/
|
||||
@@ -135,9 +147,9 @@ public final class UsbPort implements Parcelable {
|
||||
* in a bit-field.
|
||||
*
|
||||
* @param powerRole The desired power role: {@link UsbPort#POWER_ROLE_SOURCE}
|
||||
* or {@link UsbPort#POWER_ROLE_SINK}, or 0 if no power role.
|
||||
* @param dataRole The desired data role: {@link UsbPort#DATA_ROLE_HOST}
|
||||
* or {@link UsbPort#DATA_ROLE_DEVICE}, or 0 if no data role.
|
||||
* or {@link UsbPort#POWER_ROLE_SINK}, or 0 if no power role.
|
||||
* @param dataRole The desired data role: {@link UsbPort#DATA_ROLE_HOST}
|
||||
* or {@link UsbPort#DATA_ROLE_DEVICE}, or 0 if no data role.
|
||||
* @hide
|
||||
*/
|
||||
public static int combineRolesAsBit(int powerRole, int dataRole) {
|
||||
@@ -148,18 +160,31 @@ public final class UsbPort implements Parcelable {
|
||||
|
||||
/** @hide */
|
||||
public static String modeToString(int mode) {
|
||||
switch (mode) {
|
||||
case MODE_NONE:
|
||||
return "none";
|
||||
case MODE_DFP:
|
||||
return "dfp";
|
||||
case MODE_UFP:
|
||||
return "ufp";
|
||||
case MODE_DUAL:
|
||||
return "dual";
|
||||
default:
|
||||
return Integer.toString(mode);
|
||||
StringBuilder modeString = new StringBuilder();
|
||||
if (mode == MODE_NONE) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
if ((mode & MODE_DUAL) == MODE_DUAL) {
|
||||
modeString.append("dual, ");
|
||||
} else {
|
||||
if ((mode & MODE_DFP) == MODE_DFP) {
|
||||
modeString.append("dfp, ");
|
||||
} else if ((mode & MODE_UFP) == MODE_UFP) {
|
||||
modeString.append("ufp, ");
|
||||
}
|
||||
}
|
||||
if ((mode & MODE_AUDIO_ACCESSORY) == MODE_AUDIO_ACCESSORY) {
|
||||
modeString.append("audio_acc, ");
|
||||
}
|
||||
if ((mode & MODE_DEBUG_ACCESSORY) == MODE_DEBUG_ACCESSORY) {
|
||||
modeString.append("debug_acc, ");
|
||||
}
|
||||
|
||||
if (modeString.length() == 0) {
|
||||
return Integer.toString(mode);
|
||||
}
|
||||
return modeString.substring(0, modeString.length() - 2);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@@ -240,6 +265,13 @@ public final class UsbPort implements Parcelable {
|
||||
Preconditions.checkArgumentInRange(dataRole, DATA_ROLE_NONE, DATA_ROLE_DEVICE, "dataRole");
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public boolean isModeSupported(int mode) {
|
||||
if ((mSupportedModes & mode) == mode) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UsbPort{id=" + mId + ", supportedModes=" + modeToString(mSupportedModes) + "}";
|
||||
@@ -258,16 +290,16 @@ public final class UsbPort implements Parcelable {
|
||||
|
||||
public static final Parcelable.Creator<UsbPort> CREATOR =
|
||||
new Parcelable.Creator<UsbPort>() {
|
||||
@Override
|
||||
public UsbPort createFromParcel(Parcel in) {
|
||||
String id = in.readString();
|
||||
int supportedModes = in.readInt();
|
||||
return new UsbPort(id, supportedModes);
|
||||
}
|
||||
@Override
|
||||
public UsbPort createFromParcel(Parcel in) {
|
||||
String id = in.readString();
|
||||
int supportedModes = in.readInt();
|
||||
return new UsbPort(id, supportedModes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsbPort[] newArray(int size) {
|
||||
return new UsbPort[size];
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public UsbPort[] newArray(int size) {
|
||||
return new UsbPort[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ LOCAL_SRC_FILES += \
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := services.core
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := android.hardware.usb-V1.0-java-static \
|
||||
android.hardware.usb-V1.1-java-static \
|
||||
android.hidl.manager-V1.0-java-static
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
@@ -22,11 +22,12 @@ import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.hardware.usb.V1_0.IUsb;
|
||||
import android.hardware.usb.V1_0.IUsbCallback;
|
||||
import android.hardware.usb.V1_0.PortRole;
|
||||
import android.hardware.usb.V1_0.PortRoleType;
|
||||
import android.hardware.usb.V1_0.PortStatus;
|
||||
import android.hardware.usb.V1_0.Status;
|
||||
import android.hardware.usb.V1_1.IUsbCallback;
|
||||
import android.hardware.usb.V1_1.PortStatus_1_1;
|
||||
import android.hidl.manager.V1_0.IServiceManager;
|
||||
import android.hidl.manager.V1_0.IServiceNotification;
|
||||
import android.os.Bundle;
|
||||
@@ -454,6 +455,39 @@ public class UsbPortManager {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public void notifyPortStatusChange_1_1(ArrayList<PortStatus_1_1> currentPortStatus,
|
||||
int retval) {
|
||||
if (!portManager.mSystemReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (retval != Status.SUCCESS) {
|
||||
logAndPrint(Log.ERROR, pw, "port status enquiry failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<RawPortInfo> newPortInfo = new ArrayList<RawPortInfo>();
|
||||
|
||||
for (PortStatus_1_1 current : currentPortStatus) {
|
||||
RawPortInfo temp = new RawPortInfo(current.status.portName,
|
||||
current.supportedModes, current.currentMode,
|
||||
current.status.canChangeMode, current.status.currentPowerRole,
|
||||
current.status.canChangePowerRole,
|
||||
current.status.currentDataRole, current.status.canChangeDataRole);
|
||||
newPortInfo.add(temp);
|
||||
logAndPrint(Log.INFO, pw, "ClientCallback: " + current.status.portName);
|
||||
}
|
||||
|
||||
Message message = portManager.mHandler.obtainMessage();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList(PORT_INFO, newPortInfo);
|
||||
message.what = MSG_UPDATE_PORTS;
|
||||
message.setData(bundle);
|
||||
portManager.mHandler.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
|
||||
public void notifyRoleSwitchStatus(String portName, PortRole role, int retval) {
|
||||
if (retval == Status.SUCCESS) {
|
||||
logAndPrint(Log.INFO, pw, portName + " role switch successful");
|
||||
@@ -568,7 +602,7 @@ public class UsbPortManager {
|
||||
IndentingPrintWriter pw) {
|
||||
// Only allow mode switch capability for dual role ports.
|
||||
// Validate that the current mode matches the supported modes we expect.
|
||||
if (supportedModes != UsbPort.MODE_DUAL) {
|
||||
if ((supportedModes & UsbPort.MODE_DUAL) != UsbPort.MODE_DUAL) {
|
||||
canChangeMode = false;
|
||||
if (currentMode != 0 && currentMode != supportedModes) {
|
||||
logAndPrint(Log.WARN, pw, "Ignoring inconsistent current mode from USB "
|
||||
|
||||
Reference in New Issue
Block a user