Skip to content

Commit e60c302

Browse files
authored
Release/5.6.1 (#448)
* bump beta (other versions are used) * release 5.6.1 * Fix possible NPE when Leanplum.getContext is null. Crash is in Util.hasPlayServices * Remove unnecessary unit tests * bump beta * release 5.6.1
1 parent e8059db commit e60c302

File tree

5 files changed

+21
-35
lines changed

5 files changed

+21
-35
lines changed

AndroidSDKMiPush/src/main/java/com/leanplum/LeanplumMiPushProvider.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,11 @@
3434
*/
3535
class LeanplumMiPushProvider extends LeanplumCloudMessagingProvider {
3636

37-
boolean appRegistered = false;
38-
3937
/**
4038
* Constructor called by reflection.
4139
*/
4240
public LeanplumMiPushProvider() {
43-
if (Leanplum.getContext() != null) {
44-
// there is theoretical possibility for context to be null
45-
registerApp(Leanplum.getContext());
46-
} else {
47-
Log.e("MiPush app not registered because context is null");
48-
}
41+
registerApp(Leanplum.getContext());
4942
}
5043

5144
private void registerApp(@NonNull Context context) {
@@ -60,7 +53,6 @@ private void registerApp(@NonNull Context context) {
6053

6154
Log.d("Calling MiPushClient.registerPush");
6255
MiPushClient.registerPush(context, miAppId, miAppKey);
63-
appRegistered = true;
6456
}
6557

6658
@Override
@@ -86,10 +78,6 @@ public void updateRegistrationId() {
8678
if (Leanplum.getContext() == null)
8779
return;
8880

89-
if (!appRegistered) {
90-
registerApp(Leanplum.getContext());
91-
}
92-
9381
String regId = MiPushClient.getRegId(Leanplum.getContext());
9482
if (!TextUtils.isEmpty(regId)) {
9583
setRegistrationId(regId);

AndroidSDKPush/src/main/java/com/leanplum/LeanplumPushService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ public static void unregister() {
663663
* Call this when Leanplum starts. This method will call by reflection from AndroidSDKCore.
664664
*/
665665
static void onStart() {
666+
pushProviders.init();
666667
pushProviders.updateRegistrationIdsAndBackend();
667668
}
668669

AndroidSDKPush/src/main/java/com/leanplum/PushProviders.java

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

2424
import android.content.Context;
25-
import android.os.Build;
2625
import android.text.TextUtils;
2726
import androidx.annotation.VisibleForTesting;
2827
import com.leanplum.internal.APIConfig;
@@ -31,16 +30,30 @@
3130
import com.leanplum.internal.OperationQueue;
3231
import com.leanplum.internal.Util;
3332
import com.leanplum.utils.SharedPreferencesUtil;
34-
import java.util.HashMap;
3533
import java.util.Map;
34+
import java.util.concurrent.ConcurrentHashMap;
3635

3736
class PushProviders {
3837
private static String FCM_PROVIDER_CLASS = "com.leanplum.LeanplumFcmProvider";
3938
private static String MIPUSH_PROVIDER_CLASS = "com.leanplum.LeanplumMiPushProvider";
4039

41-
private final Map<PushProviderType, IPushProvider> providers = new HashMap<>();
40+
private final Map<PushProviderType, IPushProvider> providers = new ConcurrentHashMap<>();
41+
private boolean initialized = false;
4242

4343
public PushProviders() {
44+
init();
45+
}
46+
47+
public synchronized void init() { // synchronize access to 'initialized' variable
48+
if (initialized) {
49+
return;
50+
}
51+
52+
if (Leanplum.getContext() == null) {
53+
// init() method will be called for second time from LeanplumPushService.onStart
54+
return;
55+
}
56+
4457
IPushProvider fcm = createFcm();
4558
if (fcm != null) {
4659
providers.put(PushProviderType.FCM, fcm);
@@ -50,6 +63,8 @@ public PushProviders() {
5063
if (miPush != null) {
5164
providers.put(PushProviderType.MIPUSH, miPush);
5265
}
66+
67+
initialized = true;
5368
}
5469

5570
public void updateRegistrationIdsAndBackend() {

AndroidSDKTests/src/test/java/com/leanplum/LeanplumMiPushHandlerTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,4 @@ public void testParsePayloadMessage() {
116116
assertEquals(nestedItem, handler.parsePayload("{\"lp_version\":\"1\", \"lp_channel\":{\"importance\":3,\"name\":\"rondo-channel\",\"id\":\"123\"}, \"lp_message\":\"Push message goes here.\", \"_lpm\":\"4700540011347968\", \"_lpx\":{\"__name__\":\"Request App Rating\"}}"));
117117
}
118118

119-
@Test
120-
public void testSetApplicationFail() {
121-
String appId = "";
122-
String appKey = "";
123-
LeanplumMiPushHandler.setApplication(appId, appKey);
124-
LeanplumMiPushProvider provider = new LeanplumMiPushProvider();
125-
assertFalse(provider.appRegistered);
126-
}
127-
128-
@Test
129-
public void testSetApplication() {
130-
String appId = "id";
131-
String appKey = "key";
132-
LeanplumMiPushHandler.setApplication(appId, appKey);
133-
LeanplumMiPushProvider provider = new LeanplumMiPushProvider();
134-
assertTrue(provider.appRegistered);
135-
}
136-
137119
}

sdk-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.6.0
1+
5.6.1

0 commit comments

Comments
 (0)