Merge "Revert "Fix testRegisterComponentCallbacksOnWindowContext flaky"" into tm-dev

This commit is contained in:
Charles Chen
2022-04-22 04:33:20 +00:00
committed by Android (Google) Code Review
6 changed files with 18 additions and 49 deletions

View File

@@ -165,11 +165,10 @@ public abstract class WindowProviderService extends Service implements WindowPro
} }
} }
// Suppress the lint because ths is overridden from Context.
@SuppressLint("OnNameExpected") @SuppressLint("OnNameExpected")
@Override @Override
@Nullable // Suppress the lint because ths is overridden from Context.
public Object getSystemService(@NonNull String name) { public @Nullable Object getSystemService(@NonNull String name) {
if (WINDOW_SERVICE.equals(name)) { if (WINDOW_SERVICE.equals(name)) {
return mWindowManager; return mWindowManager;
} }

View File

@@ -91,6 +91,7 @@ public class WindowTokenClient extends IWindowToken.Stub {
throw new IllegalStateException("Context is already attached."); throw new IllegalStateException("Context is already attached.");
} }
mContextRef = new WeakReference<>(context); mContextRef = new WeakReference<>(context);
mConfiguration.setTo(context.getResources().getConfiguration());
mShouldDumpConfigForIme = Build.IS_DEBUGGABLE mShouldDumpConfigForIme = Build.IS_DEBUGGABLE
&& context instanceof AbstractInputMethodService; && context instanceof AbstractInputMethodService;
} }
@@ -111,8 +112,7 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (configuration == null) { if (configuration == null) {
return false; return false;
} }
mHandler.runWithScissors(() -> onConfigurationChanged(configuration, displayId, onConfigurationChanged(configuration, displayId, false /* shouldReportConfigChange */);
false /* shouldReportConfigChange */), 0 /* timeout */);
mAttachToWindowContainer = true; mAttachToWindowContainer = true;
return true; return true;
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -137,8 +137,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (configuration == null) { if (configuration == null) {
return false; return false;
} }
mHandler.runWithScissors(() -> onConfigurationChanged(configuration, displayId, mHandler.post(() -> onConfigurationChanged(configuration, displayId,
false /* shouldReportConfigChange */), 0 /* timeout */); false /* shouldReportConfigChange */));
mAttachToWindowContainer = true; mAttachToWindowContainer = true;
return true; return true;
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@@ -637,20 +637,13 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
} }
void registerConfigurationChangeListener(ConfigurationContainerListener listener) { void registerConfigurationChangeListener(ConfigurationContainerListener listener) {
registerConfigurationChangeListener(listener, true /* shouldDispatchConfig */);
}
void registerConfigurationChangeListener(ConfigurationContainerListener listener,
boolean shouldDispatchConfig) {
if (mChangeListeners.contains(listener)) { if (mChangeListeners.contains(listener)) {
return; return;
} }
mChangeListeners.add(listener); mChangeListeners.add(listener);
if (shouldDispatchConfig) {
listener.onRequestedOverrideConfigurationChanged(mResolvedOverrideConfiguration); listener.onRequestedOverrideConfigurationChanged(mResolvedOverrideConfiguration);
listener.onMergedOverrideConfigurationChanged(mMergedOverrideConfiguration); listener.onMergedOverrideConfigurationChanged(mMergedOverrideConfiguration);
} }
}
void unregisterConfigurationChangeListener(ConfigurationContainerListener listener) { void unregisterConfigurationChangeListener(ConfigurationContainerListener listener) {
mChangeListeners.remove(listener); mChangeListeners.remove(listener);

View File

@@ -3747,21 +3747,14 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
} }
void registerWindowContainerListener(WindowContainerListener listener) { void registerWindowContainerListener(WindowContainerListener listener) {
registerWindowContainerListener(listener, true /* shouldPropConfig */);
}
void registerWindowContainerListener(WindowContainerListener listener,
boolean shouldDispatchConfig) {
if (mListeners.contains(listener)) { if (mListeners.contains(listener)) {
return; return;
} }
mListeners.add(listener); mListeners.add(listener);
// Also register to ConfigurationChangeListener to receive configuration changes. // Also register to ConfigurationChangeListener to receive configuration changes.
registerConfigurationChangeListener(listener, shouldDispatchConfig); registerConfigurationChangeListener(listener);
if (shouldDispatchConfig) {
listener.onDisplayChanged(getDisplayContent()); listener.onDisplayChanged(getDisplayContent());
} }
}
void unregisterWindowContainerListener(WindowContainerListener listener) { void unregisterWindowContainerListener(WindowContainerListener listener) {
mListeners.remove(listener); mListeners.remove(listener);

View File

@@ -68,16 +68,6 @@ class WindowContextListenerController {
@VisibleForTesting @VisibleForTesting
final ArrayMap<IBinder, WindowContextListenerImpl> mListeners = new ArrayMap<>(); 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 * Registers the listener to a {@code container} which is associated with
* a {@code clientToken}, which is a {@link android.window.WindowContext} representation. If the * a {@code clientToken}, which is a {@link android.window.WindowContext} representation. If the
@@ -90,18 +80,15 @@ class WindowContextListenerController {
* @param ownerUid the caller UID * @param ownerUid the caller UID
* @param type the window type * @param type the window type
* @param options a bundle used to pass window-related options. * @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, void registerWindowContainerListener(@NonNull IBinder clientToken,
@NonNull WindowContainer<?> container, int ownerUid, @WindowType int type, @NonNull WindowContainer<?> container, int ownerUid, @WindowType int type,
@Nullable Bundle options, boolean shouDispatchConfigWhenRegistering) { @Nullable Bundle options) {
WindowContextListenerImpl listener = mListeners.get(clientToken); WindowContextListenerImpl listener = mListeners.get(clientToken);
if (listener == null) { if (listener == null) {
listener = new WindowContextListenerImpl(clientToken, container, ownerUid, type, listener = new WindowContextListenerImpl(clientToken, container, ownerUid, type,
options); options);
listener.register(shouDispatchConfigWhenRegistering); listener.register();
} else { } else {
listener.updateContainer(container); listener.updateContainer(container);
} }
@@ -241,16 +228,12 @@ class WindowContextListenerController {
} }
private void register() { private void register() {
register(true /* shouldDispatchConfig */);
}
private void register(boolean shouldDispatchConfig) {
final IBinder token = mClientToken.asBinder(); final IBinder token = mClientToken.asBinder();
if (mDeathRecipient == null) { if (mDeathRecipient == null) {
throw new IllegalStateException("Invalid client token: " + token); throw new IllegalStateException("Invalid client token: " + token);
} }
mListeners.putIfAbsent(token, this); mListeners.putIfAbsent(token, this);
mContainer.registerWindowContainerListener(this, shouldDispatchConfig); mContainer.registerWindowContainerListener(this);
} }
private void unregister() { private void unregister() {

View File

@@ -2770,10 +2770,12 @@ public class WindowManagerService extends IWindowManager.Stub
} }
// TODO(b/155340867): Investigate if we still need roundedCornerOverlay after // TODO(b/155340867): Investigate if we still need roundedCornerOverlay after
// the feature b/155340867 is completed. // the feature b/155340867 is completed.
final DisplayArea<?> da = dc.findAreaForWindowType(type, options, final DisplayArea da = dc.findAreaForWindowType(type, options,
callerCanManageAppTokens, false /* roundedCornerOverlay */); callerCanManageAppTokens, false /* roundedCornerOverlay */);
// TODO(b/190019118): Avoid to send onConfigurationChanged because it has been done
// in return value of attachWindowContextToDisplayArea.
mWindowContextListenerController.registerWindowContainerListener(clientToken, da, mWindowContextListenerController.registerWindowContainerListener(clientToken, da,
callingUid, type, options, false /* shouDispatchConfigWhenRegistering */); callingUid, type, options);
return da.getConfiguration(); return da.getConfiguration();
} }
} finally { } finally {
@@ -2869,8 +2871,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
mWindowContextListenerController.registerWindowContainerListener(clientToken, dc, mWindowContextListenerController.registerWindowContainerListener(clientToken, dc,
callingUid, INVALID_WINDOW_TYPE, null /* options */, callingUid, INVALID_WINDOW_TYPE, null /* options */);
false /* shouDispatchConfigWhenRegistering */);
return dc.getConfiguration(); return dc.getConfiguration();
} }
} finally { } finally {