Merge "[RESTRICT AUTOMERGE] Trim the activity info of another uid if no privilege" into rvc-dev

This commit is contained in:
TreeHugger Robot
2022-10-27 16:28:45 +00:00
committed by Android (Google) Code Review
4 changed files with 32 additions and 3 deletions

View File

@@ -84,7 +84,7 @@ class AppTaskImpl extends IAppTask.Stub {
throw new IllegalArgumentException("Unable to find task ID " + mTaskId); throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
} }
return mService.getRecentTasks().createRecentTaskInfo(task, return mService.getRecentTasks().createRecentTaskInfo(task,
false /* stripExtras */); false /* stripExtras */, true /* getTasksAllowed */);
} finally { } finally {
Binder.restoreCallingIdentity(origId); Binder.restoreCallingIdentity(origId);
} }

View File

@@ -961,7 +961,7 @@ class RecentTasks {
continue; continue;
} }
res.add(createRecentTaskInfo(task, true /* stripExtras */)); res.add(createRecentTaskInfo(task, true /* stripExtras */, getTasksAllowed));
} }
return res; return res;
} }
@@ -1833,12 +1833,16 @@ class RecentTasks {
/** /**
* Creates a new RecentTaskInfo from a Task. * Creates a new RecentTaskInfo from a Task.
*/ */
ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras) { ActivityManager.RecentTaskInfo createRecentTaskInfo(Task tr, boolean stripExtras,
boolean getTasksAllowed) {
ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo(); ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
tr.fillTaskInfo(rti, stripExtras); tr.fillTaskInfo(rti, stripExtras);
// Fill in some deprecated values // Fill in some deprecated values
rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID; rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID;
rti.persistentId = rti.taskId; rti.persistentId = rti.taskId;
if (!getTasksAllowed) {
Task.trimIneffectiveInfo(tr, rti);
}
return rti; return rti;
} }

View File

@@ -129,6 +129,10 @@ class RunningTasks {
final RunningTaskInfo rti = task.getTaskInfo(); final RunningTaskInfo rti = task.getTaskInfo();
// Fill in some deprecated values // Fill in some deprecated values
rti.id = rti.taskId; rti.id = rti.taskId;
if (!mAllowed) {
Task.trimIneffectiveInfo(task, rti);
}
return rti; return rti;
} }
} }

View File

@@ -3631,6 +3631,27 @@ class Task extends WindowContainer<WindowContainer> {
: null; : 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;
}
}
/** /**
* Returns a {@link TaskInfo} with information from this task. * Returns a {@link TaskInfo} with information from this task.
*/ */