Repository: flutter
Issue: [FlutterEngine] Android `BroadcastReceiverControlSurface#attachToBroadcastReceiver` declares useless parameter, `Lifecycle`
Labels: platform-android,engine,e: embedder,P2,team-android,triaged-android

`BroadcastReceiverControlSurface` declares a method: [`void attachToBroadcastReceiver(
      @NonNull BroadcastReceiver broadcastReceiver, @NonNull Lifecycle lifecycle);`](https://github.com/flutter/engine/blob/47a8b6226e1ac8a05f3d043bcda9a73cf3757f4c/shell/platform/android/io/flutter/embedding/engine/plugins/broadcastreceiver/BroadcastReceiverControlSurface.java#L32-L34)

[`FlutterEngineConnectionRegistry` implements it](https://github.com/flutter/engine/blob/47a8b6226e1ac8a05f3d043bcda9a73cf3757f4c/shell/platform/android/io/flutter/embedding/engine/FlutterEngineConnectionRegistry.java#L543-L561), but unfortunately it doesn't use `lifecycle at all`:
```java
  @Override
  public void attachToBroadcastReceiver(
      @NonNull BroadcastReceiver broadcastReceiver, @NonNull Lifecycle lifecycle) {
    Log.v(TAG, "Attaching to BroadcastReceiver: " + broadcastReceiver);
    // If we were already attached to an Android component, detach from it.
    detachFromAppComponent();

    this.broadcastReceiver = broadcastReceiver;
    this.broadcastReceiverPluginBinding =
        new FlutterEngineBroadcastReceiverPluginBinding(broadcastReceiver);
    // TODO(mattcarroll): resolve possibility of different lifecycles between this and engine
    // attachment

    // Notify all BroadcastReceiverAware plugins that they are now attached to a new
    // BroadcastReceiver.
    for (BroadcastReceiverAware broadcastReceiverAware : broadcastReceiverAwarePlugins.values()) {
      broadcastReceiverAware.onAttachedToBroadcastReceiver(broadcastReceiverPluginBinding);
    }
  }
```

@matthew-carroll, you added a TODO saying: `resolve possibility of different lifecycles between this and engine attachment`. BroadcastReceiver's aren't LifecycleOwners, there is no way to get a lifecycle, unless I create a my own, which would be pretty useless for Flutter IMHO. This was your PR: https://github.com/flutter/engine/pull/8962 ([code](https://github.com/flutter/engine/pull/8962/files#diff))

**Can you confirm this was a mistake.** You may have copy and pasted the same comment from another implementation: `attachToContentProvider`:
```java
  public void attachToContentProvider(
      @NonNull ContentProvider contentProvider, @NonNull Lifecycle lifecycle) {
    Log.v(TAG, "Attaching to ContentProvider: " + contentProvider);
    // If we were already attached to an Android component, detach from it.
    detachFromAppComponent();

    this.contentProvider = contentProvider;
    this.contentProviderPluginBinding =
        new FlutterEngineContentProviderPluginBinding(contentProvider);
    // TODO(mattcarroll): resolve possibility of different lifecycles between this and engine
    // attachment
```

## Solution

I think we should create a function overload with only 1 parameter: `BroadcastReceiver`, and deprecate this existing method. Or even just remove it completely, because it never made sense for `BroadcastReceiver`s. 

I'm happy to create a PR for this.

## More information about [Lifecycle](https://developer.android.com/reference/androidx/lifecycle/Lifecycle)

> Defines an object that has an Android Lifecycle. Fragment and FragmentActivity classes implement LifecycleOwner interface which has the getLifecycle method to access the Lifecycle. You can also implement LifecycleOwner in your own classes.