Gustav Sennton | c83e3fa | 2016-02-18 12:19:13 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.server.webkit; |
| 17 | |
| 18 | import android.os.RemoteException; |
| 19 | import android.os.ShellCommand; |
| 20 | import android.webkit.IWebViewUpdateService; |
| 21 | |
| 22 | import java.io.PrintWriter; |
| 23 | |
| 24 | class 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 Sennton | c83e3fa | 2016-02-18 12:19:13 +0000 | [diff] [blame] | 39 | switch(cmd) { |
| 40 | case "enable-redundant-packages": |
| 41 | return enableFallbackLogic(false); |
| 42 | case "disable-redundant-packages": |
| 43 | return enableFallbackLogic(true); |
Gustav Sennton | ab3b6b1 | 2016-03-16 17:38:42 +0000 | [diff] [blame] | 44 | case "set-webview-implementation": |
| 45 | return setWebViewImplementation(); |
Gustav Sennton | b265016 | 2017-04-07 14:41:38 +0100 | [diff] [blame] | 46 | case "enable-multiprocess": |
| 47 | return enableMultiProcess(true); |
| 48 | case "disable-multiprocess": |
| 49 | return enableMultiProcess(false); |
Gustav Sennton | c83e3fa | 2016-02-18 12:19:13 +0000 | [diff] [blame] | 50 | 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 Sennton | ab3b6b1 | 2016-03-16 17:38:42 +0000 | [diff] [blame] | 66 | 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 Sennton | b265016 | 2017-04-07 14:41:38 +0100 | [diff] [blame] | 81 | 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 Sennton | c83e3fa | 2016-02-18 12:19:13 +0000 | [diff] [blame] | 88 | @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 Sennton | ab3b6b1 | 2016-03-16 17:38:42 +0000 | [diff] [blame] | 102 | pw.println(" set-webview-implementation PACKAGE"); |
| 103 | pw.println(" Set the WebView implementation to the specified package."); |
Gustav Sennton | b265016 | 2017-04-07 14:41:38 +0100 | [diff] [blame] | 104 | 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 Sennton | c83e3fa | 2016-02-18 12:19:13 +0000 | [diff] [blame] | 108 | pw.println(); |
| 109 | } |
| 110 | } |