summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Diego Vela <diegovela@google.com> 2023-09-15 21:27:06 +0000
committer Diego Vela <diegovela@google.com> 2023-09-22 16:46:36 +0000
commit1a7c2f292e7cc1fddfc9b0c64d1e5e4264f60144 (patch)
tree517f283b6320bd9b4ceece5fce2a06337cc9b37d /libs
parentb1deb55446c3b5a2d46cc2751ac0200ef5986fa2 (diff)
Add raw configuration change listener updates.
Add raw configuration change listener updates. Letterboxed Activities do not receive a configuration update when they are repositioned. Listening to all configuration changes will correctly update folding features. Change exceptions from hard exceptions to Log.wtf so that we do not crash on production apps. Bug: 295785410 Test: Open Samples and open the slim (letterbox) Activities. Merged-In: Ia079d06a403a59bb0f1eafdaad6ce238749a2af2 Change-Id: Ia079d06a403a59bb0f1eafdaad6ce238749a2af2
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java39
1 files changed, 35 insertions, 4 deletions
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java
index 6130fa456476..becd0020a157 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java
@@ -25,6 +25,7 @@ import static androidx.window.util.ExtensionHelper.rotateRectToDisplayRotation;
import static androidx.window.util.ExtensionHelper.transformToWindowSpaceRect;
import android.app.Activity;
+import android.app.ActivityThread;
import android.app.Application;
import android.app.WindowConfiguration;
import android.content.ComponentCallbacks;
@@ -34,6 +35,7 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.os.IBinder;
import android.util.ArrayMap;
+import android.util.Log;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
@@ -60,7 +62,7 @@ import java.util.Set;
* Please refer to {@link androidx.window.sidecar.SampleSidecarImpl} instead.
*/
public class WindowLayoutComponentImpl implements WindowLayoutComponent {
- private static final String TAG = "SampleExtension";
+ private static final String TAG = WindowLayoutComponentImpl.class.getSimpleName();
private final Object mLock = new Object();
@@ -82,6 +84,9 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
private final Map<java.util.function.Consumer<WindowLayoutInfo>, Consumer<WindowLayoutInfo>>
mJavaToExtConsumers = new ArrayMap<>();
+ private final RawConfigurationChangedListener mRawConfigurationChangedListener =
+ new RawConfigurationChangedListener();
+
public WindowLayoutComponentImpl(@NonNull Context context,
@NonNull DeviceStateManagerFoldingFeatureProducer foldingFeatureProducer) {
((Application) context.getApplicationContext())
@@ -110,6 +115,7 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
final Consumer<WindowLayoutInfo> extConsumer = consumer::accept;
synchronized (mLock) {
mJavaToExtConsumers.put(consumer, extConsumer);
+ updateListenerRegistrations();
}
addWindowLayoutInfoListener(activity, extConsumer);
}
@@ -163,6 +169,7 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
final Consumer<WindowLayoutInfo> extConsumer;
synchronized (mLock) {
extConsumer = mJavaToExtConsumers.remove(consumer);
+ updateListenerRegistrations();
}
if (extConsumer != null) {
removeWindowLayoutInfoListener(extConsumer);
@@ -193,6 +200,17 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
}
@GuardedBy("mLock")
+ private void updateListenerRegistrations() {
+ ActivityThread currentThread = ActivityThread.currentActivityThread();
+ if (mJavaToExtConsumers.isEmpty()) {
+ currentThread.removeConfigurationChangedListener(mRawConfigurationChangedListener);
+ } else {
+ currentThread.addConfigurationChangedListener(Runnable::run,
+ mRawConfigurationChangedListener);
+ }
+ }
+
+ @GuardedBy("mLock")
@NonNull
private Set<Context> getContextsListeningForLayoutChanges() {
return mWindowLayoutChangeListeners.keySet();
@@ -337,25 +355,28 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
continue;
}
if (featureRect.left != 0 && featureRect.top != 0) {
- throw new IllegalArgumentException("Bounding rectangle must start at the top or "
+ Log.wtf(TAG, "Bounding rectangle must start at the top or "
+ "left of the window. BaseFeatureRect: " + baseFeature.getRect()
+ ", FeatureRect: " + featureRect
+ ", WindowConfiguration: " + windowConfiguration);
+ continue;
}
if (featureRect.left == 0
&& featureRect.width() != windowConfiguration.getBounds().width()) {
- throw new IllegalArgumentException("Horizontal FoldingFeature must have full width."
+ Log.wtf(TAG, "Horizontal FoldingFeature must have full width."
+ " BaseFeatureRect: " + baseFeature.getRect()
+ ", FeatureRect: " + featureRect
+ ", WindowConfiguration: " + windowConfiguration);
+ continue;
}
if (featureRect.top == 0
&& featureRect.height() != windowConfiguration.getBounds().height()) {
- throw new IllegalArgumentException("Vertical FoldingFeature must have full height."
+ Log.wtf(TAG, "Vertical FoldingFeature must have full height."
+ " BaseFeatureRect: " + baseFeature.getRect()
+ ", FeatureRect: " + featureRect
+ ", WindowConfiguration: " + windowConfiguration);
+ continue;
}
features.add(new FoldingFeature(featureRect, baseFeature.getType(), state));
}
@@ -408,6 +429,16 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
}
}
+ private final class RawConfigurationChangedListener implements
+ java.util.function.Consumer<IBinder> {
+ @Override
+ public void accept(IBinder activityToken) {
+ synchronized (mLock) {
+ onDisplayFeaturesChangedIfListening(activityToken);
+ }
+ }
+ }
+
private final class ConfigurationChangeListener implements ComponentCallbacks {
final IBinder mToken;