From 93e6dbe5ab0f45d7b6b132c5e1a8d73964388ba7 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Wed, 24 Nov 2021 11:41:40 -0800 Subject: [PATCH] Bump androidx.window:window-java (flutter/engine#29897) --- DEPS | 2 +- .../embedding/android/FlutterView.java | 22 ++++---- ...wInfoRepositoryCallbackAdapterWrapper.java | 22 ++++---- .../embedding/android/FlutterViewTest.java | 4 +- .../platform/android/test_runner/build.gradle | 2 +- engine/src/flutter/tools/androidx/files.json | 4 +- .../cipd/android_embedding_bundle/README.md | 52 ++----------------- .../android_embedding_bundle/build.gradle | 2 +- .../cipd/android_embedding_bundle/generate.sh | 29 +++++++++++ 9 files changed, 65 insertions(+), 74 deletions(-) create mode 100755 engine/src/flutter/tools/cipd/android_embedding_bundle/generate.sh diff --git a/DEPS b/DEPS index 1624574770..bf4fbd52bf 100644 --- a/DEPS +++ b/DEPS @@ -526,7 +526,7 @@ deps = { 'packages': [ { 'package': 'flutter/android/embedding_bundle', - 'version': 'last_updated:2021-11-03T10:29:50-0700' + 'version': 'last_updated:2021-11-23T12:31:07-0800' } ], 'condition': 'download_android_deps', diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 3bfd377710..36a18ad226 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -38,12 +38,12 @@ import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; import androidx.core.util.Consumer; -import androidx.window.java.layout.WindowInfoRepositoryCallbackAdapter; +import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter; import androidx.window.layout.DisplayFeature; import androidx.window.layout.FoldingFeature; import androidx.window.layout.FoldingFeature.OcclusionType; import androidx.window.layout.FoldingFeature.State; -import androidx.window.layout.WindowInfoRepository; +import androidx.window.layout.WindowInfoTracker; import androidx.window.layout.WindowLayoutInfo; import io.flutter.Log; import io.flutter.embedding.engine.FlutterEngine; @@ -454,8 +454,8 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC protected WindowInfoRepositoryCallbackAdapterWrapper createWindowInfoRepo() { try { return new WindowInfoRepositoryCallbackAdapterWrapper( - new WindowInfoRepositoryCallbackAdapter( - WindowInfoRepository.getOrCreate((Activity) getContext()))); + new WindowInfoTrackerCallbackAdapter( + WindowInfoTracker.getOrCreate((Activity) getContext()))); } catch (NoClassDefFoundError noClassDefFoundError) { // Testing environment uses gn/javac, which does not work with aar files. This is why aar // are converted to jar files, losing resources and other android-specific files. @@ -470,7 +470,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC /** * Invoked when this is attached to the window. * - *

We register for {@link androidx.window.layout.WindowInfoRepository} updates. + *

We register for {@link androidx.window.layout.WindowInfoTracker} updates. */ @Override protected void onAttachedToWindow() { @@ -478,14 +478,14 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC this.windowInfoRepo = createWindowInfoRepo(); if (windowInfoRepo != null) { windowInfoRepo.addWindowLayoutInfoListener( - ContextCompat.getMainExecutor(getContext()), windowInfoListener); + (Activity) getContext(), ContextCompat.getMainExecutor(getContext()), windowInfoListener); } } /** * Invoked when this is detached from the window. * - *

We unregister from {@link androidx.window.layout.WindowInfoRepository} updates. + *

We unregister from {@link androidx.window.layout.WindowInfoTracker} updates. */ @Override protected void onDetachedFromWindow() { @@ -497,20 +497,20 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC } /** - * Refresh {@link androidx.window.layout.WindowInfoRepository} and {@link - * android.view.DisplayCutout} display features. Fold, hinge and cutout areas are populated here. + * Refresh {@link androidx.window.layout.WindowInfoTracker} and {@link android.view.DisplayCutout} + * display features. Fold, hinge and cutout areas are populated here. */ @TargetApi(28) protected void setWindowInfoListenerDisplayFeatures(WindowLayoutInfo layoutInfo) { List displayFeatures = layoutInfo.getDisplayFeatures(); List result = new ArrayList<>(); - // Data from WindowInfoRepository display features. Fold and hinge areas are + // Data from WindowInfoTracker display features. Fold and hinge areas are // populated here. for (DisplayFeature displayFeature : displayFeatures) { Log.v( TAG, - "WindowInfoRepository Display Feature reported with bounds = " + "WindowInfoTracker Display Feature reported with bounds = " + displayFeature.getBounds().toString() + " and type = " + displayFeature.getClass().getSimpleName()); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java index 3d5bc3043d..9ffd3191ae 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/WindowInfoRepositoryCallbackAdapterWrapper.java @@ -4,27 +4,31 @@ package io.flutter.embedding.android; +import android.app.Activity; +import androidx.annotation.NonNull; import androidx.core.util.Consumer; -import androidx.window.java.layout.WindowInfoRepositoryCallbackAdapter; +import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter; import androidx.window.layout.WindowLayoutInfo; import java.util.concurrent.Executor; -/** - * Wraps {@link WindowInfoRepositoryCallbackAdapter} in order to be able to mock it during testing. - */ +/** Wraps {@link WindowInfoTrackerCallbackAdapter} in order to be able to mock it during testing. */ public class WindowInfoRepositoryCallbackAdapterWrapper { - final WindowInfoRepositoryCallbackAdapter adapter; + @NonNull final WindowInfoTrackerCallbackAdapter adapter; - public WindowInfoRepositoryCallbackAdapterWrapper(WindowInfoRepositoryCallbackAdapter adapter) { + public WindowInfoRepositoryCallbackAdapterWrapper( + @NonNull WindowInfoTrackerCallbackAdapter adapter) { this.adapter = adapter; } - public void addWindowLayoutInfoListener(Executor executor, Consumer consumer) { - adapter.addWindowLayoutInfoListener(executor, consumer); + public void addWindowLayoutInfoListener( + @NonNull Activity activity, + @NonNull Executor executor, + @NonNull Consumer consumer) { + adapter.addWindowLayoutInfoListener(activity, executor, consumer); } - public void removeWindowLayoutInfoListener(Consumer consumer) { + public void removeWindowLayoutInfoListener(@NonNull Consumer consumer) { adapter.removeWindowLayoutInfoListener(consumer); } } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java index 87660ded83..721f28d7da 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java @@ -652,7 +652,7 @@ public class FlutterViewTest { flutterView.onAttachedToWindow(); // Then the WindowManager callback is registered - verify(windowInfoRepo, times(1)).addWindowLayoutInfoListener(any(), any()); + verify(windowInfoRepo, times(1)).addWindowLayoutInfoListener(any(), any(), any()); // When the FlutterView is detached from the window flutterView.onDetachedFromWindow(); @@ -695,7 +695,7 @@ public class FlutterViewTest { flutterView.onAttachedToWindow(); ArgumentCaptor> wmConsumerCaptor = ArgumentCaptor.forClass((Class) Consumer.class); - verify(windowInfoRepo).addWindowLayoutInfoListener(any(), wmConsumerCaptor.capture()); + verify(windowInfoRepo).addWindowLayoutInfoListener(any(), any(), wmConsumerCaptor.capture()); Consumer wmConsumer = wmConsumerCaptor.getValue(); wmConsumer.accept(testWindowLayout); diff --git a/engine/src/flutter/shell/platform/android/test_runner/build.gradle b/engine/src/flutter/shell/platform/android/test_runner/build.gradle index 0fe346a39a..10945a98a4 100644 --- a/engine/src/flutter/shell/platform/android/test_runner/build.gradle +++ b/engine/src/flutter/shell/platform/android/test_runner/build.gradle @@ -43,7 +43,7 @@ android { testImplementation "androidx.lifecycle:lifecycle-common-java8:2.2.0" testImplementation "androidx.test:core:1.4.0" testImplementation "androidx.tracing:tracing:1.0.0" - testImplementation "androidx.window:window-java:1.0.0-beta03" + testImplementation "androidx.window:window-java:1.0.0-beta04" testImplementation "com.google.android.play:core:1.8.0" testImplementation "com.ibm.icu:icu4j:69.1" testImplementation "org.mockito:mockito-core:3.11.2" diff --git a/engine/src/flutter/tools/androidx/files.json b/engine/src/flutter/tools/androidx/files.json index 07410fb298..2c055ebbb4 100644 --- a/engine/src/flutter/tools/androidx/files.json +++ b/engine/src/flutter/tools/androidx/files.json @@ -67,9 +67,9 @@ ] }, { - "url": "https://maven.google.com/androidx/window/window-java/1.0.0-beta03/window-java-1.0.0-beta03.aar", + "url": "https://maven.google.com/androidx/window/window-java/1.0.0-beta04/window-java-1.0.0-beta04.aar", "out_file_name": "androidx_window_java.aar", - "maven_dependency": "androidx.window:window-java:1.0.0-beta03", + "maven_dependency": "androidx.window:window-java:1.0.0-beta04", "provides": [ "androidx.window.java.layout.WindowInfoRepositoryCallbackAdapter", "androidx.window.layout.DisplayFeature", diff --git a/engine/src/flutter/tools/cipd/android_embedding_bundle/README.md b/engine/src/flutter/tools/cipd/android_embedding_bundle/README.md index 01d5fb7551..3370bfc16e 100644 --- a/engine/src/flutter/tools/cipd/android_embedding_bundle/README.md +++ b/engine/src/flutter/tools/cipd/android_embedding_bundle/README.md @@ -7,50 +7,8 @@ ## Steps -To update the embedding dependencies, just `cd` into this directory, -modify the dependencies in `build.gradle` and run `gradle updateDependencies`. - -Once you have updated the dependencies, you can upload a new version by running -`cipd create --pkg-def cipd.yaml`. For more, see the Chromium instructions on ["Updating a CIPD -dependency"](https://chromium.googlesource.com/chromium/src/+/main/docs/cipd_and_3pp.md#Updating-a-CIPD-dependency) for how to upload a package update to CIPD. - -On successful upload, you will receive a hash for the upload such as - -`cipd: successfully uploaded and verified flutter/android/embedding_bundle:NZvE-rL3E66nHQZb5Vyl9-1Y_1MWEX7KURgOHqX2cYcC` - -Let's further annotate the new upload with the current timestamp. - - $ cipd set-tag flutter/android/embedding_bundle --version= -tag=last_updated: - -Example of a last-updated timestamp: 2019-07-29T15:27:42-0700 - -You can generate the same date format with `date +%Y-%m-%dT%T%z`. - -You can run `cipd describe flutter/android/embedding_bundle ---version=` to verify. You should see: - -``` -Package: flutter/android/embedding_bundle -Instance ID: -... -Tags: - last_updated: -``` - -Then update the `DEPS` file (located at /src/flutter/DEPS) to use the new version by pointing to -your new `last_updated_at` tag. - -``` - 'src/third_party/android_embedding_dependencies': { - 'packages': [ - { - 'package': 'flutter/android/embedding_bundle', - 'version': 'last_updated:' - } - ], - 'condition': 'download_android_deps', - 'dep_type': 'cipd', - }, -``` - -You can now re-run `gclient sync` to fetch the latest package version. +1. `cd` into this directory. +2. Update the dependency in build.gradle. +3. Update the dependency used in Android unit tests `shell/platform/android/test_runner/build.gradle` +4. Run `./generate.sh`. +5. Update tools/androidx/files.json. (This file includes the Maven dependencies used to build Flutter apps). diff --git a/engine/src/flutter/tools/cipd/android_embedding_bundle/build.gradle b/engine/src/flutter/tools/cipd/android_embedding_bundle/build.gradle index 73388cc23d..f98a4ce450 100644 --- a/engine/src/flutter/tools/cipd/android_embedding_bundle/build.gradle +++ b/engine/src/flutter/tools/cipd/android_embedding_bundle/build.gradle @@ -44,7 +44,7 @@ android { embedding "androidx.core:core:1.6.0" embedding "androidx.fragment:fragment:1.1.0" embedding "androidx.tracing:tracing:1.0.0" - embedding "androidx.window:window-java:1.0.0-beta03" + embedding "androidx.window:window-java:1.0.0-beta04" def lifecycle_version = "2.2.0" embedding "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" diff --git a/engine/src/flutter/tools/cipd/android_embedding_bundle/generate.sh b/engine/src/flutter/tools/cipd/android_embedding_bundle/generate.sh new file mode 100755 index 0000000000..bf20190719 --- /dev/null +++ b/engine/src/flutter/tools/cipd/android_embedding_bundle/generate.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -e + +gradle updateDependencies + +version_tag=`date +%Y-%m-%dT%T%z` + +cipd create --pkg-def cipd.yaml -tag last_updated:"$version_tag" + +echo "" +echo "Update the dependency in the DEPS file:" +echo "" +echo "'src/third_party/android_embedding_dependencies': {" +echo " 'packages': [" +echo " {" +echo " 'package': 'flutter/android/embedding_bundle'," +echo " 'version': 'last_updated:$version_tag'" +echo " }" +echo " ]," +echo " 'condition': 'download_android_deps'," +echo " 'dep_type': 'cipd'," +echo "}" +echo "" +echo "Run gclient sync"