summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Charles Chen <charlesccchen@google.com> 2022-04-21 13:17:16 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-04-21 13:17:16 +0000
commit257ac41d75dd92963bf1e8ab93e5283d07f57cef (patch)
tree016c2da9c94cb9f68cf6b8abac2000cb29d341d2
parentf97c045a8b61b56f7067443f80e1328d93489155 (diff)
parent4a649744d89071ed0242a901b4ea7158e2194e3a (diff)
Merge "Fix testRegisterComponentCallbacksOnWindowContext flaky" into tm-dev am: db7b4503f3 am: 4a649744d8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17799887 Change-Id: Icc3d67ee5a67179a4940cafa4acdfafe1acda926 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--core/java/android/window/WindowProviderService.java5
-rw-r--r--core/java/android/window/WindowTokenClient.java8
-rw-r--r--services/core/java/com/android/server/wm/ConfigurationContainer.java11
-rw-r--r--services/core/java/com/android/server/wm/WindowContainer.java11
-rw-r--r--services/core/java/com/android/server/wm/WindowContextListenerController.java23
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java9
6 files changed, 49 insertions, 18 deletions
diff --git a/core/java/android/window/WindowProviderService.java b/core/java/android/window/WindowProviderService.java
index f8484d15344e..2d2c8de72646 100644
--- a/core/java/android/window/WindowProviderService.java
+++ b/core/java/android/window/WindowProviderService.java
@@ -165,10 +165,11 @@ public abstract class WindowProviderService extends Service implements WindowPro
}
}
+ // Suppress the lint because ths is overridden from Context.
@SuppressLint("OnNameExpected")
@Override
- // Suppress the lint because ths is overridden from Context.
- public @Nullable Object getSystemService(@NonNull String name) {
+ @Nullable
+ public Object getSystemService(@NonNull String name) {
if (WINDOW_SERVICE.equals(name)) {
return mWindowManager;
}
diff --git a/core/java/android/window/WindowTokenClient.java b/core/java/android/window/WindowTokenClient.java
index 547535d90e5a..b0be0df80b29 100644
--- a/core/java/android/window/WindowTokenClient.java
+++ b/core/java/android/window/WindowTokenClient.java
@@ -91,7 +91,6 @@ public class WindowTokenClient extends IWindowToken.Stub {
throw new IllegalStateException("Context is already attached.");
}
mContextRef = new WeakReference<>(context);
- mConfiguration.setTo(context.getResources().getConfiguration());
mShouldDumpConfigForIme = Build.IS_DEBUGGABLE
&& context instanceof AbstractInputMethodService;
}
@@ -112,7 +111,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (configuration == null) {
return false;
}
- onConfigurationChanged(configuration, displayId, false /* shouldReportConfigChange */);
+ mHandler.runWithScissors(() -> onConfigurationChanged(configuration, displayId,
+ false /* shouldReportConfigChange */), 0 /* timeout */);
mAttachToWindowContainer = true;
return true;
} catch (RemoteException e) {
@@ -137,8 +137,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (configuration == null) {
return false;
}
- mHandler.post(() -> onConfigurationChanged(configuration, displayId,
- false /* shouldReportConfigChange */));
+ mHandler.runWithScissors(() -> onConfigurationChanged(configuration, displayId,
+ false /* shouldReportConfigChange */), 0 /* timeout */);
mAttachToWindowContainer = true;
return true;
} catch (RemoteException e) {
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainer.java b/services/core/java/com/android/server/wm/ConfigurationContainer.java
index dbc08cd5d1a9..e7c03aa7a099 100644
--- a/services/core/java/com/android/server/wm/ConfigurationContainer.java
+++ b/services/core/java/com/android/server/wm/ConfigurationContainer.java
@@ -637,12 +637,19 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
}
void registerConfigurationChangeListener(ConfigurationContainerListener listener) {
+ registerConfigurationChangeListener(listener, true /* shouldDispatchConfig */);
+ }
+
+ void registerConfigurationChangeListener(ConfigurationContainerListener listener,
+ boolean shouldDispatchConfig) {
if (mChangeListeners.contains(listener)) {
return;
}
mChangeListeners.add(listener);
- listener.onRequestedOverrideConfigurationChanged(mResolvedOverrideConfiguration);
- listener.onMergedOverrideConfigurationChanged(mMergedOverrideConfiguration);
+ if (shouldDispatchConfig) {
+ listener.onRequestedOverrideConfigurationChanged(mResolvedOverrideConfiguration);
+ listener.onMergedOverrideConfigurationChanged(mMergedOverrideConfiguration);
+ }
}
void unregisterConfigurationChangeListener(ConfigurationContainerListener listener) {
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 82a00b255241..60188f56f5bb 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -3747,13 +3747,20 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
}
void registerWindowContainerListener(WindowContainerListener listener) {
+ registerWindowContainerListener(listener, true /* shouldPropConfig */);
+ }
+
+ void registerWindowContainerListener(WindowContainerListener listener,
+ boolean shouldDispatchConfig) {
if (mListeners.contains(listener)) {
return;
}
mListeners.add(listener);
// Also register to ConfigurationChangeListener to receive configuration changes.
- registerConfigurationChangeListener(listener);
- listener.onDisplayChanged(getDisplayContent());
+ registerConfigurationChangeListener(listener, shouldDispatchConfig);
+ if (shouldDispatchConfig) {
+ listener.onDisplayChanged(getDisplayContent());
+ }
}
void unregisterWindowContainerListener(WindowContainerListener listener) {
diff --git a/services/core/java/com/android/server/wm/WindowContextListenerController.java b/services/core/java/com/android/server/wm/WindowContextListenerController.java
index 7956a112539e..912fdb2e32af 100644
--- a/services/core/java/com/android/server/wm/WindowContextListenerController.java
+++ b/services/core/java/com/android/server/wm/WindowContextListenerController.java
@@ -69,6 +69,16 @@ class WindowContextListenerController {
final ArrayMap<IBinder, WindowContextListenerImpl> mListeners = new ArrayMap<>();
/**
+ * @see #registerWindowContainerListener(IBinder, WindowContainer, int, int, Bundle, boolean)
+ */
+ void registerWindowContainerListener(@NonNull IBinder clientToken,
+ @NonNull WindowContainer<?> container, int ownerUid, @WindowType int type,
+ @Nullable Bundle options) {
+ registerWindowContainerListener(clientToken, container, ownerUid, type, options,
+ true /* shouDispatchConfigWhenRegistering */);
+ }
+
+ /**
* Registers the listener to a {@code container} which is associated with
* a {@code clientToken}, which is a {@link android.window.WindowContext} representation. If the
* listener associated with {@code clientToken} hasn't been initialized yet, create one
@@ -80,15 +90,18 @@ class WindowContextListenerController {
* @param ownerUid the caller UID
* @param type the window type
* @param options a bundle used to pass window-related options.
+ * @param shouDispatchConfigWhenRegistering {@code true} to indicate the current
+ * {@code container}'s config will dispatch to the client side when
+ * registering the {@link WindowContextListenerImpl}
*/
void registerWindowContainerListener(@NonNull IBinder clientToken,
@NonNull WindowContainer<?> container, int ownerUid, @WindowType int type,
- @Nullable Bundle options) {
+ @Nullable Bundle options, boolean shouDispatchConfigWhenRegistering) {
WindowContextListenerImpl listener = mListeners.get(clientToken);
if (listener == null) {
listener = new WindowContextListenerImpl(clientToken, container, ownerUid, type,
options);
- listener.register();
+ listener.register(shouDispatchConfigWhenRegistering);
} else {
listener.updateContainer(container);
}
@@ -228,12 +241,16 @@ class WindowContextListenerController {
}
private void register() {
+ register(true /* shouldDispatchConfig */);
+ }
+
+ private void register(boolean shouldDispatchConfig) {
final IBinder token = mClientToken.asBinder();
if (mDeathRecipient == null) {
throw new IllegalStateException("Invalid client token: " + token);
}
mListeners.putIfAbsent(token, this);
- mContainer.registerWindowContainerListener(this);
+ mContainer.registerWindowContainerListener(this, shouldDispatchConfig);
}
private void unregister() {
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 4a3e37d6187a..b45961953dcf 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -2759,12 +2759,10 @@ public class WindowManagerService extends IWindowManager.Stub
}
// TODO(b/155340867): Investigate if we still need roundedCornerOverlay after
// the feature b/155340867 is completed.
- final DisplayArea da = dc.findAreaForWindowType(type, options,
+ final DisplayArea<?> da = dc.findAreaForWindowType(type, options,
callerCanManageAppTokens, false /* roundedCornerOverlay */);
- // TODO(b/190019118): Avoid to send onConfigurationChanged because it has been done
- // in return value of attachWindowContextToDisplayArea.
mWindowContextListenerController.registerWindowContainerListener(clientToken, da,
- callingUid, type, options);
+ callingUid, type, options, false /* shouDispatchConfigWhenRegistering */);
return da.getConfiguration();
}
} finally {
@@ -2860,7 +2858,8 @@ public class WindowManagerService extends IWindowManager.Stub
}
mWindowContextListenerController.registerWindowContainerListener(clientToken, dc,
- callingUid, INVALID_WINDOW_TYPE, null /* options */);
+ callingUid, INVALID_WINDOW_TYPE, null /* options */,
+ false /* shouDispatchConfigWhenRegistering */);
return dc.getConfiguration();
}
} finally {