@sentiance-react-native/core 6.0.0-beta.9
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 +24 -0
- package/android/build.gradle +17 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +2 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/package-json-reader.gradle +62 -0
- package/android/sentiance-version-finder.gradle +17 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceConverter.java +364 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceEmitter.java +46 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceHelper.java +207 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceModule.java +529 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentiancePackage.java +30 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/UserLinker.java +34 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceEmitter.java +59 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceModule.java +33 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/ErrorCodes.java +16 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/SentianceUtils.java +160 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/UserCreationCompletionHandler.java +31 -0
- package/ios/RNSentianceCore+Converter.h +46 -0
- package/ios/RNSentianceCore+Converter.m +986 -0
- package/ios/RNSentianceCore.h +29 -0
- package/ios/RNSentianceCore.m +1036 -0
- package/ios/RNSentianceCore.podspec +24 -0
- package/ios/RNSentianceCore.xcodeproj/project.pbxproj +290 -0
- package/ios/RNSentianceErrorCodes.h +20 -0
- package/ios/RNSentianceErrorCodes.m +22 -0
- package/ios/RNSentianceHelper.h +31 -0
- package/ios/RNSentianceHelper.m +38 -0
- package/ios/RNSentianceNativeInitialization.h +6 -0
- package/ios/RNSentianceNativeInitialization.m +56 -0
- package/lib/core.js +64 -0
- package/lib/index.d.ts +198 -0
- package/lib/index.js +194 -0
- package/lib/utils.js +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_GET_TOKEN_ERROR;
|
|
4
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_MISSING_PARAMS;
|
|
5
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_RESET_ERROR;
|
|
6
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_START_TRIP_ERROR;
|
|
7
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_STOP_TRIP_ERROR;
|
|
8
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_SUBMIT_DETECTIONS_ERROR;
|
|
9
|
+
|
|
10
|
+
import android.annotation.SuppressLint;
|
|
11
|
+
import android.app.Notification;
|
|
12
|
+
import android.os.Handler;
|
|
13
|
+
import android.os.Looper;
|
|
14
|
+
import android.util.Log;
|
|
15
|
+
|
|
16
|
+
import androidx.annotation.NonNull;
|
|
17
|
+
import androidx.annotation.Nullable;
|
|
18
|
+
|
|
19
|
+
import com.facebook.react.bridge.Promise;
|
|
20
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
22
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
23
|
+
import com.sentiance.react.bridge.core.base.AbstractSentianceModule;
|
|
24
|
+
import com.sentiance.react.bridge.core.utils.SentianceUtils;
|
|
25
|
+
import com.sentiance.react.bridge.core.utils.UserCreationCompletionHandler;
|
|
26
|
+
import com.sentiance.sdk.InitState;
|
|
27
|
+
import com.sentiance.sdk.SdkStatus;
|
|
28
|
+
import com.sentiance.sdk.Sentiance;
|
|
29
|
+
import com.sentiance.sdk.SubmitDetectionsError;
|
|
30
|
+
import com.sentiance.sdk.Token;
|
|
31
|
+
import com.sentiance.sdk.UserAccessTokenError;
|
|
32
|
+
import com.sentiance.sdk.detectionupdates.UserActivity;
|
|
33
|
+
import com.sentiance.sdk.reset.ResetError;
|
|
34
|
+
import com.sentiance.sdk.trip.StartTripError;
|
|
35
|
+
import com.sentiance.sdk.trip.StopTripError;
|
|
36
|
+
import com.sentiance.sdk.trip.TransportMode;
|
|
37
|
+
import com.sentiance.sdk.trip.TripTimeoutListener;
|
|
38
|
+
import com.sentiance.sdk.trip.TripType;
|
|
39
|
+
|
|
40
|
+
import java.lang.ref.WeakReference;
|
|
41
|
+
import java.util.HashMap;
|
|
42
|
+
import java.util.Map;
|
|
43
|
+
|
|
44
|
+
public class SentianceModule extends AbstractSentianceModule {
|
|
45
|
+
|
|
46
|
+
private static final String NATIVE_MODULE_NAME = "SentianceCore";
|
|
47
|
+
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
|
48
|
+
private final SentianceHelper sentianceHelper;
|
|
49
|
+
private final SentianceEmitter emitter;
|
|
50
|
+
|
|
51
|
+
public SentianceModule(ReactApplicationContext reactContext) {
|
|
52
|
+
super(reactContext);
|
|
53
|
+
sentianceHelper = SentianceHelper.getInstance(reactContext);
|
|
54
|
+
emitter = new SentianceEmitter(reactContext);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@NonNull
|
|
58
|
+
@Override
|
|
59
|
+
public String getName() {
|
|
60
|
+
return NATIVE_MODULE_NAME;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactMethod
|
|
64
|
+
@SuppressWarnings("unused")
|
|
65
|
+
public void userLinkCallback(final Boolean linkResult) {
|
|
66
|
+
mHandler.post(() -> sentianceHelper.userLinkCallback(linkResult));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
@SuppressWarnings("unused")
|
|
71
|
+
public void enableDetections(final Promise promise) {
|
|
72
|
+
if (rejectIfNotInitialized(promise)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
sentianceHelper.enableDetections(promise);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
@SuppressWarnings("unused")
|
|
80
|
+
public void enableDetectionsWithExpiryDate(@Nullable final Double expiryEpochTimeMs, final Promise promise) {
|
|
81
|
+
if (rejectIfNotInitialized(promise)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
Long expiryTime = expiryEpochTimeMs == null ? null : expiryEpochTimeMs.longValue();
|
|
85
|
+
sentianceHelper.enableDetections(expiryTime, promise);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
@SuppressWarnings("unused")
|
|
90
|
+
public void disableDetections(final Promise promise) {
|
|
91
|
+
if (rejectIfNotInitialized(promise)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
sentianceHelper.disableDetections(promise);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactMethod
|
|
98
|
+
@SuppressWarnings("unused")
|
|
99
|
+
public void createUnlinkedUser(String appId, String secret, @Nullable String platformUrl, final Promise promise) {
|
|
100
|
+
if (rejectIfNotInitialized(promise)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
sentianceHelper.createUnlinkedUser(appId, secret, platformUrl)
|
|
104
|
+
.addOnCompleteListener(new UserCreationCompletionHandler(promise));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@ReactMethod
|
|
108
|
+
@SuppressWarnings("unused")
|
|
109
|
+
public void createLinkedUser(String appId, String secret, @Nullable String platformUrl, final Promise promise) {
|
|
110
|
+
if (rejectIfNotInitialized(promise)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
sentianceHelper.createLinkedUser(appId, secret, platformUrl)
|
|
114
|
+
.addOnCompleteListener(new UserCreationCompletionHandler(promise));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@ReactMethod
|
|
118
|
+
@SuppressWarnings("unused")
|
|
119
|
+
public void createLinkedUserWithAuthCode(String authCode, @Nullable String platformUrl, final Promise promise) {
|
|
120
|
+
if (rejectIfNotInitialized(promise)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
sentianceHelper.createLinkedUser(authCode, platformUrl)
|
|
124
|
+
.addOnCompleteListener(new UserCreationCompletionHandler(promise));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@ReactMethod
|
|
128
|
+
@SuppressWarnings("unused")
|
|
129
|
+
public void linkUser(final Promise promise) {
|
|
130
|
+
if (rejectIfNotInitialized(promise)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
sentianceHelper.linkUser(promise);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@ReactMethod
|
|
137
|
+
@SuppressWarnings("unused")
|
|
138
|
+
public void linkUserWithAuthCode(String authCode, final Promise promise) {
|
|
139
|
+
if (rejectIfNotInitialized(promise)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
sentianceHelper.linkUser(authCode, promise);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@ReactMethod
|
|
146
|
+
@SuppressWarnings("unused")
|
|
147
|
+
public void userExists(final Promise promise) {
|
|
148
|
+
promise.resolve(sdk.userExists());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
@SuppressWarnings("unused")
|
|
153
|
+
public void isUserLinked(final Promise promise) {
|
|
154
|
+
promise.resolve(sdk.isUserLinked());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ReactMethod
|
|
158
|
+
@SuppressWarnings("unused")
|
|
159
|
+
public void reset(final Promise promise) {
|
|
160
|
+
sdk.reset()
|
|
161
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
162
|
+
if (pendingOperation.isSuccessful()) {
|
|
163
|
+
promise.resolve(SentianceConverter.convertResetResult(pendingOperation.getResult()));
|
|
164
|
+
} else {
|
|
165
|
+
ResetError error = pendingOperation.getError();
|
|
166
|
+
promise.reject(E_SDK_RESET_ERROR, SentianceConverter.stringifyResetError(error));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod
|
|
172
|
+
@SuppressWarnings("unused")
|
|
173
|
+
public void getInitState(final Promise promise) {
|
|
174
|
+
InitState initState = sdk.getInitState();
|
|
175
|
+
promise.resolve(SentianceConverter.convertInitState(initState));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@ReactMethod
|
|
179
|
+
@SuppressWarnings("unused")
|
|
180
|
+
public void startTrip(@Nullable ReadableMap metadata, int hint, final Promise promise) {
|
|
181
|
+
if (rejectIfNotInitialized(promise)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
Map<String, String> metadataMap = new HashMap<>();
|
|
186
|
+
if (metadata != null) {
|
|
187
|
+
for (Map.Entry<String, Object> entry : metadata.toHashMap().entrySet()) {
|
|
188
|
+
metadataMap.put(entry.getKey(), entry.getValue().toString());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
final TransportMode transportModeHint = SentianceConverter.toTransportMode(hint);
|
|
192
|
+
sdk.startTrip(metadataMap, transportModeHint)
|
|
193
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
194
|
+
if (pendingOperation.isSuccessful()) {
|
|
195
|
+
promise.resolve(SentianceConverter.createEmptyResult());
|
|
196
|
+
} else {
|
|
197
|
+
StartTripError error = pendingOperation.getError();
|
|
198
|
+
promise.reject(E_SDK_START_TRIP_ERROR,
|
|
199
|
+
SentianceConverter.stringifyStartTripError(error));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@ReactMethod
|
|
205
|
+
@SuppressWarnings("unused")
|
|
206
|
+
public void stopTrip(final Promise promise) {
|
|
207
|
+
if (rejectIfNotInitialized(promise)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
sdk.stopTrip()
|
|
211
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
212
|
+
if (pendingOperation.isSuccessful()) {
|
|
213
|
+
promise.resolve(SentianceConverter.createEmptyResult());
|
|
214
|
+
} else {
|
|
215
|
+
StopTripError error = pendingOperation.getError();
|
|
216
|
+
promise.reject(E_SDK_STOP_TRIP_ERROR,
|
|
217
|
+
SentianceConverter.stringifyStopTripError(error));
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@ReactMethod
|
|
223
|
+
@SuppressWarnings("unused")
|
|
224
|
+
public void getSdkStatus(final Promise promise) {
|
|
225
|
+
if (rejectIfNotInitialized(promise)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
SdkStatus sdkStatus = sdk.getSdkStatus();
|
|
230
|
+
promise.resolve(SentianceConverter.convertSdkStatus(sdkStatus));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@ReactMethod
|
|
234
|
+
@SuppressWarnings("unused")
|
|
235
|
+
public void getVersion(final Promise promise) {
|
|
236
|
+
String version = sdk.getVersion();
|
|
237
|
+
promise.resolve(version);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@ReactMethod
|
|
241
|
+
@SuppressWarnings("unused")
|
|
242
|
+
public void isTripOngoing(String typeParam, final Promise promise) {
|
|
243
|
+
if (rejectIfNotInitialized(promise)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (typeParam == null) {
|
|
248
|
+
promise.reject(E_SDK_MISSING_PARAMS, "TripType is required");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
final TripType type = SentianceConverter.toTripType(typeParam);
|
|
252
|
+
Boolean isTripOngoing = sdk.isTripOngoing(type);
|
|
253
|
+
promise.resolve(isTripOngoing);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@ReactMethod
|
|
257
|
+
@SuppressWarnings("unused")
|
|
258
|
+
public void requestUserAccessToken(final Promise promise) {
|
|
259
|
+
if (rejectIfNotInitialized(promise)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
sdk.requestUserAccessToken()
|
|
264
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
265
|
+
if (pendingOperation.isSuccessful()) {
|
|
266
|
+
Token token = pendingOperation.getResult();
|
|
267
|
+
promise.resolve(SentianceConverter.convertToken(token));
|
|
268
|
+
} else {
|
|
269
|
+
UserAccessTokenError error = pendingOperation.getError();
|
|
270
|
+
promise.reject(E_SDK_GET_TOKEN_ERROR,
|
|
271
|
+
SentianceConverter.stringifyUserAccessTokenError(error));
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@ReactMethod
|
|
277
|
+
@SuppressWarnings("unused")
|
|
278
|
+
public void getUserId(final Promise promise) {
|
|
279
|
+
if (rejectIfNotInitialized(promise)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
String userId = sdk.getUserId();
|
|
284
|
+
promise.resolve(userId);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@ReactMethod
|
|
288
|
+
@SuppressWarnings("unused")
|
|
289
|
+
public void addUserMetadataField(final String label, final String value, final Promise promise) {
|
|
290
|
+
if (rejectIfNotInitialized(promise)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (label == null || value == null) {
|
|
295
|
+
promise.reject(E_SDK_MISSING_PARAMS, "label and value are required");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
sdk.addUserMetadataField(label, value);
|
|
300
|
+
promise.resolve(null);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
@ReactMethod
|
|
304
|
+
@SuppressWarnings("unused")
|
|
305
|
+
public void addTripMetadata(ReadableMap inputMetadata, final Promise promise) {
|
|
306
|
+
if (rejectIfNotInitialized(promise)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
final Map<String, String> metadata = SentianceConverter.convertReadableMapToMap(inputMetadata);
|
|
311
|
+
boolean result = sdk.addTripMetadata(metadata);
|
|
312
|
+
promise.resolve(result);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
@ReactMethod
|
|
316
|
+
@SuppressWarnings("unused")
|
|
317
|
+
public void addUserMetadataFields(ReadableMap inputMetadata, final Promise promise) {
|
|
318
|
+
if (rejectIfNotInitialized(promise)) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (inputMetadata == null) {
|
|
323
|
+
promise.reject(E_SDK_MISSING_PARAMS, "metadata object is required");
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
final Map<String, String> metadata = SentianceConverter.convertReadableMapToMap(inputMetadata);
|
|
328
|
+
sdk.addUserMetadataFields(metadata);
|
|
329
|
+
promise.resolve(null);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@ReactMethod
|
|
333
|
+
@SuppressWarnings("unused")
|
|
334
|
+
public void removeUserMetadataField(final String label, final Promise promise) {
|
|
335
|
+
if (rejectIfNotInitialized(promise)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (label == null) {
|
|
340
|
+
promise.reject(E_SDK_MISSING_PARAMS, "label is required");
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
sdk.removeUserMetadataField(label);
|
|
345
|
+
promise.resolve(null);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@ReactMethod
|
|
349
|
+
@SuppressWarnings("unused")
|
|
350
|
+
public void submitDetections(final Promise promise) {
|
|
351
|
+
if (rejectIfNotInitialized(promise)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
sdk.submitDetections()
|
|
356
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
357
|
+
if (pendingOperation.isSuccessful()) {
|
|
358
|
+
promise.resolve(SentianceConverter.createEmptyResult());
|
|
359
|
+
} else {
|
|
360
|
+
SubmitDetectionsError error = pendingOperation.getError();
|
|
361
|
+
promise.reject(E_SDK_SUBMIT_DETECTIONS_ERROR, error.getReason().name());
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@ReactMethod
|
|
367
|
+
@SuppressWarnings("unused")
|
|
368
|
+
public void getWiFiQuotaLimit(final Promise promise) {
|
|
369
|
+
if (rejectIfNotInitialized(promise)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
long wifiQuotaLimit = sdk.getWiFiQuotaLimit();
|
|
374
|
+
promise.resolve(Long.toString(wifiQuotaLimit));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@ReactMethod
|
|
378
|
+
@SuppressWarnings("unused")
|
|
379
|
+
public void getWiFiQuotaUsage(final Promise promise) {
|
|
380
|
+
if (rejectIfNotInitialized(promise)) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
long wifiQuotaUsage = sdk.getWiFiQuotaUsage();
|
|
385
|
+
promise.resolve(Long.toString(wifiQuotaUsage));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
@ReactMethod
|
|
389
|
+
@SuppressWarnings("unused")
|
|
390
|
+
public void getMobileQuotaLimit(final Promise promise) {
|
|
391
|
+
if (rejectIfNotInitialized(promise)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
long mobileQuotaLimit = sdk.getMobileQuotaLimit();
|
|
396
|
+
promise.resolve(Long.toString(mobileQuotaLimit));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
@ReactMethod
|
|
400
|
+
@SuppressWarnings("unused")
|
|
401
|
+
public void getMobileQuotaUsage(final Promise promise) {
|
|
402
|
+
if (rejectIfNotInitialized(promise)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
long mobileQuotaUsage = sdk.getMobileQuotaUsage();
|
|
407
|
+
promise.resolve(Long.toString(mobileQuotaUsage));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
@ReactMethod
|
|
411
|
+
@SuppressWarnings("unused")
|
|
412
|
+
public void getDiskQuotaLimit(final Promise promise) {
|
|
413
|
+
if (rejectIfNotInitialized(promise)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
long diskQuotaLimit = sdk.getDiskQuotaLimit();
|
|
418
|
+
promise.resolve(Long.toString(diskQuotaLimit));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
@ReactMethod
|
|
422
|
+
@SuppressWarnings("unused")
|
|
423
|
+
public void getDiskQuotaUsage(final Promise promise) {
|
|
424
|
+
if (rejectIfNotInitialized(promise)) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
long diskQuotaUsage = sdk.getDiskQuotaUsage();
|
|
429
|
+
promise.resolve(Long.toString(diskQuotaUsage));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
@SuppressLint("MissingPermission")
|
|
433
|
+
@ReactMethod
|
|
434
|
+
@SuppressWarnings("unused")
|
|
435
|
+
public void disableBatteryOptimization(final Promise promise) {
|
|
436
|
+
if (rejectIfNotInitialized(promise)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
sdk.disableBatteryOptimization();
|
|
441
|
+
promise.resolve(null);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@ReactMethod
|
|
445
|
+
@SuppressWarnings("unused")
|
|
446
|
+
public void listenUserActivityUpdates(Promise promise) {
|
|
447
|
+
if (rejectIfNotInitialized(promise)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
Sentiance.getInstance(reactContext).setUserActivityListener(emitter::sendUserActivityUpdate);
|
|
452
|
+
promise.resolve(null);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
@ReactMethod
|
|
456
|
+
@SuppressWarnings("unused")
|
|
457
|
+
public void getUserActivity(final Promise promise) {
|
|
458
|
+
if (rejectIfNotInitialized(promise)) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
UserActivity activity = Sentiance.getInstance(reactContext).getUserActivity();
|
|
463
|
+
promise.resolve(SentianceConverter.convertUserActivity(activity));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
@ReactMethod
|
|
467
|
+
@SuppressWarnings("unused")
|
|
468
|
+
public void updateSdkNotification(final String title, final String message, Promise promise) {
|
|
469
|
+
if (rejectIfNotInitialized(promise)) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
Notification notification = SentianceUtils.createNotificationFromManifestData(
|
|
474
|
+
new WeakReference<>(reactContext.getApplicationContext()),
|
|
475
|
+
title,
|
|
476
|
+
message);
|
|
477
|
+
if (notification != null) {
|
|
478
|
+
Sentiance.getInstance(reactContext)
|
|
479
|
+
.updateSdkNotification(notification);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
promise.resolve(null);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
@ReactMethod
|
|
486
|
+
@SuppressWarnings("unused")
|
|
487
|
+
public void setAppSessionDataCollectionEnabled(boolean enabled, Promise promise) {
|
|
488
|
+
if (rejectIfNotInitialized(promise)) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
Sentiance.getInstance(reactContext).setAppSessionDataCollectionEnabled(enabled);
|
|
493
|
+
promise.resolve(null);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
@ReactMethod
|
|
497
|
+
@SuppressWarnings("unused")
|
|
498
|
+
public void isAppSessionDataCollectionEnabled(Promise promise) {
|
|
499
|
+
if (rejectIfNotInitialized(promise)) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
promise.resolve(Sentiance.getInstance(reactContext).isAppSessionDataCollectionEnabled());
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
@ReactMethod
|
|
507
|
+
@SuppressWarnings("unused")
|
|
508
|
+
public void listenSdkStatusUpdates(Promise promise) {
|
|
509
|
+
if (rejectIfNotInitialized(promise)) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
Sentiance.getInstance(reactContext).setSdkStatusUpdateListener(sentianceHelper.getOnSdkStatusUpdateListener());
|
|
514
|
+
promise.resolve(null);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
@ReactMethod
|
|
518
|
+
@SuppressWarnings("unused")
|
|
519
|
+
public void listenTripTimeout(Promise promise) {
|
|
520
|
+
if (rejectIfNotInitialized(promise)) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
Sentiance.getInstance(reactContext)
|
|
525
|
+
.setTripTimeoutListener(emitter::sendOnTripTimedOutEvent);
|
|
526
|
+
promise.resolve(null);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class SentiancePackage implements ReactPackage {
|
|
15
|
+
|
|
16
|
+
@NonNull
|
|
17
|
+
@Override
|
|
18
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
19
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
20
|
+
SentianceModule sentianceModule = new SentianceModule(reactContext);
|
|
21
|
+
modules.add(sentianceModule);
|
|
22
|
+
return modules;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@NonNull
|
|
26
|
+
@Override
|
|
27
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
28
|
+
return Collections.emptyList();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import java.util.concurrent.CountDownLatch;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
public class UserLinker implements com.sentiance.sdk.UserLinker {
|
|
9
|
+
|
|
10
|
+
private final SentianceEmitter mSentianceEmitter;
|
|
11
|
+
private boolean mUserLinkResult;
|
|
12
|
+
private CountDownLatch mCountDownLatch;
|
|
13
|
+
|
|
14
|
+
public UserLinker (SentianceEmitter sentianceEmitter) {
|
|
15
|
+
mSentianceEmitter = sentianceEmitter;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
public boolean link(@NonNull String installId) {
|
|
20
|
+
mCountDownLatch = new CountDownLatch(1);
|
|
21
|
+
mSentianceEmitter.sendUserLinkEvent(installId);
|
|
22
|
+
try {
|
|
23
|
+
mCountDownLatch.await();
|
|
24
|
+
return mUserLinkResult;
|
|
25
|
+
} catch (InterruptedException e) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public void setUserLinkResult(boolean userLinkResult) {
|
|
31
|
+
mUserLinkResult = userLinkResult;
|
|
32
|
+
mCountDownLatch.countDown();
|
|
33
|
+
}
|
|
34
|
+
}
|
package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceEmitter.java
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core.base;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.os.Handler;
|
|
5
|
+
import android.os.Looper;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.ReactApplication;
|
|
8
|
+
import com.facebook.react.ReactNativeHost;
|
|
9
|
+
import com.facebook.react.bridge.ReactContext;
|
|
10
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
12
|
+
|
|
13
|
+
public abstract class AbstractSentianceEmitter {
|
|
14
|
+
|
|
15
|
+
protected final Handler mHandler = new Handler(Looper.getMainLooper());
|
|
16
|
+
protected ReactContext reactContext;
|
|
17
|
+
protected ReactNativeHost reactNativeHost;
|
|
18
|
+
|
|
19
|
+
protected AbstractSentianceEmitter(Context context) {
|
|
20
|
+
ReactApplication reactApplication = ((ReactApplication) context.getApplicationContext());
|
|
21
|
+
reactNativeHost = reactApplication.getReactNativeHost();
|
|
22
|
+
reactContext = createReactContext();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected ReactContext createReactContext() {
|
|
26
|
+
if (!reactNativeHost.getReactInstanceManager().hasStartedCreatingInitialContext())
|
|
27
|
+
reactNativeHost.getReactInstanceManager().createReactContextInBackground();
|
|
28
|
+
return reactNativeHost.getReactInstanceManager().getCurrentReactContext();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected void sendEvent(final String key, final WritableMap map) {
|
|
32
|
+
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
|
|
33
|
+
this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
|
|
34
|
+
} else {
|
|
35
|
+
// add delay
|
|
36
|
+
final Counter retry = new Counter(20);
|
|
37
|
+
mHandler.postDelayed(new Runnable() {
|
|
38
|
+
@Override
|
|
39
|
+
public void run() {
|
|
40
|
+
if (AbstractSentianceEmitter.this.reactContext == null)
|
|
41
|
+
AbstractSentianceEmitter.this.reactContext = createReactContext();
|
|
42
|
+
if (AbstractSentianceEmitter.this.reactContext != null && AbstractSentianceEmitter.this.reactContext.hasActiveCatalystInstance()) {
|
|
43
|
+
AbstractSentianceEmitter.this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
|
|
44
|
+
} else if (retry.count-- > 0) {
|
|
45
|
+
mHandler.postDelayed(this, 500);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, 500);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private static class Counter {
|
|
53
|
+
int count;
|
|
54
|
+
|
|
55
|
+
Counter(int count) {
|
|
56
|
+
this.count = count;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceModule.java
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core.base;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_NOT_INITIALIZED;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Promise;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
|
+
import com.sentiance.sdk.InitState;
|
|
9
|
+
import com.sentiance.sdk.Sentiance;
|
|
10
|
+
|
|
11
|
+
public abstract class AbstractSentianceModule extends ReactContextBaseJavaModule {
|
|
12
|
+
|
|
13
|
+
protected final ReactApplicationContext reactContext;
|
|
14
|
+
protected final Sentiance sdk;
|
|
15
|
+
|
|
16
|
+
public AbstractSentianceModule(ReactApplicationContext reactApplicationContext) {
|
|
17
|
+
super(reactApplicationContext);
|
|
18
|
+
reactContext = reactApplicationContext;
|
|
19
|
+
sdk = Sentiance.getInstance(reactContext);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected boolean rejectIfNotInitialized(Promise promise) {
|
|
23
|
+
if (!isSdkInitialized()) {
|
|
24
|
+
promise.reject(E_SDK_NOT_INITIALIZED, "Sdk not initialized");
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private boolean isSdkInitialized() {
|
|
31
|
+
return sdk.getInitState() == InitState.INITIALIZED;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core.utils;
|
|
2
|
+
|
|
3
|
+
public class ErrorCodes {
|
|
4
|
+
public static final String E_SDK_MISSING_PARAMS = "E_SDK_MISSING_PARAMS";
|
|
5
|
+
public static final String E_SDK_GET_TOKEN_ERROR = "E_SDK_GET_TOKEN_ERROR";
|
|
6
|
+
public static final String E_SDK_START_TRIP_ERROR = "E_SDK_START_TRIP_ERROR";
|
|
7
|
+
public static final String E_SDK_STOP_TRIP_ERROR = "E_SDK_STOP_TRIP_ERROR";
|
|
8
|
+
public static final String E_SDK_NOT_INITIALIZED = "E_SDK_NOT_INITIALIZED";
|
|
9
|
+
public static final String E_SDK_SUBMIT_DETECTIONS_ERROR = "E_SDK_SUBMIT_DETECTIONS_ERROR";
|
|
10
|
+
public static final String E_SDK_ENABLE_DETECTIONS_ERROR = "E_SDK_ENABLE_DETECTIONS_ERROR";
|
|
11
|
+
public static final String E_SDK_DISABLE_DETECTIONS_ERROR = "E_SDK_DISABLE_DETECTIONS_ERROR";
|
|
12
|
+
public static final String E_SDK_USER_LINK_ERROR = "E_SDK_USER_LINK_ERROR";
|
|
13
|
+
public static final String E_SDK_USER_LINK_AUTH_CODE_ERROR = "E_SDK_USER_LINK_AUTH_CODE_ERROR";
|
|
14
|
+
public static final String E_SDK_CREATE_USER_ERROR = "E_SDK_CREATE_USER_ERROR";
|
|
15
|
+
public static final String E_SDK_RESET_ERROR = "E_SDK_RESET_ERROR";
|
|
16
|
+
}
|