summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-10 17:54:23 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-02-10 17:54:23 -0800
commit4c2d1bb9d7c0d7a02d92bf5e8181bd0fefd553c2 (patch)
tree3d90ba7d8a5a30f286782db4551ebd4dd1864c2c
parent9956306eecb081d9fd72b1a6fa2095a81c5096f1 (diff)
parent9c62414f8d7c528809205790dba0b3973f5873db (diff)
Merge "Refactor how config change is propagated to WindowTokenClient from VRI" into main
-rw-r--r--core/java/android/view/ViewRootImpl.java20
-rw-r--r--core/java/android/window/WindowTokenClient.java1
-rw-r--r--core/java/android/window/WindowTokenClientController.java17
-rw-r--r--core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java21
4 files changed, 48 insertions, 11 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 0d6f82773622..80b4f2caabbb 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -272,9 +272,9 @@ import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.ScreenCapture;
import android.window.SurfaceSyncGroup;
-import android.window.WindowContext;
import android.window.WindowOnBackInvokedDispatcher;
import android.window.WindowTokenClient;
+import android.window.WindowTokenClientController;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -6614,12 +6614,15 @@ public final class ViewRootImpl implements ViewParent,
} else {
if (enableWindowContextResourcesUpdateOnConfigChange()) {
// There is no activity callback - update resources for window token, if needed.
- final WindowTokenClient windowTokenClient = getWindowTokenClient();
- if (windowTokenClient != null) {
- windowTokenClient.onConfigurationChanged(
+ final IBinder windowContextToken = mContext.getWindowContextToken();
+ if (windowContextToken instanceof WindowTokenClient) {
+ WindowTokenClientController.getInstance().onWindowConfigurationChanged(
+ windowContextToken,
mLastReportedMergedConfiguration.getMergedConfiguration(),
- newDisplayId == INVALID_DISPLAY ? mDisplay.getDisplayId()
- : newDisplayId);
+ newDisplayId == INVALID_DISPLAY
+ ? mDisplay.getDisplayId()
+ : newDisplayId
+ );
}
}
updateConfiguration(newDisplayId);
@@ -6627,11 +6630,6 @@ public final class ViewRootImpl implements ViewParent,
mForceNextConfigUpdate = false;
}
- private WindowTokenClient getWindowTokenClient() {
- if (!(mContext instanceof WindowContext)) return null;
- return (WindowTokenClient) mContext.getWindowContextToken();
- }
-
/**
* Update display and views if last applied merged configuration changed.
* @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} otherwise.
diff --git a/core/java/android/window/WindowTokenClient.java b/core/java/android/window/WindowTokenClient.java
index f7bee619bc4b..5a544d3549a0 100644
--- a/core/java/android/window/WindowTokenClient.java
+++ b/core/java/android/window/WindowTokenClient.java
@@ -107,6 +107,7 @@ public class WindowTokenClient extends Binder {
* @param newDisplayId the updated {@link android.view.Display} ID
*/
@MainThread
+ @VisibleForTesting(visibility = PACKAGE)
public void onConfigurationChanged(Configuration newConfig, int newDisplayId) {
onConfigurationChanged(newConfig, newDisplayId, true /* shouldReportConfigChange */);
}
diff --git a/core/java/android/window/WindowTokenClientController.java b/core/java/android/window/WindowTokenClientController.java
index fcd7dfbb1769..72278d927d74 100644
--- a/core/java/android/window/WindowTokenClientController.java
+++ b/core/java/android/window/WindowTokenClientController.java
@@ -25,7 +25,9 @@ import android.app.IApplicationThread;
import android.app.servertransaction.WindowContextInfoChangeItem;
import android.app.servertransaction.WindowContextWindowRemovalItem;
import android.content.Context;
+import android.content.res.Configuration;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.ArraySet;
@@ -50,6 +52,7 @@ public class WindowTokenClientController {
private final Object mLock = new Object();
private final IApplicationThread mAppThread = ActivityThread.currentActivityThread()
.getApplicationThread();
+ private final Handler mHandler = ActivityThread.currentActivityThread().getHandler();
/** Attached {@link WindowTokenClient}. */
@GuardedBy("mLock")
@@ -257,6 +260,20 @@ public class WindowTokenClientController {
}
}
+ /** Propagates the configuration change to the client token. */
+ public void onWindowConfigurationChanged(@NonNull IBinder clientToken,
+ @NonNull Configuration config, int displayId) {
+ final WindowTokenClient windowTokenClient = getWindowTokenClientIfAttached(clientToken);
+ if (windowTokenClient != null) {
+ // Let's make sure it's called on the main thread!
+ if (mHandler.getLooper().isCurrentThread()) {
+ windowTokenClient.onConfigurationChanged(config, displayId);
+ } else {
+ windowTokenClient.postOnConfigurationChanged(config, displayId);
+ }
+ }
+ }
+
@Nullable
private WindowTokenClient getWindowTokenClientIfAttached(@NonNull IBinder clientToken) {
if (!(clientToken instanceof WindowTokenClient windowTokenClient)) {
diff --git a/core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java b/core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java
index 84ff40f0dcf0..116dc124c902 100644
--- a/core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java
+++ b/core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java
@@ -266,4 +266,25 @@ public class WindowTokenClientControllerTest {
verify(mWindowTokenClient).onWindowTokenRemoved();
}
+
+ @Test
+ public void testOnWindowConfigurationChanged_propagatedToCorrectToken() throws RemoteException {
+ doReturn(mWindowContextInfo).when(mWindowManagerService)
+ .attachWindowContextToDisplayContent(any(), any(), anyInt());
+
+ mController.onWindowConfigurationChanged(mWindowTokenClient, mConfiguration,
+ DEFAULT_DISPLAY + 1);
+
+ // Not propagated before attaching
+ verify(mWindowTokenClient, never()).onConfigurationChanged(mConfiguration,
+ DEFAULT_DISPLAY + 1);
+
+ assertTrue(mController.attachToDisplayContent(mWindowTokenClient, DEFAULT_DISPLAY));
+
+ mController.onWindowConfigurationChanged(mWindowTokenClient, mConfiguration,
+ DEFAULT_DISPLAY + 1);
+
+ // Now that's attached, propagating it.
+ verify(mWindowTokenClient).postOnConfigurationChanged(mConfiguration, DEFAULT_DISPLAY + 1);
+ }
}