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

Commit 60b1ab72 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make the task affinity of a single-instance activity unique"

parents fa817ade 28b58644
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -1586,7 +1586,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        hasBeenLaunched = false;
        mStackSupervisor = supervisor;

        info.taskAffinity = getTaskAffinityWithUid(info.taskAffinity, info.applicationInfo.uid);
        info.taskAffinity = computeTaskAffinity(info.taskAffinity, info.applicationInfo.uid,
                launchMode);
        taskAffinity = info.taskAffinity;
        final String uid = Integer.toString(info.applicationInfo.uid);
        if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
@@ -1647,17 +1648,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }

    /**
     * Generate the task affinity with uid. For b/35954083, Limit task affinity to uid to avoid
     * issues associated with sharing affinity across uids.
     * Generate the task affinity with uid and activity launch mode. For b/35954083, Limit task
     * affinity to uid to avoid issues associated with sharing affinity across uids.
     *
     * @param affinity The affinity of the activity.
     * @param uid The user-ID that has been assigned to this application.
     * @return The task affinity with uid.
     * @param launchMode The activity launch mode
     * @return The task affinity
     */
    static String getTaskAffinityWithUid(String affinity, int uid) {
    static String computeTaskAffinity(String affinity, int uid, int launchMode) {
        final String uidStr = Integer.toString(uid);
        if (affinity != null && !affinity.startsWith(uidStr)) {
            affinity = uidStr + ":" + affinity;
            affinity = uidStr + (launchMode == LAUNCH_SINGLE_INSTANCE ? "-si:" : ":") + affinity;
        }
        return affinity;
    }
+2 −1
Original line number Diff line number Diff line
@@ -6637,7 +6637,8 @@ class Task extends WindowContainer<WindowContainer> {
        // Basic case: for simple app-centric recents, we need to recreate
        // the task if the affinity has changed.

        final String affinity = ActivityRecord.getTaskAffinityWithUid(destAffinity, srec.getUid());
        final String affinity = ActivityRecord.computeTaskAffinity(destAffinity, srec.getUid(),
                srec.launchMode);
        if (srec == null || srec.getTask().affinity == null
                || !srec.getTask().affinity.equals(affinity)) {
            return true;
+27 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -446,6 +448,31 @@ public class RecentTasksTest extends WindowTestsBase {
        assertThat(mCallbacksRecorder.mRemoved).isEmpty();
    }

    @Test
    public void testRemoveAffinityTask() {
        // Add task to recents
        final String taskAffinity = "affinity";
        final int uid = 10123;
        final Task task1 = createTaskBuilder(".Task1").setStack(mStack).build();
        task1.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE);
        mRecentTasks.add(task1);

        // Add another task to recents, and make sure the previous task was removed.
        final Task task2 = createTaskBuilder(".Task2").setStack(mStack).build();
        task2.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE);
        mRecentTasks.add(task2);
        assertEquals(1, mRecentTasks.getRecentTasks(MAX_VALUE, 0 /* flags */,
                true /* getTasksAllowed */, TEST_USER_0_ID, 0).getList().size());

        // Add another single-instance task to recents, and make sure no task is removed.
        final Task task3 = createTaskBuilder(".Task3").setStack(mStack).build();
        task3.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid,
                LAUNCH_SINGLE_INSTANCE);
        mRecentTasks.add(task3);
        assertEquals(2, mRecentTasks.getRecentTasks(MAX_VALUE, 0 /* flags */,
                true /* getTasksAllowed */, TEST_USER_0_ID, 0).getList().size());
    }

    @Test
    public void testAddTasksHomeClearUntrackedTasks_expectFinish() {
        // There may be multiple tasks with the same base intent by flags (FLAG_ACTIVITY_NEW_TASK |