Loading core/java/android/view/ViewRootImpl.java +9 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading @@ -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. Loading core/java/android/window/WindowTokenClient.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 */); } Loading core/java/android/window/WindowTokenClientController.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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") Loading Loading @@ -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)) { Loading core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading
core/java/android/view/ViewRootImpl.java +9 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading @@ -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. Loading
core/java/android/window/WindowTokenClient.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 */); } Loading
core/java/android/window/WindowTokenClientController.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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") Loading Loading @@ -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)) { Loading
core/tests/coretests/src/android/window/WindowTokenClientControllerTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } }