@onekeyfe/react-native-jpush 0.0.0-stage → 6.7.0-23
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/LICENSE +21 -0
- package/README.md +56 -2
- package/ReactNativeJpush.podspec +66 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +144 -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/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +143 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/cn/android/service/JTransitActivity.java +19 -0
- package/android/src/main/java/cn/jiguang/android/BuildConfig.java +10 -0
- package/android/src/main/java/cn/jiguang/android/IDataShare.java +190 -0
- package/android/src/main/java/cn/jiguang/api/BaseLogger.java +82 -0
- package/android/src/main/java/cn/jiguang/api/JAction.java +22 -0
- package/android/src/main/java/cn/jiguang/api/JActionExtra.java +21 -0
- package/android/src/main/java/cn/jiguang/api/JAnalyticsAction.java +11 -0
- package/android/src/main/java/cn/jiguang/api/JCoreInterface.java +228 -0
- package/android/src/main/java/cn/jiguang/api/JCoreManager.java +156 -0
- package/android/src/main/java/cn/jiguang/api/JDispatchAction.java +66 -0
- package/android/src/main/java/cn/jiguang/api/MultiSpHelper.java +114 -0
- package/android/src/main/java/cn/jiguang/api/ReportCallBack.java +9 -0
- package/android/src/main/java/cn/jiguang/api/SdkType.java +13 -0
- package/android/src/main/java/cn/jiguang/api/utils/JCollectionAuth.java +28 -0
- package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +545 -0
- package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +737 -0
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +1395 -0
- package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1716 -0
- package/android/src/main/java/cn/jiguang/internal/ActionManager.java +63 -0
- package/android/src/main/java/cn/jiguang/internal/JConstants.java +61 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreHelperAction.java +12 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreInternalHelper.java +102 -0
- package/android/src/main/java/cn/jiguang/net/DefaultHostVerifier.java +40 -0
- package/android/src/main/java/cn/jiguang/net/HttpRequest.java +78 -0
- package/android/src/main/java/cn/jiguang/net/HttpResponse.java +48 -0
- package/android/src/main/java/cn/jiguang/net/HttpUtils.java +106 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +91 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCorePackage.java +27 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +773 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushPackage.java +25 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +88 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JLogger.java +122 -0
- package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +710 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushBroadcastReceiver.java +37 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +264 -0
- package/android/src/main/java/cn/jiguang/plugins/service/JCoreModuleService.java +7 -0
- package/android/src/main/java/cn/jpush/android/api/BasicPushNotificationBuilder.java +83 -0
- package/android/src/main/java/cn/jpush/android/api/CallBackParams.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/CmdMessage.java +33 -0
- package/android/src/main/java/cn/jpush/android/api/CustomMessage.java +28 -0
- package/android/src/main/java/cn/jpush/android/api/CustomPushNotificationBuilder.java +81 -0
- package/android/src/main/java/cn/jpush/android/api/DefaultPushNotificationBuilder.java +90 -0
- package/android/src/main/java/cn/jpush/android/api/InAppSlotParams.java +65 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedListActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +490 -0
- package/android/src/main/java/cn/jpush/android/api/JPushMessage.java +121 -0
- package/android/src/main/java/cn/jpush/android/api/JThirdPlatFormInterface.java +247 -0
- package/android/src/main/java/cn/jpush/android/api/MultiActionsNotificationBuilder.java +72 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationCustomButton.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationMessage.java +67 -0
- package/android/src/main/java/cn/jpush/android/api/PushNotificationBuilder.java +13 -0
- package/android/src/main/java/cn/jpush/android/api/TagAliasCallback.java +8 -0
- package/android/src/main/java/cn/jpush/android/data/JPushCollectControl.java +96 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfig.java +79 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfigEx.java +41 -0
- package/android/src/main/java/cn/jpush/android/data/JPushLocalNotification.java +155 -0
- package/android/src/main/java/cn/jpush/android/helper/JCoreHelper.java +70 -0
- package/android/src/main/java/cn/jpush/android/helper/Logger.java +82 -0
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +1293 -0
- package/android/src/main/java/cn/jpush/android/local/ActivityLifeCallBack.java +47 -0
- package/android/src/main/java/cn/jpush/android/local/JPushAction.java +67 -0
- package/android/src/main/java/cn/jpush/android/local/JPushConstants.java +34 -0
- package/android/src/main/java/cn/jpush/android/local/JPushResponse.java +26 -0
- package/android/src/main/java/cn/jpush/android/local/ProxyActivityAction.java +34 -0
- package/android/src/main/java/cn/jpush/android/service/AlarmReceiver.java +15 -0
- package/android/src/main/java/cn/jpush/android/service/BActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DaemonService.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/DataProvider.java +136 -0
- package/android/src/main/java/cn/jpush/android/service/DataShare.java +129 -0
- package/android/src/main/java/cn/jpush/android/service/DownloadProvider.java +139 -0
- package/android/src/main/java/cn/jpush/android/service/InitProvider.java +48 -0
- package/android/src/main/java/cn/jpush/android/service/JCommonService.java +79 -0
- package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/JPushMessageReceiver.java +94 -0
- package/android/src/main/java/cn/jpush/android/service/PushReceiver.java +26 -0
- package/android/src/main/java/cn/jpush/android/service/PushService.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/SchedulerReceiver.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/TagAliasReceiver.java +11 -0
- package/android/src/main/java/cn/jpush/android/service/WakedResultReceiver.java +24 -0
- package/android/src/main/java/cn/jpush/android/ui/FullScreenView.java +11 -0
- package/android/src/main/java/cn/jpush/android/ui/PopWinActivity.java +16 -0
- package/android/src/main/java/cn/jpush/android/ui/PushActivity.java +27 -0
- package/android/src/main/java/cn/jpush/android/ui/RoundedImageView.java +63 -0
- package/android/src/main/java/cn/jpush/android/ui/ShadowViewCard.java +56 -0
- package/android/src/main/java/cn/jpush/android/ups/ICallbackResult.java +5 -0
- package/android/src/main/java/cn/jpush/android/ups/JPushUPSManager.java +37 -0
- package/android/src/main/java/cn/jpush/android/ups/TokenResult.java +47 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSRegisterCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSTurnCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSUnRegisterCallBack.java +4 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +455 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushPackage.kt +50 -0
- package/android/src/main/res/values/jpush_string.xml +7 -0
- package/android/src/main/res/values/jpush_style.xml +22 -0
- 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 +908 -0
- package/ios/ReactNativeJpush.swift +522 -0
- package/ios/bridge/RCTJCoreModule.h +5 -0
- package/ios/bridge/RCTJCoreModule.m +31 -0
- package/ios/bridge/RCTJPushEventQueue.h +14 -0
- package/ios/bridge/RCTJPushEventQueue.m +23 -0
- package/ios/bridge/RCTJPushModule.h +37 -0
- package/ios/bridge/RCTJPushModule.m +1165 -0
- package/ios/include/JCOREService.h +3 -0
- package/ios/include/JGCOREAPI.h +14 -0
- package/ios/include/JGInforCollectionAuth.h +17 -0
- package/ios/include/JGInforCollectionAuthItems.h +2 -0
- package/ios/include/JGPushNotificationTrigger.h +2 -0
- package/ios/include/JPUSHService.h +359 -0
- package/ios/jcore/JCOREConfiguration.h +141 -0
- package/ios/jcore/JCOREConfiguration.m +703 -0
- package/ios/jcore/JCORECrypto.h +73 -0
- package/ios/jcore/JCORECrypto.m +649 -0
- package/ios/jcore/JCORESisResolver.h +56 -0
- package/ios/jcore/JCORESisResolver.m +525 -0
- package/ios/jcore/JCORETcpSession.h +42 -0
- package/ios/jcore/JCORETcpSession.m +956 -0
- package/ios/jcore/JCOREWireProtocol.h +274 -0
- package/ios/jcore/JCOREWireProtocol.m +1453 -0
- package/ios/jpush/JPUSHModels.m +214 -0
- package/ios/jpush/JPUSHNotificationManager.h +34 -0
- package/ios/jpush/JPUSHNotificationManager.m +360 -0
- package/ios/jpush/JPUSHService.m +794 -0
- package/ios/tests/ReactNativeJpushTests.m +148 -0
- package/lib/module/ReactNativeJpush.nitro.js +4 -0
- package/lib/module/ReactNativeJpush.nitro.js.map +1 -0
- package/lib/module/index.js +801 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts +60 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +235 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.cpp +310 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.hpp +115 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_std__string_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/HybridReactNativeJpushSpec.kt +274 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/reactnativejpushOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.cpp +58 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/ReactNativeJpush+autolinking.rb +62 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.hpp +147 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.hpp +402 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec.swift +107 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec_cxx.swift +723 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.cpp +73 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.hpp +116 -0
- package/package.json +174 -4
- package/src/ReactNativeJpush.nitro.ts +93 -0
- package/src/index.tsx +1090 -0
|
@@ -0,0 +1,1293 @@
|
|
|
1
|
+
package cn.jpush.android.local;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.app.ActivityManager;
|
|
5
|
+
import android.app.KeyguardManager;
|
|
6
|
+
import android.app.Notification;
|
|
7
|
+
import android.app.NotificationChannel;
|
|
8
|
+
import android.app.NotificationManager;
|
|
9
|
+
import android.app.PendingIntent;
|
|
10
|
+
import android.content.Context;
|
|
11
|
+
import android.content.Intent;
|
|
12
|
+
import android.content.pm.ApplicationInfo;
|
|
13
|
+
import android.os.Build;
|
|
14
|
+
import android.os.Bundle;
|
|
15
|
+
import cn.jiguang.core.JCoreStorage;
|
|
16
|
+
import cn.jiguang.core.JCoreTcpEngine;
|
|
17
|
+
import cn.jiguang.core.JCoreWireCodec;
|
|
18
|
+
import cn.jpush.android.api.CmdMessage;
|
|
19
|
+
import cn.jpush.android.api.CustomMessage;
|
|
20
|
+
import cn.jpush.android.api.JPushInterface;
|
|
21
|
+
import cn.jpush.android.api.JThirdPlatFormInterface;
|
|
22
|
+
import cn.jpush.android.api.JPushMessage;
|
|
23
|
+
import cn.jpush.android.api.NotificationCustomButton;
|
|
24
|
+
import cn.jpush.android.api.NotificationMessage;
|
|
25
|
+
import cn.jpush.android.api.TagAliasCallback;
|
|
26
|
+
import cn.jpush.android.data.JPushLocalNotification;
|
|
27
|
+
import cn.jpush.android.service.JNotifyActivity;
|
|
28
|
+
import cn.jpush.android.service.JPushMessageReceiver;
|
|
29
|
+
import java.io.Serializable;
|
|
30
|
+
import java.util.ArrayList;
|
|
31
|
+
import java.util.Calendar;
|
|
32
|
+
import java.util.HashMap;
|
|
33
|
+
import java.util.HashSet;
|
|
34
|
+
import java.util.LinkedList;
|
|
35
|
+
import java.util.List;
|
|
36
|
+
import java.util.Map;
|
|
37
|
+
import java.util.Set;
|
|
38
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
39
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
40
|
+
import java.util.concurrent.Executors;
|
|
41
|
+
import java.util.concurrent.ScheduledExecutorService;
|
|
42
|
+
import java.util.concurrent.ScheduledFuture;
|
|
43
|
+
import java.util.concurrent.ThreadFactory;
|
|
44
|
+
import java.util.concurrent.TimeUnit;
|
|
45
|
+
import org.json.JSONArray;
|
|
46
|
+
import org.json.JSONObject;
|
|
47
|
+
|
|
48
|
+
public class ActionHelper {
|
|
49
|
+
public static final String ACTION_RECEIVER_MESSAGE = "cn.jpush.android.intent.RECEIVER_MESSAGE";
|
|
50
|
+
public static final String ACTION_RECEIVE_MESSAGE = "cn.jpush.android.intent.RECEIVE_MESSAGE";
|
|
51
|
+
public static final String DEFAULT_CHANNEL_ID = "jpush_default_channel";
|
|
52
|
+
public static final String DEFAULT_SILENT_CHANNEL_ID = "jpush_silent_channel";
|
|
53
|
+
|
|
54
|
+
private static final String KEY_EVENT_TYPE = "jpush_event_type";
|
|
55
|
+
private static final String KEY_SEQUENCE = "jpush_sequence";
|
|
56
|
+
private static final String KEY_ERROR_CODE = "jpush_error_code";
|
|
57
|
+
private static final String KEY_ALIAS = "jpush_alias";
|
|
58
|
+
private static final String KEY_TAGS = "jpush_tags";
|
|
59
|
+
private static final String KEY_CHECK_TAG = "jpush_check_tag";
|
|
60
|
+
private static final String KEY_TAG_BIND_STATE = "jpush_tag_bind_state";
|
|
61
|
+
private static final String KEY_MOBILE_NUMBER = "jpush_mobile_number";
|
|
62
|
+
private static final String KEY_PROPS_MAP = "jpush_props_map";
|
|
63
|
+
private static final String KEY_NOTIFICATION_MESSAGE = "jpush_notification_message";
|
|
64
|
+
private static final String KEY_CUSTOM_MESSAGE = "jpush_custom_message";
|
|
65
|
+
private static final String KEY_CUSTOM_BUTTON = "jpush_custom_button";
|
|
66
|
+
|
|
67
|
+
private static volatile ActionHelper instance;
|
|
68
|
+
private final List<JPushMessageReceiver> registeredReceivers = new CopyOnWriteArrayList<JPushMessageReceiver>();
|
|
69
|
+
private final LinkedList<Integer> activeNotificationIds = new LinkedList<Integer>();
|
|
70
|
+
private final ConcurrentHashMap<Integer, ScheduledFuture<?>> pendingLocalNotifications =
|
|
71
|
+
new ConcurrentHashMap<Integer, ScheduledFuture<?>>();
|
|
72
|
+
private final ScheduledExecutorService localNotificationScheduler =
|
|
73
|
+
Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
|
74
|
+
@Override
|
|
75
|
+
public Thread newThread(Runnable r) {
|
|
76
|
+
Thread t = new Thread(r, "jpush-local-notify");
|
|
77
|
+
t.setDaemon(true);
|
|
78
|
+
return t;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
private ActionHelper() {
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public static ActionHelper getInstance() {
|
|
86
|
+
if (instance == null) {
|
|
87
|
+
synchronized (ActionHelper.class) {
|
|
88
|
+
if (instance == null) {
|
|
89
|
+
instance = new ActionHelper();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return instance;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void registerReceiver(JPushMessageReceiver receiver) {
|
|
97
|
+
if (receiver != null && !registeredReceivers.contains(receiver)) {
|
|
98
|
+
registeredReceivers.add(receiver);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void unregisterReceiver(JPushMessageReceiver receiver) {
|
|
103
|
+
if (receiver != null) {
|
|
104
|
+
registeredReceivers.remove(receiver);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void clearRegisteredReceivers() {
|
|
109
|
+
registeredReceivers.clear();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public void init(Context context) {
|
|
113
|
+
JPushConstants.init(context);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public void doAction(Context context, String action, Object data) {
|
|
117
|
+
if (!(data instanceof Bundle) || JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
Bundle bundle = (Bundle) data;
|
|
121
|
+
if ("third_action".equals(action)) {
|
|
122
|
+
action = bundle.getString("third_key_action", "");
|
|
123
|
+
}
|
|
124
|
+
if (JThirdPlatFormInterface.ACTION_REGISTER_TOKEN.equals(action)) {
|
|
125
|
+
String token = bundle.getString("token", "");
|
|
126
|
+
byte platform = bundle.getByte("platform", (byte) 8);
|
|
127
|
+
if (platform == 8 && !token.isEmpty()) {
|
|
128
|
+
setThirdTokenWithCallBack(context, token, platform, false);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (JThirdPlatFormInterface.ACTION_SEND_EXCEPTION.equals(action)) {
|
|
133
|
+
cn.jiguang.plugins.push.common.JLogger.w("FCM plugin reported an error");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
String raw = bundle.getString("data", bundle.getString("JMessageExtra", ""));
|
|
137
|
+
String decoded = JThirdPlatFormInterface.decodeMessageJson(raw);
|
|
138
|
+
if (decoded == null) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
NotificationMessage message = JThirdPlatFormInterface.parseMessage(context, decoded);
|
|
142
|
+
if (message.msgId == null || message.msgId.isEmpty()) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
message.notificationId = bundle.getInt("noti_id", message.notificationId);
|
|
146
|
+
if (JThirdPlatFormInterface.ACTION_PLUGIN_PALTFORM_ON_MESSAGING.equals(action)) {
|
|
147
|
+
try {
|
|
148
|
+
JSONObject json = new JSONObject(decoded);
|
|
149
|
+
if (json.has("message") && message.notificationContent.isEmpty()) {
|
|
150
|
+
CustomMessage custom = new CustomMessage();
|
|
151
|
+
custom.messageId = message.msgId;
|
|
152
|
+
custom.message = json.optString("message", "");
|
|
153
|
+
custom.title = message.notificationTitle;
|
|
154
|
+
custom.extra = message.notificationExtras;
|
|
155
|
+
custom.contentType = json.optString("content_type", "");
|
|
156
|
+
custom.platform = 8;
|
|
157
|
+
dispatchCustomMessageEvent(context, custom);
|
|
158
|
+
} else {
|
|
159
|
+
if ("0".equals(message.displayForeground) && isApplicationForeground(context)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
postSystemNotification(context, message);
|
|
163
|
+
dispatchNotificationEvent(context, "notify_arrived", message);
|
|
164
|
+
}
|
|
165
|
+
} catch (Exception invalidMessage) {
|
|
166
|
+
cn.jiguang.plugins.push.common.JLogger.w("FCM payload rejected");
|
|
167
|
+
}
|
|
168
|
+
} else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_ARRIVED.equals(action)) {
|
|
169
|
+
recordNotificationPosted(context, message.notificationId);
|
|
170
|
+
dispatchNotificationEvent(context, "notify_arrived", message);
|
|
171
|
+
} else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_CLCKED.equals(action)) {
|
|
172
|
+
dispatchNotificationEvent(context, "notify_opened", message);
|
|
173
|
+
broadcastNotificationOpened(context, message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private boolean isApplicationForeground(Context context) {
|
|
178
|
+
KeyguardManager keyguard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
|
179
|
+
if (keyguard != null && keyguard.isKeyguardLocked()) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
ActivityManager.RunningAppProcessInfo process = new ActivityManager.RunningAppProcessInfo();
|
|
183
|
+
ActivityManager.getMyMemoryState(process);
|
|
184
|
+
return process.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public void doSingleAction(Context context, String action, Object data) {
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public void onEvent(Thread thread, Throwable error) {
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public void onActivityLifeCallback(Activity activity, String lifecycleEvent) {
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public ProxyActivityAction getPopWinActivity(Context context) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public ProxyActivityAction getPushActivity(Context context) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public void handleNotificationIntent(Context context, Intent intent) {
|
|
205
|
+
if (context == null || intent == null) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
String action = intent.getAction();
|
|
210
|
+
if (action != null && !action.isEmpty()
|
|
211
|
+
&& !"cn.jpush.android.intent.JNotifyActivity".equals(action)
|
|
212
|
+
&& !JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
String targetPkg = intent.getPackage();
|
|
216
|
+
String appPkg = context.getPackageName();
|
|
217
|
+
if (targetPkg != null && !targetPkg.isEmpty() && appPkg != null && !appPkg.isEmpty()
|
|
218
|
+
&& !appPkg.equals(targetPkg)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
Serializable msg = intent.getSerializableExtra("multi_notification_msg");
|
|
222
|
+
boolean fcmClick = !(msg instanceof NotificationMessage) && intent.hasExtra("JMessageExtra");
|
|
223
|
+
if (fcmClick) {
|
|
224
|
+
if (JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
NotificationMessage message = JThirdPlatFormInterface.parseMessage(context, intent.getStringExtra("JMessageExtra"));
|
|
228
|
+
if (message.msgId == null || message.msgId.isEmpty()) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
msg = message;
|
|
232
|
+
}
|
|
233
|
+
if (msg instanceof NotificationMessage) {
|
|
234
|
+
NotificationMessage notificationMessage = (NotificationMessage) msg;
|
|
235
|
+
if (notificationMessage.platform == 8
|
|
236
|
+
&& (JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context))) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
dispatchNotificationEvent(context, "notify_opened", notificationMessage);
|
|
240
|
+
broadcastNotificationOpened(context, notificationMessage);
|
|
241
|
+
if (fcmClick || notificationMessage.platform == 8) {
|
|
242
|
+
android.content.pm.PackageManager manager = context.getPackageManager();
|
|
243
|
+
Intent launcher = manager != null ? manager.getLaunchIntentForPackage(appPkg) : null;
|
|
244
|
+
if (launcher != null) {
|
|
245
|
+
launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
246
|
+
context.startActivity(launcher);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} catch (Throwable ignored) {
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public void broadcastNotificationOpened(Context context, NotificationMessage message) {
|
|
255
|
+
Context app = JCoreStorage.getAppContext(context);
|
|
256
|
+
if (app == null || message == null) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
Intent openIntent = new Intent(JPushInterface.ACTION_NOTIFICATION_OPENED);
|
|
261
|
+
String pkg = app.getPackageName();
|
|
262
|
+
if (pkg != null && !pkg.isEmpty()) {
|
|
263
|
+
openIntent.setPackage(pkg);
|
|
264
|
+
openIntent.addCategory(pkg);
|
|
265
|
+
}
|
|
266
|
+
openIntent.putExtra(JPushInterface.EXTRA_MSG_ID, message.msgId != null ? message.msgId : "");
|
|
267
|
+
openIntent.putExtra(
|
|
268
|
+
JPushInterface.EXTRA_NOTIFICATION_TITLE,
|
|
269
|
+
message.notificationTitle != null ? message.notificationTitle : ""
|
|
270
|
+
);
|
|
271
|
+
openIntent.putExtra(
|
|
272
|
+
JPushInterface.EXTRA_ALERT,
|
|
273
|
+
message.notificationContent != null ? message.notificationContent : ""
|
|
274
|
+
);
|
|
275
|
+
openIntent.putExtra(
|
|
276
|
+
JPushInterface.EXTRA_EXTRA,
|
|
277
|
+
message.notificationExtras != null ? message.notificationExtras : ""
|
|
278
|
+
);
|
|
279
|
+
openIntent.putExtra(JPushInterface.EXTRA_NOTIFICATION_ID, message.notificationId);
|
|
280
|
+
openIntent.putExtra(JPushInterface.EXTRA_NOTI_TYPE, message.notificationType);
|
|
281
|
+
openIntent.putExtra("jpush_already_dispatched", true);
|
|
282
|
+
app.sendBroadcast(openIntent);
|
|
283
|
+
} catch (Throwable ignored) {
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public synchronized List<Integer> getActiveNotificationIds() {
|
|
288
|
+
return new ArrayList<Integer>(activeNotificationIds);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public synchronized void removeActiveNotificationId(int notificationId) {
|
|
292
|
+
ScheduledFuture<?> pending = pendingLocalNotifications.remove(Integer.valueOf(notificationId));
|
|
293
|
+
if (pending != null) {
|
|
294
|
+
pending.cancel(false);
|
|
295
|
+
}
|
|
296
|
+
activeNotificationIds.remove(Integer.valueOf(notificationId));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public synchronized void clearActiveNotificationIds() {
|
|
300
|
+
for (ScheduledFuture<?> pending : pendingLocalNotifications.values()) {
|
|
301
|
+
if (pending != null) {
|
|
302
|
+
pending.cancel(false);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
pendingLocalNotifications.clear();
|
|
306
|
+
activeNotificationIds.clear();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public synchronized void recordNotificationPosted(Context context, int notifyId) {
|
|
310
|
+
activeNotificationIds.remove(Integer.valueOf(notifyId));
|
|
311
|
+
activeNotificationIds.addLast(Integer.valueOf(notifyId));
|
|
312
|
+
enforceLatestNotificationLimit(context, JCoreStorage.getLatestNotificationNumber(context));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public synchronized void enforceLatestNotificationLimit(Context context, int maxNum) {
|
|
316
|
+
if (maxNum <= 0) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
Context app = JCoreStorage.getAppContext(context);
|
|
320
|
+
NotificationManager nm = null;
|
|
321
|
+
if (app != null) {
|
|
322
|
+
try {
|
|
323
|
+
nm = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
324
|
+
} catch (Throwable ignored) {
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
while (activeNotificationIds.size() > maxNum) {
|
|
328
|
+
Integer evictedId = activeNotificationIds.removeFirst();
|
|
329
|
+
if (evictedId != null && nm != null) {
|
|
330
|
+
try {
|
|
331
|
+
nm.cancel(evictedId.intValue());
|
|
332
|
+
} catch (Throwable ignored) {
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public void postSystemNotification(Context context, NotificationMessage message) {
|
|
339
|
+
if (message == null) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
Context app = JCoreStorage.getAppContext(context);
|
|
343
|
+
Calendar now = Calendar.getInstance();
|
|
344
|
+
int dayOfWeekZeroBased = now.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
|
|
345
|
+
int hourOfDay = now.get(Calendar.HOUR_OF_DAY);
|
|
346
|
+
int minute = now.get(Calendar.MINUTE);
|
|
347
|
+
if (!JCoreStorage.isPushTimeAllowed(app, dayOfWeekZeroBased, hourOfDay)) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
boolean silenceActive = JCoreStorage.isInSilenceTime(app, hourOfDay, minute);
|
|
351
|
+
int notifyId = message.notificationId != 0
|
|
352
|
+
? message.notificationId
|
|
353
|
+
: (message.msgId != null ? Math.abs(message.msgId.hashCode()) : 1);
|
|
354
|
+
recordNotificationPosted(app, notifyId);
|
|
355
|
+
if (app == null) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
NotificationManager nm = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
360
|
+
if (nm == null) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
String channelId = (message.notificationChannelId != null && !message.notificationChannelId.isEmpty())
|
|
364
|
+
? message.notificationChannelId
|
|
365
|
+
: (silenceActive ? DEFAULT_SILENT_CHANNEL_ID : DEFAULT_CHANNEL_ID);
|
|
366
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
367
|
+
String channelName = JCoreStorage.getChannel(app);
|
|
368
|
+
if (channelName == null || channelName.isEmpty()) {
|
|
369
|
+
channelName = "Notifications";
|
|
370
|
+
}
|
|
371
|
+
int importance = silenceActive
|
|
372
|
+
? NotificationManager.IMPORTANCE_LOW
|
|
373
|
+
: NotificationManager.IMPORTANCE_HIGH;
|
|
374
|
+
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
|
|
375
|
+
if (silenceActive) {
|
|
376
|
+
channel.setSound(null, null);
|
|
377
|
+
channel.enableVibration(false);
|
|
378
|
+
}
|
|
379
|
+
nm.createNotificationChannel(channel);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
Notification.Builder builder;
|
|
383
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
384
|
+
builder = new Notification.Builder(app, channelId);
|
|
385
|
+
} else {
|
|
386
|
+
builder = new Notification.Builder(app);
|
|
387
|
+
}
|
|
388
|
+
if (silenceActive) {
|
|
389
|
+
builder.setDefaults(0).setSound(null).setVibrate(null);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
int smallIcon = android.R.drawable.ic_dialog_info;
|
|
393
|
+
try {
|
|
394
|
+
ApplicationInfo appInfo = app.getApplicationInfo();
|
|
395
|
+
if (appInfo != null && appInfo.icon != 0) {
|
|
396
|
+
smallIcon = appInfo.icon;
|
|
397
|
+
}
|
|
398
|
+
} catch (Throwable ignored) {
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
builder.setSmallIcon(smallIcon)
|
|
402
|
+
.setContentTitle(message.notificationTitle != null ? message.notificationTitle : "")
|
|
403
|
+
.setContentText(message.notificationContent != null ? message.notificationContent : "")
|
|
404
|
+
.setAutoCancel(true);
|
|
405
|
+
|
|
406
|
+
Intent clickIntent = new Intent(app, JNotifyActivity.class);
|
|
407
|
+
clickIntent.setAction("cn.jpush.android.intent.JNotifyActivity");
|
|
408
|
+
clickIntent.putExtra("multi_notification_msg", message);
|
|
409
|
+
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
410
|
+
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
411
|
+
if (Build.VERSION.SDK_INT >= 23) {
|
|
412
|
+
flags |= PendingIntent.FLAG_IMMUTABLE;
|
|
413
|
+
}
|
|
414
|
+
PendingIntent pendingIntent = PendingIntent.getActivity(app, message.notificationId, clickIntent, flags);
|
|
415
|
+
if (pendingIntent != null) {
|
|
416
|
+
builder.setContentIntent(pendingIntent);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
Notification notification = builder.build();
|
|
420
|
+
nm.notify(notifyId, notification);
|
|
421
|
+
} catch (Throwable ignored) {
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public void handleDownlinkPushMessage(Context context, byte messageType, long messageId, String rawContent) {
|
|
426
|
+
String content = rawContent != null ? rawContent : "";
|
|
427
|
+
int lastNewline = content.lastIndexOf('\n');
|
|
428
|
+
if (lastNewline >= 0 && lastNewline + 1 < content.length()) {
|
|
429
|
+
content = content.substring(lastNewline + 1).trim();
|
|
430
|
+
}
|
|
431
|
+
String msgId = String.valueOf(messageId);
|
|
432
|
+
String parsedMsgId = JCoreWireCodec.extractJsonString(content, "_j_msgid");
|
|
433
|
+
if (parsedMsgId.isEmpty()) {
|
|
434
|
+
parsedMsgId = JCoreWireCodec.extractJsonString(content, "msg_id");
|
|
435
|
+
}
|
|
436
|
+
if (!parsedMsgId.isEmpty()) {
|
|
437
|
+
msgId = parsedMsgId;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
String nTitle = JCoreWireCodec.extractJsonString(content, "n_title");
|
|
441
|
+
if (nTitle.isEmpty()) {
|
|
442
|
+
nTitle = JCoreWireCodec.extractJsonString(content, "notificationTitle");
|
|
443
|
+
}
|
|
444
|
+
String nContent = JCoreWireCodec.extractJsonString(content, "n_content");
|
|
445
|
+
if (nContent.isEmpty()) {
|
|
446
|
+
nContent = JCoreWireCodec.extractJsonString(content, "notificationContent");
|
|
447
|
+
}
|
|
448
|
+
if (nContent.isEmpty()) {
|
|
449
|
+
nContent = JCoreWireCodec.extractJsonString(content, "alert");
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
boolean isCustom = (messageType == 2) || (nTitle.isEmpty() && nContent.isEmpty() && content.contains("\"message\""));
|
|
453
|
+
if (!isCustom && (!nTitle.isEmpty() || !nContent.isEmpty() || messageType == 0 || messageType == 1)) {
|
|
454
|
+
NotificationMessage notification = new NotificationMessage();
|
|
455
|
+
notification.msgId = msgId;
|
|
456
|
+
notification.notificationId = JCoreWireCodec.extractJsonInt(
|
|
457
|
+
content,
|
|
458
|
+
"notification_id",
|
|
459
|
+
(int) (messageId & 0x7FFFFFFFL)
|
|
460
|
+
);
|
|
461
|
+
notification.notificationTitle = !nTitle.isEmpty()
|
|
462
|
+
? nTitle
|
|
463
|
+
: JCoreWireCodec.extractJsonString(content, "title");
|
|
464
|
+
notification.notificationContent = !nContent.isEmpty()
|
|
465
|
+
? nContent
|
|
466
|
+
: JCoreWireCodec.extractJsonString(content, "content");
|
|
467
|
+
notification.notificationExtras = extractJsonObjectAsString(content, "n_extras", "extras");
|
|
468
|
+
notification.notificationType = JCoreWireCodec.extractJsonInt(
|
|
469
|
+
content,
|
|
470
|
+
"notification_type",
|
|
471
|
+
JCoreWireCodec.extractJsonInt(content, "notificaion_type", 0)
|
|
472
|
+
);
|
|
473
|
+
notification.platform = JCoreWireCodec.extractJsonInt(content, "platform", 0);
|
|
474
|
+
postSystemNotification(context, notification);
|
|
475
|
+
dispatchNotificationEvent(context, "notify_arrived", notification);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
CustomMessage custom = new CustomMessage();
|
|
480
|
+
custom.messageId = msgId;
|
|
481
|
+
custom.title = JCoreWireCodec.extractJsonString(content, "title");
|
|
482
|
+
String msgBody = JCoreWireCodec.extractJsonString(content, "message");
|
|
483
|
+
if (msgBody.isEmpty()) {
|
|
484
|
+
msgBody = JCoreWireCodec.extractJsonString(content, "content");
|
|
485
|
+
}
|
|
486
|
+
if (msgBody.isEmpty() && !content.startsWith("{")) {
|
|
487
|
+
msgBody = content;
|
|
488
|
+
}
|
|
489
|
+
custom.message = msgBody;
|
|
490
|
+
custom.contentType = JCoreWireCodec.extractJsonString(content, "content_type");
|
|
491
|
+
custom.extra = extractJsonObjectAsString(content, "extras", "n_extras");
|
|
492
|
+
custom.platform = (byte) JCoreWireCodec.extractJsonInt(content, "platform", 0);
|
|
493
|
+
dispatchCustomMessageEvent(context, custom);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private static String extractJsonObjectAsString(String json, String primaryKey, String fallbackKey) {
|
|
497
|
+
if (json == null || json.isEmpty()) {
|
|
498
|
+
return "{}";
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
JSONObject obj = new JSONObject(json);
|
|
502
|
+
JSONObject nested = obj.optJSONObject(primaryKey);
|
|
503
|
+
if (nested == null && fallbackKey != null) {
|
|
504
|
+
nested = obj.optJSONObject(fallbackKey);
|
|
505
|
+
}
|
|
506
|
+
if (nested != null) {
|
|
507
|
+
return nested.toString();
|
|
508
|
+
}
|
|
509
|
+
JSONObject mContent = obj.optJSONObject("m_content");
|
|
510
|
+
if (mContent != null) {
|
|
511
|
+
nested = mContent.optJSONObject(primaryKey);
|
|
512
|
+
if (nested == null && fallbackKey != null) {
|
|
513
|
+
nested = mContent.optJSONObject(fallbackKey);
|
|
514
|
+
}
|
|
515
|
+
if (nested != null) {
|
|
516
|
+
return nested.toString();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
} catch (Throwable ignored) {
|
|
520
|
+
}
|
|
521
|
+
Map<String, String> map = JCoreWireCodec.extractJsonStringMap(json, primaryKey);
|
|
522
|
+
if (map.isEmpty() && fallbackKey != null) {
|
|
523
|
+
map = JCoreWireCodec.extractJsonStringMap(json, fallbackKey);
|
|
524
|
+
}
|
|
525
|
+
if (map.isEmpty()) {
|
|
526
|
+
return "{}";
|
|
527
|
+
}
|
|
528
|
+
StringBuilder sb = new StringBuilder("{");
|
|
529
|
+
boolean first = true;
|
|
530
|
+
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
531
|
+
if (!first) {
|
|
532
|
+
sb.append(',');
|
|
533
|
+
}
|
|
534
|
+
first = false;
|
|
535
|
+
sb.append('"').append(entry.getKey()).append("\":\"").append(entry.getValue()).append('"');
|
|
536
|
+
}
|
|
537
|
+
sb.append('}');
|
|
538
|
+
return sb.toString();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
public void setAliasAndTagsWithCallBack(
|
|
542
|
+
final Context context,
|
|
543
|
+
final String alias,
|
|
544
|
+
final Set<String> tags,
|
|
545
|
+
final TagAliasCallback callback,
|
|
546
|
+
int protoType,
|
|
547
|
+
int action
|
|
548
|
+
) {
|
|
549
|
+
JCoreTcpEngine.getInstance().executeAsync(new Runnable() {
|
|
550
|
+
@Override
|
|
551
|
+
public void run() {
|
|
552
|
+
if (alias != null) {
|
|
553
|
+
JCoreStorage.saveAlias(context, alias);
|
|
554
|
+
}
|
|
555
|
+
Set<String> validTags = JPushInterface.filterValidTags(tags);
|
|
556
|
+
if (tags != null) {
|
|
557
|
+
JCoreStorage.saveTags(context, validTags);
|
|
558
|
+
}
|
|
559
|
+
if (callback != null) {
|
|
560
|
+
callback.gotResult(0, alias, validTags);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
private boolean shouldQueueOrWaitForServerAck() {
|
|
567
|
+
JCoreTcpEngine engine = JCoreTcpEngine.getInstance();
|
|
568
|
+
return engine.isRequireServerAckForOperations()
|
|
569
|
+
|| (!engine.isLoggedIn() && !engine.getCustomHost().isEmpty());
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
public void setAliasWithCallBack(
|
|
573
|
+
final Context context,
|
|
574
|
+
final int sequence,
|
|
575
|
+
String alias,
|
|
576
|
+
int protoType,
|
|
577
|
+
final int action
|
|
578
|
+
) {
|
|
579
|
+
final String previousAlias = JCoreStorage.getAlias(context);
|
|
580
|
+
String resolvedAlias = alias != null ? alias : "";
|
|
581
|
+
if (action == 2) {
|
|
582
|
+
JCoreStorage.saveAlias(context, resolvedAlias);
|
|
583
|
+
} else if (action == 3) {
|
|
584
|
+
JCoreStorage.saveAlias(context, "");
|
|
585
|
+
resolvedAlias = "";
|
|
586
|
+
} else if (action == 5) {
|
|
587
|
+
resolvedAlias = previousAlias;
|
|
588
|
+
}
|
|
589
|
+
final String effectiveAlias = resolvedAlias;
|
|
590
|
+
|
|
591
|
+
byte[] wireBody = JCoreWireCodec.buildAliasOperationPayload(action, sequence, effectiveAlias);
|
|
592
|
+
if (shouldQueueOrWaitForServerAck()) {
|
|
593
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
594
|
+
context,
|
|
595
|
+
JCoreWireCodec.CMD_ALIAS_OP,
|
|
596
|
+
JCoreWireCodec.VER_ALIAS_OP,
|
|
597
|
+
sequence,
|
|
598
|
+
wireBody,
|
|
599
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
600
|
+
0,
|
|
601
|
+
new JCoreTcpEngine.RequestCallback() {
|
|
602
|
+
@Override
|
|
603
|
+
public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
|
|
604
|
+
if (statusCode != 0 && (action == 2 || action == 3)) {
|
|
605
|
+
JCoreStorage.saveAlias(context, previousAlias);
|
|
606
|
+
}
|
|
607
|
+
String resultAlias = effectiveAlias;
|
|
608
|
+
if (statusCode == 0 && responseFrame != null && responseFrame.body != null && responseFrame.body.length > 0) {
|
|
609
|
+
String respJson = JCoreWireCodec.parseJsonCommandBody(responseFrame.body);
|
|
610
|
+
if (action == 5 && respJson.contains("\"alias\"")) {
|
|
611
|
+
String srvAlias = JCoreWireCodec.extractJsonString(respJson, "alias");
|
|
612
|
+
JCoreStorage.saveAlias(context, srvAlias);
|
|
613
|
+
resultAlias = srvAlias;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
Intent intent = buildBaseReceiverIntent(context, "alias_op", sequence, statusCode);
|
|
617
|
+
intent.putExtra(KEY_ALIAS, resultAlias);
|
|
618
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
619
|
+
JPushMessage msg = new JPushMessage();
|
|
620
|
+
msg.setSequence(sequence);
|
|
621
|
+
msg.setErrorCode(statusCode);
|
|
622
|
+
msg.setAlias(resultAlias);
|
|
623
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
624
|
+
receiver.onAliasOperatorResult(context, msg);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
sendToReceiver(context, intent);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
JCoreTcpEngine.getInstance().sendFrameRaw(
|
|
635
|
+
JCoreWireCodec.CMD_ALIAS_OP,
|
|
636
|
+
JCoreWireCodec.VER_ALIAS_OP,
|
|
637
|
+
sequence,
|
|
638
|
+
JCoreTcpEngine.getInstance().getSessionId(),
|
|
639
|
+
JCoreStorage.getUid(context),
|
|
640
|
+
wireBody
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
Intent intent = buildBaseReceiverIntent(context, "alias_op", sequence, 0);
|
|
644
|
+
intent.putExtra(KEY_ALIAS, effectiveAlias);
|
|
645
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
646
|
+
JPushMessage msg = new JPushMessage();
|
|
647
|
+
msg.setSequence(sequence);
|
|
648
|
+
msg.setErrorCode(0);
|
|
649
|
+
msg.setAlias(effectiveAlias);
|
|
650
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
651
|
+
receiver.onAliasOperatorResult(context, msg);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
sendToReceiver(context, intent);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
public void setTagsWithCallBack(
|
|
658
|
+
final Context context,
|
|
659
|
+
final int sequence,
|
|
660
|
+
Set<String> tags,
|
|
661
|
+
int protoType,
|
|
662
|
+
final int action
|
|
663
|
+
) {
|
|
664
|
+
final Set<String> validInput = JPushInterface.filterValidTags(tags);
|
|
665
|
+
Set<String> stored = JCoreStorage.getTags(context);
|
|
666
|
+
final Set<String> previousTags = new HashSet<String>(stored);
|
|
667
|
+
|
|
668
|
+
if (action == 1) { // add
|
|
669
|
+
stored.addAll(validInput);
|
|
670
|
+
JCoreStorage.saveTags(context, stored);
|
|
671
|
+
} else if (action == 2) { // set
|
|
672
|
+
stored = new HashSet<String>(validInput);
|
|
673
|
+
JCoreStorage.saveTags(context, stored);
|
|
674
|
+
} else if (action == 3) { // delete
|
|
675
|
+
stored.removeAll(validInput);
|
|
676
|
+
JCoreStorage.saveTags(context, stored);
|
|
677
|
+
} else if (action == 4) { // clean
|
|
678
|
+
stored.clear();
|
|
679
|
+
JCoreStorage.saveTags(context, stored);
|
|
680
|
+
}
|
|
681
|
+
final Set<String> finalStored = new HashSet<String>(stored);
|
|
682
|
+
|
|
683
|
+
byte[] wireBody = JCoreWireCodec.buildTagOperationPayload(action, sequence, validInput);
|
|
684
|
+
if (shouldQueueOrWaitForServerAck()) {
|
|
685
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
686
|
+
context,
|
|
687
|
+
JCoreWireCodec.CMD_TAG_OP,
|
|
688
|
+
JCoreWireCodec.VER_TAG_OP,
|
|
689
|
+
sequence,
|
|
690
|
+
wireBody,
|
|
691
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
692
|
+
0,
|
|
693
|
+
new JCoreTcpEngine.RequestCallback() {
|
|
694
|
+
@Override
|
|
695
|
+
public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
|
|
696
|
+
if (statusCode != 0 && action >= 1 && action <= 4) {
|
|
697
|
+
JCoreStorage.saveTags(context, previousTags);
|
|
698
|
+
}
|
|
699
|
+
dispatchTagResultIntent(context, sequence, action, statusCode, validInput, finalStored, responseFrame);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
JCoreTcpEngine.getInstance().sendFrameRaw(
|
|
707
|
+
JCoreWireCodec.CMD_TAG_OP,
|
|
708
|
+
JCoreWireCodec.VER_TAG_OP,
|
|
709
|
+
sequence,
|
|
710
|
+
JCoreTcpEngine.getInstance().getSessionId(),
|
|
711
|
+
JCoreStorage.getUid(context),
|
|
712
|
+
wireBody
|
|
713
|
+
);
|
|
714
|
+
dispatchTagResultIntent(context, sequence, action, 0, validInput, finalStored, null);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
private static boolean parseJsonBindFlag(String respJson, boolean defaultBind) {
|
|
718
|
+
try {
|
|
719
|
+
JSONObject obj = new JSONObject(respJson);
|
|
720
|
+
Object raw = obj.opt("bind");
|
|
721
|
+
if (raw == null) {
|
|
722
|
+
raw = obj.opt("is_bind");
|
|
723
|
+
}
|
|
724
|
+
if (raw instanceof Boolean) {
|
|
725
|
+
return ((Boolean) raw).booleanValue();
|
|
726
|
+
}
|
|
727
|
+
if (raw instanceof Number) {
|
|
728
|
+
return ((Number) raw).intValue() != 0;
|
|
729
|
+
}
|
|
730
|
+
if (raw instanceof String) {
|
|
731
|
+
String s = ((String) raw).trim();
|
|
732
|
+
if ("true".equalsIgnoreCase(s) || "1".equals(s)) {
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
if ("false".equalsIgnoreCase(s) || "0".equals(s)) {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
} catch (Throwable ignored) {
|
|
740
|
+
}
|
|
741
|
+
return defaultBind;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
private static Set<String> parseJsonTagsSet(String respJson) {
|
|
745
|
+
Set<String> serverTags = new HashSet<String>();
|
|
746
|
+
try {
|
|
747
|
+
JSONObject obj = new JSONObject(respJson);
|
|
748
|
+
JSONArray arr = obj.optJSONArray("tags");
|
|
749
|
+
if (arr != null) {
|
|
750
|
+
for (int i = 0; i < arr.length(); i++) {
|
|
751
|
+
String item = arr.optString(i, null);
|
|
752
|
+
if (item != null && !item.isEmpty()) {
|
|
753
|
+
serverTags.add(item);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return serverTags;
|
|
757
|
+
}
|
|
758
|
+
} catch (Throwable ignored) {
|
|
759
|
+
}
|
|
760
|
+
serverTags.addAll(JCoreWireCodec.extractJsonStringArray(respJson, "tags"));
|
|
761
|
+
return serverTags;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
private void dispatchTagResultIntent(
|
|
765
|
+
Context context,
|
|
766
|
+
int sequence,
|
|
767
|
+
int action,
|
|
768
|
+
int statusCode,
|
|
769
|
+
Set<String> validInput,
|
|
770
|
+
Set<String> stored,
|
|
771
|
+
JCoreWireCodec.DecodedFrame responseFrame
|
|
772
|
+
) {
|
|
773
|
+
String respJson = (statusCode == 0 && responseFrame != null && responseFrame.body != null && responseFrame.body.length > 0)
|
|
774
|
+
? JCoreWireCodec.parseJsonCommandBody(responseFrame.body)
|
|
775
|
+
: "";
|
|
776
|
+
if (action == 6) { // checkTagBindState
|
|
777
|
+
String checkTag = validInput.isEmpty() ? "" : validInput.iterator().next();
|
|
778
|
+
boolean isBind = !checkTag.isEmpty() && stored.contains(checkTag);
|
|
779
|
+
if (statusCode == 0 && !respJson.isEmpty()
|
|
780
|
+
&& (respJson.contains("\"bind\"") || respJson.contains("\"is_bind\""))) {
|
|
781
|
+
isBind = parseJsonBindFlag(respJson, isBind);
|
|
782
|
+
}
|
|
783
|
+
Intent checkIntent = buildBaseReceiverIntent(context, "check_tag_op", sequence, statusCode);
|
|
784
|
+
checkIntent.putExtra(KEY_CHECK_TAG, checkTag);
|
|
785
|
+
checkIntent.putExtra(KEY_TAG_BIND_STATE, isBind);
|
|
786
|
+
if (checkIntent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
787
|
+
JPushMessage msg = new JPushMessage();
|
|
788
|
+
msg.setSequence(sequence);
|
|
789
|
+
msg.setErrorCode(statusCode);
|
|
790
|
+
msg.setCheckTag(checkTag);
|
|
791
|
+
msg.setTagCheckStateResult(isBind);
|
|
792
|
+
msg.setTagCheckOperator(true);
|
|
793
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
794
|
+
receiver.onCheckTagOperatorResult(context, msg);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
sendToReceiver(context, checkIntent);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
Set<String> resultTags = (action == 5) ? stored : validInput;
|
|
802
|
+
if (action == 5 && statusCode == 0 && !respJson.isEmpty() && respJson.contains("\"tags\"")) {
|
|
803
|
+
Set<String> serverTags = parseJsonTagsSet(respJson);
|
|
804
|
+
JCoreStorage.saveTags(context, serverTags);
|
|
805
|
+
resultTags = serverTags;
|
|
806
|
+
}
|
|
807
|
+
Intent intent = buildBaseReceiverIntent(context, "tag_op", sequence, statusCode);
|
|
808
|
+
intent.putStringArrayListExtra(KEY_TAGS, new ArrayList<String>(resultTags));
|
|
809
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
810
|
+
JPushMessage msg = new JPushMessage();
|
|
811
|
+
msg.setSequence(sequence);
|
|
812
|
+
msg.setErrorCode(statusCode);
|
|
813
|
+
msg.setTags(new HashSet<String>(resultTags));
|
|
814
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
815
|
+
receiver.onTagOperatorResult(context, msg);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
sendToReceiver(context, intent);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
public void setPropertyWithCallBack(
|
|
822
|
+
final Context context,
|
|
823
|
+
final int sequence,
|
|
824
|
+
final Map<String, Object> properties,
|
|
825
|
+
int protoType,
|
|
826
|
+
final int action
|
|
827
|
+
) {
|
|
828
|
+
Map<String, Object> stored = JCoreStorage.getProperties(context);
|
|
829
|
+
final Map<String, Object> previousProps = new HashMap<String, Object>(stored);
|
|
830
|
+
if (action == 1 && properties != null) {
|
|
831
|
+
stored.putAll(properties);
|
|
832
|
+
JCoreStorage.saveProperties(context, stored);
|
|
833
|
+
} else if (action == 2 && properties != null) {
|
|
834
|
+
for (String key : properties.keySet()) {
|
|
835
|
+
stored.remove(key);
|
|
836
|
+
}
|
|
837
|
+
JCoreStorage.saveProperties(context, stored);
|
|
838
|
+
} else if (action == 3) {
|
|
839
|
+
stored.clear();
|
|
840
|
+
JCoreStorage.saveProperties(context, stored);
|
|
841
|
+
}
|
|
842
|
+
final Map<String, Object> finalStored = new HashMap<String, Object>(stored);
|
|
843
|
+
|
|
844
|
+
byte[] wireBody = JCoreWireCodec.buildPropertyOperationPayload(action, sequence, properties);
|
|
845
|
+
if (shouldQueueOrWaitForServerAck()) {
|
|
846
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
847
|
+
context,
|
|
848
|
+
JCoreWireCodec.CMD_PROPERTY_OP,
|
|
849
|
+
JCoreWireCodec.VER_PROPERTY_OP,
|
|
850
|
+
sequence,
|
|
851
|
+
wireBody,
|
|
852
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
853
|
+
0,
|
|
854
|
+
new JCoreTcpEngine.RequestCallback() {
|
|
855
|
+
@Override
|
|
856
|
+
public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
|
|
857
|
+
if (statusCode != 0) {
|
|
858
|
+
JCoreStorage.saveProperties(context, previousProps);
|
|
859
|
+
}
|
|
860
|
+
Intent intent = buildBaseReceiverIntent(context, "property_op", sequence, statusCode);
|
|
861
|
+
HashMap<String, Object> serializableProps = new HashMap<String, Object>();
|
|
862
|
+
if ((action == 1 || action == 2) && properties != null) {
|
|
863
|
+
serializableProps.putAll(properties);
|
|
864
|
+
} else {
|
|
865
|
+
serializableProps.putAll(statusCode == 0 ? finalStored : previousProps);
|
|
866
|
+
}
|
|
867
|
+
intent.putExtra(KEY_PROPS_MAP, serializableProps);
|
|
868
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
869
|
+
JPushMessage msg = new JPushMessage();
|
|
870
|
+
msg.setSequence(sequence);
|
|
871
|
+
msg.setErrorCode(statusCode);
|
|
872
|
+
msg.setPros(serializableProps);
|
|
873
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
874
|
+
receiver.onPropertyOperatorResult(context, msg);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
sendToReceiver(context, intent);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
);
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
JCoreTcpEngine.getInstance().sendFrameRaw(
|
|
885
|
+
JCoreWireCodec.CMD_PROPERTY_OP,
|
|
886
|
+
JCoreWireCodec.VER_PROPERTY_OP,
|
|
887
|
+
sequence,
|
|
888
|
+
JCoreTcpEngine.getInstance().getSessionId(),
|
|
889
|
+
JCoreStorage.getUid(context),
|
|
890
|
+
wireBody
|
|
891
|
+
);
|
|
892
|
+
|
|
893
|
+
Intent intent = buildBaseReceiverIntent(context, "property_op", sequence, 0);
|
|
894
|
+
HashMap<String, Object> serializableProps = new HashMap<String, Object>();
|
|
895
|
+
if ((action == 1 || action == 2) && properties != null) {
|
|
896
|
+
serializableProps.putAll(properties);
|
|
897
|
+
} else {
|
|
898
|
+
serializableProps.putAll(finalStored);
|
|
899
|
+
}
|
|
900
|
+
intent.putExtra(KEY_PROPS_MAP, serializableProps);
|
|
901
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
902
|
+
JPushMessage msg = new JPushMessage();
|
|
903
|
+
msg.setSequence(sequence);
|
|
904
|
+
msg.setErrorCode(0);
|
|
905
|
+
msg.setPros(serializableProps);
|
|
906
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
907
|
+
receiver.onPropertyOperatorResult(context, msg);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
sendToReceiver(context, intent);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
public void setMobileNumberWithCallBack(final Context context, final int sequence, final String mobileNumber) {
|
|
914
|
+
final String previousMobile = JCoreStorage.getMobileNumber(context);
|
|
915
|
+
JCoreStorage.saveMobileNumber(context, mobileNumber);
|
|
916
|
+
byte[] wireBody = JCoreWireCodec.buildMobileNumberPayload(sequence, mobileNumber);
|
|
917
|
+
if (shouldQueueOrWaitForServerAck()) {
|
|
918
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
919
|
+
context,
|
|
920
|
+
JCoreWireCodec.CMD_MOBILE_NUMBER,
|
|
921
|
+
JCoreWireCodec.VER_MOBILE_NUMBER,
|
|
922
|
+
sequence,
|
|
923
|
+
wireBody,
|
|
924
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
925
|
+
0,
|
|
926
|
+
new JCoreTcpEngine.RequestCallback() {
|
|
927
|
+
@Override
|
|
928
|
+
public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
|
|
929
|
+
if (statusCode != 0) {
|
|
930
|
+
JCoreStorage.saveMobileNumber(context, previousMobile);
|
|
931
|
+
}
|
|
932
|
+
Intent intent = buildBaseReceiverIntent(context, "mobile_number_op", sequence, statusCode);
|
|
933
|
+
intent.putExtra(KEY_MOBILE_NUMBER, mobileNumber != null ? mobileNumber : "");
|
|
934
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
935
|
+
JPushMessage msg = new JPushMessage();
|
|
936
|
+
msg.setSequence(sequence);
|
|
937
|
+
msg.setErrorCode(statusCode);
|
|
938
|
+
msg.setMobileNumber(mobileNumber != null ? mobileNumber : "");
|
|
939
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
940
|
+
receiver.onMobileNumberOperatorResult(context, msg);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
sendToReceiver(context, intent);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
);
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
JCoreTcpEngine.getInstance().sendFrameRaw(
|
|
951
|
+
JCoreWireCodec.CMD_MOBILE_NUMBER,
|
|
952
|
+
JCoreWireCodec.VER_MOBILE_NUMBER,
|
|
953
|
+
sequence,
|
|
954
|
+
JCoreTcpEngine.getInstance().getSessionId(),
|
|
955
|
+
JCoreStorage.getUid(context),
|
|
956
|
+
wireBody
|
|
957
|
+
);
|
|
958
|
+
|
|
959
|
+
Intent intent = buildBaseReceiverIntent(context, "mobile_number_op", sequence, 0);
|
|
960
|
+
intent.putExtra(KEY_MOBILE_NUMBER, mobileNumber != null ? mobileNumber : "");
|
|
961
|
+
if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
|
|
962
|
+
JPushMessage msg = new JPushMessage();
|
|
963
|
+
msg.setSequence(sequence);
|
|
964
|
+
msg.setErrorCode(0);
|
|
965
|
+
msg.setMobileNumber(mobileNumber != null ? mobileNumber : "");
|
|
966
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
967
|
+
receiver.onMobileNumberOperatorResult(context, msg);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
sendToReceiver(context, intent);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
public void setThirdTokenWithCallBack(
|
|
974
|
+
final Context context,
|
|
975
|
+
final String token,
|
|
976
|
+
final byte platform,
|
|
977
|
+
final boolean unbind
|
|
978
|
+
) {
|
|
979
|
+
byte[] wireBody = JCoreWireCodec.buildThirdTokenPayload(token, platform, unbind);
|
|
980
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
981
|
+
context,
|
|
982
|
+
JCoreWireCodec.CMD_THIRD_TOKEN,
|
|
983
|
+
JCoreWireCodec.VER_THIRD_TOKEN,
|
|
984
|
+
JCoreStorage.nextRid(),
|
|
985
|
+
wireBody,
|
|
986
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
987
|
+
3,
|
|
988
|
+
new JCoreTcpEngine.RequestCallback() {
|
|
989
|
+
@Override
|
|
990
|
+
public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
|
|
991
|
+
if (statusCode == 0) {
|
|
992
|
+
JCoreStorage.saveThirdToken(context, platform, unbind ? "" : token);
|
|
993
|
+
}
|
|
994
|
+
cn.jiguang.plugins.push.common.JLogger.i("Third token result platform=" + platform + " code=" + statusCode);
|
|
995
|
+
Intent intent = buildBaseReceiverIntent(context, "cmd_result", 0, statusCode);
|
|
996
|
+
intent.putExtra("cmd", 10000);
|
|
997
|
+
intent.putExtra("msg", unbind ? "unbind" : "bind");
|
|
998
|
+
intent.putExtra("token", token != null ? token : "");
|
|
999
|
+
intent.putExtra("platform", (int) platform);
|
|
1000
|
+
sendToReceiver(context, intent);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
public void setPushStatusWithCallBack(Context context, int protoType, int action) {
|
|
1007
|
+
boolean stopped = (action == 0);
|
|
1008
|
+
byte[] wireBody = JCoreWireCodec.buildPushControlPayload(stopped);
|
|
1009
|
+
if (!stopped && shouldQueueOrWaitForServerAck()) {
|
|
1010
|
+
JCoreTcpEngine.getInstance().enqueueOrSendRequest(
|
|
1011
|
+
context,
|
|
1012
|
+
JCoreWireCodec.CMD_PUSH_CTRL,
|
|
1013
|
+
JCoreWireCodec.VER_PUSH_CTRL,
|
|
1014
|
+
JCoreStorage.nextRid(),
|
|
1015
|
+
wireBody,
|
|
1016
|
+
JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
|
|
1017
|
+
0,
|
|
1018
|
+
null
|
|
1019
|
+
);
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
JCoreTcpEngine.getInstance().sendFrameRaw(
|
|
1023
|
+
JCoreWireCodec.CMD_PUSH_CTRL,
|
|
1024
|
+
JCoreWireCodec.VER_PUSH_CTRL,
|
|
1025
|
+
JCoreStorage.nextRid(),
|
|
1026
|
+
JCoreTcpEngine.getInstance().getSessionId(),
|
|
1027
|
+
JCoreStorage.getUid(context),
|
|
1028
|
+
wireBody
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
public void dispatchRegisterEvent(Context context, String registrationId) {
|
|
1033
|
+
Intent intent = buildBaseReceiverIntent(context, "register", 0, 0);
|
|
1034
|
+
intent.putExtra("registration_id", registrationId != null ? registrationId : "");
|
|
1035
|
+
sendToReceiver(context, intent);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
public void dispatchConnectedEvent(Context context, boolean connected) {
|
|
1039
|
+
Intent intent = buildBaseReceiverIntent(context, "connected", 0, 0);
|
|
1040
|
+
intent.putExtra("connected", connected);
|
|
1041
|
+
sendToReceiver(context, intent);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
public void dispatchLocalNotification(final Context context, final JPushLocalNotification localNotification) {
|
|
1045
|
+
if (localNotification == null) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
final int notifyId = (int) localNotification.getNotificationId();
|
|
1049
|
+
long broadcastTime = localNotification.getBroadcastTime();
|
|
1050
|
+
long now = System.currentTimeMillis();
|
|
1051
|
+
long delayMs = 0L;
|
|
1052
|
+
if (broadcastTime > 1000000000000L) {
|
|
1053
|
+
delayMs = broadcastTime - now;
|
|
1054
|
+
} else if (broadcastTime > 0L) {
|
|
1055
|
+
delayMs = broadcastTime;
|
|
1056
|
+
}
|
|
1057
|
+
ScheduledFuture<?> previous = pendingLocalNotifications.remove(Integer.valueOf(notifyId));
|
|
1058
|
+
if (previous != null) {
|
|
1059
|
+
previous.cancel(false);
|
|
1060
|
+
}
|
|
1061
|
+
if (delayMs > 0L) {
|
|
1062
|
+
ScheduledFuture<?> future = localNotificationScheduler.schedule(new Runnable() {
|
|
1063
|
+
@Override
|
|
1064
|
+
public void run() {
|
|
1065
|
+
pendingLocalNotifications.remove(Integer.valueOf(notifyId));
|
|
1066
|
+
deliverLocalNotificationNow(context, localNotification);
|
|
1067
|
+
}
|
|
1068
|
+
}, delayMs, TimeUnit.MILLISECONDS);
|
|
1069
|
+
pendingLocalNotifications.put(Integer.valueOf(notifyId), future);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
deliverLocalNotificationNow(context, localNotification);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
private void deliverLocalNotificationNow(Context context, JPushLocalNotification localNotification) {
|
|
1076
|
+
NotificationMessage message = new NotificationMessage();
|
|
1077
|
+
message.notificationId = (int) localNotification.getNotificationId();
|
|
1078
|
+
message.msgId = String.valueOf(localNotification.getNotificationId());
|
|
1079
|
+
message.notificationTitle = localNotification.getTitle() != null ? localNotification.getTitle() : "";
|
|
1080
|
+
message.notificationContent = localNotification.getContent() != null ? localNotification.getContent() : "";
|
|
1081
|
+
message.notificationExtras = localNotification.getExtras() != null ? localNotification.getExtras() : "";
|
|
1082
|
+
message.notificationType = 1;
|
|
1083
|
+
message.notificationPriority = localNotification.getPriority();
|
|
1084
|
+
message.notificationCategory = localNotification.getCategory();
|
|
1085
|
+
postSystemNotification(context, message);
|
|
1086
|
+
dispatchNotificationEvent(context, "notify_arrived", message);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
public void dispatchNotificationEvent(Context context, String eventType, NotificationMessage message) {
|
|
1090
|
+
if (message == null) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
Intent intent = buildBaseReceiverIntent(context, eventType, 0, 0);
|
|
1094
|
+
intent.putExtra(KEY_NOTIFICATION_MESSAGE, message);
|
|
1095
|
+
sendToReceiver(context, intent);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
public void dispatchCustomMessageEvent(Context context, CustomMessage message) {
|
|
1099
|
+
if (message == null) {
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
Intent intent = buildBaseReceiverIntent(context, "custom_msg", 0, 0);
|
|
1103
|
+
intent.putExtra(KEY_CUSTOM_MESSAGE, message);
|
|
1104
|
+
sendToReceiver(context, intent);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
private Intent buildBaseReceiverIntent(Context context, String eventType, int sequence, int errorCode) {
|
|
1108
|
+
Intent intent = new Intent(ACTION_RECEIVER_MESSAGE);
|
|
1109
|
+
Context app = JCoreStorage.getAppContext(context);
|
|
1110
|
+
if (app != null) {
|
|
1111
|
+
try {
|
|
1112
|
+
String pkg = app.getPackageName();
|
|
1113
|
+
if (pkg != null && !pkg.isEmpty()) {
|
|
1114
|
+
intent.setPackage(pkg);
|
|
1115
|
+
intent.addCategory(pkg);
|
|
1116
|
+
}
|
|
1117
|
+
} catch (Throwable ignored) {
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
intent.putExtra(KEY_EVENT_TYPE, eventType);
|
|
1121
|
+
intent.putExtra(KEY_SEQUENCE, sequence);
|
|
1122
|
+
intent.putExtra(KEY_ERROR_CODE, errorCode);
|
|
1123
|
+
return intent;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
private void sendToReceiver(Context context, Intent intent) {
|
|
1127
|
+
if (intent == null) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
Context app = JCoreStorage.getAppContext(context);
|
|
1131
|
+
for (JPushMessageReceiver receiver : registeredReceivers) {
|
|
1132
|
+
try {
|
|
1133
|
+
onJPushMessageReceive(app != null ? app : context, receiver, intent);
|
|
1134
|
+
} catch (Throwable ignored) {
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
if (app != null && registeredReceivers.isEmpty()) {
|
|
1138
|
+
try {
|
|
1139
|
+
app.sendBroadcast(intent);
|
|
1140
|
+
} catch (Throwable ignored) {
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
@SuppressWarnings("unchecked")
|
|
1146
|
+
public void onJPushMessageReceive(Context context, JPushMessageReceiver receiver, Intent intent) {
|
|
1147
|
+
if (receiver == null || intent == null) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
String eventType = intent.getStringExtra(KEY_EVENT_TYPE);
|
|
1151
|
+
if (eventType == null) {
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
int sequence = intent.getIntExtra(KEY_SEQUENCE, 0);
|
|
1155
|
+
int errorCode = intent.getIntExtra(KEY_ERROR_CODE, 0);
|
|
1156
|
+
|
|
1157
|
+
if ("register".equals(eventType)) {
|
|
1158
|
+
String regId = intent.getStringExtra("registration_id");
|
|
1159
|
+
receiver.onRegister(context, regId != null ? regId : "");
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
if ("connected".equals(eventType)) {
|
|
1163
|
+
boolean connected = intent.getBooleanExtra("connected", true);
|
|
1164
|
+
receiver.onConnected(context, connected);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
if ("alias_op".equals(eventType)) {
|
|
1168
|
+
JPushMessage msg = new JPushMessage();
|
|
1169
|
+
msg.setSequence(sequence);
|
|
1170
|
+
msg.setErrorCode(errorCode);
|
|
1171
|
+
msg.setAlias(intent.getStringExtra(KEY_ALIAS));
|
|
1172
|
+
receiver.onAliasOperatorResult(context, msg);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
if ("tag_op".equals(eventType)) {
|
|
1176
|
+
JPushMessage msg = new JPushMessage();
|
|
1177
|
+
msg.setSequence(sequence);
|
|
1178
|
+
msg.setErrorCode(errorCode);
|
|
1179
|
+
ArrayList<String> tagList = intent.getStringArrayListExtra(KEY_TAGS);
|
|
1180
|
+
msg.setTags(tagList != null ? new HashSet<String>(tagList) : new HashSet<String>());
|
|
1181
|
+
receiver.onTagOperatorResult(context, msg);
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
if ("check_tag_op".equals(eventType)) {
|
|
1185
|
+
JPushMessage msg = new JPushMessage();
|
|
1186
|
+
msg.setSequence(sequence);
|
|
1187
|
+
msg.setErrorCode(errorCode);
|
|
1188
|
+
msg.setCheckTag(intent.getStringExtra(KEY_CHECK_TAG));
|
|
1189
|
+
msg.setTagCheckStateResult(intent.getBooleanExtra(KEY_TAG_BIND_STATE, false));
|
|
1190
|
+
msg.setTagCheckOperator(true);
|
|
1191
|
+
receiver.onCheckTagOperatorResult(context, msg);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
if ("property_op".equals(eventType)) {
|
|
1195
|
+
JPushMessage msg = new JPushMessage();
|
|
1196
|
+
msg.setSequence(sequence);
|
|
1197
|
+
msg.setErrorCode(errorCode);
|
|
1198
|
+
Serializable mapObj = intent.getSerializableExtra(KEY_PROPS_MAP);
|
|
1199
|
+
if (mapObj instanceof Map) {
|
|
1200
|
+
msg.setPros((Map<String, Object>) mapObj);
|
|
1201
|
+
}
|
|
1202
|
+
receiver.onPropertyOperatorResult(context, msg);
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
if ("mobile_number_op".equals(eventType)) {
|
|
1206
|
+
JPushMessage msg = new JPushMessage();
|
|
1207
|
+
msg.setSequence(sequence);
|
|
1208
|
+
msg.setErrorCode(errorCode);
|
|
1209
|
+
msg.setMobileNumber(intent.getStringExtra(KEY_MOBILE_NUMBER));
|
|
1210
|
+
receiver.onMobileNumberOperatorResult(context, msg);
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
if ("notify_arrived".equals(eventType)) {
|
|
1214
|
+
Serializable nMsg = intent.getSerializableExtra(KEY_NOTIFICATION_MESSAGE);
|
|
1215
|
+
if (nMsg instanceof NotificationMessage) {
|
|
1216
|
+
receiver.onNotifyMessageArrived(context, (NotificationMessage) nMsg);
|
|
1217
|
+
}
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
if ("notify_opened".equals(eventType)) {
|
|
1221
|
+
Serializable nMsg = intent.getSerializableExtra(KEY_NOTIFICATION_MESSAGE);
|
|
1222
|
+
if (nMsg instanceof NotificationMessage) {
|
|
1223
|
+
receiver.onNotifyMessageOpened(context, (NotificationMessage) nMsg);
|
|
1224
|
+
}
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
if ("notify_dismiss".equals(eventType)) {
|
|
1228
|
+
Serializable nMsg = intent.getSerializableExtra(KEY_NOTIFICATION_MESSAGE);
|
|
1229
|
+
if (nMsg instanceof NotificationMessage) {
|
|
1230
|
+
receiver.onNotifyMessageDismiss(context, (NotificationMessage) nMsg);
|
|
1231
|
+
}
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
if ("custom_msg".equals(eventType)) {
|
|
1235
|
+
Serializable cMsg = intent.getSerializableExtra(KEY_CUSTOM_MESSAGE);
|
|
1236
|
+
if (cMsg instanceof CustomMessage) {
|
|
1237
|
+
receiver.onMessage(context, (CustomMessage) cMsg);
|
|
1238
|
+
}
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
if ("inapp_show".equals(eventType)) {
|
|
1242
|
+
Serializable nMsg = intent.getSerializableExtra(KEY_NOTIFICATION_MESSAGE);
|
|
1243
|
+
if (nMsg instanceof NotificationMessage) {
|
|
1244
|
+
receiver.onInAppMessageShow(context, (NotificationMessage) nMsg);
|
|
1245
|
+
}
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
if ("inapp_click".equals(eventType)) {
|
|
1249
|
+
Serializable nMsg = intent.getSerializableExtra(KEY_NOTIFICATION_MESSAGE);
|
|
1250
|
+
if (nMsg instanceof NotificationMessage) {
|
|
1251
|
+
receiver.onInAppMessageClick(context, (NotificationMessage) nMsg);
|
|
1252
|
+
}
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if ("notify_button_click".equals(eventType)) {
|
|
1256
|
+
Serializable btn = intent.getSerializableExtra(KEY_CUSTOM_BUTTON);
|
|
1257
|
+
if (btn instanceof NotificationCustomButton) {
|
|
1258
|
+
receiver.onNotifyButtonClick(context, (NotificationCustomButton) btn);
|
|
1259
|
+
}
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
if ("cmd_result".equals(eventType)) {
|
|
1263
|
+
int cmd = intent.getIntExtra("cmd", 0);
|
|
1264
|
+
String msgText = intent.getStringExtra("msg");
|
|
1265
|
+
receiver.onCommandResult(context, new CmdMessage(cmd, errorCode, msgText, intent.getExtras()));
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
public void onJPushMessageReceive(Context context, String receiverClassName, String messageType, Bundle bundle) {
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
public void onMessage(Context context, CustomMessage message) {
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
public void onNotifyMessageArrived(Context context, NotificationMessage message) {
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
public void onNotifyMessageOpened(Context context, NotificationMessage message) {
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
public void onMultiAction(Context context, Intent intent) {
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
public void onInAppMessageShow(Context context, NotificationMessage message) {
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
public void onInAppMessageClick(Context context, NotificationMessage message) {
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
public boolean isSupportedCMD(String sdkType, int command) {
|
|
1291
|
+
return command == 3 || command == 10 || command == 26 || command == 27 || command == 28 || command == 29 || command == 38 || command == 40;
|
|
1292
|
+
}
|
|
1293
|
+
}
|