Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aeedd739 authored by Louis Chang's avatar Louis Chang Committed by Automerger Merge Worker
Browse files

Merge "Sending RESULT_CANCELED to caller if the activity cannot be started"...

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

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



Change-Id: If4f66b311d96cc1fb54ecb0f95f5d367eb791220
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents abfd3672 6b11b0f8
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -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;
            }
        }
+17 −0
Original line number Diff line number Diff line
@@ -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) {