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

Commit 2f9acd22 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix lost intent extra when starting activity from recents

Always create a copy for task info to avoid the original intent
being modified.

Bug: 119052114
Test: atest TaskRecordTests#testCopyBaseIntentForTaskInfo
Change-Id: Ib27bc52c436f3e8b379b4374dc9d5b6031fa0316
parent 44f74d11
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1960,7 +1960,7 @@ public class TaskRecord extends ConfigurationContainer implements TaskWindowCont
        info.stackId = getStackId();
        info.taskId = taskId;
        info.isRunning = getTopActivity() != null;
        info.baseIntent = getBaseIntent();
        info.baseIntent = new Intent(getBaseIntent());
        info.baseActivity = reuseActivitiesReport.base != null
                ? reuseActivitiesReport.base.intent.getComponent()
                : null;
+15 −0
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.server.wm;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;

import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import android.app.ActivityManager;
@@ -92,6 +95,18 @@ public class TaskRecordTests extends ActivityTestsBase {
        assertNotNull(TaskRecord.getTaskRecordFactory());
    }

    /** Ensure we have no chance to modify the original intent. */
    @Test
    public void testCopyBaseIntentForTaskInfo() {
        final TaskRecord task = createTaskRecord(1);
        task.lastTaskDescription = new ActivityManager.TaskDescription();
        final ActivityManager.RecentTaskInfo info = new ActivityManager.RecentTaskInfo();
        task.fillTaskInfo(info, new TaskRecord.TaskActivitiesReport());

        // The intent of info should be a copy so assert that they are different instances.
        assertThat(info.baseIntent, not(sameInstance(task.getBaseIntent())));
    }

    @Test
    public void testCreateTestRecordUsingCustomizedFactory() throws Exception {
        TestTaskRecordFactory factory = new TestTaskRecordFactory();