Merge "Add new shell commands for DeviceStateChanged CTS test" into sc-v2-dev am: 4c80c3bda3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15325771

Change-Id: Iba7ca3ec0e0ada05dd1914d0e4df7d06a16afcfe
This commit is contained in:
András Klöczl
2021-07-29 18:34:26 +00:00
committed by Automerger Merge Worker

View File

@@ -27,7 +27,9 @@ import android.os.Binder;
import android.os.ShellCommand; import android.os.ShellCommand;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* ShellCommands for {@link DeviceStateManagerService}. * ShellCommands for {@link DeviceStateManagerService}.
@@ -56,14 +58,18 @@ public class DeviceStateManagerShellCommand extends ShellCommand {
switch (cmd) { switch (cmd) {
case "state": case "state":
return runState(pw); return runState(pw);
case "print-state":
return runPrintState(pw);
case "print-states": case "print-states":
return runPrintStates(pw); return runPrintStates(pw);
case "print-states-simple":
return runPrintStatesSimple(pw);
default: default:
return handleDefaultCommands(cmd); return handleDefaultCommands(cmd);
} }
} }
private void printState(PrintWriter pw) { private void printAllStates(PrintWriter pw) {
Optional<DeviceState> committedState = mService.getCommittedState(); Optional<DeviceState> committedState = mService.getCommittedState();
Optional<DeviceState> baseState = mService.getBaseState(); Optional<DeviceState> baseState = mService.getBaseState();
Optional<DeviceState> overrideState = mService.getOverrideState(); Optional<DeviceState> overrideState = mService.getOverrideState();
@@ -79,7 +85,8 @@ public class DeviceStateManagerShellCommand extends ShellCommand {
private int runState(PrintWriter pw) { private int runState(PrintWriter pw) {
final String nextArg = getNextArg(); final String nextArg = getNextArg();
if (nextArg == null) { if (nextArg == null) {
printState(pw); printAllStates(pw);
return 0;
} }
final Context context = mService.getContext(); final Context context = mService.getContext();
@@ -123,6 +130,16 @@ public class DeviceStateManagerShellCommand extends ShellCommand {
return 0; return 0;
} }
private int runPrintState(PrintWriter pw) {
Optional<DeviceState> deviceState = mService.getCommittedState();
if (deviceState.isPresent()) {
pw.println(deviceState.get().getIdentifier());
return 0;
}
getErrPrintWriter().println("Error: device state not available.");
return 1;
}
private int runPrintStates(PrintWriter pw) { private int runPrintStates(PrintWriter pw) {
DeviceState[] states = mService.getSupportedStates(); DeviceState[] states = mService.getSupportedStates();
pw.print("Supported states: [\n"); pw.print("Supported states: [\n");
@@ -133,6 +150,14 @@ public class DeviceStateManagerShellCommand extends ShellCommand {
return 0; return 0;
} }
private int runPrintStatesSimple(PrintWriter pw) {
pw.print(Arrays.stream(mService.getSupportedStates())
.map(DeviceState::getIdentifier)
.map(Object::toString)
.collect(Collectors.joining(",")));
return 0;
}
@Override @Override
public void onHelp() { public void onHelp() {
PrintWriter pw = getOutPrintWriter(); PrintWriter pw = getOutPrintWriter();
@@ -141,8 +166,12 @@ public class DeviceStateManagerShellCommand extends ShellCommand {
pw.println(" Print this help text."); pw.println(" Print this help text.");
pw.println(" state [reset|OVERRIDE_DEVICE_STATE]"); pw.println(" state [reset|OVERRIDE_DEVICE_STATE]");
pw.println(" Return or override device state."); pw.println(" Return or override device state.");
pw.println(" print-state");
pw.println(" Return the current device state.");
pw.println(" print-states"); pw.println(" print-states");
pw.println(" Return list of currently supported device states."); pw.println(" Return list of currently supported device states.");
pw.println(" print-states-simple");
pw.println(" Return the currently supported device states in comma separated format.");
} }
private static String toString(@NonNull Optional<DeviceState> state) { private static String toString(@NonNull Optional<DeviceState> state) {