diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 7feefe7de4094..455e7ae8ee450 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1997,11 +1997,7 @@ class ActivityStarter { } } - boolean shouldBlockActivityStart = true; - // Used for logging/toasts. Would we block the start if target sdk was U and feature was - // enabled? - boolean wouldBlockActivityStartIgnoringFlags = true; - + Pair pair = null; if (mSourceRecord != null) { boolean passesAsmChecks = true; Task sourceTask = mSourceRecord.getTask(); @@ -2017,14 +2013,25 @@ class ActivityStarter { if (passesAsmChecks) { Task taskToCheck = taskToFront ? sourceTask : targetTask; - // first == false means Should Block - // second == false means Would Block disregarding flags - Pair pair = ActivityTaskSupervisor + pair = ActivityTaskSupervisor .doesTopActivityMatchingUidExistForAsm(taskToCheck, mSourceRecord.getUid(), mSourceRecord); - shouldBlockActivityStart = !pair.first; - wouldBlockActivityStartIgnoringFlags = !pair.second; } + } else if (!taskToFront) { + // We don't have a sourceRecord, and we're launching into an existing task. + // Allow if callingUid is top of stack. + pair = ActivityTaskSupervisor + .doesTopActivityMatchingUidExistForAsm(targetTask, mCallingUid, + /*sourceRecord*/null); + } + + boolean shouldBlockActivityStart = true; + if (pair != null) { + // We block if feature flag is enabled + shouldBlockActivityStart = !pair.first; + // Used for logging/toasts. Would we block if target sdk was U and feature was + // enabled? If so, we can't return here but we also might not block at the end + boolean wouldBlockActivityStartIgnoringFlags = !pair.second; if (!wouldBlockActivityStartIgnoringFlags) { return true;