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

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

Merge "Do not override finish activity behavior on back event" into udc-dev...

Merge "Do not override finish activity behavior on back event" into udc-dev am: 4381f324 am: f8cb90cf

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



Change-Id: I3d02fd3b8d5c8ce56c205885ce2e4f7d91c150ae
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e05216c2 f8cb90cf
Loading
Loading
Loading
Loading
+4 −34
Original line number Original line Diff line number Diff line
@@ -78,8 +78,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
@@ -1645,18 +1643,15 @@ class ActivityClientController extends IActivityClientController.Stub {
                launchedFromHome = root.isLaunchSourceType(ActivityRecord.LAUNCH_SOURCE_TYPE_HOME);
                launchedFromHome = root.isLaunchSourceType(ActivityRecord.LAUNCH_SOURCE_TYPE_HOME);
            }
            }


            // If the activity is one of the main entry points for the application, then we should
            // If the activity was launched directly from the home screen, then we should
            // refrain from finishing the activity and instead move it to the back to keep it in
            // refrain from finishing the activity and instead move it to the back to keep it in
            // memory. The requirements for this are:
            // memory. The requirements for this are:
            //   1. The activity is the last running activity in the task.
            //   1. The activity is the last running activity in the task.
            //   2. The current activity is the base activity for the task.
            //   2. The current activity is the base activity for the task.
            //   3. a. If the activity was launched by the home process, we trust that its intent
            //   3. The activity was launched by the home process, and is one of the main entry
            //         was resolved, so we check if the it is a main intent for the application.
            //      points for the application.
            //      b. Otherwise, we query Package Manager to verify whether the activity is a
            //         launcher activity for the application.
            if (baseActivityIntent != null && isLastRunningActivity
            if (baseActivityIntent != null && isLastRunningActivity
                    && ((launchedFromHome && ActivityRecord.isMainIntent(baseActivityIntent))
                    && launchedFromHome && ActivityRecord.isMainIntent(baseActivityIntent)) {
                        || isLauncherActivity(baseActivityIntent.getComponent()))) {
                moveActivityTaskToBack(token, true /* nonRoot */);
                moveActivityTaskToBack(token, true /* nonRoot */);
                return;
                return;
            }
            }
@@ -1668,31 +1663,6 @@ class ActivityClientController extends IActivityClientController.Stub {
        }
        }
    }
    }


    /**
     * Queries PackageManager to see if the given activity is one of the main entry point for the
     * application. This should not be called with the WM lock held.
     */
    @SuppressWarnings("unchecked")
    private boolean isLauncherActivity(@NonNull ComponentName activity) {
        final Intent queryIntent = new Intent(Intent.ACTION_MAIN);
        queryIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        queryIntent.setPackage(activity.getPackageName());
        try {
            final ParceledListSlice<ResolveInfo> resolved =
                    mService.getPackageManager().queryIntentActivities(
                            queryIntent, null, 0, mContext.getUserId());
            if (resolved == null) return false;
            for (final ResolveInfo ri : resolved.getList()) {
                if (ri.getComponentInfo().getComponentName().equals(activity)) {
                    return true;
                }
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to query intent activities", e);
        }
        return false;
    }

    @Override
    @Override
    public void enableTaskLocaleOverride(IBinder token) {
    public void enableTaskLocaleOverride(IBinder token) {
        if (UserHandle.getAppId(Binder.getCallingUid()) != SYSTEM_UID) {
        if (UserHandle.getAppId(Binder.getCallingUid()) != SYSTEM_UID) {
+18 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_CANCELLED;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_CANCELLED;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REMOVED;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REMOVED;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REQUESTED;
import static com.android.server.wm.ActivityRecord.FINISH_RESULT_REQUESTED;
import static com.android.server.wm.ActivityRecord.LAUNCH_SOURCE_TYPE_HOME;
import static com.android.server.wm.ActivityRecord.State.DESTROYED;
import static com.android.server.wm.ActivityRecord.State.DESTROYED;
import static com.android.server.wm.ActivityRecord.State.DESTROYING;
import static com.android.server.wm.ActivityRecord.State.DESTROYING;
import static com.android.server.wm.ActivityRecord.State.FINISHING;
import static com.android.server.wm.ActivityRecord.State.FINISHING;
@@ -3688,6 +3689,23 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertTrue(activity.inTransition());
        assertTrue(activity.inTransition());
    }
    }


    /**
     * Verifies the task is moved to back when back pressed if the root activity was originally
     * started from Launcher.
     */
    @Test
    public void testMoveTaskToBackWhenStartedFromLauncher() {
        final Task task = createTask(mDisplayContent);
        final ActivityRecord ar = createActivityRecord(task);
        task.realActivity = ar.mActivityComponent;
        ar.intent.setAction(Intent.ACTION_MAIN);
        ar.intent.addCategory(Intent.CATEGORY_LAUNCHER);
        doReturn(true).when(ar).isLaunchSourceType(eq(LAUNCH_SOURCE_TYPE_HOME));

        mAtm.mActivityClientController.onBackPressed(ar.token, null /* callback */);
        verify(task).moveTaskToBack(any());
    }

    private ICompatCameraControlCallback getCompatCameraControlCallback() {
    private ICompatCameraControlCallback getCompatCameraControlCallback() {
        return new ICompatCameraControlCallback.Stub() {
        return new ICompatCameraControlCallback.Stub() {
            @Override
            @Override