OSDN Git Service

Dump the entire state of WebViewUpdateService on demand.
authorGustav Sennton <gsennton@google.com>
Fri, 21 Oct 2016 12:40:10 +0000 (13:40 +0100)
committerGustav Sennton <gsennton@google.com>
Mon, 14 Nov 2016 20:50:19 +0000 (20:50 +0000)
It is especially useful to know which is the current WebView package but
we also add some other state to be able to debug WebViewUpdateService.

Bug: 32307028
Test: Run 'adb shell dumpsys webviewupdate' and inspect printed
contents.
Test: Take bug report and inspect the 'webviewupdate' dump section.
Change-Id: I79c2cda87ea7633a915eae5de3c3015b18ed6d7c

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

index 6d97796..0a7454f 100644 (file)
@@ -36,6 +36,7 @@ import android.webkit.WebViewProviderResponse;
 import com.android.server.SystemService;
 
 import java.io.FileDescriptor;
+import java.io.PrintWriter;
 import java.util.Arrays;
 
 /**
@@ -259,5 +260,18 @@ public class WebViewUpdateService extends SystemService {
                 Binder.restoreCallingIdentity(callingId);
             }
         }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+
+                pw.println("Permission Denial: can't dump webviewupdate service from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            WebViewUpdateService.this.mImpl.dumpState(pw);
+        }
     }
 }
index 453e745..1a77c68 100644 (file)
@@ -30,6 +30,7 @@ import android.webkit.WebViewFactory;
 import android.webkit.WebViewProviderInfo;
 import android.webkit.WebViewProviderResponse;
 
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -673,6 +674,27 @@ public class WebViewUpdateServiceImpl {
             mMinimumVersionCode = minimumVersionCode;
             return mMinimumVersionCode;
         }
+
+        public void dumpState(PrintWriter pw) {
+            synchronized (mLock) {
+                if (mCurrentWebViewPackage == null) {
+                    pw.println("  Current WebView package is null");
+                } else {
+                    pw.println(String.format("  Current WebView package (name, version): (%s, %s)",
+                            mCurrentWebViewPackage.packageName,
+                            mCurrentWebViewPackage.versionName));
+                }
+                pw.println(String.format("  Minimum WebView version code: %d",
+                      mMinimumVersionCode));
+                pw.println(String.format("  Number of relros started: %d",
+                        mNumRelroCreationsStarted));
+                pw.println(String.format("  Number of relros finished: %d",
+                            mNumRelroCreationsFinished));
+                pw.println(String.format("  WebView package dirty: %b", mWebViewPackageDirty));
+                pw.println(String.format("  Any WebView package installed: %b",
+                        mAnyWebViewInstalled));
+            }
+        }
     }
 
     private static boolean providerHasValidSignature(WebViewProviderInfo provider,
@@ -741,4 +763,14 @@ public class WebViewUpdateServiceImpl {
             mSystemInterface.setMultiProcessEnabledFromContext(mContext);
         }
     }
+
+    /**
+     * Dump the state of this Service.
+     */
+    void dumpState(PrintWriter pw) {
+        pw.println("Current WebView Update Service state");
+        pw.println(String.format("  Fallback logic enabled: %b",
+                mSystemInterface.isFallbackLogicEnabled()));
+        mWebViewUpdater.dumpState(pw);
+    }
 }