diff options
3 files changed, 31 insertions, 16 deletions
diff --git a/core/java/android/window/flags/responsible_apis.aconfig b/core/java/android/window/flags/responsible_apis.aconfig index 6ce9725f95b0..cd31850b281c 100644 --- a/core/java/android/window/flags/responsible_apis.aconfig +++ b/core/java/android/window/flags/responsible_apis.aconfig @@ -71,3 +71,11 @@ flag { bug: "339720406" } +flag { + name: "bal_reduce_grace_period" + namespace: "responsible_apis" + description: "Changes to reduce or ideally remove the grace period exemption." + bug: "362575865" +} + + diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java index 20c5f02aaee2..a5cea34bf79d 100644 --- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java +++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java @@ -1685,6 +1685,21 @@ public class BackgroundActivityStartController { (state.mOriginatingPendingIntent != null)); } + if (finalVerdict.getRawCode() == BAL_ALLOW_GRACE_PERIOD) { + if (state.realCallerExplicitOptInOrAutoOptIn() + && state.mResultForRealCaller.allows() + && state.mResultForRealCaller.getRawCode() != BAL_ALLOW_GRACE_PERIOD) { + // real caller could allow with a different exemption + } else if (state.callerExplicitOptInOrAutoOptIn() && state.mResultForCaller.allows() + && state.mResultForCaller.getRawCode() != BAL_ALLOW_GRACE_PERIOD) { + // caller could allow with a different exemption + } else { + // log to determine grace period length distribution + Slog.wtf(TAG, "Activity start ONLY allowed by BAL_ALLOW_GRACE_PERIOD " + + finalVerdict.mMessage + ": " + state); + } + } + if (balImprovedMetrics()) { if (shouldLogStats(finalVerdict, state)) { String activityName; diff --git a/services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java b/services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java index 4a870a3a5b6e..5f5365dca1e9 100644 --- a/services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java +++ b/services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java @@ -17,7 +17,6 @@ package com.android.server.wm; import static com.android.internal.util.Preconditions.checkArgument; -import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ACTIVITY_STARTS; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskManagerService.ACTIVITY_BG_START_GRACE_PERIOD_MS; @@ -48,7 +47,6 @@ import android.os.SystemClock; import android.os.UserHandle; import android.util.ArrayMap; import android.util.IntArray; -import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.server.wm.BackgroundActivityStartController.BalVerdict; @@ -138,22 +136,16 @@ class BackgroundLaunchProcessController { if (appSwitchState == APP_SWITCH_ALLOW) { // 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(); - if (now - lastActivityLaunchTime < ACTIVITY_BG_START_GRACE_PERIOD_MS - || now - lastActivityFinishTime < ACTIVITY_BG_START_GRACE_PERIOD_MS) { - // If activity is started and finished before stop app switch time, we should not - // let app to be able to start background activity even it's in grace period. - if (lastActivityLaunchTime > lastStopAppSwitchesTime - || lastActivityFinishTime > lastStopAppSwitchesTime) { + if (lastActivityLaunchTime > lastStopAppSwitchesTime + || lastActivityFinishTime > lastStopAppSwitchesTime) { + final long now = SystemClock.uptimeMillis(); + long timeSinceLastStartOrFinish = now - Math.max(lastActivityLaunchTime, + lastActivityFinishTime); + if (timeSinceLastStartOrFinish < ACTIVITY_BG_START_GRACE_PERIOD_MS) { return new BalVerdict(BAL_ALLOW_GRACE_PERIOD, /*background*/ true, - "within " + ACTIVITY_BG_START_GRACE_PERIOD_MS + "ms grace period"); + "within " + ACTIVITY_BG_START_GRACE_PERIOD_MS + "ms grace period (" + + timeSinceLastStartOrFinish + "ms)"); } - if (DEBUG_ACTIVITY_STARTS) { - Slog.d(TAG, "[Process(" + pid + ")] Activity start within " - + ACTIVITY_BG_START_GRACE_PERIOD_MS - + "ms grace period but also within stop app switch window"); - } - } } return BalVerdict.BLOCK; |