@onekeyfe/react-native-jpush 6.7.0-alpha.435 → 6.7.0-alpha.436
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/android/fcm/build.gradle +29 -0
- package/android/fcm/consumer-rules.pro +2 -0
- package/android/fcm/src/main/AndroidManifest.xml +16 -0
- package/android/fcm/src/main/java/com/onekey/jpush/fcm/FcmMessagingService.java +72 -0
- package/android/fcm/src/main/java/com/onekey/jpush/fcm/FcmPushManager.java +69 -0
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +1 -0
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +2 -0
- package/android/src/main/java/cn/jpush/android/api/JThirdPlatFormInterface.java +107 -7
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +79 -0
- package/android/src/main/java/cn/jpush/android/service/JPushMessageReceiver.java +2 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -22,3 +22,19 @@ yarn workspace @onekeyfe/react-native-jpush test
|
|
|
22
22
|
# Native iOS & Android E2E protocol verification (uses non-production demo key 1f2027d3cfb1b51dac664c42)
|
|
23
23
|
python3 native-modules/react-native-jpush/scripts/verify_clean_sdk.py
|
|
24
24
|
```
|
|
25
|
+
|
|
26
|
+
## Android Google / FCM source transport
|
|
27
|
+
|
|
28
|
+
The optional Android source library in `android/fcm` replaces the opaque Jiguang FCM plugin. It delegates the Google transport to the official Firebase Messaging SDK and forwards tokens and messages into this package's JCore/JPush pipeline. Link it alongside the project's autolinked JPush module (the alias below matches app-monorepo):
|
|
29
|
+
|
|
30
|
+
```groovy
|
|
31
|
+
// settings.gradle, after React Native autolinking
|
|
32
|
+
include ':onekey-jpush-fcm'
|
|
33
|
+
project(':onekey-jpush-fcm').projectDir = new File(project(':jpush-react-native').projectDir, 'fcm')
|
|
34
|
+
|
|
35
|
+
// app/build.gradle: replace cn.jiguang.sdk.plugin:fcm
|
|
36
|
+
// Keep this dependency scoped to the Google distribution.
|
|
37
|
+
googleImplementation project(':onekey-jpush-fcm')
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The host retains its existing `google-services.json` and Google Services Gradle plugin. Firebase auto-init stays disabled; JPush initialization requests the token after authorization. Cloud acceptance requires the matching Firebase credentials configured in the Jiguang sender. For Firebase-managed background notification payloads, use `cn.jpush.android.intent.NOTIFICATION_OPENED` as the click action so the private JPush activity receives `JMessageExtra`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
android {
|
|
4
|
+
namespace 'com.onekey.jpush.fcm'
|
|
5
|
+
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
6
|
+
|
|
7
|
+
defaultConfig {
|
|
8
|
+
minSdkVersion rootProject.ext.minSdkVersion
|
|
9
|
+
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
10
|
+
consumerProguardFiles 'consumer-rules.pro'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
compileOptions {
|
|
14
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
15
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def coreProject = rootProject.subprojects.find {
|
|
20
|
+
it.projectDir.canonicalFile == projectDir.parentFile.canonicalFile
|
|
21
|
+
}
|
|
22
|
+
if (coreProject == null) {
|
|
23
|
+
throw new GradleException('The FCM library requires the autolinked JPush core project.')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
dependencies {
|
|
27
|
+
implementation project(coreProject.path)
|
|
28
|
+
implementation 'com.google.firebase:firebase-messaging:25.0.1'
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<application>
|
|
3
|
+
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
|
|
4
|
+
<service android:name="com.onekey.jpush.fcm.FcmMessagingService" android:exported="false">
|
|
5
|
+
<intent-filter>
|
|
6
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
7
|
+
</intent-filter>
|
|
8
|
+
</service>
|
|
9
|
+
<activity android:name="cn.jpush.android.service.JNotifyActivity" android:exported="false">
|
|
10
|
+
<intent-filter>
|
|
11
|
+
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
|
|
12
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
13
|
+
</intent-filter>
|
|
14
|
+
</activity>
|
|
15
|
+
</application>
|
|
16
|
+
</manifest>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
package com.onekey.jpush.fcm;
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle;
|
|
4
|
+
import cn.jiguang.core.JCoreStorage;
|
|
5
|
+
import cn.jiguang.plugins.push.common.JLogger;
|
|
6
|
+
import cn.jpush.android.api.JPushInterface;
|
|
7
|
+
import cn.jpush.android.api.JThirdPlatFormInterface;
|
|
8
|
+
import cn.jpush.android.local.ActionHelper;
|
|
9
|
+
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
10
|
+
import com.google.firebase.messaging.RemoteMessage;
|
|
11
|
+
import java.util.Map;
|
|
12
|
+
import org.json.JSONObject;
|
|
13
|
+
|
|
14
|
+
public final class FcmMessagingService extends FirebaseMessagingService {
|
|
15
|
+
@Override
|
|
16
|
+
public void onNewToken(String token) {
|
|
17
|
+
if (JCoreStorage.isPushStopped(this) || !JCoreStorage.isCollectionAuth(this)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
JPushInterface.init(getApplicationContext());
|
|
21
|
+
FcmPushManager.acceptToken(getApplicationContext(), token);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void onMessageReceived(RemoteMessage remoteMessage) {
|
|
26
|
+
if (JCoreStorage.isPushStopped(this) || !JCoreStorage.isCollectionAuth(this)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
Map<String, String> data = remoteMessage.getData();
|
|
31
|
+
String raw = data.get("JMessageExtra");
|
|
32
|
+
JSONObject message;
|
|
33
|
+
if (raw == null || raw.isEmpty()) {
|
|
34
|
+
message = new JSONObject(data);
|
|
35
|
+
} else {
|
|
36
|
+
String decoded = JThirdPlatFormInterface.decodeMessageJson(raw);
|
|
37
|
+
if (decoded == null) {
|
|
38
|
+
JLogger.w("FCM payload rejected");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
message = new JSONObject(decoded);
|
|
42
|
+
}
|
|
43
|
+
RemoteMessage.Notification notification = remoteMessage.getNotification();
|
|
44
|
+
if (notification != null) {
|
|
45
|
+
if (!message.has("n_title") && !message.has("title")) {
|
|
46
|
+
message.put("n_title", notification.getTitle());
|
|
47
|
+
}
|
|
48
|
+
if (!message.has("n_content") && !message.has("alert") && !message.has("content")) {
|
|
49
|
+
message.put("n_content", notification.getBody());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!message.has("msg_id") && !message.has("_jmsgid_") && !message.has("_j_msgid")) {
|
|
53
|
+
message.put("msg_id", remoteMessage.getMessageId());
|
|
54
|
+
}
|
|
55
|
+
if (!message.has("n_extras") && !message.has("extras") && !data.containsKey("JMessageExtra")) {
|
|
56
|
+
message.put("n_extras", new JSONObject(data));
|
|
57
|
+
}
|
|
58
|
+
raw = message.toString();
|
|
59
|
+
Bundle payload = new Bundle();
|
|
60
|
+
payload.putString("JMessageExtra", raw);
|
|
61
|
+
payload.putByte("platform", (byte) 8);
|
|
62
|
+
ActionHelper.getInstance().doAction(
|
|
63
|
+
getApplicationContext(),
|
|
64
|
+
JThirdPlatFormInterface.ACTION_PLUGIN_PALTFORM_ON_MESSAGING,
|
|
65
|
+
payload
|
|
66
|
+
);
|
|
67
|
+
JLogger.i("FCM message forwarded to native dispatcher");
|
|
68
|
+
} catch (Exception invalidMessage) {
|
|
69
|
+
JLogger.w("FCM payload rejected");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package com.onekey.jpush.fcm;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.os.Bundle;
|
|
5
|
+
import cn.jiguang.core.JCoreStorage;
|
|
6
|
+
import cn.jiguang.plugins.push.common.JLogger;
|
|
7
|
+
import cn.jpush.android.api.JPushInterface;
|
|
8
|
+
import cn.jpush.android.api.JThirdPlatFormInterface;
|
|
9
|
+
import com.google.android.gms.common.GoogleApiAvailabilityLight;
|
|
10
|
+
import com.google.firebase.FirebaseApp;
|
|
11
|
+
import com.google.firebase.messaging.FirebaseMessaging;
|
|
12
|
+
|
|
13
|
+
public final class FcmPushManager extends JThirdPlatFormInterface {
|
|
14
|
+
@Override
|
|
15
|
+
public void init(Context context) {
|
|
16
|
+
FirebaseApp.initializeApp(context);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public void register(Context context, Bundle options) {
|
|
21
|
+
init(context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public String getToken(final Context context) {
|
|
26
|
+
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
|
|
27
|
+
if (!task.isSuccessful()) {
|
|
28
|
+
Exception error = task.getException();
|
|
29
|
+
JLogger.w("FCM token request failed type="
|
|
30
|
+
+ (error != null ? error.getClass().getSimpleName() : "unknown"));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
acceptToken(context, task.getResult());
|
|
34
|
+
});
|
|
35
|
+
return JCoreStorage.getThirdToken(context, (byte) 8);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static void acceptToken(Context context, String token) {
|
|
39
|
+
if (token == null || token.isEmpty() || JCoreStorage.isPushStopped(context)
|
|
40
|
+
|| !JCoreStorage.isCollectionAuth(context)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
Bundle result = new Bundle();
|
|
44
|
+
result.putString(KEY_TOKEN, token);
|
|
45
|
+
result.putByte(KEY_PLATFORM, (byte) 8);
|
|
46
|
+
doAction(context, ACTION_REGISTER_TOKEN, result);
|
|
47
|
+
JLogger.i("FCM token submitted to JCore");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public boolean isSupport(Context context) {
|
|
52
|
+
if (context == null) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
int status = GoogleApiAvailabilityLight.getInstance().isGooglePlayServicesAvailable(context);
|
|
56
|
+
if (status != 0) {
|
|
57
|
+
JLogger.w("FCM Google Play services unavailable code=" + status);
|
|
58
|
+
}
|
|
59
|
+
return status == 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Override public byte getRomType(Context context) { return 8; }
|
|
63
|
+
@Override public String getRomName() { return "fcm"; }
|
|
64
|
+
@Override public boolean isNeedClearToken(Context context) { return false; }
|
|
65
|
+
@Override public String getAppkey(Context context) { return FirebaseApp.getInstance().getOptions().getApiKey(); }
|
|
66
|
+
@Override public String getAppId(Context context) { return FirebaseApp.getInstance().getOptions().getApplicationId(); }
|
|
67
|
+
@Override public void clearNotification(Context context, int id) { JPushInterface.clearNotificationById(context, id); }
|
|
68
|
+
@Override public void clearAllNotification(Context context) { JPushInterface.clearAllNotifications(context); }
|
|
69
|
+
}
|
|
@@ -1323,6 +1323,7 @@ public final class JCoreTcpEngine {
|
|
|
1323
1323
|
String regId = JCoreStorage.getRegistrationId(context);
|
|
1324
1324
|
ActionHelper.getInstance().dispatchRegisterEvent(context, regId);
|
|
1325
1325
|
ActionHelper.getInstance().dispatchConnectedEvent(context, true);
|
|
1326
|
+
cn.jpush.android.api.JThirdPlatFormInterface.initializeFcm(context);
|
|
1326
1327
|
}
|
|
1327
1328
|
|
|
1328
1329
|
public Bundle handleEvent(Context context, String sdkType, int cmd, String action, Bundle bundle, Object... extras) {
|
|
@@ -81,6 +81,7 @@ public class JPushInterface {
|
|
|
81
81
|
JPushConstants.init(app);
|
|
82
82
|
ActionHelper.getInstance().init(app);
|
|
83
83
|
JCoreManager.init(app);
|
|
84
|
+
JThirdPlatFormInterface.initializeFcm(app);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
public static void init(Context context, JPushConfig config) {
|
|
@@ -104,6 +105,7 @@ public class JPushInterface {
|
|
|
104
105
|
public static void resumePush(Context context) {
|
|
105
106
|
JCoreStorage.setPushStopped(context, false);
|
|
106
107
|
JCoreManager.init(context);
|
|
108
|
+
JThirdPlatFormInterface.initializeFcm(context);
|
|
107
109
|
ActionHelper.getInstance().setPushStatusWithCallBack(context, 4, 1);
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -4,11 +4,21 @@ import android.app.Notification;
|
|
|
4
4
|
import android.content.Context;
|
|
5
5
|
import android.os.Bundle;
|
|
6
6
|
import cn.jiguang.core.JCoreCrypto;
|
|
7
|
+
import cn.jiguang.core.JCoreStorage;
|
|
8
|
+
import cn.jiguang.core.JCoreTcpEngine;
|
|
9
|
+
import cn.jiguang.plugins.push.common.JLogger;
|
|
7
10
|
import cn.jpush.android.helper.JCoreHelper;
|
|
8
11
|
import cn.jpush.android.local.ActionHelper;
|
|
12
|
+
import java.io.ByteArrayInputStream;
|
|
13
|
+
import java.io.ByteArrayOutputStream;
|
|
14
|
+
import java.nio.charset.StandardCharsets;
|
|
15
|
+
import java.util.zip.GZIPInputStream;
|
|
9
16
|
import org.json.JSONObject;
|
|
10
17
|
|
|
11
18
|
public abstract class JThirdPlatFormInterface {
|
|
19
|
+
private static JThirdPlatFormInterface fcmPlugin;
|
|
20
|
+
private static boolean fcmRegistered;
|
|
21
|
+
private static final int MAX_MESSAGE_BYTES = 65536;
|
|
12
22
|
public static final String ACTION_NOTIFICATION_SHOW = "action_notification_show";
|
|
13
23
|
public static final String ACTION_NOTIFICATION_ARRIVED = "action_notification_arrived";
|
|
14
24
|
public static final String ACTION_NOTIFICATION_UN_SHOW = "action_notification_unshow";
|
|
@@ -69,6 +79,44 @@ public abstract class JThirdPlatFormInterface {
|
|
|
69
79
|
return false;
|
|
70
80
|
}
|
|
71
81
|
|
|
82
|
+
public static void initializeFcm(final Context context) {
|
|
83
|
+
if (context == null || JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
JCoreTcpEngine.getInstance().executeAsync(new Runnable() {
|
|
87
|
+
@Override
|
|
88
|
+
public void run() {
|
|
89
|
+
synchronized (JThirdPlatFormInterface.class) {
|
|
90
|
+
if (JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
if (fcmPlugin == null) {
|
|
95
|
+
// This optional source module is linked only by Google hosts.
|
|
96
|
+
fcmPlugin = (JThirdPlatFormInterface) Class.forName(
|
|
97
|
+
"com.onekey.jpush.fcm.FcmPushManager"
|
|
98
|
+
).getDeclaredConstructor().newInstance();
|
|
99
|
+
}
|
|
100
|
+
if (!fcmPlugin.isSupport(context)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!fcmRegistered) {
|
|
104
|
+
fcmPlugin.init(context);
|
|
105
|
+
fcmPlugin.register(context, new Bundle());
|
|
106
|
+
fcmRegistered = true;
|
|
107
|
+
}
|
|
108
|
+
fcmPlugin.getToken(context);
|
|
109
|
+
JLogger.i("FCM registration requested");
|
|
110
|
+
} catch (ClassNotFoundException absentPlugin) {
|
|
111
|
+
// Non-Google hosts intentionally do not include the optional plugin.
|
|
112
|
+
} catch (Exception | LinkageError unavailablePlugin) {
|
|
113
|
+
JLogger.w("FCM registration unavailable");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
72
120
|
public static void onEvent(Thread thread, Throwable error) {
|
|
73
121
|
ActionHelper.getInstance().onEvent(thread, error);
|
|
74
122
|
}
|
|
@@ -84,6 +132,10 @@ public abstract class JThirdPlatFormInterface {
|
|
|
84
132
|
}
|
|
85
133
|
|
|
86
134
|
public static void sendActionByJCore(Context context, Bundle bundle, String action) {
|
|
135
|
+
if (ACTION_PLUGIN_PALTFORM_ON_MESSAGING.equals(action)) {
|
|
136
|
+
ActionHelper.getInstance().doAction(context, action, bundle);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
87
139
|
JCoreHelper.runActionWithService(context, "JPUSH", action, bundle);
|
|
88
140
|
}
|
|
89
141
|
|
|
@@ -132,16 +184,64 @@ public abstract class JThirdPlatFormInterface {
|
|
|
132
184
|
public static NotificationMessage parseMessage(Context context, String rawJson) {
|
|
133
185
|
NotificationMessage message = new NotificationMessage();
|
|
134
186
|
message.context = context;
|
|
135
|
-
|
|
187
|
+
message.platform = 8;
|
|
188
|
+
message.displayForeground = "0";
|
|
189
|
+
String decoded = decodeMessageJson(rawJson);
|
|
190
|
+
if (decoded != null) {
|
|
136
191
|
try {
|
|
137
|
-
JSONObject json = new JSONObject(
|
|
138
|
-
message.msgId = json.optString("
|
|
139
|
-
message.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
192
|
+
JSONObject json = new JSONObject(decoded);
|
|
193
|
+
message.msgId = json.optString("_jmsgid_", json.optString("_j_msgid", ""));
|
|
194
|
+
if (message.msgId.isEmpty()) {
|
|
195
|
+
message.msgId = json.optString("msg_id", "");
|
|
196
|
+
}
|
|
197
|
+
String overrideId = json.optString("override_msg_id", "");
|
|
198
|
+
if (!overrideId.isEmpty()) {
|
|
199
|
+
message.msgId = overrideId;
|
|
200
|
+
}
|
|
201
|
+
message.notificationId = getNofiticationID(message.msgId, 0);
|
|
202
|
+
message.notificationTitle = json.optString("n_title", json.optString("title", ""));
|
|
203
|
+
message.notificationContent = json.optString("n_content", json.optString("alert", json.optString("content", "")));
|
|
204
|
+
Object extras = json.opt("n_extras");
|
|
205
|
+
if (extras == null) {
|
|
206
|
+
extras = json.opt("extras");
|
|
207
|
+
}
|
|
208
|
+
message.notificationExtras = extras != null ? extras.toString() : "";
|
|
209
|
+
message.notificationChannelId = json.optString("n_channel_id", "");
|
|
210
|
+
if (!JCoreStorage.isPushStopped(context) && JCoreStorage.isCollectionAuth(context)) {
|
|
211
|
+
message.displayForeground = json.optString("n_foreground", "1");
|
|
212
|
+
}
|
|
213
|
+
} catch (Exception invalidMessage) {
|
|
214
|
+
JLogger.w("FCM payload rejected");
|
|
143
215
|
}
|
|
144
216
|
}
|
|
145
217
|
return message;
|
|
146
218
|
}
|
|
219
|
+
|
|
220
|
+
public static String decodeMessageJson(String rawJson) {
|
|
221
|
+
if (rawJson == null || rawJson.length() > MAX_MESSAGE_BYTES
|
|
222
|
+
|| rawJson.getBytes(StandardCharsets.UTF_8).length > MAX_MESSAGE_BYTES) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
JSONObject json = new JSONObject(rawJson);
|
|
227
|
+
if (!json.has("jg_c")) {
|
|
228
|
+
return rawJson;
|
|
229
|
+
}
|
|
230
|
+
byte[] compressed = JCoreCrypto.base64Decode(json.getString("jg_c"));
|
|
231
|
+
try (GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(compressed));
|
|
232
|
+
ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
233
|
+
byte[] buffer = new byte[2048];
|
|
234
|
+
int count;
|
|
235
|
+
while ((count = input.read(buffer)) != -1) {
|
|
236
|
+
if (output.size() + count > MAX_MESSAGE_BYTES) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
output.write(buffer, 0, count);
|
|
240
|
+
}
|
|
241
|
+
return new String(output.toByteArray(), StandardCharsets.UTF_8);
|
|
242
|
+
}
|
|
243
|
+
} catch (Exception invalidMessage) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
147
247
|
}
|
|
@@ -16,6 +16,7 @@ import cn.jiguang.core.JCoreWireCodec;
|
|
|
16
16
|
import cn.jpush.android.api.CmdMessage;
|
|
17
17
|
import cn.jpush.android.api.CustomMessage;
|
|
18
18
|
import cn.jpush.android.api.JPushInterface;
|
|
19
|
+
import cn.jpush.android.api.JThirdPlatFormInterface;
|
|
19
20
|
import cn.jpush.android.api.JPushMessage;
|
|
20
21
|
import cn.jpush.android.api.NotificationCustomButton;
|
|
21
22
|
import cn.jpush.android.api.NotificationMessage;
|
|
@@ -111,6 +112,64 @@ public class ActionHelper {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
public void doAction(Context context, String action, Object data) {
|
|
115
|
+
if (!(data instanceof Bundle) || JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
Bundle bundle = (Bundle) data;
|
|
119
|
+
if ("third_action".equals(action)) {
|
|
120
|
+
action = bundle.getString("third_key_action", "");
|
|
121
|
+
}
|
|
122
|
+
if (JThirdPlatFormInterface.ACTION_REGISTER_TOKEN.equals(action)) {
|
|
123
|
+
String token = bundle.getString("token", "");
|
|
124
|
+
byte platform = bundle.getByte("platform", (byte) 8);
|
|
125
|
+
if (platform == 8 && !token.isEmpty()) {
|
|
126
|
+
setThirdTokenWithCallBack(context, token, platform, false);
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (JThirdPlatFormInterface.ACTION_SEND_EXCEPTION.equals(action)) {
|
|
131
|
+
cn.jiguang.plugins.push.common.JLogger.w("FCM plugin reported an error");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
String raw = bundle.getString("data", bundle.getString("JMessageExtra", ""));
|
|
135
|
+
String decoded = JThirdPlatFormInterface.decodeMessageJson(raw);
|
|
136
|
+
if (decoded == null) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
NotificationMessage message = JThirdPlatFormInterface.parseMessage(context, decoded);
|
|
140
|
+
if (message.msgId == null || message.msgId.isEmpty()) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
message.notificationId = bundle.getInt("noti_id", message.notificationId);
|
|
144
|
+
if (JThirdPlatFormInterface.ACTION_PLUGIN_PALTFORM_ON_MESSAGING.equals(action)) {
|
|
145
|
+
try {
|
|
146
|
+
JSONObject json = new JSONObject(decoded);
|
|
147
|
+
if (json.has("message") && message.notificationContent.isEmpty()) {
|
|
148
|
+
CustomMessage custom = new CustomMessage();
|
|
149
|
+
custom.messageId = message.msgId;
|
|
150
|
+
custom.message = json.optString("message", "");
|
|
151
|
+
custom.title = message.notificationTitle;
|
|
152
|
+
custom.extra = message.notificationExtras;
|
|
153
|
+
custom.contentType = json.optString("content_type", "");
|
|
154
|
+
custom.platform = 8;
|
|
155
|
+
dispatchCustomMessageEvent(context, custom);
|
|
156
|
+
} else {
|
|
157
|
+
if ("0".equals(message.displayForeground)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
postSystemNotification(context, message);
|
|
161
|
+
dispatchNotificationEvent(context, "notify_arrived", message);
|
|
162
|
+
}
|
|
163
|
+
} catch (Exception invalidMessage) {
|
|
164
|
+
cn.jiguang.plugins.push.common.JLogger.w("FCM payload rejected");
|
|
165
|
+
}
|
|
166
|
+
} else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_ARRIVED.equals(action)) {
|
|
167
|
+
recordNotificationPosted(context, message.notificationId);
|
|
168
|
+
dispatchNotificationEvent(context, "notify_arrived", message);
|
|
169
|
+
} else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_CLCKED.equals(action)) {
|
|
170
|
+
dispatchNotificationEvent(context, "notify_opened", message);
|
|
171
|
+
broadcastNotificationOpened(context, message);
|
|
172
|
+
}
|
|
114
173
|
}
|
|
115
174
|
|
|
116
175
|
public void doSingleAction(Context context, String action, Object data) {
|
|
@@ -148,10 +207,29 @@ public class ActionHelper {
|
|
|
148
207
|
return;
|
|
149
208
|
}
|
|
150
209
|
Serializable msg = intent.getSerializableExtra("multi_notification_msg");
|
|
210
|
+
boolean fcmClick = !(msg instanceof NotificationMessage) && intent.hasExtra("JMessageExtra");
|
|
211
|
+
if (fcmClick) {
|
|
212
|
+
if (JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
NotificationMessage message = JThirdPlatFormInterface.parseMessage(context, intent.getStringExtra("JMessageExtra"));
|
|
216
|
+
if (message.msgId == null || message.msgId.isEmpty()) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
msg = message;
|
|
220
|
+
}
|
|
151
221
|
if (msg instanceof NotificationMessage) {
|
|
152
222
|
NotificationMessage notificationMessage = (NotificationMessage) msg;
|
|
153
223
|
dispatchNotificationEvent(context, "notify_opened", notificationMessage);
|
|
154
224
|
broadcastNotificationOpened(context, notificationMessage);
|
|
225
|
+
if (fcmClick || notificationMessage.platform == 8) {
|
|
226
|
+
android.content.pm.PackageManager manager = context.getPackageManager();
|
|
227
|
+
Intent launcher = manager != null ? manager.getLaunchIntentForPackage(appPkg) : null;
|
|
228
|
+
if (launcher != null) {
|
|
229
|
+
launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
230
|
+
context.startActivity(launcher);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
155
233
|
}
|
|
156
234
|
} catch (Throwable ignored) {
|
|
157
235
|
}
|
|
@@ -897,6 +975,7 @@ public class ActionHelper {
|
|
|
897
975
|
if (statusCode == 0) {
|
|
898
976
|
JCoreStorage.saveThirdToken(context, platform, unbind ? "" : token);
|
|
899
977
|
}
|
|
978
|
+
cn.jiguang.plugins.push.common.JLogger.i("Third token result platform=" + platform + " code=" + statusCode);
|
|
900
979
|
Intent intent = buildBaseReceiverIntent(context, "cmd_result", 0, statusCode);
|
|
901
980
|
intent.putExtra("cmd", 10000);
|
|
902
981
|
intent.putExtra("msg", unbind ? "unbind" : "bind");
|
|
@@ -10,6 +10,7 @@ import cn.jpush.android.api.JPushMessage;
|
|
|
10
10
|
import cn.jpush.android.api.NotificationCustomButton;
|
|
11
11
|
import cn.jpush.android.api.NotificationMessage;
|
|
12
12
|
import cn.jpush.android.local.ActionHelper;
|
|
13
|
+
import cn.jiguang.core.JCoreStorage;
|
|
13
14
|
|
|
14
15
|
public abstract class JPushMessageReceiver extends BroadcastReceiver {
|
|
15
16
|
@Override
|
|
@@ -74,7 +75,7 @@ public abstract class JPushMessageReceiver extends BroadcastReceiver {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
public boolean isNeedShowNotification(Context context, NotificationMessage notificationMessage, String processName) {
|
|
77
|
-
return
|
|
78
|
+
return !JCoreStorage.isPushStopped(context) && JCoreStorage.isCollectionAuth(context);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
public void onInAppMessageShow(Context context, NotificationMessage notificationMessage) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-jpush",
|
|
3
|
-
"version": "6.7.0-alpha.
|
|
3
|
+
"version": "6.7.0-alpha.436",
|
|
4
4
|
"description": "Clean-room JPush and JCore React Native Nitro module for OneKey",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"react-native.config.js",
|
|
25
25
|
"!ios/build",
|
|
26
26
|
"!android/build",
|
|
27
|
+
"!android/fcm/build",
|
|
27
28
|
"!android/gradle",
|
|
28
29
|
"!android/gradlew",
|
|
29
30
|
"!android/gradlew.bat",
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
"typescript": "^5.9.2"
|
|
94
95
|
},
|
|
95
96
|
"peerDependencies": {
|
|
96
|
-
"@onekeyfe/react-native-native-logger": "6.7.0-alpha.
|
|
97
|
+
"@onekeyfe/react-native-native-logger": "6.7.0-alpha.436",
|
|
97
98
|
"react": "*",
|
|
98
99
|
"react-native": "*",
|
|
99
100
|
"react-native-nitro-modules": "0.37.0"
|