Include Activities That Have Not Been Assigned...

...to a Process Yet in TaskFragmentInfo

TaskFragmentInfo might be reported before an activity
has been assigned to a process, which would prevent
the activity from being reported in the TaskFragmentInfo
activities array because the activity process id does
not match the TaskFragmentOrganizer process id. However,
the activity is still reported in the running activity
count and makes the TaskFragment non-empty.

This discrepency results in unnecessary split info
callbacks because the change in TaskFragmentInfo#isEmpty
or runningActivityCount triggers an onTaskFragmentInfoChanged
callback in SplitController, which triggers a split info
callback. However, this split info callback will soon be stale
information because once the activity has been attached to a
process, the activity lifecycle listener in SplitController
will send a split info callback.

This CL uses a combination of uid and process name to check
that the activity belongs to the TaskFragmentOrganizer process
instead of the process id. uid and process name are set
during activity creation whereas pid is set afterwards, which
causes the discrepency.

Bug: b/204193051 b/205240942 b/204721225 b/204405410
Test: atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingLaunchTests
Change-Id: Icfa28325da0278d2fb70e1111ffd39412b370bdb
This commit is contained in:
Shivam Agrawal
2021-10-27 16:20:14 -07:00
parent d6cf8c85ac
commit 9c906fbc94
2 changed files with 13 additions and 13 deletions

View File

@@ -31,6 +31,7 @@ import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
import static android.os.Process.INVALID_UID;
import static android.os.UserHandle.USER_NULL;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.TRANSIT_CLOSE;
@@ -221,6 +222,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
/** Organizer that organizing this TaskFragment. */
@Nullable
private ITaskFragmentOrganizer mTaskFragmentOrganizer;
private int mTaskFragmentOrganizerUid = INVALID_UID;
private @Nullable String mTaskFragmentOrganizerProcessName;
/** Client assigned unique token for this TaskFragment if this is created by an organizer. */
@Nullable
@@ -233,13 +236,6 @@ class TaskFragment extends WindowContainer<WindowContainer> {
*/
private boolean mDelayLastActivityRemoval;
/**
* The PID of the organizer that created this TaskFragment. It should be the same as the PID
* of {@link android.window.TaskFragmentCreationParams#getOwnerToken()}.
* {@link ActivityRecord#INVALID_PID} if this is not an organizer-created TaskFragment.
*/
private int mTaskFragmentOrganizerPid = ActivityRecord.INVALID_PID;
final Point mLastSurfaceSize = new Point();
private final Rect mTmpInsets = new Rect();
@@ -338,9 +334,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
mDelayLastActivityRemoval = false;
}
void setTaskFragmentOrganizer(TaskFragmentOrganizerToken organizer, int pid) {
void setTaskFragmentOrganizer(@NonNull TaskFragmentOrganizerToken organizer, int uid,
@NonNull String processName) {
mTaskFragmentOrganizer = ITaskFragmentOrganizer.Stub.asInterface(organizer.asBinder());
mTaskFragmentOrganizerPid = pid;
mTaskFragmentOrganizerUid = uid;
mTaskFragmentOrganizerProcessName = processName;
}
/** Whether this TaskFragment is organized by the given {@code organizer}. */
@@ -2178,9 +2176,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
List<IBinder> childActivities = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
WindowContainer wc = getChildAt(i);
if (mTaskFragmentOrganizerPid != ActivityRecord.INVALID_PID
if (mTaskFragmentOrganizerUid != INVALID_UID
&& wc.asActivityRecord() != null
&& wc.asActivityRecord().getPid() == mTaskFragmentOrganizerPid) {
&& wc.asActivityRecord().info.processName.equals(
mTaskFragmentOrganizerProcessName)
&& wc.asActivityRecord().getUid() == mTaskFragmentOrganizerUid) {
// Only includes Activities that belong to the organizer process for security.
childActivities.add(wc.asActivityRecord().appToken);
}

View File

@@ -1205,8 +1205,8 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
creationParams.getFragmentToken(), true /* createdByOrganizer */);
// Set task fragment organizer immediately, since it might have to be notified about further
// actions.
taskFragment.setTaskFragmentOrganizer(
creationParams.getOrganizer(), ownerActivity.getPid());
taskFragment.setTaskFragmentOrganizer(creationParams.getOrganizer(),
ownerActivity.getUid(), ownerActivity.info.processName);
ownerActivity.getTask().addChild(taskFragment, POSITION_TOP);
taskFragment.setWindowingMode(creationParams.getWindowingMode());
taskFragment.setBounds(creationParams.getInitialBounds());