From 7d3a33f353513add1b04f25e3aa64ae93ff791ae Mon Sep 17 00:00:00 2001 From: Michal Karpinski Date: Thu, 25 Apr 2019 16:03:30 +0100 Subject: [PATCH] If the ServiceRecord already has a ProcessRecord attached in startServiceLocked(), whitelist the process at that point (previously we'd just set the valiable to true, and not add the token) If the process was already attached, realStartServiceLocked() wouldn't run. Also, don't remove bg actvity starts token as soon as the service is stopped in stopServiceLocked() - instead only remove the token in the timeout callback. Bug: 131240614 Bug: 130810805 Test: manual (for the quoted bugs) Change-Id: I0e704e7b6e8cbafb026c90533fbe4a193a47c883 --- .../com/android/server/am/ActiveServices.java | 7 +---- .../com/android/server/am/ServiceRecord.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 76136dfc81a0d..fdfa0638c428d 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -634,7 +634,7 @@ public final class ActiveServices { } if (allowBackgroundActivityStarts) { - r.hasStartedWhitelistingBgActivityStarts = true; + r.setHasStartedWhitelistingBgActivityStarts(true); scheduleCleanUpHasStartedWhitelistingBgActivityStartsLocked(r); } @@ -761,11 +761,6 @@ public final class ActiveServices { } service.callStart = false; - // the service will not necessarily be brought down, so only clear the whitelisting state - // for start-based bg activity starts now, and drop any existing future cleanup callback - service.setHasStartedWhitelistingBgActivityStarts(false); - mAm.mHandler.removeCallbacks(service.startedWhitelistingBgActivityStartsCleanUp); - bringDownServiceIfNeededLocked(service, false, false); } diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 27c62d03f960e..b36671f719eb0 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -131,10 +131,10 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN int pendingConnectionImportance; // To be filled in to ProcessRecord once it connects // any current binding to this service has BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS flag? - private boolean hasBindingWhitelistingBgActivityStarts; + private boolean mHasBindingWhitelistingBgActivityStarts; // is this service currently whitelisted to start activities from background by providing // allowBackgroundActivityStarts=true to startServiceLocked()? - boolean hasStartedWhitelistingBgActivityStarts; + private boolean mHasStartedWhitelistingBgActivityStarts; // used to clean up the state of hasStartedWhitelistingBgActivityStarts after a timeout Runnable startedWhitelistingBgActivityStartsCleanUp; @@ -384,13 +384,13 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN if (whitelistManager) { pw.print(prefix); pw.print("whitelistManager="); pw.println(whitelistManager); } - if (hasBindingWhitelistingBgActivityStarts) { + if (mHasBindingWhitelistingBgActivityStarts) { pw.print(prefix); pw.print("hasBindingWhitelistingBgActivityStarts="); - pw.println(hasBindingWhitelistingBgActivityStarts); + pw.println(mHasBindingWhitelistingBgActivityStarts); } - if (hasStartedWhitelistingBgActivityStarts) { + if (mHasStartedWhitelistingBgActivityStarts) { pw.print(prefix); pw.print("hasStartedWhitelistingBgActivityStarts="); - pw.println(hasStartedWhitelistingBgActivityStarts); + pw.println(mHasStartedWhitelistingBgActivityStarts); } if (delayed) { pw.print(prefix); pw.print("delayed="); pw.println(delayed); @@ -542,7 +542,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN public void setProcess(ProcessRecord _proc) { if (_proc != null) { - if (hasStartedWhitelistingBgActivityStarts || hasBindingWhitelistingBgActivityStarts) { + if (mHasStartedWhitelistingBgActivityStarts + || mHasBindingWhitelistingBgActivityStarts) { _proc.addAllowBackgroundActivityStartsToken(this); } else { _proc.removeAllowBackgroundActivityStartsToken(this); @@ -614,22 +615,22 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN break; } } - if (hasBindingWhitelistingBgActivityStarts != hasWhitelistingBinding) { - hasBindingWhitelistingBgActivityStarts = hasWhitelistingBinding; + if (mHasBindingWhitelistingBgActivityStarts != hasWhitelistingBinding) { + mHasBindingWhitelistingBgActivityStarts = hasWhitelistingBinding; updateParentProcessBgActivityStartsWhitelistingToken(); } } void setHasBindingWhitelistingBgActivityStarts(boolean newValue) { - if (hasBindingWhitelistingBgActivityStarts != newValue) { - hasBindingWhitelistingBgActivityStarts = newValue; + if (mHasBindingWhitelistingBgActivityStarts != newValue) { + mHasBindingWhitelistingBgActivityStarts = newValue; updateParentProcessBgActivityStartsWhitelistingToken(); } } void setHasStartedWhitelistingBgActivityStarts(boolean newValue) { - if (hasStartedWhitelistingBgActivityStarts != newValue) { - hasStartedWhitelistingBgActivityStarts = newValue; + if (mHasStartedWhitelistingBgActivityStarts != newValue) { + mHasStartedWhitelistingBgActivityStarts = newValue; updateParentProcessBgActivityStartsWhitelistingToken(); } } @@ -647,7 +648,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN if (app == null) { return; } - if (hasStartedWhitelistingBgActivityStarts || hasBindingWhitelistingBgActivityStarts) { + if (mHasStartedWhitelistingBgActivityStarts || mHasBindingWhitelistingBgActivityStarts) { // if the token is already there it's safe to "re-add it" - we're deadling with // a set of Binder objects app.addAllowBackgroundActivityStartsToken(this);