Usb frameworks simulate compliance warnings

Adds ability to set Compliance Warning support for simulated ports
within UsbService, and fixes mislabeled constants.

Test: manual simulation testing verifies proper behavior
Bug: 261480822
Change-Id: Ic4c445b068719497b0c08d6735ca6cfc7553a287
This commit is contained in:
RD Babiera
2022-12-19 01:31:09 +00:00
parent f6f0b58c20
commit 4a3a5e200b
2 changed files with 48 additions and 11 deletions

View File

@@ -682,7 +682,10 @@ public class UsbPortManager {
mHandler.sendMessage(message);
}
public void addSimulatedPort(String portId, int supportedModes, IndentingPrintWriter pw) {
public void addSimulatedPort(String portId, int supportedModes,
boolean supportsComplianceWarnings,
IndentingPrintWriter pw) {
synchronized (mLock) {
if (mSimulatedPorts.containsKey(portId)) {
pw.println("Port with same name already exists. Please remove it first.");
@@ -692,7 +695,25 @@ public class UsbPortManager {
pw.println("Adding simulated port: portId=" + portId
+ ", supportedModes=" + UsbPort.modeToString(supportedModes));
mSimulatedPorts.put(portId,
new RawPortInfo(portId, supportedModes));
new RawPortInfo(
portId,
supportedModes,
UsbPortStatus.CONTAMINANT_PROTECTION_NONE,
UsbPortStatus.MODE_NONE,
false,
UsbPortStatus.POWER_ROLE_NONE,
false,
UsbPortStatus.DATA_ROLE_NONE,
false,
false,
UsbPortStatus.CONTAMINANT_PROTECTION_NONE,
false,
UsbPortStatus.CONTAMINANT_DETECTION_NOT_SUPPORTED,
UsbPortStatus.DATA_STATUS_UNKNOWN,
false,
UsbPortStatus.POWER_BRICK_STATUS_UNKNOWN,
supportsComplianceWarnings,
new int[] {}));
updatePortsLocked(pw, null);
}
}

View File

@@ -987,9 +987,12 @@ public class UsbService extends IUsbManager.Stub {
mPortManager.dump(new DualDumpOutputStream(new IndentingPrintWriter(pw, " ")),
"", 0);
}
} else if ("add-port".equals(args[0]) && args.length == 3) {
} else if ("add-port".equals(args[0]) && args.length >= 3) {
final String portId = args[1];
final int supportedModes;
int i;
boolean supportsComplianceWarnings = false;
switch (args[2]) {
case "ufp":
supportedModes = MODE_UFP;
@@ -1007,8 +1010,19 @@ public class UsbService extends IUsbManager.Stub {
pw.println("Invalid mode: " + args[2]);
return;
}
for (i=3; i<args.length; i++) {
switch (args[i]) {
case "--compliance-warnings":
supportsComplianceWarnings = true;
continue;
default:
pw.println("Invalid Identifier: " + args[i]);
}
}
if (mPortManager != null) {
mPortManager.addSimulatedPort(portId, supportedModes, pw);
mPortManager.addSimulatedPort(portId, supportedModes,
supportsComplianceWarnings,
pw);
pw.println();
mPortManager.dump(new DualDumpOutputStream(new IndentingPrintWriter(pw, " ")),
"", 0);
@@ -1121,7 +1135,9 @@ public class UsbService extends IUsbManager.Stub {
pw.println("Dump current USB state or issue command:");
pw.println(" ports");
pw.println(" set-port-roles <id> <source|sink|no-power> <host|device|no-data>");
pw.println(" add-port <id> <ufp|dfp|dual|none>");
pw.println(" add-port <id> <ufp|dfp|dual|none> <optional args>");
pw.println(" <optional args> include:");
pw.println(" --compliance-warnings: enables compliance warnings on port");
pw.println(" connect-port <id> <ufp|dfp><?> <source|sink><?> <host|device><?>");
pw.println(" (add ? suffix if mode, power role, or data role can be changed)");
pw.println(" disconnect-port <id>");
@@ -1132,7 +1148,7 @@ public class UsbService extends IUsbManager.Stub {
pw.println(" dumpsys usb set-port-roles \"default\" source device");
pw.println();
pw.println("Example USB type C port simulation with full capabilities:");
pw.println(" dumpsys usb add-port \"matrix\" dual");
pw.println(" dumpsys usb add-port \"matrix\" dual --compliance-warnings");
pw.println(" dumpsys usb connect-port \"matrix\" ufp? sink? device?");
pw.println(" dumpsys usb ports");
pw.println(" dumpsys usb disconnect-port \"matrix\"");
@@ -1160,15 +1176,15 @@ public class UsbService extends IUsbManager.Stub {
pw.println(" dumpsys usb set-contaminant-status \"matrix\" false");
pw.println();
pw.println("Example simulate compliance warnings:");
pw.println(" dumpsys usb add-port \"matrix\" dual");
pw.println(" dumpsys usb add-port \"matrix\" dual --compliance-warnings");
pw.println(" dumpsys usb set-compliance-reasons \"matrix\" <reason-list>");
pw.println(" dumpsys usb clear-compliance-reasons \"matrix\"");
pw.println("<reason-list> is expected to be formatted as \"1, ..., 4\"");
pw.println("with reasons that need to be simulated.");
pw.println(" 1: debug accessory");
pw.println(" 2: bc12");
pw.println(" 3: missing rp");
pw.println(" 4: type c");
pw.println(" 1: other");
pw.println(" 2: debug accessory");
pw.println(" 3: bc12");
pw.println(" 4: missing rp");
pw.println();
pw.println("Example USB device descriptors:");
pw.println(" dumpsys usb dump-descriptors -dump-short");