Merge "Allow uid processes in foreground task to start activity in FG app switch state" into sc-v2-dev am: a7bea448c9

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

Change-Id: I19bd7b0102f4c038d33cdb61b35bc14e3bbdd175
This commit is contained in:
Louis Chang
2021-12-10 01:13:23 +00:00
committed by Automerger Merge Worker
3 changed files with 15 additions and 14 deletions

View File

@@ -1278,9 +1278,6 @@ class ActivityStarter {
// This is used to block background activity launch even if the app is still // This is used to block background activity launch even if the app is still
// visible to user after user clicking home button. // visible to user after user clicking home button.
final int appSwitchState = mService.getBalAppSwitchesState(); final int appSwitchState = mService.getBalAppSwitchesState();
final boolean appSwitchAllowed = appSwitchState == APP_SWITCH_ALLOW;
final boolean appSwitchAllowedOrFg =
appSwitchState == APP_SWITCH_ALLOW || appSwitchState == APP_SWITCH_FG_ONLY;
// don't abort if the callingUid has a visible window or is a persistent system process // don't abort if the callingUid has a visible window or is a persistent system process
final int callingUidProcState = mService.mActiveUids.getUidState(callingUid); final int callingUidProcState = mService.mActiveUids.getUidState(callingUid);
@@ -1293,6 +1290,8 @@ class ActivityStarter {
// Normal apps with visible app window will be allowed to start activity if app switching // Normal apps with visible app window will be allowed to start activity if app switching
// is allowed, or apps like live wallpaper with non app visible window will be allowed. // is allowed, or apps like live wallpaper with non app visible window will be allowed.
final boolean appSwitchAllowedOrFg =
appSwitchState == APP_SWITCH_ALLOW || appSwitchState == APP_SWITCH_FG_ONLY;
if (((appSwitchAllowedOrFg || mService.mActiveUids.hasNonAppVisibleWindow(callingUid)) if (((appSwitchAllowedOrFg || mService.mActiveUids.hasNonAppVisibleWindow(callingUid))
&& callingUidHasAnyVisibleWindow) && callingUidHasAnyVisibleWindow)
|| isCallingUidPersistentSystemProcess) { || isCallingUidPersistentSystemProcess) {
@@ -1403,7 +1402,7 @@ class ActivityStarter {
// don't abort if the callerApp or other processes of that uid are allowed in any way // don't abort if the callerApp or other processes of that uid are allowed in any way
if (callerApp != null) { if (callerApp != null) {
// first check the original calling process // first check the original calling process
if (callerApp.areBackgroundActivityStartsAllowed(appSwitchAllowed)) { if (callerApp.areBackgroundActivityStartsAllowed(appSwitchState)) {
if (DEBUG_ACTIVITY_STARTS) { if (DEBUG_ACTIVITY_STARTS) {
Slog.d(TAG, "Background activity start allowed: callerApp process (pid = " Slog.d(TAG, "Background activity start allowed: callerApp process (pid = "
+ callerApp.getPid() + ", uid = " + callerAppUid + ") is allowed"); + callerApp.getPid() + ", uid = " + callerAppUid + ") is allowed");
@@ -1417,7 +1416,7 @@ class ActivityStarter {
for (int i = uidProcesses.size() - 1; i >= 0; i--) { for (int i = uidProcesses.size() - 1; i >= 0; i--) {
final WindowProcessController proc = uidProcesses.valueAt(i); final WindowProcessController proc = uidProcesses.valueAt(i);
if (proc != callerApp if (proc != callerApp
&& proc.areBackgroundActivityStartsAllowed(appSwitchAllowed)) { && proc.areBackgroundActivityStartsAllowed(appSwitchState)) {
if (DEBUG_ACTIVITY_STARTS) { if (DEBUG_ACTIVITY_STARTS) {
Slog.d(TAG, Slog.d(TAG,
"Background activity start allowed: process " + proc.getPid() "Background activity start allowed: process " + proc.getPid()

View File

@@ -20,6 +20,8 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ACTIVIT
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; 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.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerService.ACTIVITY_BG_START_GRACE_PERIOD_MS; import static com.android.server.wm.ActivityTaskManagerService.ACTIVITY_BG_START_GRACE_PERIOD_MS;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_FG_ONLY;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -70,13 +72,13 @@ class BackgroundLaunchProcessController {
} }
boolean areBackgroundActivityStartsAllowed(int pid, int uid, String packageName, boolean areBackgroundActivityStartsAllowed(int pid, int uid, String packageName,
boolean appSwitchAllowed, boolean isCheckingForFgsStart, int appSwitchState, boolean isCheckingForFgsStart,
boolean hasActivityInVisibleTask, boolean hasBackgroundActivityStartPrivileges, boolean hasActivityInVisibleTask, boolean hasBackgroundActivityStartPrivileges,
long lastStopAppSwitchesTime, long lastActivityLaunchTime, long lastStopAppSwitchesTime, long lastActivityLaunchTime,
long lastActivityFinishTime) { long lastActivityFinishTime) {
// If app switching is not allowed, we ignore all the start activity grace period // If app switching is not allowed, we ignore all the start activity grace period
// exception so apps cannot start itself in onPause() after pressing home button. // exception so apps cannot start itself in onPause() after pressing home button.
if (appSwitchAllowed) { if (appSwitchState == APP_SWITCH_ALLOW) {
// 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();
@@ -111,7 +113,8 @@ class BackgroundLaunchProcessController {
return true; return true;
} }
// Allow if the caller has an activity in any foreground task. // Allow if the caller has an activity in any foreground task.
if (appSwitchAllowed && hasActivityInVisibleTask) { if (hasActivityInVisibleTask
&& (appSwitchState == APP_SWITCH_ALLOW || appSwitchState == APP_SWITCH_FG_ONLY)) {
if (DEBUG_ACTIVITY_STARTS) { if (DEBUG_ACTIVITY_STARTS) {
Slog.d(TAG, "[Process(" + pid Slog.d(TAG, "[Process(" + pid
+ ")] Activity start allowed: process has activity in foreground task"); + ")] Activity start allowed: process has activity in foreground task");

View File

@@ -37,7 +37,6 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFI
import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; 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.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.ActivityTaskManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MILLIS; import static com.android.server.wm.ActivityTaskManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MILLIS;
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
@@ -513,19 +512,19 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
*/ */
@HotPath(caller = HotPath.START_SERVICE) @HotPath(caller = HotPath.START_SERVICE)
public boolean areBackgroundFgsStartsAllowed() { public boolean areBackgroundFgsStartsAllowed() {
return areBackgroundActivityStartsAllowed(mAtm.getBalAppSwitchesState() == APP_SWITCH_ALLOW, return areBackgroundActivityStartsAllowed(mAtm.getBalAppSwitchesState(),
true /* isCheckingForFgsStart */); true /* isCheckingForFgsStart */);
} }
boolean areBackgroundActivityStartsAllowed(boolean appSwitchAllowed) { boolean areBackgroundActivityStartsAllowed(int appSwitchState) {
return areBackgroundActivityStartsAllowed(appSwitchAllowed, return areBackgroundActivityStartsAllowed(appSwitchState,
false /* isCheckingForFgsStart */); false /* isCheckingForFgsStart */);
} }
private boolean areBackgroundActivityStartsAllowed(boolean appSwitchAllowed, private boolean areBackgroundActivityStartsAllowed(int appSwitchState,
boolean isCheckingForFgsStart) { boolean isCheckingForFgsStart) {
return mBgLaunchController.areBackgroundActivityStartsAllowed(mPid, mUid, mInfo.packageName, return mBgLaunchController.areBackgroundActivityStartsAllowed(mPid, mUid, mInfo.packageName,
appSwitchAllowed, isCheckingForFgsStart, hasActivityInVisibleTask(), appSwitchState, isCheckingForFgsStart, hasActivityInVisibleTask(),
mInstrumentingWithBackgroundActivityStartPrivileges, mInstrumentingWithBackgroundActivityStartPrivileges,
mAtm.getLastStopAppSwitchesTime(), mAtm.getLastStopAppSwitchesTime(),
mLastActivityLaunchTime, mLastActivityFinishTime); mLastActivityLaunchTime, mLastActivityFinishTime);