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

WindowProcessController.areBackgroundActivityStartsAllowed() has the 10 seconds grace period,
starts from last activity's launch time or finish time.

Expose this method for AMS to call, to determine if BG-FGS while-in-use permission is allowed.

Bug: 182400165
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Merged-In: I30706dc1950bf5d49926a8e26c0493d9e168eb1b
Change-Id: I3615d0a2dc3464b6e980237b906c83872c3b4bce
This commit is contained in:
Hui Yu
2021-03-14 22:07:55 -07:00
parent 4221ca489c
commit 28644e3b9e
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) {