Merge "Sending RESULT_CANCELED to caller if the activity cannot be started" into tm-dev am: 6b11b0f83b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18131149 Change-Id: I8897f9313d54d548a343ffa6516d06fd6b94b1f7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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.
|
// Check if starting activity on given task or on a new task is allowed.
|
||||||
int startResult = isAllowedToStart(r, newTask, targetTask);
|
int startResult = isAllowedToStart(r, newTask, targetTask);
|
||||||
if (startResult != START_SUCCESS) {
|
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;
|
return startResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1976,13 +1980,9 @@ class ActivityStarter {
|
|||||||
mPreferredWindowingMode = mLaunchParams.mWindowingMode;
|
mPreferredWindowingMode = mLaunchParams.mWindowingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int isAllowedToStart(ActivityRecord r, boolean newTask, Task targetTask) {
|
@VisibleForTesting
|
||||||
if (mStartActivity.packageName == null) {
|
int isAllowedToStart(ActivityRecord r, boolean newTask, Task targetTask) {
|
||||||
if (mStartActivity.resultTo != null) {
|
if (r.packageName == null) {
|
||||||
mStartActivity.resultTo.sendResult(INVALID_UID, mStartActivity.resultWho,
|
|
||||||
mStartActivity.requestCode, RESULT_CANCELED,
|
|
||||||
null /* data */, null /* dataGrants */);
|
|
||||||
}
|
|
||||||
ActivityOptions.abort(mOptions);
|
ActivityOptions.abort(mOptions);
|
||||||
return START_CLASS_NOT_FOUND;
|
return START_CLASS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
@@ -2005,8 +2005,7 @@ class ActivityStarter {
|
|||||||
|| !targetTask.isUidPresent(mCallingUid)
|
|| !targetTask.isUidPresent(mCallingUid)
|
||||||
|| (LAUNCH_SINGLE_INSTANCE == mLaunchMode && targetTask.inPinnedWindowingMode()));
|
|| (LAUNCH_SINGLE_INSTANCE == mLaunchMode && targetTask.inPinnedWindowingMode()));
|
||||||
|
|
||||||
if (mRestrictedBgActivity && blockBalInTask
|
if (mRestrictedBgActivity && blockBalInTask && handleBackgroundActivityAbort(r)) {
|
||||||
&& handleBackgroundActivityAbort(mStartActivity)) {
|
|
||||||
Slog.e(TAG, "Abort background activity starts from " + mCallingUid);
|
Slog.e(TAG, "Abort background activity starts from " + mCallingUid);
|
||||||
return START_ABORTED;
|
return START_ABORTED;
|
||||||
}
|
}
|
||||||
@@ -2020,12 +2019,12 @@ class ActivityStarter {
|
|||||||
if (!newTask) {
|
if (!newTask) {
|
||||||
if (mService.getLockTaskController().isLockTaskModeViolation(targetTask,
|
if (mService.getLockTaskController().isLockTaskModeViolation(targetTask,
|
||||||
isNewClearTask)) {
|
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;
|
return START_RETURN_LOCK_TASK_MODE_VIOLATION;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(mStartActivity)) {
|
if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(r)) {
|
||||||
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;
|
return START_RETURN_LOCK_TASK_MODE_VIOLATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server.wm;
|
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.PROCESS_STATE_TOP;
|
||||||
import static android.app.ActivityManager.START_ABORTED;
|
import static android.app.ActivityManager.START_ABORTED;
|
||||||
import static android.app.ActivityManager.START_CANCELED;
|
import static android.app.ActivityManager.START_CANCELED;
|
||||||
@@ -1297,6 +1298,22 @@ public class ActivityStarterTests extends WindowTestsBase {
|
|||||||
assertEquals(targetRecord.getLaunchIntoPipHostActivity(), sourceRecord);
|
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,
|
private static void startActivityInner(ActivityStarter starter, ActivityRecord target,
|
||||||
ActivityRecord source, ActivityOptions options, Task inTask,
|
ActivityRecord source, ActivityOptions options, Task inTask,
|
||||||
TaskFragment inTaskFragment) {
|
TaskFragment inTaskFragment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user