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

Commit b515fa15 authored by Jiaming Liu's avatar Jiaming Liu Committed by Android (Google) Code Review
Browse files

Merge "Exclude embedded activities from updateHomeProcess" into main

parents b8478363 039349e3
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -6501,9 +6501,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        newIntents = null;

        if (isActivityTypeHome()) {
            mTaskSupervisor.updateHomeProcess(task.getBottomMostActivity().app);
        }
        mTaskSupervisor.updateHomeProcessIfNeeded(this);

        if (nowVisible) {
            mTaskSupervisor.stopWaitingForActivityVisible(this);
+11 −4
Original line number Diff line number Diff line
@@ -902,10 +902,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                                + " andResume=" + andResume);
                EventLogTags.writeWmRestartActivity(r.mUserId, System.identityHashCode(r),
                        task.mTaskId, r.shortComponentName);
                if (r.isActivityTypeHome()) {
                    // Home process is the root process of the task.
                    updateHomeProcess(task.getBottomMostActivity().app);
                }
                updateHomeProcessIfNeeded(r);
                mService.getPackageManagerInternalLocked().notifyPackageUse(
                        r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY);
                mService.getAppWarningsLocked().onStartActivity(r);
@@ -1050,6 +1047,16 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        return true;
    }

    void updateHomeProcessIfNeeded(@NonNull ActivityRecord r) {
        if (!r.isActivityTypeHome()) return;
        // Make sure that we use the bottom most activity from the same package, because the home
        // task can also embed third-party -1 activities.
        final ActivityRecord bottom = r.getTask().getBottomMostActivityInSamePackage();
        if (bottom != null) {
            updateHomeProcess(bottom.app);
        }
    }

    void updateHomeProcess(WindowProcessController app) {
        if (app != null && mService.mHomeProcess != app) {
            scheduleStartHome("homeChanged");
+9 −0
Original line number Diff line number Diff line
@@ -6799,6 +6799,15 @@ class Task extends TaskFragment {
        }
    }

    @Nullable
    ActivityRecord getBottomMostActivityInSamePackage() {
        if (realActivity == null) {
            return null;
        }
        return getActivity(ar -> ar.packageName.equals(
                realActivity.getPackageName()), false /* traverseTopToBottom */);
    }

    /**
     * Associates the decor surface with the given TF, or create one if there
     * isn't one in the Task yet. The surface will be removed with the TF,
+21 −0
Original line number Diff line number Diff line
@@ -1960,6 +1960,27 @@ public class TaskTests extends WindowTestsBase {
        verify(task).startPausing(eq(true) /* userLeaving */, anyBoolean(), any(), any());
    }

    @Test
    public void testGetBottomMostActivityInSamePackage() {
        final String packageName = "homePackage";
        final TaskFragmentOrganizer organizer = new TaskFragmentOrganizer(Runnable::run);
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(false).build();
        task.realActivity = new ComponentName(packageName, packageName + ".root_activity");
        doNothing().when(task).sendTaskFragmentParentInfoChangedIfNeeded();

        final TaskFragment fragment1 = createTaskFragmentWithEmbeddedActivity(task, organizer);
        final ActivityRecord activityDifferentPackage =
                new ActivityBuilder(mAtm).setTask(task).build();
        final ActivityRecord activitySamePackage =
                new ActivityBuilder(mAtm)
                        .setComponent(new ComponentName(packageName, packageName + ".activity2"))
                        .setTask(task).build();

        assertEquals(fragment1.getChildAt(0), task.getBottomMostActivity());
        assertEquals(activitySamePackage, task.getBottomMostActivityInSamePackage());
        assertNotEquals(activityDifferentPackage, task.getBottomMostActivityInSamePackage());
    }

    private Task getTestTask() {
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }