Skip to content

Commit a55acaf

Browse files
committed
feat(manifest): adding check for fcm services
1 parent 55771ba commit a55acaf

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

AndroidSDK/src/com/leanplum/LeanplumFcmProvider.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@
2121

2222
package com.leanplum;
2323

24+
import android.content.Context;
25+
2426
import com.google.firebase.iid.FirebaseInstanceId;
27+
import com.leanplum.internal.LeanplumManifestHelper;
2528
import 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

AndroidSDK/src/com/leanplum/LeanplumGcmProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public boolean isManifestSetup() {
157157
} catch (Throwable t) {
158158
Util.handleException(t);
159159
}
160-
Log.i("Failed to setup Google Cloud Messaging, check your manifest configuration.");
160+
Log.e("Failed to setup Google Cloud Messaging, check your manifest configuration.");
161161
return false;
162162
}
163163

AndroidSDK/src/com/leanplum/internal/LeanplumManifestHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@
4141
* @author Anna Orlova
4242
*/
4343
public class LeanplumManifestHelper {
44+
// Google Cloud Messaging
4445
public static final String SEND_PERMISSION = "com.google.android.c2dm.permission.SEND";
4546
public static final String RECEIVE_PERMISSION = "com.google.android.c2dm.permission.RECEIVE";
4647
public static final String RECEIVE_ACTION = "com.google.android.c2dm.intent.RECEIVE";
4748
public static final String REGISTRATION_ACTION = "com.google.android.c2dm.intent.REGISTRATION";
4849
public static final String INSTANCE_ID_ACTION = "com.google.android.gms.iid.InstanceID";
4950
public static final String GCM_RECEIVER = "com.google.android.gms.gcm.GcmReceiver";
51+
52+
// Firebase
53+
public static final String INSTANCE_ID_EVENT = "com.google.firebase.INSTANCE_ID_EVENT";
54+
public static final String MESSAGING_EVENT = "com.google.firebase.MESSAGING_EVENT";
55+
56+
// Leanplum
5057
public static final String PUSH_LISTENER_SERVICE_FILTER = "com.leanplum.LeanplumPushListenerService";
5158

5259
/**

0 commit comments

Comments
 (0)