Merge "Add a dedicated method to check task windowing mode" into tm-qpr-dev am: 945dbc0427

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19223678

Change-Id: Ib724bc4fb67162962502026e38c37f67d17cf622
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Andrii Kulian
2022-07-19 03:22:03 +00:00
committed by Automerger Merge Worker
4 changed files with 64 additions and 46 deletions

View File

@@ -226,6 +226,18 @@ public class ActivityClient {
} }
} }
/**
* Returns the windowing mode of the task that hosts the activity, or {@code -1} if task is not
* found.
*/
public int getTaskWindowingMode(IBinder activityToken) {
try {
return getActivityClientController().getTaskWindowingMode(activityToken);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** /**
* Returns the non-finishing activity token below in the same task if it belongs to the same * Returns the non-finishing activity token below in the same task if it belongs to the same
* process. * process.

View File

@@ -78,6 +78,7 @@ interface IActivityClientController {
boolean willActivityBeVisible(in IBinder token); boolean willActivityBeVisible(in IBinder token);
int getDisplayId(in IBinder activityToken); int getDisplayId(in IBinder activityToken);
int getTaskForActivity(in IBinder token, in boolean onlyRoot); int getTaskForActivity(in IBinder token, in boolean onlyRoot);
int getTaskWindowingMode(in IBinder activityToken);
IBinder getActivityTokenBelow(IBinder token); IBinder getActivityTokenBelow(IBinder token);
ComponentName getCallingActivity(in IBinder token); ComponentName getCallingActivity(in IBinder token);
String getCallingPackage(in IBinder token); String getCallingPackage(in IBinder token);

View File

@@ -25,8 +25,7 @@ import static androidx.window.util.ExtensionHelper.transformToWindowSpaceRect;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityClient;
import android.app.ActivityManager.AppTask;
import android.app.Application; import android.app.Application;
import android.app.WindowConfiguration; import android.app.WindowConfiguration;
import android.content.Context; import android.content.Context;
@@ -34,7 +33,6 @@ import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.window.common.CommonFoldingFeature; import androidx.window.common.CommonFoldingFeature;
@@ -179,57 +177,49 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
private List<DisplayFeature> getDisplayFeatures( private List<DisplayFeature> getDisplayFeatures(
@NonNull Activity activity, List<CommonFoldingFeature> storedFeatures) { @NonNull Activity activity, List<CommonFoldingFeature> storedFeatures) {
List<DisplayFeature> features = new ArrayList<>(); List<DisplayFeature> features = new ArrayList<>();
int displayId = activity.getDisplay().getDisplayId(); if (!shouldReportDisplayFeatures(activity)) {
if (displayId != DEFAULT_DISPLAY) {
Log.w(TAG, "This sample doesn't support display features on secondary displays");
return features;
} else if (isTaskInMultiWindowMode(activity)) {
// It is recommended not to report any display features in multi-window mode, since it
// won't be possible to synchronize the display feature positions with window movement.
return features;
} else {
for (CommonFoldingFeature baseFeature : storedFeatures) {
Integer state = convertToExtensionState(baseFeature.getState());
if (state == null) {
continue;
}
Rect featureRect = baseFeature.getRect();
rotateRectToDisplayRotation(displayId, featureRect);
transformToWindowSpaceRect(activity, featureRect);
if (!isRectZero(featureRect)) {
// TODO(b/228641877) Remove guarding if when fixed.
features.add(new FoldingFeature(featureRect, baseFeature.getType(), state));
}
}
return features; return features;
} }
int displayId = activity.getDisplay().getDisplayId();
for (CommonFoldingFeature baseFeature : storedFeatures) {
Integer state = convertToExtensionState(baseFeature.getState());
if (state == null) {
continue;
}
Rect featureRect = baseFeature.getRect();
rotateRectToDisplayRotation(displayId, featureRect);
transformToWindowSpaceRect(activity, featureRect);
if (!isRectZero(featureRect)) {
// TODO(b/228641877): Remove guarding when fixed.
features.add(new FoldingFeature(featureRect, baseFeature.getType(), state));
}
}
return features;
} }
/** /**
* Checks whether the task associated with the activity is in multi-window. If task info is not * Checks whether display features should be reported for the activity.
* available it defaults to {@code true}. * TODO(b/238948678): Support reporting display features in all windowing modes.
*/ */
private boolean isTaskInMultiWindowMode(@NonNull Activity activity) { private boolean shouldReportDisplayFeatures(@NonNull Activity activity) {
final ActivityManager am = activity.getSystemService(ActivityManager.class); int displayId = activity.getDisplay().getDisplayId();
if (am == null) { if (displayId != DEFAULT_DISPLAY) {
return true; // Display features are not supported on secondary displays.
return false;
} }
final int taskWindowingMode = ActivityClient.getInstance().getTaskWindowingMode(
final List<AppTask> appTasks = am.getAppTasks(); activity.getActivityToken());
final int taskId = activity.getTaskId(); if (taskWindowingMode == -1) {
AppTask task = null; // If we cannot determine the task windowing mode for any reason, it is likely that we
for (AppTask t : appTasks) { // won't be able to determine its position correctly as well. DisplayFeatures' bounds
if (t.getTaskInfo().taskId == taskId) { // in this case can't be computed correctly, so we should skip.
task = t; return false;
break;
}
} }
if (task == null) { // It is recommended not to report any display features in multi-window mode, since it
// The task might be removed on the server already. // won't be possible to synchronize the display feature positions with window movement.
return true; return !WindowConfiguration.inMultiWindowMode(taskWindowingMode);
}
return WindowConfiguration.inMultiWindowMode(task.getTaskInfo().getWindowingMode());
} }
/** /**

View File

@@ -577,6 +577,21 @@ class ActivityClientController extends IActivityClientController.Stub {
} }
} }
/**
* Returns the windowing mode of the task that hosts the activity, or {@code -1} if task is not
* found.
*/
@Override
public int getTaskWindowingMode(IBinder activityToken) {
synchronized (mGlobalLock) {
final ActivityRecord ar = ActivityRecord.isInAnyTask(activityToken);
if (ar == null) {
return -1;
}
return ar.getTask().getWindowingMode();
}
}
@Override @Override
@Nullable @Nullable
public IBinder getActivityTokenBelow(IBinder activityToken) { public IBinder getActivityTokenBelow(IBinder activityToken) {