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