[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
(cherry picked from commit 401e782b24)
This commit is contained in:
@@ -84,7 +84,8 @@ class AppTaskImpl extends IAppTask.Stub {
|
||||
if (tr == null) {
|
||||
throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
|
||||
}
|
||||
return mService.getRecentTasks().createRecentTaskInfo(tr);
|
||||
return mService.getRecentTasks().createRecentTaskInfo(tr,
|
||||
true /* getTasksAllowed */);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(origId);
|
||||
}
|
||||
|
||||
@@ -944,7 +944,7 @@ class RecentTasks {
|
||||
continue;
|
||||
}
|
||||
|
||||
final ActivityManager.RecentTaskInfo rti = createRecentTaskInfo(tr);
|
||||
final ActivityManager.RecentTaskInfo rti = createRecentTaskInfo(tr, getTasksAllowed);
|
||||
if (!getDetailedTasks) {
|
||||
rti.baseIntent.replaceExtras((Bundle) null);
|
||||
}
|
||||
@@ -1715,12 +1715,15 @@ class RecentTasks {
|
||||
/**
|
||||
* Creates a new RecentTaskInfo from a TaskRecord.
|
||||
*/
|
||||
ActivityManager.RecentTaskInfo createRecentTaskInfo(TaskRecord tr) {
|
||||
ActivityManager.RecentTaskInfo createRecentTaskInfo(TaskRecord tr, boolean getTasksAllowed) {
|
||||
ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
|
||||
tr.fillTaskInfo(rti);
|
||||
// Fill in some deprecated values
|
||||
rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID;
|
||||
rti.persistentId = rti.taskId;
|
||||
if (!getTasksAllowed) {
|
||||
TaskRecord.trimIneffectiveInfo(tr, rti);
|
||||
}
|
||||
return rti;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class RunningTasks {
|
||||
}
|
||||
|
||||
final TaskRecord task = iter.next();
|
||||
list.add(createRunningTaskInfo(task));
|
||||
list.add(createRunningTaskInfo(task, allowed));
|
||||
maxNum--;
|
||||
}
|
||||
}
|
||||
@@ -76,11 +76,15 @@ class RunningTasks {
|
||||
/**
|
||||
* Constructs a {@link RunningTaskInfo} from a given {@param task}.
|
||||
*/
|
||||
private RunningTaskInfo createRunningTaskInfo(TaskRecord task) {
|
||||
private RunningTaskInfo createRunningTaskInfo(TaskRecord task, boolean allowed) {
|
||||
final RunningTaskInfo rti = new RunningTaskInfo();
|
||||
task.fillTaskInfo(rti);
|
||||
// Fill in some deprecated values
|
||||
rti.id = rti.taskId;
|
||||
|
||||
if (!allowed) {
|
||||
TaskRecord.trimIneffectiveInfo(task, rti);
|
||||
}
|
||||
return rti;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2436,6 +2436,40 @@ class TaskRecord extends ConfigurationContainer {
|
||||
info.configuration.setTo(getConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(TaskRecord task, TaskInfo info) {
|
||||
int topActivityUid = task.effectiveUid;
|
||||
for (int i = task.mActivities.size() - 1; i >= 0; --i) {
|
||||
final ActivityRecord r = task.mActivities.get(i);
|
||||
if (r.finishing || r.isState(ActivityState.INITIALIZING)) {
|
||||
continue;
|
||||
}
|
||||
topActivityUid = r.info.applicationInfo.uid;
|
||||
break;
|
||||
}
|
||||
|
||||
if (task.effectiveUid != topActivityUid) {
|
||||
info.topActivity = null;
|
||||
}
|
||||
|
||||
int baseActivityUid = task.effectiveUid;
|
||||
for (int i = 0; i < task.mActivities.size(); ++i) {
|
||||
final ActivityRecord r = task.mActivities.get(i);
|
||||
if (r.finishing) {
|
||||
continue;
|
||||
}
|
||||
baseActivityUid = r.info.applicationInfo.uid;
|
||||
break;
|
||||
}
|
||||
|
||||
if (task.effectiveUid != baseActivityUid) {
|
||||
info.baseActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link TaskInfo} with information from this task.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user