Sending RESULT_CANCELED to caller if the activity cannot be started
The caller activity cannot get the result if the launching Activity was unable to be started. Bug: 227291099 Test: atest ActivityStarterTests Change-Id: I74659f0e93eda671139e73d32b0dd6c1afe62b2c
This commit is contained in:
@@ -1807,6 +1807,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;
|
||||
}
|
||||
|
||||
@@ -1976,13 +1980,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;
|
||||
}
|
||||
@@ -2005,8 +2005,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;
|
||||
}
|
||||
@@ -2020,12 +2019,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user