@onekeyfe/react-native-jpush 6.7.0-alpha.435 → 6.7.0-alpha.444
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 +34 -1
- package/android/build.gradle +1 -0
- package/android/fcm/build.gradle +36 -0
- package/android/fcm/consumer-rules.pro +2 -0
- package/android/fcm/src/main/AndroidManifest.xml +25 -0
- package/android/fcm/src/main/java/com/onekey/jpush/fcm/FcmInitProvider.java +25 -0
- package/android/fcm/src/main/java/com/onekey/jpush/fcm/FcmMessagingService.java +84 -0
- package/android/fcm/src/main/java/com/onekey/jpush/fcm/FcmPushManager.java +69 -0
- package/android/fcm/src/test/java/com/onekey/jpush/fcm/FcmAdapterTest.java +684 -0
- package/android/fcm/src/test/java/com/onekey/jpush/fcm/FcmManifestTest.java +54 -0
- package/android/src/main/java/cn/jiguang/api/utils/JCollectionAuth.java +6 -1
- 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 +95 -0
- package/android/src/main/java/cn/jpush/android/service/JPushMessageReceiver.java +2 -1
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/JPushCloudHandshakeTest.java +110 -0
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/JPushHandshakeFailureTest.java +73 -0
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +0 -108
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,6 +19,39 @@ yarn workspace @onekeyfe/react-native-jpush typecheck
|
|
|
19
19
|
yarn workspace @onekeyfe/react-native-jpush lint
|
|
20
20
|
yarn workspace @onekeyfe/react-native-jpush test
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# Resolve JUnit dependencies and run the core/FCM module suites
|
|
23
|
+
(cd example/react-native/android && ./gradlew :onekeyfe_react-native-jpush:testDebugUnitTest :onekey-jpush-fcm:testDebugUnitTest)
|
|
24
|
+
|
|
25
|
+
# macOS: native host build/protocol regressions (loopback servers and isolated RN/Android shims)
|
|
23
26
|
python3 native-modules/react-native-jpush/scripts/verify_clean_sdk.py
|
|
24
27
|
```
|
|
28
|
+
|
|
29
|
+
Java and Objective-C host fixtures live in `tests/android` and `tests/ios`; Python only builds, runs and checks artifacts. Android host tests use real JUnit 4.13.2 from the Gradle dependency cache. The FCM Gradle suite uses Robolectric and real Firebase message/task types, with mocked external token requests. These checks do not establish physical-device or cloud delivery.
|
|
30
|
+
|
|
31
|
+
The external Jiguang sandbox register/login test is explicitly skipped by default. Set `JPUSH_LIVE_TESTS=1` when running either Android test entry to enable it; then all network/protocol/assertion failures fail the test. CI runs both host suites plus Gradle FCM tests. A manual `native-tests` workflow can enable the same cloud check with `jpush_live_cloud`.
|
|
32
|
+
|
|
33
|
+
## Android Google / FCM source transport
|
|
34
|
+
|
|
35
|
+
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):
|
|
36
|
+
|
|
37
|
+
```groovy
|
|
38
|
+
// settings.gradle, after React Native autolinking
|
|
39
|
+
include ':onekey-jpush-fcm'
|
|
40
|
+
project(':onekey-jpush-fcm').projectDir = new File(project(':jpush-react-native').projectDir, 'fcm')
|
|
41
|
+
|
|
42
|
+
// app/build.gradle: replace cn.jiguang.sdk.plugin:fcm
|
|
43
|
+
// Keep this dependency scoped to the Google distribution.
|
|
44
|
+
googleImplementation project(':onekey-jpush-fcm')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
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. Granting authorization after a previously unauthorized init also requests registration without reconnecting. Cloud acceptance requires the matching Firebase credentials configured in the Jiguang sender.
|
|
48
|
+
|
|
49
|
+
### Client enforcement of stopped/authorization controls
|
|
50
|
+
|
|
51
|
+
Vendor payloads do not need to change. `FcmMessagingService.handleIntent` checks `stopPush()` and collection authorization before calling the pinned Firebase Messaging 25.0.1 receive handler. This covers Firebase's automatic background display of notification/combined payloads as well as data-only delivery. Authorized messages retain Firebase's normal dispatch and deduplication; callback-level guards remain. Blocked events are discarded and are not replayed on resume or authorization grant. Keep the receive-entry integration tests when upgrading Firebase because this override uses its internal public receive hook.
|
|
52
|
+
|
|
53
|
+
The optional Google module disables Firebase notification delegation and removes the unguarded fallback service. A private startup provider clears any existing Google Play services notification delegate on Android 10+ after an upgrade, without requesting a token or changing consent. Other delegates are preserved. The provider runs before JS initialization, including when push is stopped or consent is absent. Existing delegation is revoked when the updated app first starts; code in a never-started update cannot revoke an already-installed delegate. Direct-boot reception before user unlock is not enabled.
|
|
54
|
+
|
|
55
|
+
For vendor background notification/combined payloads, Firebase still owns display after the gate allows delivery. Their click action must remain `cn.jpush.android.intent.NOTIFICATION_OPENED` so the private JPush activity receives `JMessageExtra`. Data-only payloads continue through the native arrival/custom-message pipeline.
|
|
56
|
+
|
|
57
|
+
Device acceptance must cover background notification-only, combined and data-only payloads: normal authorized delivery, no display/callback after stop or authorization withdrawal, normal delivery after resume/regrant, and an upgrade from existing Play services delegation. Robolectric tests run Firebase's real Intent receive/display code with only its transport acknowledgement mocked; they do not establish vendor cloud or physical-device acceptance.
|
package/android/build.gradle
CHANGED
|
@@ -107,6 +107,7 @@ android {
|
|
|
107
107
|
testOptions {
|
|
108
108
|
unitTests.returnDefaultValues = true
|
|
109
109
|
unitTests.all {
|
|
110
|
+
inputs.property("jpushLiveTests", System.getenv("JPUSH_LIVE_TESTS") ?: "0")
|
|
110
111
|
testLogging {
|
|
111
112
|
events "passed", "skipped", "failed", "standardOut", "standardError"
|
|
112
113
|
outputs.upToDateWhen { false }
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
testOptions {
|
|
19
|
+
unitTests.includeAndroidResources = true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def coreProject = rootProject.subprojects.find {
|
|
24
|
+
it.projectDir.canonicalFile == projectDir.parentFile.canonicalFile
|
|
25
|
+
}
|
|
26
|
+
if (coreProject == null) {
|
|
27
|
+
throw new GradleException('The FCM library requires the autolinked JPush core project.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
dependencies {
|
|
31
|
+
implementation project(coreProject.path)
|
|
32
|
+
implementation 'com.google.firebase:firebase-messaging:25.0.1'
|
|
33
|
+
testImplementation 'junit:junit:4.13.2'
|
|
34
|
+
testImplementation 'org.robolectric:robolectric:4.17'
|
|
35
|
+
testImplementation 'org.mockito:mockito-core:5.20.0'
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools">
|
|
3
|
+
<application>
|
|
4
|
+
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
|
|
5
|
+
<meta-data android:name="firebase_messaging_notification_delegation_enabled" android:value="false" />
|
|
6
|
+
<provider
|
|
7
|
+
android:name="com.onekey.jpush.fcm.FcmInitProvider"
|
|
8
|
+
android:authorities="${applicationId}.onekey.fcm.init"
|
|
9
|
+
android:exported="false" />
|
|
10
|
+
<service
|
|
11
|
+
android:name="com.google.firebase.messaging.FirebaseMessagingService"
|
|
12
|
+
tools:node="remove" />
|
|
13
|
+
<service android:name="com.onekey.jpush.fcm.FcmMessagingService" android:exported="false">
|
|
14
|
+
<intent-filter>
|
|
15
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
16
|
+
</intent-filter>
|
|
17
|
+
</service>
|
|
18
|
+
<activity android:name="cn.jpush.android.service.JNotifyActivity" android:exported="false">
|
|
19
|
+
<intent-filter>
|
|
20
|
+
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
|
|
21
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
22
|
+
</intent-filter>
|
|
23
|
+
</activity>
|
|
24
|
+
</application>
|
|
25
|
+
</manifest>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.onekey.jpush.fcm;
|
|
2
|
+
|
|
3
|
+
import android.app.NotificationManager;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import cn.jiguang.plugins.push.common.JLogger;
|
|
7
|
+
import cn.jpush.android.service.InitProvider;
|
|
8
|
+
|
|
9
|
+
public final class FcmInitProvider extends InitProvider {
|
|
10
|
+
@Override
|
|
11
|
+
public boolean onCreate() {
|
|
12
|
+
super.onCreate();
|
|
13
|
+
Context context = getContext();
|
|
14
|
+
if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
15
|
+
NotificationManager notifications = context.getSystemService(NotificationManager.class);
|
|
16
|
+
// Firebase caches delegation initialization across upgrades, so manifest opt-out alone
|
|
17
|
+
// does not revoke an existing Play services delegate.
|
|
18
|
+
if (notifications != null && "com.google.android.gms".equals(notifications.getNotificationDelegate())) {
|
|
19
|
+
notifications.setNotificationDelegate(null);
|
|
20
|
+
JLogger.i("FCM notification delegation disabled");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package com.onekey.jpush.fcm;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.os.Bundle;
|
|
5
|
+
import cn.jiguang.api.JCoreManager;
|
|
6
|
+
import cn.jiguang.core.JCoreStorage;
|
|
7
|
+
import cn.jiguang.plugins.push.common.JLogger;
|
|
8
|
+
import cn.jpush.android.api.JThirdPlatFormInterface;
|
|
9
|
+
import cn.jpush.android.local.ActionHelper;
|
|
10
|
+
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
11
|
+
import com.google.firebase.messaging.RemoteMessage;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
import org.json.JSONObject;
|
|
14
|
+
|
|
15
|
+
public final class FcmMessagingService extends FirebaseMessagingService {
|
|
16
|
+
@Override
|
|
17
|
+
public void handleIntent(Intent intent) {
|
|
18
|
+
// Firebase may display background notifications before onMessageReceived is called.
|
|
19
|
+
if (JCoreStorage.isPushStopped(this) || !JCoreStorage.isCollectionAuth(this)) {
|
|
20
|
+
JLogger.i("FCM receive blocked by push or authorization state");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
super.handleIntent(intent);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void onNewToken(String token) {
|
|
28
|
+
if (JCoreStorage.isPushStopped(this) || !JCoreStorage.isCollectionAuth(this)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Initialize the transport without fetching and submitting this token a second time.
|
|
32
|
+
JCoreManager.init(getApplicationContext());
|
|
33
|
+
FcmPushManager.acceptToken(getApplicationContext(), token);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Override
|
|
37
|
+
public void onMessageReceived(RemoteMessage remoteMessage) {
|
|
38
|
+
if (JCoreStorage.isPushStopped(this) || !JCoreStorage.isCollectionAuth(this)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
Map<String, String> data = remoteMessage.getData();
|
|
43
|
+
String raw = data.get("JMessageExtra");
|
|
44
|
+
JSONObject message;
|
|
45
|
+
if (raw == null || raw.isEmpty()) {
|
|
46
|
+
message = new JSONObject(data);
|
|
47
|
+
} else {
|
|
48
|
+
String decoded = JThirdPlatFormInterface.decodeMessageJson(raw);
|
|
49
|
+
if (decoded == null) {
|
|
50
|
+
JLogger.w("FCM payload rejected");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
message = new JSONObject(decoded);
|
|
54
|
+
}
|
|
55
|
+
RemoteMessage.Notification notification = remoteMessage.getNotification();
|
|
56
|
+
if (notification != null) {
|
|
57
|
+
if (!message.has("n_title") && !message.has("title")) {
|
|
58
|
+
message.put("n_title", notification.getTitle());
|
|
59
|
+
}
|
|
60
|
+
if (!message.has("n_content") && !message.has("alert") && !message.has("content")) {
|
|
61
|
+
message.put("n_content", notification.getBody());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!message.has("msg_id") && !message.has("_jmsgid_") && !message.has("_j_msgid")) {
|
|
65
|
+
message.put("msg_id", remoteMessage.getMessageId());
|
|
66
|
+
}
|
|
67
|
+
if (!message.has("n_extras") && !message.has("extras") && !data.containsKey("JMessageExtra")) {
|
|
68
|
+
message.put("n_extras", new JSONObject(data));
|
|
69
|
+
}
|
|
70
|
+
raw = message.toString();
|
|
71
|
+
Bundle payload = new Bundle();
|
|
72
|
+
payload.putString("JMessageExtra", raw);
|
|
73
|
+
payload.putByte("platform", (byte) 8);
|
|
74
|
+
ActionHelper.getInstance().doAction(
|
|
75
|
+
getApplicationContext(),
|
|
76
|
+
JThirdPlatFormInterface.ACTION_PLUGIN_PALTFORM_ON_MESSAGING,
|
|
77
|
+
payload
|
|
78
|
+
);
|
|
79
|
+
JLogger.i("FCM message forwarded to native dispatcher");
|
|
80
|
+
} catch (Exception invalidMessage) {
|
|
81
|
+
JLogger.w("FCM payload rejected");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -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
|
+
}
|