Skip to content

Commit

Permalink
[many] More v1 embedding deletion that was missed in #6494 (#6923)
Browse files Browse the repository at this point in the history
There were some additional v1 Android embedding references missed by #6494.

This PR aims to remove those missed references.

I built the android example app of each plugin affected here on the [deletion branch](flutter/engine#52022) to be completely sure:

Final testing, I tested that the `all_packages` app builds on the v1 embedding deletion branch: 
```
$ ./.ci/scripts/create_all_packages_app.sh && cd all_packages
...
$ flutter build apk --debug --local-engine-src-path=/Users/mackall/development/engine/src --local-engine=android_debug_arm64 --local-engine-host=host_debug

Running Gradle task 'assembleDebug'...                              4.8s
� Built build/app/outputs/flutter-apk/app-debug.apk
```

� 

Linux repo checks are failing 
```
The following packages had errors:
  packages/google_maps_flutter/google_maps_flutter:
    Missing CHANGELOG change
  packages/palette_generator:
    Missing CHANGELOG change
  packages/quick_actions/quick_actions:
    Missing CHANGELOG change
  packages/webview_flutter/webview_flutter:
    Missing CHANGELOG change
```
The only changes to these packages are `xml` changes to example apps which won't cause build failures even when the v1 embedding is deleted (they will just be unused). So I believe these changes should be version exempt.
  • Loading branch information
gmackall authored Jun 20, 2024
1 parent 5ba990b commit b135e2a
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 191 deletions.
4 changes: 4 additions & 0 deletions packages/espresso/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0+10

* Removes additional references to v1 Android embedding.

## 0.3.0+9

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nonnull;
import okhttp3.OkHttpClient;
import org.hamcrest.Matcher;

Expand Down Expand Up @@ -97,14 +98,19 @@ public String getDescription() {

@ExperimentalTestApi
@Override
public void perform(UiController uiController, View flutterView) {
public void perform(UiController uiController, View view) {
checkNotNull(view, "The Flutter View instance cannot be null.");
if (!(view instanceof FlutterView)) {
throw new FlutterProtocolException(
String.format("This is not a Flutter View instance [id: %d].", view.getId()));
}
FlutterView flutterView = (FlutterView) view;
// There could be a gap between when the Flutter view is available in the view hierarchy and the
// engine & Dart isolates are actually up and running. Check whether the first frame has been
// rendered before proceeding in an unblocking way.
loopUntilFlutterViewRendered(flutterView, uiController);
// The url {@code FlutterNativeView} returns is the http url that the Dart VM Observatory http
// server serves at. Need to convert to the one that the WebSocket uses.

URI dartVmServiceProtocolUrl =
DartVmServiceUtil.getServiceProtocolUri(FlutterJNI.getVMServiceUri());
String isolateId = DartVmServiceUtil.getDartIsolateId(flutterView);
Expand Down Expand Up @@ -171,7 +177,8 @@ public T waitUntilCompleted(long timeout, TimeUnit unit)
return resultFuture.get(timeout, unit);
}

private static void loopUntilFlutterViewRendered(View flutterView, UiController uiController) {
private static void loopUntilFlutterViewRendered(
@Nonnull FlutterView flutterView, UiController uiController) {
FlutterViewRenderedIdlingResource idlingResource =
new FlutterViewRenderedIdlingResource(flutterView);
try {
Expand All @@ -188,31 +195,22 @@ private static void loopUntilFlutterViewRendered(View flutterView, UiController
*/
static final class FlutterViewRenderedIdlingResource implements IdlingResource {

private final View flutterView;
private final FlutterView flutterView;
// Written from main thread, read from any thread.
private volatile ResourceCallback resourceCallback;

FlutterViewRenderedIdlingResource(View flutterView) {
this.flutterView = checkNotNull(flutterView);
FlutterViewRenderedIdlingResource(@Nonnull FlutterView flutterView) {
this.flutterView = flutterView;
}

@Override
public String getName() {
return FlutterViewRenderedIdlingResource.class.getSimpleName();
}

@SuppressWarnings("deprecation")
@Override
public boolean isIdleNow() {
boolean isIdle = false;
if (flutterView instanceof FlutterView) {
isIdle = ((FlutterView) flutterView).hasRenderedFirstFrame();
} else if (flutterView instanceof io.flutter.view.FlutterView) {
isIdle = ((io.flutter.view.FlutterView) flutterView).hasRenderedFirstFrame();
} else {
throw new FlutterProtocolException(
String.format("This is not a Flutter View instance [id: %d].", flutterView.getId()));
}
boolean isIdle = flutterView.hasRenderedFirstFrame();
if (isIdle) {
resourceCallback.onTransitionToIdle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* action that's performed via Flutter engine. It's supposed to be used for complex interactions or
* those that are brittle if performed through Android system. Most of the actions should be
* associated with a {@link WidgetMatcher}, but some may not, e.g. an action that checks the
* rendering status of the entire {@link io.flutter.view.FlutterView}.
* rendering status of the entire {@link io.flutter.embedding.android.FlutterView}.
*/
@Beta
public abstract class SyntheticAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

package androidx.test.espresso.flutter.internal.protocol.impl;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import android.util.Log;
import android.view.View;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.annotation.Nonnull;

/** Util class for dealing with Dart VM service protocols. */
public final class DartVmServiceUtil {
Expand Down Expand Up @@ -59,8 +59,7 @@ public static URI getServiceProtocolUri(String observatoryUrl) {
}

/** Gets the Dart isolate ID for the given {@code flutterView}. */
public static String getDartIsolateId(View flutterView) {
checkNotNull(flutterView, "The Flutter View instance cannot be null.");
public static String getDartIsolateId(FlutterView flutterView) {
String uiIsolateId = getDartExecutor(flutterView).getIsolateServiceId();
Log.d(
TAG,
Expand All @@ -71,25 +70,13 @@ public static String getDartIsolateId(View flutterView) {
}

/** Gets the Dart executor for the given {@code flutterView}. */
@SuppressWarnings("deprecation")
public static DartExecutor getDartExecutor(View flutterView) {
checkNotNull(flutterView, "The Flutter View instance cannot be null.");
// Flutter's embedding is in the phase of rewriting/refactoring. Let's be compatible with both
// the old and the new FlutterView classes.
if (flutterView instanceof io.flutter.view.FlutterView) {
return ((io.flutter.view.FlutterView) flutterView).getDartExecutor();
} else if (flutterView instanceof io.flutter.embedding.android.FlutterView) {
FlutterEngine flutterEngine =
((io.flutter.embedding.android.FlutterView) flutterView).getAttachedFlutterEngine();
if (flutterEngine == null) {
throw new FlutterProtocolException(
String.format(
"No Flutter engine attached to the Flutter view [id: %d].", flutterView.getId()));
}
return flutterEngine.getDartExecutor();
} else {
public static DartExecutor getDartExecutor(@Nonnull FlutterView flutterView) {
FlutterEngine flutterEngine = flutterView.getAttachedFlutterEngine();
if (flutterEngine == null) {
throw new FlutterProtocolException(
String.format("This is not a Flutter View instance [id: %d].", flutterView.getId()));
String.format(
"No Flutter engine attached to the Flutter view [id: %d].", flutterView.getId()));
}
return flutterEngine.getDartExecutor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ public void describeTo(Description description) {
description.appendText("is a FlutterView");
}

@SuppressWarnings("deprecation")
@Override
public boolean matchesSafely(View flutterView) {
return flutterView instanceof FlutterView
|| (flutterView instanceof io.flutter.view.FlutterView);
return flutterView instanceof FlutterView;
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/espresso/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Java classes for testing Flutter apps using Espresso.
Allows driving Flutter widgets from a native Espresso test.
repository: https://github.com/flutter/packages/tree/main/packages/espresso
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+espresso%22
version: 0.3.0+9
version: 0.3.0+10

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.1.26

* Removes additional references to the v1 Android embedding.

## 6.1.25

* Updates Guava to version 33.2.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public void initInstance(
GoogleSignInApi.setup(messenger, delegate);
}

@VisibleForTesting
@SuppressWarnings("deprecation")
public void setUpRegistrar(@NonNull PluginRegistry.Registrar registrar) {
delegate.setUpRegistrar(registrar);
}

private void dispose() {
delegate = null;
if (messenger != null) {
Expand Down Expand Up @@ -346,9 +340,6 @@ public static class Delegate
private static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games";

private final @NonNull Context context;
// Only set registrar for v1 embedder.
@SuppressWarnings("deprecation")
private PluginRegistry.Registrar registrar;
// Only set activity for v2 embedder. Always access activity from getActivity() method.
private @Nullable Activity activity;
// TODO(stuartmorgan): See whether this can be replaced with background channels.
Expand All @@ -364,19 +355,13 @@ public Delegate(@NonNull Context context, @NonNull GoogleSignInWrapper googleSig
this.googleSignInWrapper = googleSignInWrapper;
}

@SuppressWarnings("deprecation")
public void setUpRegistrar(@NonNull PluginRegistry.Registrar registrar) {
this.registrar = registrar;
registrar.addActivityResultListener(this);
}

public void setActivity(@Nullable Activity activity) {
this.activity = activity;
}

// Only access activity with this method.
public @Nullable Activity getActivity() {
return registrar != null ? registrar.activity() : activity;
return activity;
}

private void checkAndSetPendingOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.tasks.Task;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -48,24 +49,19 @@ public class GoogleSignInLegacyMethodChannelTest {
@Mock GoogleSignInAccount account;
@Mock GoogleSignInClient mockClient;
@Mock Task<GoogleSignInAccount> mockSignInTask;

@SuppressWarnings("deprecation")
@Mock
PluginRegistry.Registrar mockRegistrar;
@Mock ActivityPluginBinding mockActivityPluginBinding;

private GoogleSignInPlugin plugin;
private AutoCloseable mockCloseable;

@Before
public void setUp() {
mockCloseable = MockitoAnnotations.openMocks(this);
when(mockRegistrar.messenger()).thenReturn(mockMessenger);
when(mockRegistrar.context()).thenReturn(mockContext);
when(mockRegistrar.activity()).thenReturn(mockActivity);
when(mockContext.getResources()).thenReturn(mockResources);
when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);
plugin = new GoogleSignInPlugin();
plugin.initInstance(mockRegistrar.messenger(), mockRegistrar.context(), mockGoogleSignIn);
plugin.setUpRegistrar(mockRegistrar);
plugin.initInstance(mockMessenger, mockContext, mockGoogleSignIn);
plugin.onAttachedToActivity(mockActivityPluginBinding);
}

@After
Expand Down Expand Up @@ -124,7 +120,7 @@ public void requestScopes_ReturnsFalseIfPermissionDenied() {

ArgumentCaptor<PluginRegistry.ActivityResultListener> captor =
ArgumentCaptor.forClass(PluginRegistry.ActivityResultListener.class);
verify(mockRegistrar).addActivityResultListener(captor.capture());
verify(mockActivityPluginBinding).addActivityResultListener(captor.capture());
PluginRegistry.ActivityResultListener listener = captor.getValue();

when(mockGoogleSignIn.getLastSignedInAccount(mockContext)).thenReturn(account);
Expand All @@ -149,7 +145,7 @@ public void requestScopes_ReturnsTrueIfPermissionGranted() {

ArgumentCaptor<PluginRegistry.ActivityResultListener> captor =
ArgumentCaptor.forClass(PluginRegistry.ActivityResultListener.class);
verify(mockRegistrar).addActivityResultListener(captor.capture());
verify(mockActivityPluginBinding).addActivityResultListener(captor.capture());
PluginRegistry.ActivityResultListener listener = captor.getValue();

when(mockGoogleSignIn.getLastSignedInAccount(mockContext)).thenReturn(account);
Expand All @@ -172,7 +168,7 @@ public void requestScopes_mayBeCalledRepeatedly_ifAlreadyGranted() {

ArgumentCaptor<PluginRegistry.ActivityResultListener> captor =
ArgumentCaptor.forClass(PluginRegistry.ActivityResultListener.class);
verify(mockRegistrar).addActivityResultListener(captor.capture());
verify(mockActivityPluginBinding).addActivityResultListener(captor.capture());
PluginRegistry.ActivityResultListener listener = captor.getValue();

when(mockGoogleSignIn.getLastSignedInAccount(mockContext)).thenReturn(account);
Expand All @@ -198,7 +194,7 @@ public void requestScopes_mayBeCalledRepeatedly_ifNotSignedIn() {

ArgumentCaptor<PluginRegistry.ActivityResultListener> captor =
ArgumentCaptor.forClass(PluginRegistry.ActivityResultListener.class);
verify(mockRegistrar).addActivityResultListener(captor.capture());
verify(mockActivityPluginBinding).addActivityResultListener(captor.capture());
PluginRegistry.ActivityResultListener listener = captor.getValue();

when(mockGoogleSignIn.getLastSignedInAccount(mockContext)).thenReturn(null);
Expand Down
Loading

0 comments on commit b135e2a

Please sign in to comment.