Merge "Fix issue #11223338: Not retaining service started state while restarting" into klp-dev

This commit is contained in:
Dianne Hackborn
2013-11-01 23:20:08 +00:00
committed by Android (Google) Code Review

View File

@@ -76,7 +76,7 @@ public final class ActiveServices {
// How long a service needs to be running until restarting its process // How long a service needs to be running until restarting its process
// is no longer considered to be a relaunch of the service. // is no longer considered to be a relaunch of the service.
static final int SERVICE_RESTART_DURATION = 5*1000; static final int SERVICE_RESTART_DURATION = 1*1000;
// How long a service needs to be running until it will start back at // How long a service needs to be running until it will start back at
// SERVICE_RESTART_DURATION after being killed. // SERVICE_RESTART_DURATION after being killed.
@@ -301,7 +301,7 @@ public final class ActiveServices {
ServiceRecord r = res.record; ServiceRecord r = res.record;
NeededUriGrants neededGrants = mAm.checkGrantUriPermissionFromIntentLocked( NeededUriGrants neededGrants = mAm.checkGrantUriPermissionFromIntentLocked(
callingUid, r.packageName, service, service.getFlags(), null); callingUid, r.packageName, service, service.getFlags(), null);
if (unscheduleServiceRestartLocked(r)) { if (unscheduleServiceRestartLocked(r, callingUid)) {
if (DEBUG_SERVICE) Slog.v(TAG, "START SERVICE WHILE RESTART PENDING: " + r); if (DEBUG_SERVICE) Slog.v(TAG, "START SERVICE WHILE RESTART PENDING: " + r);
} }
r.lastActivity = SystemClock.uptimeMillis(); r.lastActivity = SystemClock.uptimeMillis();
@@ -695,7 +695,7 @@ public final class ActiveServices {
final long origId = Binder.clearCallingIdentity(); final long origId = Binder.clearCallingIdentity();
try { try {
if (unscheduleServiceRestartLocked(s)) { if (unscheduleServiceRestartLocked(s, callerApp.info.uid)) {
if (DEBUG_SERVICE) Slog.v(TAG, "BIND SERVICE WHILE RESTART PENDING: " if (DEBUG_SERVICE) Slog.v(TAG, "BIND SERVICE WHILE RESTART PENDING: "
+ s); + s);
} }
@@ -1141,16 +1141,9 @@ public final class ActiveServices {
r.restartCount = 1; r.restartCount = 1;
r.restartDelay = minDuration; r.restartDelay = minDuration;
} else { } else {
if ((r.serviceInfo.applicationInfo.flags r.restartDelay *= SERVICE_RESTART_DURATION_FACTOR;
&ApplicationInfo.FLAG_PERSISTENT) != 0) { if (r.restartDelay < minDuration) {
// Services in peristent processes will restart much more r.restartDelay = minDuration;
// quickly, since they are pretty important. (Think SystemUI).
r.restartDelay += minDuration/2;
} else {
r.restartDelay *= SERVICE_RESTART_DURATION_FACTOR;
if (r.restartDelay < minDuration) {
r.restartDelay = minDuration;
}
} }
} }
} }
@@ -1177,7 +1170,7 @@ public final class ActiveServices {
} while (repeat); } while (repeat);
} else { } else {
// Persistent processes are immediately restrted, so there is no // Persistent processes are immediately restarted, so there is no
// reason to hold of on restarting their services. // reason to hold of on restarting their services.
r.totalRestartCount++; r.totalRestartCount++;
r.restartCount = 0; r.restartCount = 0;
@@ -1210,12 +1203,17 @@ public final class ActiveServices {
bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true); bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true);
} }
private final boolean unscheduleServiceRestartLocked(ServiceRecord r) { private final boolean unscheduleServiceRestartLocked(ServiceRecord r, int callingUid) {
if (r.restartDelay == 0) { if (r.restartDelay == 0) {
return false; return false;
} }
r.resetRestartCounter(); // Remove from the restarting list; if the service is currently on the
mRestartingServices.remove(r); // restarting list, or the call is coming from another app, then this
// service has become of much more interest so we reset the restart interval.
boolean removed = mRestartingServices.remove(r);
if (removed || callingUid != r.appInfo.uid) {
r.resetRestartCounter();
}
mAm.mHandler.removeCallbacks(r.restarter); mAm.mHandler.removeCallbacks(r.restarter);
return true; return true;
} }
@@ -1549,7 +1547,7 @@ public final class ActiveServices {
smap.mServicesByName.remove(r.name); smap.mServicesByName.remove(r.name);
smap.mServicesByIntent.remove(r.intent); smap.mServicesByIntent.remove(r.intent);
r.totalRestartCount = 0; r.totalRestartCount = 0;
unscheduleServiceRestartLocked(r); unscheduleServiceRestartLocked(r, 0);
// Also make sure it is not on the pending list. // Also make sure it is not on the pending list.
int N = mPendingServices.size(); int N = mPendingServices.size();