Allow checking if an activity is organized

Adds an interal method to check if an activity is being organized
by any process. This can be used by WM Jetpack Extensions APIs to
inform apps about their activities being embedded.

Bug: 204399167
Test: Manual, using demo app
Change-Id: I3a0ad021ad43c97bf9b92df05e9858aae143f62b
This commit is contained in:
Andrii Kulian 2021-11-03 19:07:00 -07:00 committed by Charles Chen
parent a5f83144a3
commit bf54c4ad74
5 changed files with 50 additions and 0 deletions

View File

@ -44,4 +44,10 @@ interface ITaskFragmentOrganizerController {
* Unregisters remote animations per transition type for the organizer.
*/
void unregisterRemoteAnimations(in ITaskFragmentOrganizer organizer);
/**
* Checks if an activity organized by a {@link android.window.TaskFragmentOrganizer} and
* only occupies a portion of Task bounds.
*/
boolean isActivityEmbedded(in IBinder activityToken);
}

View File

@ -216,4 +216,17 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
return null;
}
}
/**
* Checks if an activity organized by a {@link android.window.TaskFragmentOrganizer} and
* only occupies a portion of Task bounds.
* @hide
*/
public boolean isActivityEmbedded(@NonNull IBinder activityToken) {
try {
return getController().isActivityEmbedded(activityToken);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}

View File

@ -858,4 +858,12 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
launchingContainer.getTaskFragmentToken());
}
}
/**
* Checks if an activity is embedded and its presentation is customized by a
* {@link android.window.TaskFragmentOrganizer} to only occupy a portion of Task bounds.
*/
public boolean isActivityEmbedded(@NonNull Activity activity) {
return mPresenter.isActivityEmbedded(activity.getActivityToken());
}
}

View File

@ -24,6 +24,7 @@ import static com.android.server.wm.WindowOrganizerController.configurationsAreE
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@ -579,4 +580,26 @@ public class TaskFragmentOrganizerController extends ITaskFragmentOrganizerContr
event.mException);
}
}
// TODO(b/204399167): change to push the embedded state to the client side
@Override
public boolean isActivityEmbedded(IBinder activityToken) {
synchronized (mGlobalLock) {
final ActivityRecord activity = ActivityRecord.forTokenLocked(activityToken);
if (activity == null) {
return false;
}
final TaskFragment taskFragment = activity.getOrganizedTaskFragment();
if (taskFragment == null) {
return false;
}
final Task parentTask = taskFragment.getTask();
if (parentTask != null) {
final Rect taskBounds = parentTask.getBounds();
final Rect taskFragBounds = taskFragment.getBounds();
return !taskBounds.equals(taskFragBounds) && taskBounds.contains(taskFragBounds);
}
return false;
}
}
}