12
12
import android .os .Handler ;
13
13
import android .os .Process ;
14
14
import android .util .Log ;
15
-
16
15
import androidx .localbroadcastmanager .content .LocalBroadcastManager ;
17
16
import com .google .firebase .messaging .FirebaseMessagingService ;
18
17
import com .google .firebase .messaging .RemoteMessage ;
19
-
18
+ import io .flutter .plugin .common .MethodChannel ;
19
+ import io .flutter .plugin .common .PluginRegistry ;
20
+ import io .flutter .view .FlutterCallbackInformation ;
21
+ import io .flutter .view .FlutterMain ;
22
+ import io .flutter .view .FlutterNativeView ;
23
+ import io .flutter .view .FlutterRunArguments ;
20
24
import java .util .Collections ;
21
25
import java .util .HashMap ;
22
26
import java .util .Iterator ;
26
30
import java .util .concurrent .CountDownLatch ;
27
31
import java .util .concurrent .atomic .AtomicBoolean ;
28
32
29
- import io .flutter .plugin .common .MethodChannel ;
30
- import io .flutter .plugin .common .PluginRegistry ;
31
- import io .flutter .view .FlutterCallbackInformation ;
32
- import io .flutter .view .FlutterMain ;
33
- import io .flutter .view .FlutterNativeView ;
34
- import io .flutter .view .FlutterRunArguments ;
35
-
36
33
public class FlutterFirebaseMessagingService extends FirebaseMessagingService {
37
34
38
35
public static final String ACTION_REMOTE_MESSAGE =
@@ -44,7 +41,8 @@ public class FlutterFirebaseMessagingService extends FirebaseMessagingService {
44
41
45
42
private static final String SHARED_PREFERENCES_KEY = "io.flutter.android_fcm_plugin" ;
46
43
private static final String BACKGROUND_SETUP_CALLBACK_HANDLE_KEY = "background_setup_callback" ;
47
- private static final String BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY = "background_message_callback" ;
44
+ private static final String BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY =
45
+ "background_message_callback" ;
48
46
49
47
// TODO(kroikie): make sIsIsolateRunning per-instance, not static.
50
48
private static AtomicBoolean sIsIsolateRunning = new AtomicBoolean (false );
@@ -56,7 +54,8 @@ public class FlutterFirebaseMessagingService extends FirebaseMessagingService {
56
54
57
55
private static Long sBackgroundMessageHandle ;
58
56
59
- private static List <RemoteMessage > sBackgroundMessageQueue = Collections .synchronizedList (new LinkedList <RemoteMessage >());
57
+ private static List <RemoteMessage > sBackgroundMessageQueue =
58
+ Collections .synchronizedList (new LinkedList <RemoteMessage >());
60
59
61
60
private static PluginRegistry .PluginRegistrantCallback sPluginRegistrantCallback ;
62
61
@@ -105,8 +104,8 @@ public void onMessageReceived(final RemoteMessage remoteMessage) {
105
104
new Runnable () {
106
105
@ Override
107
106
public void run () {
108
- Log . d ( TAG , "executing dart callback" );
109
- executeDartCallbackInBackgroundIsolate ( FlutterFirebaseMessagingService .this , remoteMessage , latch );
107
+ executeDartCallbackInBackgroundIsolate (
108
+ FlutterFirebaseMessagingService .this , remoteMessage , latch );
110
109
}
111
110
});
112
111
try {
@@ -199,16 +198,15 @@ public static void setBackgroundSetupHandle(Context context, long callbackHandle
199
198
}
200
199
201
200
public static Long getOnMessageCallbackHandle (Context context ) {
202
- return context .getSharedPreferences (SHARED_PREFERENCES_KEY , 0 )
201
+ return context
202
+ .getSharedPreferences (SHARED_PREFERENCES_KEY , 0 )
203
203
.getLong (BACKGROUND_MESSAGE_CALLBACK_HANDLE_KEY , 0 );
204
204
}
205
205
206
- private static void executeDartCallbackInBackgroundIsolate (Context context ,
207
- RemoteMessage remoteMessage , final CountDownLatch latch ) {
206
+ private static void executeDartCallbackInBackgroundIsolate (
207
+ Context context , RemoteMessage remoteMessage , final CountDownLatch latch ) {
208
208
if (sBackgroundChannel == null ) {
209
- Log .e (
210
- TAG ,
211
- "setBackgroundChannel was not called before messages came in, exiting." );
209
+ Log .e (TAG , "setBackgroundChannel was not called before messages came in, exiting." );
212
210
return ;
213
211
}
214
212
@@ -257,14 +255,16 @@ public void notImplemented() {
257
255
258
256
// TODO(kroikie): Find a better way to determine application state.
259
257
public static boolean isApplicationForeground (Context context ) {
260
- KeyguardManager keyguardManager = (KeyguardManager ) context .getSystemService (Context .KEYGUARD_SERVICE );
258
+ KeyguardManager keyguardManager =
259
+ (KeyguardManager ) context .getSystemService (Context .KEYGUARD_SERVICE );
261
260
262
261
if (keyguardManager .inKeyguardRestrictedInputMode ()) {
263
262
return false ;
264
263
}
265
264
int myPid = Process .myPid ();
266
265
267
- ActivityManager activityManager = (ActivityManager ) context .getSystemService (Context .ACTIVITY_SERVICE );
266
+ ActivityManager activityManager =
267
+ (ActivityManager ) context .getSystemService (Context .ACTIVITY_SERVICE );
268
268
269
269
List <ActivityManager .RunningAppProcessInfo > list ;
270
270
0 commit comments