BG-FGS while-in-use restriction uses the same grace period mechanism as BG-Activity-Launch. am: 28644e3b9e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13857624

Change-Id: Ie81a9bad37152aef941d072c12e45e4d16516927
This commit is contained in:
Hui Yu
2021-03-25 02:15:18 +00:00
committed by Automerger Merge Worker
2 changed files with 27 additions and 9 deletions

View File

@@ -4891,6 +4891,10 @@ public final class ActiveServices {
if (!pr.mAllowBackgroundActivityStartsTokens.isEmpty()) {
return true;
}
if (pr.getWindowProcessController()
.areBackgroundActivityStartsAllowedByGracePeriodSafe()) {
return true;
}
}
}

View File

@@ -455,15 +455,13 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
mAllowBackgroundActivityStarts = allowBackgroundActivityStarts;
}
boolean areBackgroundActivityStartsAllowed() {
// allow if the whitelisting flag was explicitly set
if (mAllowBackgroundActivityStarts) {
if (DEBUG_ACTIVITY_STARTS) {
Slog.d(TAG, "[WindowProcessController(" + mPid
+ ")] Activity start allowed: mAllowBackgroundActivityStarts = true");
}
return true;
public boolean areBackgroundActivityStartsAllowedByGracePeriodSafe() {
synchronized (mAtm.mGlobalLockWithoutBoost) {
return areBackgroundActivityStartsAllowedByGracePeriod();
}
}
boolean areBackgroundActivityStartsAllowedByGracePeriod() {
// allow if any activity in the caller has either started or finished very recently, and
// it must be started or finished after last stop app switches time.
final long now = SystemClock.uptimeMillis();
@@ -485,8 +483,24 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
+ ACTIVITY_BG_START_GRACE_PERIOD_MS
+ "ms grace period but also within stop app switch window");
}
}
return false;
}
boolean areBackgroundActivityStartsAllowed() {
// allow if the whitelisting flag was explicitly set
if (mAllowBackgroundActivityStarts) {
if (DEBUG_ACTIVITY_STARTS) {
Slog.d(TAG, "[WindowProcessController(" + mPid
+ ")] Activity start allowed: mAllowBackgroundActivityStarts = true");
}
return true;
}
if (areBackgroundActivityStartsAllowedByGracePeriod()) {
return true;
}
// allow if the proc is instrumenting with background activity starts privs
if (mInstrumentingWithBackgroundActivityStartPrivileges) {
if (DEBUG_ACTIVITY_STARTS) {