Skip to content

Commit 8409162

Browse files
committed
feat(Modularization): init split sdk GCM, FCM, Push.
1 parent f5c82c9 commit 8409162

Some content is hidden

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

46 files changed

+731
-440
lines changed

AndroidSDK/AndroidManifest.xml

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.leanplum"
3-
android:versionCode="1" android:versionName="1.0">
4-
5-
<uses-sdk android:minSdkVersion="14" />
2+
<manifest package="com.leanplum"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:versionCode="1"
5+
android:versionName="1.0">
66

7+
<uses-sdk android:minSdkVersion="14"/>
78
<!-- Minimum permissions needed for SDK to work -->
8-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9-
<uses-permission android:name="android.permission.INTERNET" />
10-
11-
<!-- Permissions for GCM -->
12-
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
13-
<permission android:name="${applicationId}.permission.C2D_MESSAGE"
14-
android:protectionLevel="signature" />
15-
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
9+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
10+
<uses-permission android:name="android.permission.INTERNET"/>
1611

1712
<application>
18-
19-
<!-- Leanplum Push Notification Receiver for GCM and FCM -->
20-
<receiver android:name="com.leanplum.LeanplumPushReceiver" android:exported="false"
21-
android:enabled="true">
22-
<intent-filter>
23-
<action android:name="com.leanplum.LeanplumPushListenerService" />
24-
<action android:name="com.leanplum.LeanplumPushFirebaseMessagingService" />
25-
</intent-filter>
26-
</receiver>
27-
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true"
28-
android:enabled="false" android:permission="com.google.android.c2dm.permission.SEND">
29-
<intent-filter>
30-
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
31-
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
32-
<category android:name="${applicationId}"/>
33-
</intent-filter>
34-
</receiver>
35-
36-
<!-- Leanplum Local Push Notification Service-->
37-
<service android:name="com.leanplum.LeanplumLocalPushListenerService" />
38-
39-
<!-- Leanplum GCM Message Handling Service -->
40-
<service android:name="com.leanplum.LeanplumPushListenerService" android:exported="false"
41-
android:enabled="false">
42-
<intent-filter>
43-
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
44-
</intent-filter>
45-
</service>
46-
47-
<!-- Leanplum GCM Instance ID Service -->
48-
<service android:name="com.leanplum.LeanplumPushInstanceIDService" android:exported="false"
49-
android:enabled="false">
50-
<intent-filter>
51-
<action android:name="com.google.android.gms.iid.InstanceID" />
52-
</intent-filter>
53-
</service>
54-
55-
<!-- Leanplum GCM/FCM Registration Service -->
56-
<service android:name="com.leanplum.LeanplumPushRegistrationService" />
57-
58-
<!-- Leanplum FCM Message Handling Service -->
59-
<service android:name="com.leanplum.LeanplumPushFirebaseMessagingService"
60-
android:exported="false" android:enabled="false">
61-
<intent-filter>
62-
<action android:name="com.google.firebase.MESSAGING_EVENT" />
63-
</intent-filter>
64-
</service>
65-
66-
<!-- Leanplum FCM Instance ID Service -->
67-
<service android:name="com.leanplum.LeanplumPushFcmListenerService" android:exported="false"
68-
android:enabled="false">
69-
<intent-filter>
70-
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
71-
</intent-filter>
72-
</service>
73-
74-
<!-- Leanplum Helper for FCM Instance ID Service -->
75-
<service android:name="com.leanplum.LeanplumFcmServiceHelper" android:exported="false"
76-
android:enabled="true">
77-
<intent-filter>
78-
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
79-
</intent-filter>
80-
</service>
81-
8213
<!-- Geofencing Service -->
83-
<service android:name="com.leanplum.ReceiveTransitionsIntentService" />
14+
<service android:name="com.leanplum.ReceiveTransitionsIntentService"/>
8415
</application>
8516
</manifest>

