Skip to content

Commit 3218617

Browse files
Louis ChangOhMyVenyx
authored andcommitted
[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 fa8d636) Merged-In: Ia343ac70e5bb9aeae718fca6674e1ca491a14512
1 parent fd3e1a6 commit 3218617

5 files changed

Lines changed: 54 additions & 8 deletions

File tree

services/core/java/com/android/server/wm/AppTaskImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ActivityManager.RecentTaskInfo getTaskInfo() {
8484
throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
8585
}
8686
return mService.getRecentTasks().createRecentTaskInfo(task,
87-
false /* stripExtras */);
87+
false /* stripExtras */, true /* getTasksAllowed */);
8888
} finally {
8989
Binder.restoreCallingIdentity(origId);
9090
}

services/core/java/com/android/server/wm/RecentTasks.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ private ArrayList<ActivityManager.RecentTaskInfo> getRecentTasksImpl(int maxNum,
974974
continue;
975975
}
976976

977-
res.add(createRecentTaskInfo(task, true /* stripExtras */));
977+
res.add(createRecentTaskInfo(task, true /* stripExtras */, getTasksAllowed));
978978
}
979979
return res;
980980
}
@@ -1890,7 +1890,8 @@ void dump(PrintWriter pw, boolean dumpAll, String dumpPackage) {
18901890
/**
18911891
* Creates a new RecentTaskInfo from a Task.
18921892
*/
1893-
ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras) {
1893+
ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras,
1894+
boolean getTasksAllowed) {
18941895
final ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
18951896
// If the recent Task is detached, we consider it will be re-attached to the default
18961897
// TaskDisplayArea because we currently only support recent overview in the default TDA.
@@ -1902,6 +1903,9 @@ ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras
19021903
rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID;
19031904
rti.persistentId = rti.taskId;
19041905
rti.lastSnapshotData.set(tr.mLastTaskSnapshotData);
1906+
if (!getTasksAllowed) {
1907+
Task.trimIneffectiveInfo(tr, rti);
1908+
}
19051909

19061910
// Fill in organized child task info for the task created by organizer.
19071911
if (tr.mCreatedByOrganizer) {

services/core/java/com/android/server/wm/RunningTasks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ private RunningTaskInfo createRunningTaskInfo(Task task) {
150150
task.fillTaskInfo(rti, !mKeepIntentExtra);
151151
// Fill in some deprecated values
152152
rti.id = rti.taskId;
153+
154+
if (!mAllowed) {
155+
Task.trimIneffectiveInfo(task, rti);
156+
}
153157
return rti;
154158
}
155159
}

services/core/java/com/android/server/wm/Task.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,27 @@ void fillTaskInfo(TaskInfo info, boolean stripExtras, @Nullable TaskDisplayArea
34843484
info.mTopActivityLocusId = topRecord != null ? topRecord.getLocusId() : null;
34853485
}
34863486

3487+
/**
3488+
* Removes the activity info if the activity belongs to a different uid, which is
3489+
* different from the app that hosts the task.
3490+
*/
3491+
static void trimIneffectiveInfo(Task task, TaskInfo info) {
3492+
final ActivityRecord baseActivity = task.getActivity(r -> !r.finishing,
3493+
false /* traverseTopToBottom */);
3494+
final int baseActivityUid =
3495+
baseActivity != null ? baseActivity.getUid() : task.effectiveUid;
3496+
3497+
if (info.topActivityInfo != null
3498+
&& task.effectiveUid != info.topActivityInfo.applicationInfo.uid) {
3499+
info.topActivity = null;
3500+
info.topActivityInfo = null;
3501+
}
3502+
3503+
if (task.effectiveUid != baseActivityUid) {
3504+
info.baseActivity = null;
3505+
}
3506+
}
3507+
34873508
@Nullable PictureInPictureParams getPictureInPictureParams() {
34883509
return getPictureInPictureParams(getTopMostTask());
34893510
}

services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
3131
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
3232
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
33+
import static android.os.Process.NOBODY_UID;
3334

3435
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
3536
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -1195,21 +1196,35 @@ public void testLastSnapshotData_notSet() {
11951196

11961197
@Test
11971198
public void testCreateRecentTaskInfo_detachedTask() {
1198-
final Task task = createTaskBuilder(".Task").setCreateActivity(true).build();
1199+
final Task task = createTaskBuilder(".Task").build();
1200+
new ActivityBuilder(mSupervisor.mService)
1201+
.setTask(task)
1202+
.setUid(NOBODY_UID)
1203+
.setComponent(new ComponentName("com.foo", ".BarActivity"))
1204+
.build();
11991205
final TaskDisplayArea tda = task.getDisplayArea();
12001206

12011207
assertTrue(task.isAttached());
12021208
assertTrue(task.supportsMultiWindow());
12031209

1204-
RecentTaskInfo info = mRecentTasks.createRecentTaskInfo(task, true);
1210+
RecentTaskInfo info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
1211+
true /* getTasksAllowed */);
12051212

12061213
assertTrue(info.supportsMultiWindow);
12071214
assertTrue(info.supportsSplitScreenMultiWindow);
12081215

1216+
info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
1217+
false /* getTasksAllowed */);
1218+
1219+
assertTrue(info.topActivity == null);
1220+
assertTrue(info.topActivityInfo == null);
1221+
assertTrue(info.baseActivity == null);
1222+
12091223
// The task can be put in split screen even if it is not attached now.
12101224
task.removeImmediately();
12111225

1212-
info = mRecentTasks.createRecentTaskInfo(task, true);
1226+
info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
1227+
true /* getTasksAllowed */);
12131228

12141229
assertTrue(info.supportsMultiWindow);
12151230
assertTrue(info.supportsSplitScreenMultiWindow);
@@ -1219,7 +1234,8 @@ public void testCreateRecentTaskInfo_detachedTask() {
12191234
doReturn(false).when(tda).supportsNonResizableMultiWindow();
12201235
doReturn(false).when(task).isResizeable();
12211236

1222-
info = mRecentTasks.createRecentTaskInfo(task, true);
1237+
info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
1238+
true /* getTasksAllowed */);
12231239

12241240
assertFalse(info.supportsMultiWindow);
12251241
assertFalse(info.supportsSplitScreenMultiWindow);
@@ -1228,7 +1244,8 @@ public void testCreateRecentTaskInfo_detachedTask() {
12281244
// the device supports it.
12291245
doReturn(true).when(tda).supportsNonResizableMultiWindow();
12301246

1231-
info = mRecentTasks.createRecentTaskInfo(task, true);
1247+
info = mRecentTasks.createRecentTaskInfo(task, true /* stripExtras */,
1248+
true /* getTasksAllowed */);
12321249

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

0 commit comments

Comments
 (0)