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
This commit is contained in:
Torne (Richard Coles)
2014-07-29 19:14:24 +01:00
committed by Ben Murdoch
parent 161536b597
commit 4dbeb359b2
2 changed files with 70 additions and 56 deletions

View File

@@ -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,57 +60,9 @@ 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);
/**
* 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.
*/
@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).
if (Binder.getCallingUid() != Process.SHARED_RELRO_UID &&
Binder.getCallingUid() != Process.SYSTEM_UID) {
return;
}
synchronized (this) {
if (is64Bit) {
mRelroReady64Bit = true;
} else {
mRelroReady32Bit = true;
}
this.notifyAll();
}
}
/**
* WebViewFactory calls this to block WebView loading until the relro file is created.
*/
@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());
}
synchronized (this) {
if (is64Bit) {
while (!mRelroReady64Bit) {
try {
this.wait();
} catch (InterruptedException e) {}
}
} else {
while (!mRelroReady32Bit) {
try {
this.wait();
} catch (InterruptedException e) {}
}
}
}
publishBinderService("webviewupdate", new BinderService());
}
private void onWebViewUpdateInstalled() {
@@ -117,4 +74,61 @@ public class WebViewUpdateService extends IWebViewUpdateService.Stub {
}
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.
*/
@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).
if (Binder.getCallingUid() != Process.SHARED_RELRO_UID &&
Binder.getCallingUid() != Process.SYSTEM_UID) {
return;
}
synchronized (WebViewUpdateService.this) {
if (is64Bit) {
mRelroReady64Bit = true;
} else {
mRelroReady32Bit = true;
}
WebViewUpdateService.this.notifyAll();
}
}
/**
* WebViewFactory calls this to block WebView loading until the relro file is created.
*/
@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());
}
synchronized (WebViewUpdateService.this) {
if (is64Bit) {
while (!mRelroReady64Bit) {
try {
WebViewUpdateService.this.wait();
} catch (InterruptedException e) {}
}
} else {
while (!mRelroReady32Bit) {
try {
WebViewUpdateService.this.wait();
} catch (InterruptedException e) {}
}
}
}
}
}
}

View File

@@ -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());