AndroidSDK/build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ dependencies {
1919
api "com.android.support:support-v4:[22.0.0,${SUPPORT_LIBRARY_VERSION}]"
2020
api "com.android.support:appcompat-v7:[22.0.0,${SUPPORT_LIBRARY_VERSION}]"
2121

22-
// Provided dependencies are optional dependencies and will not show up in pom file.
23-
compileOnly('com.google.android.gms:play-services-gcm:[8.3.0,)') {
24-
exclude module: 'support-v4'
25-
}
26-
compileOnly('com.google.firebase:firebase-messaging:[10.0.0,)') {
27-
exclude module: 'support-v4'
28-
}
2922
compileOnly('com.google.android.gms:play-services-location:[10.0.0,)') {
3023
exclude module: 'support-v4'
3124
}

AndroidSDK/src/com/leanplum/Leanplum.java

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222
package com.leanplum;
2323

2424
import android.app.Activity;
25-
import android.app.NotificationManager;
26-
import android.app.PendingIntent;
2725
import android.content.Context;
28-
import android.content.Intent;
2926
import android.location.Location;
3027
import android.os.AsyncTask;
31-
import android.support.v4.app.NotificationCompat;
3228
import android.text.TextUtils;
3329

3430
import com.leanplum.ActionContext.ContextualValues;
@@ -81,6 +77,7 @@ public class Leanplum {
8177
* Default event name to use for Purchase events.
8278
*/
8379
public static final String PURCHASE_EVENT_NAME = "Purchase";
80+
public static final String LEANPLUM_PUSH_SERVICE = "com.leanplum.LeanplumPushService";
8481

8582
private static final ArrayList<StartCallback> startHandlers = new ArrayList<>();
8683
private static final ArrayList<VariablesChangedCallback> variablesChangedHandlers =
@@ -90,6 +87,8 @@ public class Leanplum {
9087
private static final ArrayList<VariablesChangedCallback> onceNoDownloadsHandlers =
9188
new ArrayList<>();
9289
private static final Object heartbeatLock = new Object();
90+
private static final String LEANPLUM_NOTIFICATION_CHANNEL =
91+
"com.leanplum.LeanplumNotificationChannel";
9392
private static RegisterDeviceCallback registerDeviceHandler;
9493
private static RegisterDeviceFinishedCallback registerDeviceFinishedHandler;
9594
private static LeanplumDeviceIdMode deviceIdMode = LeanplumDeviceIdMode.MD5_MAC_ADDRESS;
@@ -577,11 +576,25 @@ protected Void doInBackground(Void... params) {
577576
}
578577
}
579578

579+
/**
580+
* Checks for leanplum notifications modules and if someone present - invoke onStart method.
581+
*/
582+
private static void checkAndStartNotificationsModules() {
583+
if (Util.hasPlayServices()) {
584+
try {
585+
Class.forName(LEANPLUM_PUSH_SERVICE).getDeclaredMethod("onStart")
586+
.invoke(null);
587+
} catch (Throwable ignored) {
588+
}
589+
} else {
590+
Log.i("No valid Google Play Services APK found.");
591+
}
592+
}
593+
580594
private static void startHelper(
581595
String userId, final Map<String, ?> attributes, final boolean isBackground) {
582596
LeanplumEventDataManager.init(context);
583-
LeanplumPushService.onStart();
584-
597+
checkAndStartNotificationsModules();
585598
Boolean limitAdTracking = null;
586599
String deviceId = Request.deviceId();
587600
if (deviceId == null) {
@@ -759,14 +772,13 @@ protected Void doInBackground(Void... params) {
759772
Constants.Keys.NOTIFICATION_GROUPS);
760773
String defaultNotificationChannel = response.optString(
761774
Constants.Keys.DEFAULT_NOTIFICATION_CHANNEL);
762-
763-
// Configure notification channels and groups
764-
LeanplumNotificationChannel.configureNotificationGroups(
765-
context, notificationGroups);
766-
LeanplumNotificationChannel.configureNotificationChannels(
767-
context, notificationChannels);
768-
LeanplumNotificationChannel.configureDefaultNotificationChannel(
769-
context, defaultNotificationChannel);
775+
try {
776+
Class.forName(LEANPLUM_NOTIFICATION_CHANNEL)
777+
.getDeclaredMethod("configureChannels", Context.class, JSONArray.class,
778+
JSONArray.class, String.class).invoke(new Object(), context,
779+
notificationGroups, notificationChannels, defaultNotificationChannel);
780+
} catch (Throwable ignored) {
781+
}
770782
}
771783

772784
String token = response.optString(Constants.Keys.TOKEN, null);
@@ -834,24 +846,10 @@ public void onResponse(boolean success) {
834846
@Override
835847
public void run() {
836848
try {
837-
NotificationCompat.Builder builder =
838-
LeanplumNotificationHelper.getDefaultCompatNotificationBuilder(context,
839-
BuildUtil.isNotificationChannelSupported(context));
840-
if (builder == null) {
841-
return;
842-
}
843-
builder.setSmallIcon(android.R.drawable.star_on)
844-
.setContentTitle("Leanplum")
845-
.setContentText("Your device is registered.");
846-
builder.setContentIntent(PendingIntent.getActivity(
847-
currentContext.getApplicationContext(), 0, new Intent(), 0));
848-
NotificationManager mNotificationManager =
849-
(NotificationManager) currentContext.getSystemService(
850-
Context.NOTIFICATION_SERVICE);
851-
// mId allows you to update the notification later on.
852-
mNotificationManager.notify(0, builder.build());
853-
} catch (Throwable t) {
854-
Log.i("Device is registered.");
849+
Class.forName(Leanplum.LEANPLUM_PUSH_SERVICE)
850+
.getDeclaredMethod("showDeviceRegistedPush", Context.class,
851+
Context.class).invoke(new Object(), context, currentContext);
852+
} catch (Throwable ignored) {
855853
}
856854
}
857855
});

AndroidSDK/src/com/leanplum/LeanplumFcmServiceHelper.java

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

0 commit comments

Comments
 (0)