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

Commit 40eda675 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Fix return value for IActivityTaskManager#finishActivity()

IActivityTaskManager#finishActivity() used to return 'true' even if
activity was already finishing prior to the call. The refactor in
I30ebc306637dea5e8b28ca4b4dfaab8df31d2be3 that merged
ActivityStack#requestFinishActivityLocked() and
ActivityRecord#finishActivityLocked() accidentally changed the
return value for the case when activity was already finishing.

This made the client think that the activity was not finished, so
the client state was not updated correctly.

This CL checks the finishing state of the activity instead to report
back to client.

Bug: 138265285
Test: atest WmTests:ActivityTaskManagerServiceTests
Change-Id: I9503cf6b9ceaece4ab6a5933c143d238f7fa7c4d
parent db313130
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PRE
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_CANCELLED;
import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
@@ -1618,8 +1617,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    // Explicitly dismissing the activity so reset its relaunch flag.
                    r.mRelaunchReason = RELAUNCH_REASON_NONE;
                } else {
                    res = r.finishActivityLocked(resultCode, resultData, "app-request",
                            true /* oomAdj */) != FINISH_RESULT_CANCELLED;
                    r.finishActivityLocked(resultCode, resultData, "app-request",
                            true /* oomAdj */);
                    res = r.finishing;
                    if (!res) {
                        Slog.i(TAG, "Failed to finish by app-request");
                    }
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wm;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;

import static org.junit.Assert.assertTrue;

import android.app.Activity;

import androidx.test.filters.MediumTest;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests for the {@link ActivityTaskManagerService} class.
 *
 * Build/Install/Run:
 *  atest WmTests:ActivityTaskManagerServiceTests
 */
@MediumTest
public class ActivityTaskManagerServiceTests extends ActivityTestsBase {

    @Before
    public void setUp() throws Exception {
        doReturn(false).when(mService).isBooting();
        doReturn(true).when(mService).isBooted();
    }

    /** Verify that activity is finished correctly upon request. */
    @Test
    public void testActivityFinish() {
        final TestActivityStack stack =
                (TestActivityStack) new StackBuilder(mRootActivityContainer).build();
        final ActivityRecord activity = stack.getChildAt(0).getTopActivity();
        assertTrue("Activity must be finished", mService.finishActivity(activity.appToken,
                0 /* resultCode */, null /* resultData */,
                Activity.DONT_FINISH_TASK_WITH_ACTIVITY));
        assertTrue(activity.finishing);

        assertTrue("Duplicate activity finish request must also return 'true'",
                mService.finishActivity(activity.appToken, 0 /* resultCode */,
                        null /* resultData */, Activity.DONT_FINISH_TASK_WITH_ACTIVITY));
    }
}