2121
2222package com .leanplum ;
2323
24+ import android .content .Context ;
25+
2426import com .google .firebase .iid .FirebaseInstanceId ;
27+ import com .leanplum .internal .LeanplumManifestHelper ;
2528import com .leanplum .internal .Log ;
29+ import com .leanplum .internal .Util ;
30+
31+ import java .util .Collections ;
2632
2733/**
2834 * Leanplum provider for work with Firebase.
@@ -41,8 +47,39 @@ public boolean isInitialized() {
4147
4248 @ Override
4349 public boolean isManifestSetup () {
50+ Context context = Leanplum .getContext ();
51+ if (context == null ) {
52+ return false ;
53+ }
54+
55+ if (!BuildConfig .DEBUG ) {
56+ return true ;
57+ }
4458 // Firebase can only be setup through gradle, so we don't have to check manually
45- // whether manifest is properly setup.
59+ // whether manifest is properly setup. We will only check our own services.
60+ try {
61+ boolean hasPushFirebaseMessagingService = LeanplumManifestHelper .checkComponent (
62+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
63+ LeanplumPushFirebaseMessagingService .class .getName (), false , null ,
64+ Collections .singletonList (LeanplumManifestHelper .MESSAGING_EVENT ), null );
65+
66+ boolean hasPushFirebaseListenerService = LeanplumManifestHelper .checkComponent (
67+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
68+ LeanplumPushFcmListenerService .class .getName (), false , null ,
69+ Collections .singletonList (LeanplumManifestHelper .INSTANCE_ID_EVENT ), null );
70+
71+ boolean hasRegistrationService = LeanplumManifestHelper .checkComponent (
72+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
73+ LeanplumPushRegistrationService .class .getName (), false , null , null , null );
74+
75+ if (hasPushFirebaseMessagingService && hasPushFirebaseListenerService && hasRegistrationService ) {
76+ Log .i ("Firebase Messaging is setup correctly." );
77+ return true ;
78+ }
79+ } catch (Throwable t ) {
80+ Util .handleException (t );
81+ }
82+ Log .e ("Failed to setup Firebase Messaging, check your manifest configuration." );
4683 return true ;
4784 }
4885
0 commit comments