Skip to content

Commit 412af11

Browse files
committed
feat(manifest): removing manifest parser
1 parent 116573b commit 412af11

File tree

7 files changed

+29
-864
lines changed

7 files changed

+29
-864
lines changed

AndroidSDK/src/com/leanplum/LeanplumCloudMessagingProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ abstract class LeanplumCloudMessagingProvider {
4545
*/
4646
public abstract String getRegistrationId();
4747

48-
/**
49-
* Verifies that Android Manifest is set up correctly.
50-
*
51-
* @return true If Android Manifest is set up correctly.
52-
*/
53-
public abstract boolean isManifestSetUp();
54-
5548
public abstract boolean isInitialized();
5649

5750
/**

AndroidSDK/src/com/leanplum/LeanplumFcmProvider.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,14 @@
2222
package com.leanplum;
2323

2424
import com.google.firebase.iid.FirebaseInstanceId;
25-
import com.leanplum.internal.LeanplumManifestHelper;
2625
import com.leanplum.internal.Log;
2726

28-
import java.util.Collections;
29-
3027
/**
3128
* Leanplum provider for work with Firebase.
3229
*
3330
* @author Anna Orlova
3431
*/
3532
class LeanplumFcmProvider extends LeanplumCloudMessagingProvider {
36-
private static final String INSTANCE_ID_EVENT = "com.google.firebase.INSTANCE_ID_EVENT";
37-
private static final String MESSAGING_EVENT = "com.google.firebase.MESSAGING_EVENT";
38-
private static final String PUSH_FCM_LISTENER_SERVICE =
39-
"com.leanplum.LeanplumPushFcmListenerService";
40-
private static final String PUSH_FIREBASE_MESSAGING_SERVICE =
41-
"com.leanplum.LeanplumPushFirebaseMessagingService";
4233

4334
public String getRegistrationId() {
4435
return FirebaseInstanceId.getInstance().getToken();
@@ -48,34 +39,13 @@ public boolean isInitialized() {
4839
return true;
4940
}
5041

51-
public boolean isManifestSetUp() {
52-
boolean hasReceivers =
53-
LeanplumManifestHelper.checkComponent(LeanplumManifestHelper.getReceivers(),
54-
PUSH_RECEIVER, false, null,
55-
Collections.singletonList(PUSH_FIREBASE_MESSAGING_SERVICE), null);
56-
57-
boolean hasPushFirebaseMessagingService = LeanplumManifestHelper.checkComponent(
58-
LeanplumManifestHelper.getServices(), PUSH_FIREBASE_MESSAGING_SERVICE, false, null,
59-
Collections.singletonList(MESSAGING_EVENT), null);
60-
boolean hasPushFcmListenerService = LeanplumManifestHelper.checkComponent(
61-
LeanplumManifestHelper.getServices(), PUSH_FCM_LISTENER_SERVICE, false, null,
62-
Collections.singletonList(INSTANCE_ID_EVENT), null);
63-
boolean hasPushRegistrationService = LeanplumManifestHelper.checkComponent(
64-
LeanplumManifestHelper.getServices(), PUSH_REGISTRATION_SERVICE, false, null, null, null);
65-
66-
boolean hasServices = hasPushFirebaseMessagingService && hasPushFcmListenerService
67-
&& hasPushRegistrationService;
68-
69-
return hasReceivers && hasServices;
70-
}
71-
7242
/**
7343
* Unregister from FCM.
7444
*/
7545
public void unregister() {
7646
try {
7747
FirebaseInstanceId.getInstance().deleteInstanceId();
78-
Log.i("Application was unregistred from FCM.");
48+
Log.i("Application was unregistered from FCM.");
7949
} catch (Exception e) {
8050
Log.e("Failed to unregister from FCM.");
8151
}

AndroidSDK/src/com/leanplum/LeanplumGcmProvider.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ class LeanplumGcmProvider extends LeanplumCloudMessagingProvider {
4747
private static final String ERROR_PHONE_REGISTRATION_ERROR = "PHONE_REGISTRATION_ERROR";
4848
private static final String ERROR_TOO_MANY_REGISTRATIONS = "TOO_MANY_REGISTRATIONS";
4949

50-
private static final String SEND_PERMISSION = "com.google.android.c2dm.permission.SEND";
51-
private static final String RECEIVE_PERMISSION = "com.google.android.c2dm.permission.RECEIVE";
52-
private static final String RECEIVE_ACTION = "com.google.android.c2dm.intent.RECEIVE";
53-
private static final String REGISTRATION_ACTION = "com.google.android.c2dm.intent.REGISTRATION";
54-
private static final String INSTANCE_ID_ACTION = "com.google.android.gms.iid.InstanceID";
55-
private static final String PUSH_LISTENER_SERVICE = "com.leanplum.LeanplumPushListenerService";
56-
private static final String GCM_RECEIVER = "com.google.android.gms.gcm.GcmReceiver";
57-
private static final String PUSH_INSTANCE_ID_SERVICE =
58-
"com.leanplum.LeanplumPushInstanceIDService";
59-
6050
private static String senderIds;
6151

6252
static void setSenderId(String senderId) {
@@ -121,41 +111,6 @@ public boolean isInitialized() {
121111
return senderIds != null || getCurrentRegistrationId() != null;
122112
}
123113

124-
public boolean isManifestSetUp() {
125-
Context context = Leanplum.getContext();
126-
if (context == null) {
127-
return false;
128-
}
129-
130-
boolean hasPermissions = LeanplumManifestHelper.checkPermission(RECEIVE_PERMISSION, false, true)
131-
&& (LeanplumManifestHelper.checkPermission(context.getPackageName() +
132-
".gcm.permission.C2D_MESSAGE", true, false) || LeanplumManifestHelper.checkPermission(
133-
context.getPackageName() + ".permission.C2D_MESSAGE", true, true));
134-
135-
boolean hasGcmReceiver = LeanplumManifestHelper.checkComponent(
136-
LeanplumManifestHelper.getReceivers(), GCM_RECEIVER, true, SEND_PERMISSION,
137-
Arrays.asList(RECEIVE_ACTION, REGISTRATION_ACTION), context.getPackageName());
138-
boolean hasPushReceiver = LeanplumManifestHelper.checkComponent(
139-
LeanplumManifestHelper.getReceivers(), PUSH_RECEIVER, false, null,
140-
Collections.singletonList(PUSH_LISTENER_SERVICE), null);
141-
142-
boolean hasReceivers = hasGcmReceiver && hasPushReceiver;
143-
144-
boolean hasPushListenerService = LeanplumManifestHelper.checkComponent(
145-
LeanplumManifestHelper.getServices(), PUSH_LISTENER_SERVICE, false, null,
146-
Collections.singletonList(RECEIVE_ACTION), null);
147-
boolean hasPushInstanceIDService = LeanplumManifestHelper.checkComponent(
148-
LeanplumManifestHelper.getServices(), PUSH_INSTANCE_ID_SERVICE, false, null,
149-
Collections.singletonList(INSTANCE_ID_ACTION), null);
150-
boolean hasPushRegistrationService = LeanplumManifestHelper.checkComponent(
151-
LeanplumManifestHelper.getServices(), PUSH_REGISTRATION_SERVICE, false, null, null, null);
152-
153-
boolean hasServices = hasPushListenerService && hasPushInstanceIDService
154-
&& hasPushRegistrationService;
155-
156-
return hasPermissions && hasReceivers && hasServices;
157-
}
158-
159114
/**
160115
* Unregister from GCM.
161116
*/

AndroidSDK/src/com/leanplum/LeanplumPushService.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -662,17 +662,19 @@ static void onStart() {
662662

663663
private static void initPushService() {
664664
if (isFirebaseEnabled()) {
665-
if (!enableServices()) {
665+
if (!enableFcmServices()) {
666+
Log.i("Failed to initialize FCM services.");
666667
return;
667668
}
668669
provider = new LeanplumFcmProvider();
669670
} else {
670-
if (!enableServices()) {
671+
if (!enableGcmServices()) {
672+
Log.i("Failed to initialize GCM services.");
671673
return;
672674
}
673675
provider = new LeanplumGcmProvider();
674676
}
675-
if (!provider.isInitialized() || !provider.isManifestSetUp()) {
677+
if (!provider.isInitialized()) {
676678
return;
677679
}
678680
if (hasAppIDChanged(Request.appId())) {
@@ -681,24 +683,15 @@ private static void initPushService() {
681683
registerInBackground();
682684
}
683685

684-
685-
/**
686-
* Enable Leanplum GCM or FCM services.
687-
*
688-
* @return True if services was enabled.
689-
*/
690-
private static boolean enableServices() {
686+
private static boolean enableFcmServices() {
691687
Context context = Leanplum.getContext();
692688
if (context == null) {
689+
Log.i("Failed to enable FCM services, context is null.");
693690
return false;
694691
}
695-
696692
PackageManager packageManager = context.getPackageManager();
697-
if (packageManager == null) {
698-
return false;
699-
}
700693

701-
if (isFirebaseEnabled) {
694+
if (isFirebaseEnabled()) {
702695
Class fcmListenerClass = getClassForName(LEANPLUM_PUSH_FCM_LISTENER_SERVICE_CLASS);
703696
if (fcmListenerClass == null) {
704697
return false;
@@ -710,20 +703,29 @@ private static boolean enableServices() {
710703
return false;
711704
}
712705
}
713-
} else {
714-
Class gcmPushInstanceIDClass = getClassForName(LEANPLUM_PUSH_INSTANCE_ID_SERVICE_CLASS);
715-
if (gcmPushInstanceIDClass == null) {
716-
return false;
717-
}
706+
}
707+
return true;
708+
}
718709

719-
if (!wasComponentEnabled(context, packageManager, gcmPushInstanceIDClass)) {
720-
if (!enableComponent(context, packageManager, LEANPLUM_PUSH_LISTENER_SERVICE_CLASS) ||
721-
!enableComponent(context, packageManager, gcmPushInstanceIDClass) ||
722-
!enableComponent(context, packageManager, GCM_RECEIVER_CLASS)) {
723-
return false;
724-
}
710+
private static boolean enableGcmServices() {
711+
Context context = Leanplum.getContext();
712+
if (context == null) {
713+
Log.i("Failed to enable FCM services, context is null.");
714+
return false;
715+
}
716+
PackageManager packageManager = context.getPackageManager();
717+
Class gcmPushInstanceIDClass = getClassForName(LEANPLUM_PUSH_INSTANCE_ID_SERVICE_CLASS);
718+
if (gcmPushInstanceIDClass == null) {
719+
return false;
720+
}
725721

722+
if (!wasComponentEnabled(context, packageManager, gcmPushInstanceIDClass)) {
723+
if (!enableComponent(context, packageManager, LEANPLUM_PUSH_LISTENER_SERVICE_CLASS) ||
724+
!enableComponent(context, packageManager, gcmPushInstanceIDClass) ||
725+
!enableComponent(context, packageManager, GCM_RECEIVER_CLASS)) {
726+
return false;
726727
}
728+
727729
}
728730
return true;
729731
}

0 commit comments

Comments
 (0)