Skip to content

Commit d18fd23

Browse files
E2 1802 fcm gcm (#345)
* Fix deprecated FCM Listener for new token * merge * gradle clean before build * bump beta version * FCM Refactor * cleanedup GCM and p1 refactor manually tested with fcm * Fully functional on start fetch and retrieval and cleanup with refacgoring * Test cases and added checks for reducing network calls
1 parent e72f341 commit d18fd23

File tree

55 files changed

+149
-4292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+149
-4292
lines changed

AndroidSDK/proguard-rules.pro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@
336336
-keep class com.leanplum.LeanplumPushService { *; }
337337
-keep class com.leanplum.LeanplumFcmProvider { *; }
338338
-keep class com.leanplum.LeanplumCloudMessagingProvider{ *; }
339-
-keep class com.leanplum.LeanplumGcmProvider { *; }
340-
-keep class com.leanplum.LeanplumPushServiceGcm { *; }
341339
-keep class com.leanplum.LocationManagerImplementation { *; }
342340

343341
-keep class com.leanplum.messagetemplates.BaseMessageOptions { *; }

AndroidSDKCore/proguard-rules.pro

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,9 @@
336336
-keep class com.leanplum.LocationManagerImplementation { *; }
337337

338338
-keep class com.leanplum.messagetemplates.BaseMessageOptions { *; }
339-
-keep class com.leanplum.LeanplumPushServiceFcm { *; }
340339
-keep class com.leanplum.LeanplumPushService { *; }
341340
-keep class com.leanplum.LeanplumFcmProvider { *; }
342341
-keep class com.leanplum.LeanplumCloudMessagingProvider{ *; }
343-
-keep class com.leanplum.LeanplumGcmProvider { *; }
344-
-keep class com.leanplum.LeanplumPushServiceGcm { *; }
345342
-keep class com.leanplum.LocationManagerImplementation { *; }
346343

347344
-dontwarn android.support.v7.**

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ private static void startHelper(
661661
int timezoneOffsetSeconds = localTimeZone.getOffset(now.getTime()) / 1000;
662662

663663
String registrationId = SharedPreferencesUtil.getString(context,
664-
Constants.Defaults.LEANPLUM_PUSH, Constants.Defaults.PROPERTY_REGISTRATION_ID);
664+
Constants.Defaults.LEANPLUM_PUSH, Constants.Defaults.PROPERTY_TOKEN_ID);
665665

666666
HashMap<String, Object> params = new HashMap<>();
667667
params.put(Constants.Params.INCLUDE_DEFAULTS, Boolean.toString(false));
@@ -1608,7 +1608,7 @@ public void run() {
16081608
try {
16091609
HashMap<String, Object> params = new HashMap<>();
16101610
params.put(Constants.Params.DEVICE_PUSH_TOKEN, registrationId);
1611-
RequestOld.post(Constants.Methods.SET_DEVICE_ATTRIBUTES, params).send();
1611+
RequestOld.post(Constants.Methods.SET_DEVICE_ATTRIBUTES, params).sendIfConnected();
16121612
} catch (Throwable t) {
16131613
Util.handleException(t);
16141614
}

AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static class Defaults {
8888
public static final String INBOX_KEY = "__leanplum_newsfeed";
8989
public static final String LEANPLUM_PUSH = "__leanplum_push__";
9090
public static final String APP_ID = "__app_id";
91-
public static final String PROPERTY_REGISTRATION_ID = "registration_id";
91+
public static final String PROPERTY_TOKEN_ID = "registration_id";
9292
public static final String PROPERTY_SENDER_IDS = "sender_ids";
9393
public static final String NOTIFICATION_CHANNELS_KEY = "__leanplum_notification_channels";
9494
public static final String DEFAULT_NOTIFICATION_CHANNEL_KEY = "__leanplum_default_notification_channels";

AndroidSDKFcm/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
releaseApi project(':AndroidSDKPush')
2929

3030
// Provided dependencies are optional dependencies and will not show up in pom file.
31-
compileOnly('com.google.firebase:firebase-messaging:[10.0.0,)') {
31+
compileOnly('com.google.firebase:firebase-messaging:[17.3.4,)') {
3232
exclude module: 'support-v4'
3333
}
3434
}

AndroidSDKFcm/javadoc/com/leanplum/LeanplumPushFcmListenerService.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@
9494
<h2 title="Class LeanplumPushFcmListenerService" class="title">Class LeanplumPushFcmListenerService</h2>
9595
</div>
9696
<div class="contentContainer">
97-
<ul class="inheritance">
98-
<li>java.lang.Object</li>
99-
<li>
100-
<ul class="inheritance">
101-
<li>FirebaseInstanceIdService</li>
102-
<li>
103-
<ul class="inheritance">
104-
<li>com.leanplum.LeanplumPushFcmListenerService</li>
105-
</ul>
106-
</li>
107-
</ul>
108-
</li>
109-
</ul>
11097
<div class="description">
11198
<ul class="blockList">
11299
<li class="blockList">

AndroidSDKFcm/proguard-rules.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@
332332
}
333333

334334
-keep class com.leanplum.utils.BitmapUtil { public private protected *; }
335-
-keep class com.leanplum.LeanplumPushServiceFcm { *; }
336335
-keep class com.leanplum.LeanplumPushService { *; }
337336
-keep class com.leanplum.LeanplumFcmProvider { *; }
338337
-keep class com.leanplum.LeanplumCloudMessagingProvider{ *; }

AndroidSDKFcm/src/main/AndroidManifest.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@
1212
</intent-filter>
1313
</service>
1414

15-
<!-- Leanplum FCM Registration Job Service. -->
16-
<service android:name="com.leanplum.LeanplumFcmRegistrationJobService"
17-
android:permission="android.permission.BIND_JOB_SERVICE"/>
18-
19-
20-
<!-- Leanplum FCM Instance ID Service. -->
21-
<service
22-
android:name="com.leanplum.LeanplumPushFcmListenerService"
23-
android:enabled="true"
24-
android:exported="false">
25-
<intent-filter>
26-
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
27-
</intent-filter>
28-
</service>
29-
3015
<!-- Leanplum Push Notification Receiver for FCM. -->
3116
<receiver
3217
android:name="com.leanplum.LeanplumPushReceiver"

AndroidSDKFcm/src/main/java/com/leanplum/LeanplumFcmProvider.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@
2222
package com.leanplum;
2323

2424
import android.content.Context;
25+
import android.nfc.Tag;
26+
import android.text.TextUtils;
2527

28+
import com.google.android.gms.tasks.OnCompleteListener;
29+
import com.google.android.gms.tasks.Task;
2630
import com.google.firebase.iid.FirebaseInstanceId;
31+
import com.google.firebase.iid.InstanceIdResult;
2732
import com.leanplum.internal.LeanplumManifestHelper;
2833
import com.leanplum.internal.Log;
2934
import com.leanplum.internal.Util;
3035

3136
import java.util.Collections;
3237

38+
import androidx.annotation.NonNull;
39+
3340
/**
3441
* Leanplum provider for work with Firebase.
3542
*
@@ -39,7 +46,26 @@ class LeanplumFcmProvider extends LeanplumCloudMessagingProvider {
3946

4047
@Override
4148
public String getRegistrationId() {
42-
return FirebaseInstanceId.getInstance().getToken();
49+
return this.getStoredRegistrationPreferences(Leanplum.getContext());
50+
}
51+
52+
@Override
53+
public void getCurrentRegistrationIdAndUpdateBackend() {
54+
FirebaseInstanceId.getInstance().getInstanceId()
55+
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
56+
@Override
57+
public void onComplete(@NonNull Task<InstanceIdResult> task) {
58+
if (!task.isSuccessful()) {
59+
Log.e("getInstanceId failed");
60+
return;
61+
}
62+
// Get new Instance ID token
63+
String tokenId = task.getResult().getToken();
64+
if (!TextUtils.isEmpty(tokenId)) {
65+
onRegistrationIdReceived(Leanplum.getContext(), tokenId);
66+
}
67+
}
68+
});
4369
}
4470

4571
@Override
@@ -64,16 +90,11 @@ public boolean isManifestSetup() {
6490
LeanplumManifestHelper.LP_PUSH_FCM_MESSAGING_SERVICE, false, null,
6591
Collections.singletonList(LeanplumManifestHelper.FCM_MESSAGING_EVENT), context.getPackageName());
6692

67-
boolean hasPushFirebaseListenerService = LeanplumManifestHelper.checkComponent(
68-
LeanplumManifestHelper.ApplicationComponent.SERVICE,
69-
LeanplumManifestHelper.LP_PUSH_FCM_LISTENER_SERVICE, false, null,
70-
Collections.singletonList(LeanplumManifestHelper.FCM_INSTANCE_ID_EVENT), context.getPackageName());
71-
7293
boolean hasRegistrationService = LeanplumManifestHelper.checkComponent(
7394
LeanplumManifestHelper.ApplicationComponent.SERVICE,
7495
LeanplumPushRegistrationService.class.getName(), false, null, null, context.getPackageName());
7596

76-
boolean hasServices = hasPushFirebaseMessagingService && hasPushFirebaseListenerService &&
97+
boolean hasServices = hasPushFirebaseMessagingService &&
7798
hasRegistrationService;
7899

79100
if (hasPushReceiver && hasServices) {

AndroidSDKFcm/src/main/java/com/leanplum/LeanplumFcmRegistrationJobService.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)