Loading core/java/android/window/flags/responsible_apis.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -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" } services/core/java/com/android/server/wm/BackgroundActivityStartController.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java +8 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { 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; Loading Loading
core/java/android/window/flags/responsible_apis.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -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" }
services/core/java/com/android/server/wm/BackgroundActivityStartController.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading
services/core/java/com/android/server/wm/BackgroundLaunchProcessController.java +8 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { 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; Loading