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
diff --git a/services/core/java/com/android/server/webkit/WebViewUpdateService.java b/services/core/java/com/android/server/webkit/WebViewUpdateService.java
index b666ada..ff68cf7 100644
--- a/services/core/java/com/android/server/webkit/WebViewUpdateService.java
+++ b/services/core/java/com/android/server/webkit/WebViewUpdateService.java
@@ -22,7 +22,6 @@
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 @@
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 @@
}
private void onWebViewUpdateInstalled() {
- Log.d(TAG, "WebView Package updated!");
+ Slog.d(TAG, "WebView Package updated!");
synchronized (this) {
mRelroReady32Bit = false;
@@ -107,26 +107,28 @@
*/
@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) {
- try {
- WebViewUpdateService.this.wait();
- } catch (InterruptedException e) {}
- }
+ while (!relroReady) {
+ final long timeNowMs = System.nanoTime() / NS_PER_MS;
+ if (timeNowMs >= timeoutTimeMs) break;
+ try {
+ WebViewUpdateService.this.wait(timeoutTimeMs - timeNowMs);
+ } catch (InterruptedException e) {}
+ relroReady = (is64Bit ? mRelroReady64Bit : mRelroReady32Bit);
}
}
+ if (!relroReady) Slog.w(TAG, "creating relro file timed out");
}
}