Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIShellCommandHandler.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * Handles the shell commands for the CompatUX.
29 *
30 * <p> Use with {@code adb shell dumpsys activity service SystemUIService WMShell compatui
31 * &lt;command&gt;}.
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 // Converts a String to boolean if possible or it returns null otherwise
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 }