diff options
author | Baligh Uddin <baligh@google.com> | 2015-09-22 20:50:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-09-22 20:50:02 +0000 |
commit | d2b597d1fdc99c512f1addfc817eea8d375a84ec (patch) | |
tree | e33ef6808f29141d17f62b3cd41026a35c849ac6 /services | |
parent | 1b57758a1bb814c3a00ec864fe164bfe7861a9ab (diff) | |
parent | 64b5e1c4f9991cbd97050bd3f183bf510fce2077 (diff) | |
download | frameworks_base-d2b597d1fdc99c512f1addfc817eea8d375a84ec.zip frameworks_base-d2b597d1fdc99c512f1addfc817eea8d375a84ec.tar.gz frameworks_base-d2b597d1fdc99c512f1addfc817eea8d375a84ec.tar.bz2 |
Merge "Enforce a timeout for Content Providers to be published." into mnc-dr-dev
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 525aac7..e3b5651 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -316,6 +316,9 @@ public final class ActivityManagerService extends ActivityManagerNative // 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. static final int PROC_START_TIMEOUT = 10*1000; + // How long we wait for an attached process to publish its content providers + // before we decide it must be hung. + static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*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 @@ -1368,6 +1371,7 @@ public final class ActivityManagerService extends ActivityManagerNative static final int REPORT_USER_SWITCH_COMPLETE_MSG = 56; static final int SHUTDOWN_UI_AUTOMATION_CONNECTION_MSG = 57; static final int APP_BOOST_DEACTIVATE_MSG = 58; + static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG = 59; static final int FIRST_ACTIVITY_STACK_MSG = 100; static final int FIRST_BROADCAST_QUEUE_MSG = 200; @@ -1701,6 +1705,12 @@ public final class ActivityManagerService extends ActivityManagerNative processStartTimedOutLocked(app); } } break; + case CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG: { + ProcessRecord app = (ProcessRecord)msg.obj; + synchronized (ActivityManagerService.this) { + processContentProviderPublishTimedOutLocked(app); + } + } break; case DO_PENDING_ACTIVITY_LAUNCHES_MSG: { synchronized (ActivityManagerService.this) { mStackSupervisor.doPendingActivityLaunchesLocked(true); @@ -5944,6 +5954,11 @@ public final class ActivityManagerService extends ActivityManagerNative return needRestart; } + private final void processContentProviderPublishTimedOutLocked(ProcessRecord app) { + cleanupAppInLaunchingProvidersLocked(app, true); + removeProcessLocked(app, false, true, "timeout publishing content providers"); + } + private final void processStartTimedOutLocked(ProcessRecord app) { final int pid = app.pid; boolean gone = false; @@ -5970,7 +5985,7 @@ public final class ActivityManagerService extends ActivityManagerNative mBatteryStatsService.removeIsolatedUid(app.uid, app.info.uid); } // Take care of any launching providers waiting for this process. - checkAppInLaunchingProvidersLocked(app, true); + cleanupAppInLaunchingProvidersLocked(app, true); // Take care of any services that are waiting for the process. mServices.processStartTimedOutLocked(app); app.kill("start timeout", true); @@ -6066,6 +6081,12 @@ public final class ActivityManagerService extends ActivityManagerNative boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info); List<ProviderInfo> providers = normalMode ? generateApplicationProvidersLocked(app) : null; + if (providers != null && checkAppInLaunchingProvidersLocked(app)) { + Message msg = mHandler.obtainMessage(CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG); + msg.obj = app; + mHandler.sendMessageDelayed(msg, CONTENT_PROVIDER_PUBLISH_TIMEOUT); + } + if (!normalMode) { Slog.i(TAG, "Launching preboot mode app: " + app); } @@ -9897,7 +9918,7 @@ public final class ActivityManagerService extends ActivityManagerNative final long origId = Binder.clearCallingIdentity(); final int N = providers.size(); - for (int i=0; i<N; i++) { + for (int i = 0; i < N; i++) { ContentProviderHolder src = providers.get(i); if (src == null || src.info == null || src.provider == null) { continue; @@ -9912,15 +9933,20 @@ public final class ActivityManagerService extends ActivityManagerNative mProviderMap.putProviderByName(names[j], dst); } - int NL = mLaunchingProviders.size(); + int launchingCount = mLaunchingProviders.size(); int j; - for (j=0; j<NL; j++) { + boolean wasInLaunchingProviders = false; + for (j = 0; j < launchingCount; j++) { if (mLaunchingProviders.get(j) == dst) { mLaunchingProviders.remove(j); + wasInLaunchingProviders = true; j--; - NL--; + launchingCount--; } } + if (wasInLaunchingProviders) { + mHandler.removeMessages(CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG, r); + } synchronized (dst) { dst.provider = src.provider; dst.proc = r; @@ -15531,7 +15557,7 @@ public final class ActivityManagerService extends ActivityManagerNative app.pubProviders.clear(); // Take care of any launching providers waiting for this process. - if (checkAppInLaunchingProvidersLocked(app, false)) { + if (cleanupAppInLaunchingProvidersLocked(app, false)) { restart = true; } @@ -15653,7 +15679,17 @@ public final class ActivityManagerService extends ActivityManagerNative return false; } - boolean checkAppInLaunchingProvidersLocked(ProcessRecord app, boolean alwaysBad) { + boolean checkAppInLaunchingProvidersLocked(ProcessRecord app) { + for (int i = mLaunchingProviders.size() - 1; i >= 0; i--) { + ContentProviderRecord cpr = mLaunchingProviders.get(i); + if (cpr.launchingApp == app) { + return true; + } + } + return false; + } + + boolean cleanupAppInLaunchingProvidersLocked(ProcessRecord app, boolean alwaysBad) { // Look through the content providers we are waiting to have launched, // and if any run in this process then either schedule a restart of // the process or kill the client waiting for it if this process has |