Merge "add @Override for addWindowLayoutInfoListener(context) and update prebuilts." into tm-qpr-dev am: 112fa53798

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19793471

Change-Id: I0c58e847e0fa761852fd17f7d4f670bf5eb8f9cc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
An An Yu
2022-10-07 21:36:29 +00:00
committed by Automerger Merge Worker
2 changed files with 12 additions and 3 deletions

View File

@@ -103,14 +103,23 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent {
/** /**
* Similar to {@link #addWindowLayoutInfoListener(Activity, Consumer)}, but takes a UI Context * Similar to {@link #addWindowLayoutInfoListener(Activity, Consumer)}, but takes a UI Context
* as a parameter. * as a parameter.
*
* Jetpack {@link androidx.window.layout.ExtensionWindowLayoutInfoBackend} makes sure all
* consumers related to the same {@link Context} gets updated {@link WindowLayoutInfo}
* together. However only the first registered consumer of a {@link Context} will actually
* invoke {@link #addWindowLayoutInfoListener(Context, Consumer)}.
* Here we enforce that {@link #addWindowLayoutInfoListener(Context, Consumer)} can only be
* called once for each {@link Context}.
*/ */
// TODO(b/204073440): Add @Override to hook the API in WM extensions library. @Override
public void addWindowLayoutInfoListener(@NonNull @UiContext Context context, public void addWindowLayoutInfoListener(@NonNull @UiContext Context context,
@NonNull Consumer<WindowLayoutInfo> consumer) { @NonNull Consumer<WindowLayoutInfo> consumer) {
if (mWindowLayoutChangeListeners.containsKey(context) if (mWindowLayoutChangeListeners.containsKey(context)
// In theory this method can be called on the same consumer with different context.
|| mWindowLayoutChangeListeners.containsValue(consumer)) { || mWindowLayoutChangeListeners.containsValue(consumer)) {
// Early return if the listener or consumer has been registered. throw new IllegalArgumentException(
return; "Context or Consumer has already been registered for WindowLayoutInfo"
+ " callback.");
} }
if (!context.isUiContext()) { if (!context.isUiContext()) {
throw new IllegalArgumentException("Context must be a UI Context, which should be" throw new IllegalArgumentException("Context must be a UI Context, which should be"