Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -535,7 +536,7 @@ private static class FlutterEngineActivityPluginBinding implements ActivityPlugi
@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
Expand All @@ -549,7 +550,7 @@ private static class FlutterEngineActivityPluginBinding implements ActivityPlugi

public FlutterEngineActivityPluginBinding(@NonNull Activity activity, @NonNull Lifecycle lifecycle) {
this.activity = activity;
this.lifecycle = lifecycle;
this.hiddenLifecycleReference = new HiddenLifecycleReference(lifecycle);
}

@Override
Expand All @@ -560,8 +561,8 @@ public Activity getActivity() {

@NonNull
@Override
public Lifecycle getLifecycle() {
return lifecycle;
public Object getLifecycle() {
return hiddenLifecycleReference;
}

@Override
Expand Down Expand Up @@ -685,13 +686,13 @@ private static class FlutterEngineServicePluginBinding implements ServicePluginB
@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
Expand All @@ -702,8 +703,8 @@ public Service getService() {

@Nullable
@Override
public Lifecycle getLifecycle() {
return lifecycle;
public Object getLifecycle() {
return hiddenLifecycleReference;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link?

Also describe that the purpose is to get a Lifecyle version compatible with the engine. Since the target audience is the plugin developer here, we can probably mention that this should match the Lifecycle version they declare in pub.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down