diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index b1aea1fca0778..c27ec6f107f29 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -455,6 +455,12 @@ public class ActivityManagerService extends IActivityManager.Stub // before we decide it must be hung. static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*1000; + /** + * How long we wait for an provider to be published. Should be longer than + * {@link #CONTENT_PROVIDER_PUBLISH_TIMEOUT}. + */ + static final int CONTENT_PROVIDER_WAIT_TIMEOUT = 20 * 1000; + // How long we wait for a launched process to attach to the activity manager // before we decide it's never going to come up for real, when the process was // started with a wrapper for instrumentation (such as Valgrind) because it @@ -7374,6 +7380,7 @@ public class ActivityManagerService extends IActivityManager.Stub ContentProviderRecord cpr; ContentProviderConnection conn = null; ProviderInfo cpi = null; + boolean providerRunning = false; synchronized(this) { long startTime = SystemClock.uptimeMillis(); @@ -7413,8 +7420,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } - boolean providerRunning = false; - if (cpr != null && cpr.proc != null) { providerRunning = !cpr.proc.killed; @@ -7739,6 +7744,7 @@ public class ActivityManagerService extends IActivityManager.Stub } // Wait for the provider to be published... + final long timeout = SystemClock.uptimeMillis() + CONTENT_PROVIDER_WAIT_TIMEOUT; synchronized (cpr) { while (cpr.provider == null) { if (cpr.launchingApp == null) { @@ -7753,13 +7759,22 @@ public class ActivityManagerService extends IActivityManager.Stub return null; } try { + final long wait = Math.max(0L, timeout - SystemClock.uptimeMillis()); if (DEBUG_MU) Slog.v(TAG_MU, "Waiting to start provider " + cpr - + " launchingApp=" + cpr.launchingApp); + + " launchingApp=" + cpr.launchingApp + " for " + wait + " ms"); if (conn != null) { conn.waiting = true; } - cpr.wait(); + cpr.wait(wait); + if (cpr.provider == null) { + Slog.wtf(TAG, "Timeout waiting for provider " + + cpi.applicationInfo.packageName + "/" + + cpi.applicationInfo.uid + " for provider " + + name + + " providerRunning=" + providerRunning); + return null; + } } catch (InterruptedException ex) { } finally { if (conn != null) {