Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kroikie committed Jul 29, 2019
1 parent fb18e66 commit 46a36a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage;

import io.flutter.plugin.common.JSONMethodCodec;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -122,9 +121,12 @@ public void onMethodCall(final MethodCall call, final Result result) {
Log.e(TAG, "There was an exception when getting callback handle from dart side");
e.printStackTrace();
}
FlutterFirebaseMessagingService.setBackgroundSetupHandle(this.registrar.context(), callbackHandle);
FlutterFirebaseMessagingService.startBackgroundIsolate(this.registrar.context(), callbackHandle);
FlutterFirebaseMessagingService.setBackgroundMessageHandle(this.registrar.context(), onMessageHandle);
FlutterFirebaseMessagingService.setBackgroundSetupHandle(
this.registrar.context(), callbackHandle);
FlutterFirebaseMessagingService.startBackgroundIsolate(
this.registrar.context(), callbackHandle);
FlutterFirebaseMessagingService.setBackgroundMessageHandle(
this.registrar.context(), onMessageHandle);
result.success(true);
} else if ("FcmDartService.initialized".equals(call.method)) {
FlutterFirebaseMessagingService.onInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
import android.os.Handler;
import android.os.Process;
import android.util.Log;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterCallbackInformation;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterRunArguments;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -26,13 +30,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterCallbackInformation;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterRunArguments;

public class FlutterFirebaseMessagingService extends FirebaseMessagingService {

public static final String ACTION_REMOTE_MESSAGE =
Expand All @@ -44,7 +41,8 @@ public class FlutterFirebaseMessagingService extends FirebaseMessagingService {

private static final String SHARED_PREFERENCES_KEY = "io.flutter.android_fcm_plugin";
private static final String BACKGROUND_SETUP_CALLBACK_HANDLE_KEY = "background_setup_callback";
private static final String BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY = "background_message_callback";
private static final String BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY =
"background_message_callback";

// TODO(kroikie): make sIsIsolateRunning per-instance, not static.
private static AtomicBoolean sIsIsolateRunning = new AtomicBoolean(false);
Expand All @@ -56,7 +54,8 @@ public class FlutterFirebaseMessagingService extends FirebaseMessagingService {

private static Long sBackgroundMessageHandle;

private static List<RemoteMessage> sBackgroundMessageQueue = Collections.synchronizedList(new LinkedList<RemoteMessage>());
private static List<RemoteMessage> sBackgroundMessageQueue =
Collections.synchronizedList(new LinkedList<RemoteMessage>());

private static PluginRegistry.PluginRegistrantCallback sPluginRegistrantCallback;

Expand Down Expand Up @@ -105,8 +104,8 @@ public void onMessageReceived(final RemoteMessage remoteMessage) {
new Runnable() {
@Override
public void run() {
Log.d(TAG, "executing dart callback");
executeDartCallbackInBackgroundIsolate(FlutterFirebaseMessagingService.this, remoteMessage, latch);
executeDartCallbackInBackgroundIsolate(
FlutterFirebaseMessagingService.this, remoteMessage, latch);
}
});
try {
Expand Down Expand Up @@ -199,16 +198,15 @@ public static void setBackgroundSetupHandle(Context context, long callbackHandle
}

public static Long getOnMessageCallbackHandle(Context context) {
return context.getSharedPreferences(SHARED_PREFERENCES_KEY, 0)
return context
.getSharedPreferences(SHARED_PREFERENCES_KEY, 0)
.getLong(BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY, 0);
}

private static void executeDartCallbackInBackgroundIsolate(Context context,
RemoteMessage remoteMessage, final CountDownLatch latch) {
private static void executeDartCallbackInBackgroundIsolate(
Context context, RemoteMessage remoteMessage, final CountDownLatch latch) {
if (sBackgroundChannel == null) {
Log.e(
TAG,
"setBackgroundChannel was not called before messages came in, exiting.");
Log.e(TAG, "setBackgroundChannel was not called before messages came in, exiting.");
return;
}

Expand Down Expand Up @@ -257,14 +255,16 @@ public void notImplemented() {

// TODO(kroikie): Find a better way to determine application state.
public static boolean isApplicationForeground(Context context) {
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager keyguardManager =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

if (keyguardManager.inKeyguardRestrictedInputMode()) {
return false;
}
int myPid = Process.myPid();

ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

List<ActivityManager.RunningAppProcessInfo> list;

Expand Down
10 changes: 6 additions & 4 deletions packages/firebase_messaging/lib/firebase_messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ void _fcmSetupCallback() {
// This is where the magic happens and we handle background events from the
// native portion of the plugin.
_channel.setMethodCallHandler((MethodCall call) async {
final CallbackHandle handle = CallbackHandle.fromRawHandle(call.arguments['handle']);
final Function handlerFunction = PluginUtilities.getCallbackFromHandle(handle);
final CallbackHandle handle =
CallbackHandle.fromRawHandle(call.arguments['handle']);
final Function handlerFunction =
PluginUtilities.getCallbackFromHandle(handle);
await handlerFunction(call.arguments['message']);
return Future<void>.value();
});
Expand Down Expand Up @@ -98,9 +100,9 @@ class FirebaseMessaging {
if (_onBackgroundMessage != null) {
_onBackgroundMessage = onBackgroundMessage;
final CallbackHandle backgroundSetupHandle =
PluginUtilities.getCallbackHandle(_fcmSetupCallback);
PluginUtilities.getCallbackHandle(_fcmSetupCallback);
final CallbackHandle backgroundMessageHandle =
PluginUtilities.getCallbackHandle(_onBackgroundMessage);
PluginUtilities.getCallbackHandle(_onBackgroundMessage);
_channel.invokeMethod<bool>(
'FcmDartService.start',
<dynamic>[
Expand Down

0 comments on commit 46a36a2

Please sign in to comment.