blob: 3199ed47503ea16177a2703f733f35d38ee048c2 [file] [log] [blame]
Gustav Senntonc83e3fa2016-02-18 12:19:13 +00001/*
2 * Copyright (C) 2016 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 */
16package com.android.server.webkit;
17
18import android.os.RemoteException;
19import android.os.ShellCommand;
20import android.webkit.IWebViewUpdateService;
21
22import java.io.PrintWriter;
23
24class WebViewUpdateServiceShellCommand extends ShellCommand {
25 final IWebViewUpdateService mInterface;
26
27 WebViewUpdateServiceShellCommand(IWebViewUpdateService service) {
28 mInterface = service;
29 }
30
31 @Override
32 public int onCommand(String cmd) {
33 if (cmd == null) {
34 return handleDefaultCommands(cmd);
35 }
36
37 final PrintWriter pw = getOutPrintWriter();
38 try {
Gustav Senntonc83e3fa2016-02-18 12:19:13 +000039 switch(cmd) {
40 case "enable-redundant-packages":
41 return enableFallbackLogic(false);
42 case "disable-redundant-packages":
43 return enableFallbackLogic(true);
Gustav Senntonab3b6b12016-03-16 17:38:42 +000044 case "set-webview-implementation":
45 return setWebViewImplementation();
Gustav Senntonb2650162017-04-07 14:41:38 +010046 case "enable-multiprocess":
47 return enableMultiProcess(true);
48 case "disable-multiprocess":
49 return enableMultiProcess(false);
Gustav Senntonc83e3fa2016-02-18 12:19:13 +000050 default:
51 return handleDefaultCommands(cmd);
52 }
53 } catch (RemoteException e) {
54 pw.println("Remote exception: " + e);
55 }
56 return -1;
57 }
58
59 private int enableFallbackLogic(boolean enable) throws RemoteException {
60 final PrintWriter pw = getOutPrintWriter();
61 mInterface.enableFallbackLogic(enable);
62 pw.println("Success");
63 return 0;
64 }
65
Gustav Senntonab3b6b12016-03-16 17:38:42 +000066 private int setWebViewImplementation() throws RemoteException {
67 final PrintWriter pw = getOutPrintWriter();
68 String shellChosenPackage = getNextArg();
Laís Minchillo2b992292018-08-03 17:00:25 +010069 if (shellChosenPackage == null) {
70 pw.println("Failed to switch, no PACKAGE provided.");
71 pw.println("");
72 helpSetWebViewImplementation();
73 return 1;
74 }
Gustav Senntonab3b6b12016-03-16 17:38:42 +000075 String newPackage = mInterface.changeProviderAndSetting(shellChosenPackage);
76 if (shellChosenPackage.equals(newPackage)) {
77 pw.println("Success");
78 return 0;
79 } else {
80 pw.println(String.format(
81 "Failed to switch to %s, the WebView implementation is now provided by %s.",
82 shellChosenPackage, newPackage));
83 return 1;
84 }
85 }
86
Gustav Senntonb2650162017-04-07 14:41:38 +010087 private int enableMultiProcess(boolean enable) throws RemoteException {
88 final PrintWriter pw = getOutPrintWriter();
89 mInterface.enableMultiProcess(enable);
90 pw.println("Success");
91 return 0;
92 }
93
Laís Minchillo2b992292018-08-03 17:00:25 +010094 public void helpSetWebViewImplementation() {
95 PrintWriter pw = getOutPrintWriter();
96 pw.println(" set-webview-implementation PACKAGE");
97 pw.println(" Set the WebView implementation to the specified package.");
98 }
99
Gustav Senntonc83e3fa2016-02-18 12:19:13 +0000100 @Override
101 public void onHelp() {
102 PrintWriter pw = getOutPrintWriter();
103 pw.println("WebView updater commands:");
104 pw.println(" help");
105 pw.println(" Print this help text.");
106 pw.println("");
107 pw.println(" enable-redundant-packages");
108 pw.println(" Allow a fallback package to be installed and enabled even when a");
109 pw.println(" more-preferred package is available. This command is useful when testing");
110 pw.println(" fallback packages.");
111 pw.println(" disable-redundant-packages");
112 pw.println(" Disallow installing and enabling fallback packages when a more-preferred");
113 pw.println(" package is available.");
Laís Minchillo2b992292018-08-03 17:00:25 +0100114 helpSetWebViewImplementation();
Gustav Senntonb2650162017-04-07 14:41:38 +0100115 pw.println(" enable-multiprocess");
116 pw.println(" Enable multi-process mode for WebView");
117 pw.println(" disable-multiprocess");
118 pw.println(" Disable multi-process mode for WebView");
Gustav Senntonc83e3fa2016-02-18 12:19:13 +0000119 pw.println();
120 }
121}