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 { |
| 39 | // TODO(gsennton) add command for changing WebView provider |
| 40 | switch(cmd) { |
| 41 | case "enable-redundant-packages": |
| 42 | return enableFallbackLogic(false); |
| 43 | case "disable-redundant-packages": |
| 44 | return enableFallbackLogic(true); |
| 45 | default: |
| 46 | return handleDefaultCommands(cmd); |
| 47 | } |
| 48 | } catch (RemoteException e) { |
| 49 | pw.println("Remote exception: " + e); |
| 50 | } |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | private int enableFallbackLogic(boolean enable) throws RemoteException { |
| 55 | final PrintWriter pw = getOutPrintWriter(); |
| 56 | mInterface.enableFallbackLogic(enable); |
| 57 | pw.println("Success"); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void onHelp() { |
| 63 | PrintWriter pw = getOutPrintWriter(); |
| 64 | pw.println("WebView updater commands:"); |
| 65 | pw.println(" help"); |
| 66 | pw.println(" Print this help text."); |
| 67 | pw.println(""); |
| 68 | pw.println(" enable-redundant-packages"); |
| 69 | pw.println(" Allow a fallback package to be installed and enabled even when a"); |
| 70 | pw.println(" more-preferred package is available. This command is useful when testing"); |
| 71 | pw.println(" fallback packages."); |
| 72 | pw.println(" disable-redundant-packages"); |
| 73 | pw.println(" Disallow installing and enabling fallback packages when a more-preferred"); |
| 74 | pw.println(" package is available."); |
| 75 | pw.println(); |
| 76 | } |
| 77 | } |