Merge "Limiting activity embedding to the activities of the same app" into sc-v2-dev

This commit is contained in:
Louis Chang
2021-09-23 00:34:31 +00:00
committed by Android (Google) Code Review

View File

@@ -16,7 +16,6 @@
package com.android.server.wm; package com.android.server.wm;
import static android.Manifest.permission.ACTIVITY_EMBEDDING;
import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND; import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND;
import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_CANCELED;
import static android.app.ActivityManager.START_ABORTED; import static android.app.ActivityManager.START_ABORTED;
@@ -1953,38 +1952,43 @@ class ActivityStarter {
} }
} }
if (mInTaskFragment != null && mInTaskFragment.getTask() != null) { if (mInTaskFragment != null && !canEmbedActivity(mInTaskFragment, r, newTask, targetTask)) {
final int hostUid = mInTaskFragment.getTask().effectiveUid; Slog.e(TAG, "Permission denied: Cannot embed " + r + " to " + mInTaskFragment.getTask()
final int embeddingUid = targetTask != null ? targetTask.effectiveUid : r.getUid(); + " targetTask= " + targetTask);
if (!canTaskBeEmbedded(hostUid, embeddingUid)) { return START_PERMISSION_DENIED;
Slog.e(TAG, "Cannot embed activity to a task owned by " + hostUid + " targetTask= "
+ targetTask);
return START_PERMISSION_DENIED;
}
} }
return START_SUCCESS; return START_SUCCESS;
} }
/** /**
* Return {@code true} if the {@param task} can embed another task. * Return {@code true} if an activity can be embedded to the TaskFragment.
* @param hostUid the uid of the host task * @param taskFragment the TaskFragment for embedding.
* @param embeddedUid the uid of the task the are going to be embedded * @param starting the starting activity.
* @param newTask whether the starting activity is going to be launched on a new task.
* @param targetTask the target task for launching activity, which could be different from
* the one who hosting the embedding.
*/ */
private boolean canTaskBeEmbedded(int hostUid, int embeddedUid) { private boolean canEmbedActivity(@NonNull TaskFragment taskFragment, ActivityRecord starting,
boolean newTask, Task targetTask) {
final Task hostTask = taskFragment.getTask();
if (hostTask == null) {
return false;
}
// Allowing the embedding if the task is owned by system. // Allowing the embedding if the task is owned by system.
final int hostUid = hostTask.effectiveUid;
if (hostUid == Process.SYSTEM_UID) { if (hostUid == Process.SYSTEM_UID) {
return true; return true;
} }
// Allowing embedding if the host task is owned by an app that has the ACTIVITY_EMBEDDING // Not allowed embedding an activity of another app.
// permission if (hostUid != starting.getUid()) {
if (mService.checkPermission(ACTIVITY_EMBEDDING, -1, hostUid) == PERMISSION_GRANTED) { return false;
return true;
} }
// Allowing embedding if it is from the same app that owned the task // Not allowed embedding task.
return hostUid == embeddedUid; return !newTask && (targetTask == null || targetTask == hostTask);
} }
/** /**
@@ -2801,10 +2805,15 @@ class ActivityStarter {
newParent = mInTaskFragment; newParent = mInTaskFragment;
} }
} else { } else {
// Use the child TaskFragment (if any) as the new parent if the activity can be embedded
final ActivityRecord top = task.topRunningActivity(false /* focusableOnly */, final ActivityRecord top = task.topRunningActivity(false /* focusableOnly */,
false /* includingEmbeddedTask */); false /* includingEmbeddedTask */);
newParent = top != null ? top.getTaskFragment() : task; final TaskFragment taskFragment = top != null ? top.getTaskFragment() : null;
if (taskFragment != null && taskFragment.isEmbedded()
&& task.effectiveUid == mStartActivity.getUid()) {
// Use the embedded TaskFragment of the top activity as the new parent if the
// activity can be embedded.
newParent = top.getTaskFragment();
}
} }
if (mStartActivity.getTaskFragment() == null if (mStartActivity.getTaskFragment() == null