Merge "Cherry-picking the following 3 getContentProviderImpl() CLs" into pi-dev

am: 8a7d8bceb5

Change-Id: Id06664361669cdb09fcb1f37c651ce024c36e693
This commit is contained in:
Makoto Onuki
2018-10-30 12:52:39 -07:00
committed by android-build-merger

View File

@@ -581,6 +581,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
@@ -12041,6 +12047,7 @@ public class ActivityManagerService extends IActivityManager.Stub
ContentProviderRecord cpr;
ContentProviderConnection conn = null;
ProviderInfo cpi = null;
boolean providerRunning = false;
synchronized(this) {
long startTime = SystemClock.uptimeMillis();
@@ -12080,7 +12087,26 @@ public class ActivityManagerService extends IActivityManager.Stub
}
}
boolean providerRunning = cpr != null && cpr.proc != null && !cpr.proc.killed;
if (cpr != null && cpr.proc != null) {
providerRunning = !cpr.proc.killed;
// Note if killedByAm is also set, this means the provider process has just been
// killed by AM (in ProcessRecord.kill()), but appDiedLocked() hasn't been called
// yet. So we need to call appDiedLocked() here and let it clean up.
// (See the commit message on I2c4ba1e87c2d47f2013befff10c49b3dc337a9a7 to see
// how to test this case.)
if (cpr.proc.killed && cpr.proc.killedByAm) {
checkTime(startTime, "getContentProviderImpl: before appDied (killedByAm)");
final long iden = Binder.clearCallingIdentity();
try {
appDiedLocked(cpr.proc);
} finally {
Binder.restoreCallingIdentity(iden);
}
checkTime(startTime, "getContentProviderImpl: after appDied (killedByAm)");
}
}
if (providerRunning) {
cpi = cpr.info;
String msg;
@@ -12373,6 +12399,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) {
@@ -12387,13 +12414,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) {