| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.compatui; |
| 18 |
|
| 19 |
import com.android.wm.shell.dagger.WMSingleton; |
| 20 |
import com.android.wm.shell.sysui.ShellCommandHandler; |
| 21 |
|
| 22 |
import java.io.PrintWriter; |
| 23 |
import java.util.function.Consumer; |
| 24 |
|
| 25 |
import javax.inject.Inject; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@WMSingleton |
| 34 |
public final class CompatUIShellCommandHandler implements |
| 35 |
ShellCommandHandler.ShellCommandActionHandler { |
| 36 |
|
| 37 |
private final CompatUIConfiguration mCompatUIConfiguration; |
| 38 |
private final ShellCommandHandler mShellCommandHandler; |
| 39 |
|
| 40 |
@Inject |
| 41 |
public CompatUIShellCommandHandler(ShellCommandHandler shellCommandHandler, |
| 42 |
CompatUIConfiguration compatUIConfiguration) { |
| 43 |
mShellCommandHandler = shellCommandHandler; |
| 44 |
mCompatUIConfiguration = compatUIConfiguration; |
| 45 |
} |
| 46 |
|
| 47 |
void onInit() { |
| 48 |
mShellCommandHandler.addCommandCallback("compatui", this, this); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public boolean onShellCommand(String[] args, PrintWriter pw) { |
| 53 |
if (args.length != 2) { |
| 54 |
pw.println("Invalid command: " + args[0]); |
| 55 |
return false; |
| 56 |
} |
| 57 |
switch (args[0]) { |
| 58 |
case "restartDialogEnabled": |
| 59 |
return invokeOrError(args[1], pw, |
| 60 |
mCompatUIConfiguration::setIsRestartDialogOverrideEnabled); |
| 61 |
case "reachabilityEducationEnabled": |
| 62 |
return invokeOrError(args[1], pw, |
| 63 |
mCompatUIConfiguration::setIsReachabilityEducationOverrideEnabled); |
| 64 |
default: |
| 65 |
pw.println("Invalid command: " + args[0]); |
| 66 |
return false; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void printShellCommandHelp(PrintWriter pw, String prefix) { |
| 72 |
pw.println(prefix + "restartDialogEnabled [0|false|1|true]"); |
| 73 |
pw.println(prefix + " Enable/Disable the restart education dialog for Size Compat Mode"); |
| 74 |
pw.println(prefix + "reachabilityEducationEnabled [0|false|1|true]"); |
| 75 |
pw.println(prefix |
| 76 |
+ " Enable/Disable the restart education dialog for letterbox reachability"); |
| 77 |
pw.println(prefix + " Disable the restart education dialog for letterbox reachability"); |
| 78 |
} |
| 79 |
|
| 80 |
private static boolean invokeOrError(String input, PrintWriter pw, |
| 81 |
Consumer<Boolean> setter) { |
| 82 |
Boolean asBoolean = strToBoolean(input); |
| 83 |
if (asBoolean == null) { |
| 84 |
pw.println("Error: expected true, 1, false, 0."); |
| 85 |
return false; |
| 86 |
} |
| 87 |
setter.accept(asBoolean); |
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
private static Boolean strToBoolean(String str) { |
| 93 |
switch(str) { |
| 94 |
case "1": |
| 95 |
case "true": |
| 96 |
return true; |
| 97 |
case "0": |
| 98 |
case "false": |
| 99 |
return false; |
| 100 |
} |
| 101 |
return null; |
| 102 |
} |
| 103 |
} |