Merge "Sending RESULT_CANCELED to caller if the activity cannot be started" into tm-dev am: 6b11b0f83b am: 9d85608c4d

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

Change-Id: I82d6ea9c333176d47f45ea67c12740047b01dee0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Louis Chang
2022-05-04 09:58:11 +00:00
committed by Automerger Merge Worker
2 changed files with 28 additions and 12 deletions

View File

@@ -1817,6 +1817,10 @@ class ActivityStarter {
// Check if starting activity on given task or on a new task is allowed.
int startResult = isAllowedToStart(r, newTask, targetTask);
if (startResult != START_SUCCESS) {
if (r.resultTo != null) {
r.resultTo.sendResult(INVALID_UID, r.resultWho, r.requestCode, RESULT_CANCELED,
null /* data */, null /* dataGrants */);
}
return startResult;
}
@@ -1986,13 +1990,9 @@ class ActivityStarter {
mPreferredWindowingMode = mLaunchParams.mWindowingMode;
}
private int isAllowedToStart(ActivityRecord r, boolean newTask, Task targetTask) {
if (mStartActivity.packageName == null) {
if (mStartActivity.resultTo != null) {
mStartActivity.resultTo.sendResult(INVALID_UID, mStartActivity.resultWho,
mStartActivity.requestCode, RESULT_CANCELED,
null /* data */, null /* dataGrants */);
}
@VisibleForTesting
int isAllowedToStart(ActivityRecord r, boolean newTask, Task targetTask) {
if (r.packageName == null) {
ActivityOptions.abort(mOptions);
return START_CLASS_NOT_FOUND;
}
@@ -2015,8 +2015,7 @@ class ActivityStarter {
|| !targetTask.isUidPresent(mCallingUid)
|| (LAUNCH_SINGLE_INSTANCE == mLaunchMode && targetTask.inPinnedWindowingMode()));
if (mRestrictedBgActivity && blockBalInTask
&& handleBackgroundActivityAbort(mStartActivity)) {
if (mRestrictedBgActivity && blockBalInTask && handleBackgroundActivityAbort(r)) {
Slog.e(TAG, "Abort background activity starts from " + mCallingUid);
return START_ABORTED;
}
@@ -2030,12 +2029,12 @@ class ActivityStarter {
if (!newTask) {
if (mService.getLockTaskController().isLockTaskModeViolation(targetTask,
isNewClearTask)) {
Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity);
Slog.e(TAG, "Attempted Lock Task Mode violation r=" + r);
return START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
} else {
if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(mStartActivity)) {
Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity);
if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(r)) {
Slog.e(TAG, "Attempted Lock Task Mode violation r=" + r);
return START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
}

View File

@@ -16,6 +16,7 @@
package com.android.server.wm;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.ActivityManager.PROCESS_STATE_TOP;
import static android.app.ActivityManager.START_ABORTED;
import static android.app.ActivityManager.START_CANCELED;
@@ -1297,6 +1298,22 @@ public class ActivityStarterTests extends WindowTestsBase {
assertEquals(targetRecord.getLaunchIntoPipHostActivity(), sourceRecord);
}
@Test
public void testResultCanceledWhenNotAllowedStartingActivity() {
final ActivityStarter starter = prepareStarter(0, false);
final ActivityRecord targetRecord = new ActivityBuilder(mAtm).build();
final ActivityRecord sourceRecord = new ActivityBuilder(mAtm).build();
targetRecord.resultTo = sourceRecord;
// Abort the activity start and ensure the sourceRecord gets the result (RESULT_CANCELED).
spyOn(starter);
doReturn(START_ABORTED).when(starter).isAllowedToStart(any(), anyBoolean(), any());
startActivityInner(starter, targetRecord, sourceRecord, null /* options */,
null /* inTask */, null /* inTaskFragment */);
verify(sourceRecord).sendResult(anyInt(), any(), anyInt(), eq(RESULT_CANCELED), any(),
any());
}
private static void startActivityInner(ActivityStarter starter, ActivityRecord target,
ActivityRecord source, ActivityOptions options, Task inTask,
TaskFragment inTaskFragment) {