blob: 39e28c74e0a5e5027c3fbee8748fba2f80dcc483 [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();
69 String newPackage = mInterface.changeProviderAndSetting(shellChosenPackage);
70 if (shellChosenPackage.equals(newPackage)) {
71 pw.println("Success");
72 return 0;
73 } else {
74 pw.println(String.format(
75 "Failed to switch to %s, the WebView implementation is now provided by %s.",
76 shellChosenPackage, newPackage));
77 return 1;
78 }
79 }
80
Gustav Senntonb2650162017-04-07 14:41:38 +010081 private int enableMultiProcess(boolean enable) throws RemoteException {
82 final PrintWriter pw = getOutPrintWriter();
83 mInterface.enableMultiProcess(enable);
84 pw.println("Success");
85 return 0;
86 }
87
Gustav Senntonc83e3fa2016-02-18 12:19:13 +000088 @Override
89 public void onHelp() {
90 PrintWriter pw = getOutPrintWriter();
91 pw.println("WebView updater commands:");
92 pw.println(" help");
93 pw.println(" Print this help text.");
94 pw.println("");
95 pw.println(" enable-redundant-packages");
96 pw.println(" Allow a fallback package to be installed and enabled even when a");
97 pw.println(" more-preferred package is available. This command is useful when testing");
98 pw.println(" fallback packages.");
99 pw.println(" disable-redundant-packages");
100 pw.println(" Disallow installing and enabling fallback packages when a more-preferred");
101 pw.println(" package is available.");
Gustav Senntonab3b6b12016-03-16 17:38:42 +0000102 pw.println(" set-webview-implementation PACKAGE");
103 pw.println(" Set the WebView implementation to the specified package.");
Gustav Senntonb2650162017-04-07 14:41:38 +0100104 pw.println(" enable-multiprocess");
105 pw.println(" Enable multi-process mode for WebView");
106 pw.println(" disable-multiprocess");
107 pw.println(" Disable multi-process mode for WebView");
Gustav Senntonc83e3fa2016-02-18 12:19:13 +0000108 pw.println();
109 }
110}