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

Commit 02382b56 authored by Louis Chang's avatar Louis Chang
Browse files

[RESTRICT AUTOMERGE] Trim the activity info of another uid if no privilege

The activity info could be from another uid which is different
from the app that hosts the task. The information should be
trimmed if the caller app doesn't have the privilege.

Bug: 243130512
Test: verified locally
Test: atest RecentTasksTest
Change-Id: Ia343ac70e5bb9aeae718fca6674e1ca491a14512
Merged-In: Ia343ac70e5bb9aeae718fca6674e1ca491a14512
(cherry picked from commit fa8d6362)
parent bc7a81d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ class AppTaskImpl extends IAppTask.Stub {
                    throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
                }
                return mService.getRecentTasks().createRecentTaskInfo(task,
                        false /* stripExtras */);
                        false /* stripExtras */, true /* getTasksAllowed */);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
+6 −2
Original line number Diff line number Diff line
@@ -974,7 +974,7 @@ class RecentTasks {
                continue;
            }

            res.add(createRecentTaskInfo(task, true /* stripExtras */));
            res.add(createRecentTaskInfo(task, true /* stripExtras */, getTasksAllowed));
        }
        return res;
    }
@@ -1890,7 +1890,8 @@ class RecentTasks {
    /**
     * Creates a new RecentTaskInfo from a Task.
     */
    ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras) {
    ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras,
            boolean getTasksAllowed) {
        final ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
        // If the recent Task is detached, we consider it will be re-attached to the default
        // TaskDisplayArea because we currently only support recent overview in the default TDA.
@@ -1902,6 +1903,9 @@ class RecentTasks {
        rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID;
        rti.persistentId = rti.taskId;
        rti.lastSnapshotData.set(tr.mLastTaskSnapshotData);
        if (!getTasksAllowed) {
            Task.trimIneffectiveInfo(tr, rti);
        }

        // Fill in organized child task info for the task created by organizer.
        if (tr.mCreatedByOrganizer) {
+4 −0
Original line number Diff line number Diff line
@@ -150,6 +150,10 @@ class RunningTasks {
        task.fillTaskInfo(rti, !mKeepIntentExtra);
        // Fill in some deprecated values
        rti.id = rti.taskId;

        if (!mAllowed) {
            Task.trimIneffectiveInfo(task, rti);
        }
        return rti;
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -3484,6 +3484,27 @@ class Task extends TaskFragment {
        info.mTopActivityLocusId = topRecord != null ? topRecord.getLocusId() : null;
    }

    /**
     * Removes the activity info if the activity belongs to a different uid, which is
     * different from the app that hosts the task.
     */
    static void trimIneffectiveInfo(Task task, TaskInfo info) {
        final ActivityRecord baseActivity = task.getActivity(r -> !r.finishing,
                false /* traverseTopToBottom */);
        final int baseActivityUid =
                baseActivity != null ? baseActivity.getUid() : task.effectiveUid;

        if (info.topActivityInfo != null
                && task.effectiveUid != info.topActivityInfo.applicationInfo.uid) {
            info.topActivity = null;
            info.topActivityInfo = null;
        }

        if (task.effectiveUid != baseActivityUid) {
            info.baseActivity = null;
        }
    }

    @Nullable PictureInPictureParams getPictureInPictureParams() {
        return getPictureInPictureParams(getTopMostTask());
    }
+22 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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 android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.os.Process.NOBODY_UID;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -1195,21 +1196,35 @@ public class RecentTasksTest extends WindowTestsBase {

    @Test
    public void testCreateRecentTaskInfo_detachedTask() {
        final Task task = createTaskBuilder(".Task").setCreateActivity(true).build();
        final Task task = createTaskBuilder(".Task").build();
        new ActivityBuilder(mSupervisor.mService)
                .setTask(task)
                .setUid(NOBODY_UID)
                .setComponent(new ComponentName("com.foo", ".BarActivity"))
                .build();
        final TaskDisplayArea tda = task.getDisplayArea();

        assertTrue(task.isAttached());
        assertTrue(task.supportsMultiWindow());

        RecentTaskInfo info = mRecentTasks.createRecentTaskInfo(task, true);
        RecentTaskInfo info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
                true /* getTasksAllowed */);

        assertTrue(info.supportsMultiWindow);
        assertTrue(info.supportsSplitScreenMultiWindow);

        info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
                false /* getTasksAllowed */);

        assertTrue(info.topActivity == null);
        assertTrue(info.topActivityInfo == null);
        assertTrue(info.baseActivity == null);

        // The task can be put in split screen even if it is not attached now.
        task.removeImmediately();

        info = mRecentTasks.createRecentTaskInfo(task, true);
        info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
                true /* getTasksAllowed */);

        assertTrue(info.supportsMultiWindow);
        assertTrue(info.supportsSplitScreenMultiWindow);
@@ -1219,7 +1234,8 @@ public class RecentTasksTest extends WindowTestsBase {
        doReturn(false).when(tda).supportsNonResizableMultiWindow();
        doReturn(false).when(task).isResizeable();

        info = mRecentTasks.createRecentTaskInfo(task, true);
        info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
                true /* getTasksAllowed */);

        assertFalse(info.supportsMultiWindow);
        assertFalse(info.supportsSplitScreenMultiWindow);
@@ -1228,7 +1244,8 @@ public class RecentTasksTest extends WindowTestsBase {
        // the device supports it.
        doReturn(true).when(tda).supportsNonResizableMultiWindow();

        info = mRecentTasks.createRecentTaskInfo(task, true);
        info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
                true /* getTasksAllowed */);

        assertTrue(info.supportsMultiWindow);
        assertTrue(info.supportsSplitScreenMultiWindow);