Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e76e81a2 authored by Primiano Tucci's avatar Primiano Tucci Committed by Ben Murdoch
Browse files

Cherry pick Cleanup debug messages in WebViewFactory and WebViewUpdateService DO NOT MERGE

This is just a cleanup CL which fixes:
- Some erroneous debug messages about the relro creator process.
- The condition checked in WebViewUpdateService, to prevent the
  WebView to be used from the SystemServer (it now looks at the
  process id, previously it was erroneously looking at the uid).
- Adds a 5s. timeout to the waitForRelroCreationCompleted.

Original BUG:16403706

Original Change-Id: I43a953949050d7df5fe334cfa7257315ee6db071

Bug: 16723226
Change-Id: I2f40be3622b8e6c68b2b52cae7f4d3a95e148cbf
parent 994e219d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ public final class WebViewFactory {
            int pid = LocalServices.getService(ActivityManagerInternal.class).startIsolatedProcess(
                    RelroFileCreator.class.getName(), nativeLibraryPaths, "WebViewLoader-" + abi, abi,
                    Process.SHARED_RELRO_UID, crashHandler);
            if (pid <= 0) throw new Exception("Failed to start the isolated process");
            if (pid <= 0) throw new Exception("Failed to start the relro file creator process");
        } catch (Throwable t) {
            // Log and discard errors as we must not crash the system server.
            Log.e(LOGTAG, "error starting relro file creator for abi " + abi, t);
@@ -307,7 +307,7 @@ public final class WebViewFactory {
                                               args[1] /* path64 */,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_64);
                if (DEBUG) Log.v(LOGTAG, "created relro file");
                if (result && DEBUG) Log.v(LOGTAG, "created relro file");
            } finally {
                // We must do our best to always notify the update service, even if something fails.
                try {
+19 −17
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.Process;
import android.util.Log;
import android.util.Slog;
import android.webkit.IWebViewUpdateService;
import android.webkit.WebViewFactory;
@@ -36,6 +35,7 @@ import com.android.server.SystemService;
public class WebViewUpdateService extends SystemService {

    private static final String TAG = "WebViewUpdateService";
    private static final int WAIT_TIMEOUT_MS = 5000; // Same as KEY_DISPATCHING_TIMEOUT.

    private boolean mRelroReady32Bit = false;
    private boolean mRelroReady64Bit = false;
@@ -66,7 +66,7 @@ public class WebViewUpdateService extends SystemService {
    }

    private void onWebViewUpdateInstalled() {
        Log.d(TAG, "WebView Package updated!");
        Slog.d(TAG, "WebView Package updated!");

        synchronized (this) {
            mRelroReady32Bit = false;
@@ -107,26 +107,28 @@ public class WebViewUpdateService extends SystemService {
         */
        @Override // Binder call
        public void waitForRelroCreationCompleted(boolean is64Bit) {
            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
                Slog.wtf(TAG, "Trying to load WebView from the SystemServer",
                         new IllegalStateException());
            // The WebViewUpdateService depends on the prepareWebViewInSystemServer call, which
            // happens later (during the PHASE_ACTIVITY_MANAGER_READY) in SystemServer.java. If
            // another service there tries to bring up a WebView in the between, the wait below
            // would deadlock without the check below.
            if (Binder.getCallingPid() == Process.myPid()) {
                throw new IllegalStateException("Cannot create a WebView from the SystemServer");
            }

            final long NS_PER_MS = 1000000;
            final long timeoutTimeMs = System.nanoTime() / NS_PER_MS + WAIT_TIMEOUT_MS;
            boolean relroReady = false;
            synchronized (WebViewUpdateService.this) {
                if (is64Bit) {
                    while (!mRelroReady64Bit) {
                        try {
                            WebViewUpdateService.this.wait();
                        } catch (InterruptedException e) {}
                    }
                } else {
                    while (!mRelroReady32Bit) {
                while (!relroReady) {
                    final long timeNowMs = System.nanoTime() / NS_PER_MS;
                    if (timeNowMs >= timeoutTimeMs) break;
                    try {
                            WebViewUpdateService.this.wait();
                        WebViewUpdateService.this.wait(timeoutTimeMs - timeNowMs);
                    } catch (InterruptedException e) {}
                    relroReady = (is64Bit ? mRelroReady64Bit : mRelroReady32Bit);
                }
            }
            }
            if (!relroReady) Slog.w(TAG, "creating relro file timed out");
        }
    }