Converted ActivityAware and ServiceAware Lifecycles to opaque objects (#43670) (flutter/engine#13402)

This commit is contained in:
Matt Carroll
2019-10-28 21:41:07 -07:00
committed by GitHub
parent 8d75fdac42
commit 63ddf0ce72
6 changed files with 62 additions and 14 deletions

View File

@@ -615,6 +615,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugin
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/contentprovider/ContentProviderAware.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/contentprovider/ContentProviderControlSurface.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/contentprovider/ContentProviderPluginBinding.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/lifecycle/HiddenLifecycleReference.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/service/ServiceAware.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/service/ServiceControlSurface.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/plugins/service/ServicePluginBinding.java

View File

@@ -163,6 +163,7 @@ android_java_sources = [
"io/flutter/embedding/engine/plugins/contentprovider/ContentProviderAware.java",
"io/flutter/embedding/engine/plugins/contentprovider/ContentProviderControlSurface.java",
"io/flutter/embedding/engine/plugins/contentprovider/ContentProviderPluginBinding.java",
"io/flutter/embedding/engine/plugins/lifecycle/HiddenLifecycleReference.java",
"io/flutter/embedding/engine/plugins/service/ServiceAware.java",
"io/flutter/embedding/engine/plugins/service/ServiceControlSurface.java",
"io/flutter/embedding/engine/plugins/service/ServicePluginBinding.java",

View File

@@ -32,6 +32,7 @@ import io.flutter.embedding.engine.plugins.broadcastreceiver.BroadcastReceiverPl
import io.flutter.embedding.engine.plugins.contentprovider.ContentProviderAware;
import io.flutter.embedding.engine.plugins.contentprovider.ContentProviderControlSurface;
import io.flutter.embedding.engine.plugins.contentprovider.ContentProviderPluginBinding;
import io.flutter.embedding.engine.plugins.lifecycle.HiddenLifecycleReference;
import io.flutter.embedding.engine.plugins.service.ServiceAware;
import io.flutter.embedding.engine.plugins.service.ServiceControlSurface;
import io.flutter.embedding.engine.plugins.service.ServicePluginBinding;
@@ -535,7 +536,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
@NonNull
private final Activity activity;
@NonNull
private final Lifecycle lifecycle;
private final HiddenLifecycleReference hiddenLifecycleReference;
@NonNull
private final Set<io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener> onRequestPermissionsResultListeners = new HashSet<>();
@NonNull
@@ -549,7 +550,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
public FlutterEngineActivityPluginBinding(@NonNull Activity activity, @NonNull Lifecycle lifecycle) {
this.activity = activity;
this.lifecycle = lifecycle;
this.hiddenLifecycleReference = new HiddenLifecycleReference(lifecycle);
}
@Override
@@ -560,8 +561,8 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
@NonNull
@Override
public Lifecycle getLifecycle() {
return lifecycle;
public Object getLifecycle() {
return hiddenLifecycleReference;
}
@Override
@@ -685,13 +686,13 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
@NonNull
private final Service service;
@Nullable
private final Lifecycle lifecycle;
private final HiddenLifecycleReference hiddenLifecycleReference;
@NonNull
private final Set<ServiceAware.OnModeChangeListener> onModeChangeListeners = new HashSet<>();
FlutterEngineServicePluginBinding(@NonNull Service service, @Nullable Lifecycle lifecycle) {
this.service = service;
this.lifecycle = lifecycle;
hiddenLifecycleReference = lifecycle != null ? new HiddenLifecycleReference(lifecycle) : null;
}
@Override
@@ -702,8 +703,8 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
@Nullable
@Override
public Lifecycle getLifecycle() {
return lifecycle;
public Object getLifecycle() {
return hiddenLifecycleReference;
}
@Override

View File

@@ -5,7 +5,6 @@
package io.flutter.embedding.engine.plugins.activity;
import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -26,10 +25,17 @@ public interface ActivityPluginBinding {
Activity getActivity();
/**
* Returns the {@link Lifecycle} associated with the attached {@code Activity}.
* Returns the {@code Lifecycle} associated with the attached {@code Activity}.
* <p>
* Use the flutter_plugin_android_lifecycle plugin to turn the returned {@code Object}
* into a {@code Lifecycle} object. See
* (https://github.com/flutter/plugins/tree/master/packages/flutter_plugin_android_lifecycle).
* Flutter plugins that rely on {@code Lifecycle} are forced to use the
* flutter_plugin_android_lifecycle plugin so that the version of the Android Lifecycle library is
* exposed to pub, which allows Flutter to manage different versions library over time.
*/
@NonNull
Lifecycle getLifecycle();
Object getLifecycle();
/**
* Adds a listener that is invoked whenever the associated {@link Activity}'s

View File

@@ -0,0 +1,33 @@
// 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.
package io.flutter.embedding.engine.plugins.lifecycle;
import android.arch.lifecycle.Lifecycle;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
/**
* An {@code Object} that can be used to obtain a {@link Lifecycle} reference.
* <p>
* <strong>DO NOT USE THIS CLASS IN AN APP OR A PLUGIN.</strong>
* <p>
* This class is used by the flutter_android_lifecycle package to provide access to a
* {@link Lifecycle} in a way that makes it easier for Flutter and the Flutter plugin ecosystem to
* handle breaking changes in Lifecycle libraries.
*/
@Keep
public class HiddenLifecycleReference {
@NonNull
private final Lifecycle lifecycle;
public HiddenLifecycleReference(@NonNull Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}
@NonNull
public Lifecycle getLifecycle() {
return lifecycle;
}
}

View File

@@ -5,7 +5,6 @@
package io.flutter.embedding.engine.plugins.service;
import android.app.Service;
import android.arch.lifecycle.Lifecycle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -22,10 +21,17 @@ public interface ServicePluginBinding {
Service getService();
/**
* Returns the {@link Lifecycle} associated with the attached {@code Service}.
* Returns the {@code Lifecycle} associated with the attached {@code Service}.
* <p>
* Use the flutter_plugin_android_lifecycle plugin to turn the returned {@code Object}
* into a {@code Lifecycle} object. See
* (https://github.com/flutter/plugins/tree/master/packages/flutter_plugin_android_lifecycle).
* Flutter plugins that rely on {@code Lifecycle} are forced to use the
* flutter_plugin_android_lifecycle plugin so that the version of the Android Lifecycle library is
* exposed to pub, which allows Flutter to manage different versions library over time.
*/
@Nullable
Lifecycle getLifecycle();
Object getLifecycle();
/**
* Adds the given {@code listener} to be notified when the associated {@link Service} goes