OSDN Git Service

Provide command to change WebView implementation.
authorGustav Sennton <gsennton@google.com>
Wed, 16 Mar 2016 17:38:42 +0000 (17:38 +0000)
committerGustav Sennton <gsennton@google.com>
Mon, 4 Apr 2016 20:46:50 +0000 (20:46 +0000)
Add a shell command for switching webview implementation so that this
can be done automatically - without interacting with a Dev Setting.

Bug: 27540566
Change-Id: I3c4acaa1b8f4ba24c637ef8a1d48cc7b2616bd91

services/core/java/com/android/server/webkit/WebViewUpdateService.java
services/core/java/com/android/server/webkit/WebViewUpdateServiceShellCommand.java

index a54c542..4669676 100644 (file)
@@ -613,7 +613,12 @@ public class WebViewUpdateService extends SystemService {
                 throw new SecurityException(msg);
             }
 
-            return WebViewUpdateService.this.changeProviderAndSetting(newProvider);
+            long callingId = Binder.clearCallingIdentity();
+            try {
+                return WebViewUpdateService.this.changeProviderAndSetting(newProvider);
+            } finally {
+                Binder.restoreCallingIdentity(callingId);
+            }
         }
 
         @Override // Binder call
index a9461e8..68448f3 100644 (file)
@@ -36,12 +36,13 @@ class WebViewUpdateServiceShellCommand extends ShellCommand {
 
         final PrintWriter pw = getOutPrintWriter();
         try {
-            // TODO(gsennton) add command for changing WebView provider
             switch(cmd) {
                 case "enable-redundant-packages":
                     return enableFallbackLogic(false);
                 case "disable-redundant-packages":
                     return enableFallbackLogic(true);
+                case "set-webview-implementation":
+                    return setWebViewImplementation();
                 default:
                     return handleDefaultCommands(cmd);
             }
@@ -58,6 +59,21 @@ class WebViewUpdateServiceShellCommand extends ShellCommand {
         return 0;
     }
 
+    private int setWebViewImplementation() throws RemoteException {
+        final PrintWriter pw = getOutPrintWriter();
+        String shellChosenPackage = getNextArg();
+        String newPackage = mInterface.changeProviderAndSetting(shellChosenPackage);
+        if (shellChosenPackage.equals(newPackage)) {
+            pw.println("Success");
+            return 0;
+        } else {
+            pw.println(String.format(
+                        "Failed to switch to %s, the WebView implementation is now provided by %s.",
+                        shellChosenPackage, newPackage));
+            return 1;
+        }
+    }
+
     @Override
     public void onHelp() {
         PrintWriter pw = getOutPrintWriter();
@@ -72,6 +88,8 @@ class WebViewUpdateServiceShellCommand extends ShellCommand {
         pw.println("  disable-redundant-packages");
         pw.println("    Disallow installing and enabling fallback packages when a more-preferred");
         pw.println("    package is available.");
+        pw.println("  set-webview-implementation PACKAGE");
+        pw.println("    Set the WebView implementation to the specified package.");
         pw.println();
     }
 }