Skip to content
Snippets Groups Projects
Commit b1deb554 authored by Diego Vela's avatar Diego Vela
Browse files

Report folding features to letterboxed apps.

Letterboxed apps lost support for Folding Features. We are enabling
reporting folding features to letterboxed apps again.
Report folding features if an Activity is embedded or not in
PiP.

Bug: 295785410
Test: atest CtsWindowManagerJetpackTestCases
Merged-In: Ib964b22278c31982a3d6bf66abaab3dac0c4093b
Change-Id: Ib964b22278c31982a3d6bf66abaab3dac0c4093b
parent 40ba3002
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,6 @@ package androidx.window.extensions;
import android.app.ActivityThread;
import android.app.Application;
import android.content.Context;
import android.window.TaskFragmentOrganizer;
import androidx.annotation.NonNull;
import androidx.window.common.DeviceStateManagerFoldingFeatureProducer;
......@@ -81,13 +80,7 @@ public class WindowExtensionsImpl implements WindowExtensions {
Context context = getApplication();
DeviceStateManagerFoldingFeatureProducer producer =
getFoldingFeatureProducer();
// TODO(b/263263909) Use the organizer to tell if an Activity is embededed.
// Need to improve our Dependency Injection and centralize the logic.
TaskFragmentOrganizer organizer = new TaskFragmentOrganizer(command -> {
throw new RuntimeException("Not allowed!");
});
mWindowLayoutComponent = new WindowLayoutComponentImpl(context, organizer,
producer);
mWindowLayoutComponent = new WindowLayoutComponentImpl(context, producer);
}
}
}
......
......@@ -25,7 +25,6 @@ import static androidx.window.util.ExtensionHelper.rotateRectToDisplayRotation;
import static androidx.window.util.ExtensionHelper.transformToWindowSpaceRect;
import android.app.Activity;
import android.app.ActivityClient;
import android.app.Application;
import android.app.WindowConfiguration;
import android.content.ComponentCallbacks;
......@@ -35,8 +34,6 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.os.IBinder;
import android.util.ArrayMap;
import android.view.WindowManager;
import android.window.TaskFragmentOrganizer;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
......@@ -52,7 +49,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
......@@ -86,16 +82,12 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
private final Map<java.util.function.Consumer<WindowLayoutInfo>, Consumer<WindowLayoutInfo>>
mJavaToExtConsumers = new ArrayMap<>();
private final TaskFragmentOrganizer mTaskFragmentOrganizer;
public WindowLayoutComponentImpl(@NonNull Context context,
@NonNull TaskFragmentOrganizer taskFragmentOrganizer,
@NonNull DeviceStateManagerFoldingFeatureProducer foldingFeatureProducer) {
((Application) context.getApplicationContext())
.registerActivityLifecycleCallbacks(new NotifyOnConfigurationChanged());
mFoldingFeatureProducer = foldingFeatureProducer;
mFoldingFeatureProducer.addDataChangedCallback(this::onDisplayFeaturesChanged);
mTaskFragmentOrganizer = taskFragmentOrganizer;
}
/** Registers to listen to {@link CommonFoldingFeature} changes */
......@@ -383,38 +375,11 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
// Display features are not supported on secondary displays.
return false;
}
final int windowingMode;
IBinder activityToken = context.getActivityToken();
if (activityToken != null) {
final Configuration taskConfig = ActivityClient.getInstance().getTaskConfiguration(
activityToken);
if (taskConfig == null) {
// If we cannot determine the task configuration for any reason, it is likely that
// we won't be able to determine its position correctly as well. DisplayFeatures'
// bounds in this case can't be computed correctly, so we should skip.
return false;
}
final Rect taskBounds = taskConfig.windowConfiguration.getBounds();
final WindowManager windowManager = Objects.requireNonNull(
context.getSystemService(WindowManager.class));
final Rect maxBounds = windowManager.getMaximumWindowMetrics().getBounds();
boolean isTaskExpanded = maxBounds.equals(taskBounds);
/*
* We need to proxy being in full screen because when a user enters PiP and exits PiP
* the task windowingMode will report multi-window/pinned until the transition is
* finished in WM Shell.
* maxBounds == taskWindowBounds is a proxy check to verify the window is full screen
*/
return isTaskExpanded;
} else {
// TODO(b/242674941): use task windowing mode for window context that associates with
// activity.
windowingMode = context.getResources().getConfiguration().windowConfiguration
.getWindowingMode();
}
// 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 !WindowConfiguration.inMultiWindowMode(windowingMode);
// We do not report folding features for Activities in PiP because the bounds are
// not updated fast enough and the window is too small for the UI to adapt.
return context.getResources().getConfiguration().windowConfiguration
.getWindowingMode() != WindowConfiguration.WINDOWING_MODE_PINNED;
}
@GuardedBy("mLock")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment