Skip to content

Commit e8059db

Browse files
authored
Start MiPush without Google Play (#447)
* Start MiPush without Google Play * Fix unit tests
1 parent 3b9f14c commit e8059db

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,14 @@ public void run() {
630630
* Checks for leanplum notifications modules and if someone present - invoke onStart method.
631631
*/
632632
private static void checkAndStartNotificationsModules() {
633-
if (Util.hasPlayServices()) {
634-
try {
635-
Log.d("Trying to starting LeanplumPushService");
633+
try {
634+
Log.d("Trying to start LeanplumPushService");
636635

637-
Class.forName(LEANPLUM_PUSH_SERVICE)
638-
.getDeclaredMethod("onStart")
639-
.invoke(null);
640-
} catch (Throwable ignored) {
641-
// ignored
642-
}
643-
} else {
644-
Log.d("No valid Google Play Services APK found.");
636+
Class.forName(LEANPLUM_PUSH_SERVICE)
637+
.getDeclaredMethod("onStart")
638+
.invoke(null);
639+
} catch (Throwable ignored) {
640+
// ignored
645641
}
646642
}
647643

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public void run() {
7171
}
7272

7373
private static IPushProvider createFcm() {
74+
if (!Util.hasPlayServices()) {
75+
Log.i("No valid Google Play Services APK found. FCM will not initialize.");
76+
return null;
77+
}
78+
7479
try {
7580
IPushProvider fcmProvider =
7681
(IPushProvider) Class.forName(FCM_PROVIDER_CLASS).getConstructor().newInstance();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ public class LeanplumPushServiceTest {
117117
*/
118118
@Before
119119
public void setUp() {
120-
mockStatic(LeanplumPushService.class);
120+
mockStatic(Util.class);
121121
spy(LeanplumPushService.class);
122-
spy(Util.class);
123122
spy(PushProviders.class);
124123

124+
when(Util.hasPlayServices()).thenReturn(true);
125+
125126
this.context = RuntimeEnvironment.application;
126127
assertNotNull(this.context);
127128
Leanplum.setApplicationContext(this.context);

0 commit comments

Comments
 (0)