Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterShellArgs;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -37,28 +36,6 @@ public static void enqueueMessageProcessing(
isHighPriority);
}

/**
* Starts the background isolate for the {@link FlutterFirebaseMessagingBackgroundService}.
*
* <p>Preconditions:
*
* <ul>
* <li>The given {@code callbackHandle} must correspond to a registered Dart callback. If the
* handle does not resolve to a Dart callback then this method does nothing.
* <li>A static {@link #pluginRegistrantCallback} must exist, otherwise a {@link
* PluginRegistrantException} will be thrown.
* </ul>
*/
@SuppressWarnings("JavadocReference")
public static void startBackgroundIsolate(long callbackHandle, FlutterShellArgs shellArgs) {
if (flutterBackgroundExecutor != null) {
Log.w(TAG, "Attempted to start a duplicate background isolate. Returning...");
return;
}
flutterBackgroundExecutor = new FlutterFirebaseMessagingBackgroundExecutor();
flutterBackgroundExecutor.startBackgroundIsolate(callbackHandle, shellArgs);
}

/**
* Called once the Dart isolate ({@code flutterBackgroundExecutor}) has finished initializing.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
Expand Down Expand Up @@ -421,12 +420,9 @@ public void onMethodCall(final MethodCall call, @NonNull final Result result) {
Task<?> methodCallTask;

switch (call.method) {
// This message is sent when the Dart side of this plugin is told to initialize.
// In response, this (native) side of the plugin needs to spin up a background
// Dart isolate by using the given pluginCallbackHandle, and then setup a background
// method channel to communicate with the new background isolate. Once completed,
// this onMethodCall() method will receive messages from both the primary and background
// method channels.
// This message is sent when the Dart side of this plugin registers a background
// message handler. We persist the callback handles to SharedPreferences so
// the background service can start the isolate later when a message arrives.
case "Messaging#startBackgroundIsolate":
@SuppressWarnings("unchecked")
Map<String, Object> arguments = ((Map<String, Object>) call.arguments);
Expand Down Expand Up @@ -455,19 +451,13 @@ public void onMethodCall(final MethodCall call, @NonNull final Result result) {
"Expected 'Long' or 'Integer' type for 'userCallbackHandle'.");
}

FlutterShellArgs shellArgs = null;
if (mainActivity != null) {
// Supports both Flutter Activity types:
// io.flutter.embedding.android.FlutterFragmentActivity
// io.flutter.embedding.android.FlutterActivity
// We could use `getFlutterShellArgs()` but this is only available on `FlutterActivity`.
shellArgs = FlutterShellArgs.fromIntent(mainActivity.getIntent());
}

// Only save the callback handles to SharedPreferences. Don't start the
// background isolate here — it will be started lazily in
// FlutterFirebaseMessagingBackgroundService.onCreate() when a background
// message actually arrives and the service is started. Starting it eagerly
// caused a duplicate Dart main() to appear in the call stack (#17163).
FlutterFirebaseMessagingBackgroundService.setCallbackDispatcher(pluginCallbackHandle);
FlutterFirebaseMessagingBackgroundService.setUserCallbackHandle(userCallbackHandle);
FlutterFirebaseMessagingBackgroundService.startBackgroundIsolate(
pluginCallbackHandle, shellArgs);
methodCallTask = Tasks.forResult(null);
break;
case "Messaging#getInitialMessage":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId = "io.flutter.plugins.firebase.messaging.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = 23
minSdkVersion = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName
Expand Down
Loading