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

Commit 4dbeb359 authored by Torne (Richard Coles)'s avatar Torne (Richard Coles) Committed by Ben Murdoch
Browse files

Cherry pick Make WebViewUpdateService a SystemService. DO NOT MERGE

Migrate WebViewUpdateService to the newer SystemService approach instead
of ServiceManager.addService.

Original Bug: 16403706
Original Change-Id: I21aa67a41c22c3c20ba9e82eb87e5d610fe130e8

Bug: 16723226
Change-Id: Id276b71ee547e683f0756bcee0f4978ce342c2af
parent 161536b5
Loading
Loading
Loading
Loading
+64 −50
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@ import android.util.Slog;
import android.webkit.IWebViewUpdateService;
import android.webkit.WebViewFactory;

import com.android.server.SystemService;

/**
 * Private service to wait for the updatable WebView to be ready for use.
 * @hide
 */
// TODO This should be implemented using the new pattern for system services.
// See comments in CL 509840.
public class WebViewUpdateService extends IWebViewUpdateService.Stub {
public class WebViewUpdateService extends SystemService {

    private static final String TAG = "WebViewUpdateService";

@@ -43,6 +43,11 @@ public class WebViewUpdateService extends IWebViewUpdateService.Stub {
    private BroadcastReceiver mWebViewUpdatedReceiver;

    public WebViewUpdateService(Context context) {
        super(context);
    }

    @Override
    public void onStart() {
        mWebViewUpdatedReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
@@ -55,29 +60,45 @@ public class WebViewUpdateService extends IWebViewUpdateService.Stub {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addDataScheme("package");
        context.registerReceiver(mWebViewUpdatedReceiver, filter);
        getContext().registerReceiver(mWebViewUpdatedReceiver, filter);

        publishBinderService("webviewupdate", new BinderService());
    }

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

        synchronized (this) {
            mRelroReady32Bit = false;
            mRelroReady64Bit = false;
        }
        WebViewFactory.prepareWebViewInSystemServer();
    }

    private class BinderService extends IWebViewUpdateService.Stub {

        /**
         * The shared relro process calls this to notify us that it's done trying to create a relro
     * file. This method gets called even if the relro creation has failed or the process crashed.
         * file. This method gets called even if the relro creation has failed or the process
         * crashed.
         */
        @Override // Binder call
        public void notifyRelroCreationCompleted(boolean is64Bit, boolean success) {
        // Verify that the caller is either the shared relro process (nominal case) or the system
        // server (only in the case the relro process crashes and we get here via the crashHandler).
            // Verify that the caller is either the shared relro process (nominal case) or the
            // system server (only in the case the relro process crashes and we get here via the
            // crashHandler).
            if (Binder.getCallingUid() != Process.SHARED_RELRO_UID &&
                    Binder.getCallingUid() != Process.SYSTEM_UID) {
                return;
            }

        synchronized (this) {
            synchronized (WebViewUpdateService.this) {
                if (is64Bit) {
                    mRelroReady64Bit = true;
                } else {
                    mRelroReady32Bit = true;
                }
            this.notifyAll();
                WebViewUpdateService.this.notifyAll();
            }
        }

@@ -91,30 +112,23 @@ public class WebViewUpdateService extends IWebViewUpdateService.Stub {
                         new IllegalStateException());
            }

        synchronized (this) {
            synchronized (WebViewUpdateService.this) {
                if (is64Bit) {
                    while (!mRelroReady64Bit) {
                        try {
                        this.wait();
                            WebViewUpdateService.this.wait();
                        } catch (InterruptedException e) {}
                    }
                } else {
                    while (!mRelroReady32Bit) {
                        try {
                        this.wait();
                            WebViewUpdateService.this.wait();
                        } catch (InterruptedException e) {}
                    }
                }
            }
        }

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

        synchronized (this) {
            mRelroReady32Bit = false;
            mRelroReady64Bit = false;
        }
        WebViewFactory.prepareWebViewInSystemServer();
    }

}
+3 −3
Original line number Diff line number Diff line
@@ -376,6 +376,9 @@ public final class SystemServer {
        mSystemServiceManager.startService(UsageStatsService.class);
        mActivityManagerService.setUsageStatsManager(
                LocalServices.getService(UsageStatsManagerInternal.class));

        // Tracks whether the updatable WebView is in a ready state and watches for update installs.
        mSystemServiceManager.startService(WebViewUpdateService.class);
    }

    /**
@@ -422,9 +425,6 @@ public final class SystemServer {
            Slog.i(TAG, "Reading configuration...");
            SystemConfig.getInstance();

            Slog.i(TAG, "WebView Update Service");
            ServiceManager.addService("webviewupdate", new WebViewUpdateService(context));

            Slog.i(TAG, "Scheduling Policy");
            ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());