@sodyo/react-native-sodyo-sdk 5.0.2 → 5.1.1
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/android/CODE_ANALYSIS.md +464 -0
- package/android/build.gradle +4 -17
- package/android/src/main/java/com/sodyo/RNSodyoSdk/ConversionUtil.java +26 -5
- package/android/src/main/java/com/sodyo/RNSodyoSdk/RNSodyoSdkModule.java +119 -37
- package/android/src/main/java/com/sodyo/RNSodyoSdk/RNSodyoSdkView.java +9 -6
- package/ios/CODE_ANALYSIS.md +360 -0
- package/ios/RNSodyoScanner.h +3 -4
- package/ios/RNSodyoScanner.m +6 -5
- package/ios/RNSodyoSdk.h +1 -3
- package/ios/RNSodyoSdk.m +107 -56
- package/ios/RNSodyoSdkManager.m +40 -17
- package/ios/RNSodyoSdkView.h +4 -2
- package/ios/RNSodyoSdkView.m +36 -12
- package/package.json +1 -1
|
@@ -61,9 +61,10 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
61
61
|
|
|
62
62
|
@Override
|
|
63
63
|
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
|
|
64
|
-
Log.i(TAG, "onActivityResult()");
|
|
64
|
+
Log.i(TAG, "onActivityResult() - requestCode: " + requestCode + ", resultCode: " + resultCode + ", activity: " + activity);
|
|
65
65
|
|
|
66
66
|
if (requestCode == SODYO_SCANNER_REQUEST_CODE) {
|
|
67
|
+
Log.i(TAG, "onActivityResult() - scanner request code matched, sending EventCloseSodyoScanner");
|
|
67
68
|
sendEvent("EventCloseSodyoScanner", null);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -75,6 +76,13 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
75
76
|
this.reactContext.addActivityEventListener(mActivityEventListener);
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
// Issue #4 fix: remove listener on destroy to prevent leak
|
|
80
|
+
@Override
|
|
81
|
+
public void onCatalystInstanceDestroy() {
|
|
82
|
+
super.onCatalystInstanceDestroy();
|
|
83
|
+
reactContext.removeActivityEventListener(mActivityEventListener);
|
|
84
|
+
}
|
|
85
|
+
|
|
78
86
|
@Override
|
|
79
87
|
public String getName() {
|
|
80
88
|
return "RNSodyoSdk";
|
|
@@ -87,6 +95,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
87
95
|
private boolean isCallbackUsed;
|
|
88
96
|
|
|
89
97
|
public SodyoCallback(Callback successCallback, Callback errorCallback) {
|
|
98
|
+
Log.d(TAG, "SodyoCallback() - successCallback: " + (successCallback != null ? "provided" : "nil") + ", errorCallback: " + (errorCallback != null ? "provided" : "nil"));
|
|
90
99
|
this.successCallback = successCallback;
|
|
91
100
|
this.errorCallback = errorCallback;
|
|
92
101
|
}
|
|
@@ -95,10 +104,10 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
95
104
|
* SodyoInitCallback implementation
|
|
96
105
|
*/
|
|
97
106
|
public void onSodyoAppLoadSuccess() {
|
|
98
|
-
|
|
99
|
-
Log.i(TAG, message);
|
|
107
|
+
Log.i(TAG, "onSodyoAppLoadSuccess - successCallback: " + (this.successCallback != null ? "provided" : "nil") + ", isCallbackUsed: " + this.isCallbackUsed);
|
|
100
108
|
|
|
101
109
|
if (this.successCallback == null || this.isCallbackUsed) {
|
|
110
|
+
Log.w(TAG, "onSodyoAppLoadSuccess - skipping: callback=" + (this.successCallback == null ? "null" : "exists") + ", used=" + this.isCallbackUsed);
|
|
102
111
|
return;
|
|
103
112
|
}
|
|
104
113
|
|
|
@@ -115,10 +124,10 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
115
124
|
* SodyoInitCallback implementation
|
|
116
125
|
*/
|
|
117
126
|
public void onSodyoAppLoadFailed(String error) {
|
|
118
|
-
|
|
119
|
-
Log.e(TAG, message);
|
|
127
|
+
Log.e(TAG, "onSodyoAppLoadFailed - error: " + error + ", errorCallback: " + (this.errorCallback != null ? "provided" : "nil") + ", isCallbackUsed: " + this.isCallbackUsed);
|
|
120
128
|
|
|
121
129
|
if (this.errorCallback == null || this.isCallbackUsed) {
|
|
130
|
+
Log.w(TAG, "onSodyoAppLoadFailed - skipping: callback=" + (this.errorCallback == null ? "null" : "exists") + ", used=" + this.isCallbackUsed);
|
|
122
131
|
return;
|
|
123
132
|
}
|
|
124
133
|
|
|
@@ -127,6 +136,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
public void permissionError(String err1, String err2) {
|
|
139
|
+
Log.w(TAG, "permissionError - err1: " + err1 + ", err2: " + err2);
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
/**
|
|
@@ -134,8 +144,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
134
144
|
*/
|
|
135
145
|
@Override
|
|
136
146
|
public void sodyoError(Error err) {
|
|
137
|
-
|
|
138
|
-
Log.e(TAG, message);
|
|
147
|
+
Log.e(TAG, "sodyoError - error: " + err + ", message: " + (err != null ? err.getMessage() : "null"));
|
|
139
148
|
|
|
140
149
|
WritableMap params = Arguments.createMap();
|
|
141
150
|
params.putString("error", err.getMessage());
|
|
@@ -147,7 +156,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
147
156
|
*/
|
|
148
157
|
@Override
|
|
149
158
|
public void onMarkerDetect(String markerType, String data, String error) {
|
|
150
|
-
Log.i(TAG, "onMarkerDetect()");
|
|
159
|
+
Log.i(TAG, "onMarkerDetect() - markerType: " + markerType + ", data: " + data + ", error: " + error);
|
|
151
160
|
|
|
152
161
|
if (data == null) {
|
|
153
162
|
data = "null";
|
|
@@ -175,7 +184,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
175
184
|
*/
|
|
176
185
|
@Override
|
|
177
186
|
public void onMarkerContent(String markerId, JSONObject data) {
|
|
178
|
-
Log.i(TAG, "onMarkerContent()");
|
|
187
|
+
Log.i(TAG, "onMarkerContent() - markerId: " + markerId + ", data: " + data);
|
|
179
188
|
|
|
180
189
|
WritableMap params = Arguments.createMap();
|
|
181
190
|
params.putString("markerId", markerId);
|
|
@@ -194,7 +203,7 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
194
203
|
*/
|
|
195
204
|
@Override
|
|
196
205
|
public void onModeChange(SettingsHelper.ScannerViewMode oldMode, SettingsHelper.ScannerViewMode newMode) {
|
|
197
|
-
Log.i(TAG, "onModeChange()");
|
|
206
|
+
Log.i(TAG, "onModeChange() - oldMode: " + oldMode + ", newMode: " + newMode);
|
|
198
207
|
|
|
199
208
|
WritableMap params = Arguments.createMap();
|
|
200
209
|
|
|
@@ -205,12 +214,16 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
|
|
217
|
+
// Issue #7 fix: invoke success callback if already initialized
|
|
208
218
|
@ReactMethod
|
|
209
219
|
public void init(final String apiKey, Callback successCallback, Callback errorCallback) {
|
|
210
|
-
Log.i(TAG, "init()");
|
|
220
|
+
Log.i(TAG, "init() - apiKey: " + apiKey + ", successCallback: " + (successCallback != null ? "provided" : "nil") + ", errorCallback: " + (errorCallback != null ? "provided" : "nil"));
|
|
211
221
|
|
|
212
222
|
if (Sodyo.isInitialized()) {
|
|
213
|
-
Log.i(TAG, "init(): already initialized,
|
|
223
|
+
Log.i(TAG, "init(): already initialized, invoking success callback directly");
|
|
224
|
+
if (successCallback != null) {
|
|
225
|
+
successCallback.invoke();
|
|
226
|
+
}
|
|
214
227
|
return;
|
|
215
228
|
}
|
|
216
229
|
|
|
@@ -228,51 +241,74 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
228
241
|
});
|
|
229
242
|
}
|
|
230
243
|
|
|
244
|
+
// Issue #1 fix: null-check getCurrentActivity()
|
|
231
245
|
@ReactMethod
|
|
232
246
|
public void start() {
|
|
233
|
-
Log.i(TAG, "start()");
|
|
234
|
-
Intent intent = new Intent(this.reactContext, SodyoScannerActivity.class);
|
|
247
|
+
Log.i(TAG, "start() - launching scanner");
|
|
235
248
|
Activity activity = getCurrentActivity();
|
|
249
|
+
Log.d(TAG, "start() - currentActivity: " + activity);
|
|
250
|
+
if (activity == null) {
|
|
251
|
+
Log.e(TAG, "start(): current activity is null, aborting");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
Intent intent = new Intent(activity, SodyoScannerActivity.class);
|
|
255
|
+
Log.d(TAG, "start() - starting SodyoScannerActivity with requestCode: " + SODYO_SCANNER_REQUEST_CODE);
|
|
236
256
|
activity.startActivityForResult(intent, SODYO_SCANNER_REQUEST_CODE);
|
|
237
257
|
}
|
|
238
258
|
|
|
239
259
|
@ReactMethod
|
|
240
260
|
public void close() {
|
|
241
|
-
Log.i(TAG, "close()");
|
|
261
|
+
Log.i(TAG, "close() - closing scanner");
|
|
242
262
|
Activity activity = getCurrentActivity();
|
|
263
|
+
Log.d(TAG, "close() - currentActivity: " + activity);
|
|
264
|
+
if (activity == null) {
|
|
265
|
+
Log.e(TAG, "close(): current activity is null, aborting");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
243
268
|
activity.finishActivity(SODYO_SCANNER_REQUEST_CODE);
|
|
244
269
|
}
|
|
245
270
|
|
|
271
|
+
// Issue #6 fix: guard against uninitialized SDK
|
|
246
272
|
@ReactMethod
|
|
247
273
|
public void setUserInfo(ReadableMap userInfo) {
|
|
248
|
-
Log.i(TAG, "setUserInfo()");
|
|
274
|
+
Log.i(TAG, "setUserInfo() - userInfo: " + userInfo);
|
|
275
|
+
|
|
276
|
+
if (!Sodyo.isInitialized()) {
|
|
277
|
+
Log.w(TAG, "setUserInfo(): SDK not initialized yet, aborting");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
249
280
|
|
|
250
281
|
if(userInfo != null) {
|
|
282
|
+
Log.d(TAG, "setUserInfo() - converted map: " + ConversionUtil.toMap(userInfo));
|
|
251
283
|
Sodyo.getInstance().setUserInfo(ConversionUtil.toMap(userInfo));
|
|
284
|
+
} else {
|
|
285
|
+
Log.w(TAG, "setUserInfo() - userInfo is null, skipping");
|
|
252
286
|
}
|
|
253
287
|
}
|
|
254
288
|
|
|
255
289
|
@ReactMethod
|
|
256
290
|
public void setCustomAdLabel(String label) {
|
|
257
|
-
Log.i(TAG, "setCustomAdLabel()");
|
|
291
|
+
Log.i(TAG, "setCustomAdLabel() - label: " + label);
|
|
258
292
|
Sodyo.setCustomAdLabel(label);
|
|
259
293
|
}
|
|
260
294
|
|
|
261
295
|
@ReactMethod
|
|
262
296
|
public void setAppUserId(String userId) {
|
|
263
|
-
Log.i(TAG, "setAppUserId()");
|
|
297
|
+
Log.i(TAG, "setAppUserId() - userId: " + userId);
|
|
264
298
|
Sodyo.setAppUserId(userId);
|
|
265
299
|
}
|
|
266
300
|
|
|
267
301
|
@ReactMethod
|
|
268
302
|
public void setScannerParams(ReadableMap scannerPreferences) {
|
|
269
|
-
Log.i(TAG, "setScannerParams()");
|
|
270
|
-
|
|
303
|
+
Log.i(TAG, "setScannerParams() - scannerPreferences: " + scannerPreferences);
|
|
304
|
+
Map<String, String> flatMap = ConversionUtil.toFlatMap(scannerPreferences);
|
|
305
|
+
Log.d(TAG, "setScannerParams() - flatMap: " + flatMap);
|
|
306
|
+
Sodyo.setScannerParams(flatMap);
|
|
271
307
|
}
|
|
272
308
|
|
|
273
309
|
@ReactMethod
|
|
274
310
|
public void addScannerParam(String key, String value) {
|
|
275
|
-
Log.i(TAG, "addScannerParam()");
|
|
311
|
+
Log.i(TAG, "addScannerParam() - key: " + key + ", value: " + value);
|
|
276
312
|
Sodyo.addScannerParams(key, value);
|
|
277
313
|
}
|
|
278
314
|
|
|
@@ -290,30 +326,45 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
290
326
|
|
|
291
327
|
@ReactMethod
|
|
292
328
|
public void setDynamicProfile(ReadableMap profile) {
|
|
293
|
-
Log.i(TAG, "setDynamicProfile()");
|
|
329
|
+
Log.i(TAG, "setDynamicProfile() - profile: " + profile);
|
|
294
330
|
if (profile != null) {
|
|
295
331
|
HashMap<String, Object> profileMap = new HashMap<>(ConversionUtil.toMap(profile));
|
|
332
|
+
Log.d(TAG, "setDynamicProfile() - profileMap: " + profileMap);
|
|
296
333
|
Sodyo.setDynamicProfile(profileMap);
|
|
334
|
+
} else {
|
|
335
|
+
Log.w(TAG, "setDynamicProfile() - profile is null, skipping");
|
|
297
336
|
}
|
|
298
337
|
}
|
|
299
338
|
|
|
300
339
|
@ReactMethod
|
|
301
340
|
public void setDynamicProfileValue(String key, String value) {
|
|
302
|
-
Log.i(TAG, "setDynamicProfileValue()");
|
|
341
|
+
Log.i(TAG, "setDynamicProfileValue() - key: " + key + ", value: " + value);
|
|
303
342
|
Sodyo.setDynamicProfileValue(key, value);
|
|
304
343
|
}
|
|
305
344
|
|
|
306
345
|
@ReactMethod
|
|
307
346
|
public void performMarker(String markerId, ReadableMap customProperties) {
|
|
308
|
-
Log.i(TAG, "performMarker()");
|
|
347
|
+
Log.i(TAG, "performMarker() - markerId: " + markerId + ", customProperties: " + customProperties);
|
|
309
348
|
Activity activity = getCurrentActivity();
|
|
310
|
-
|
|
349
|
+
Log.d(TAG, "performMarker() - currentActivity: " + activity);
|
|
350
|
+
if (activity == null) {
|
|
351
|
+
Log.e(TAG, "performMarker(): current activity is null, aborting");
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
Map<String, Object> propsMap = ConversionUtil.toMap(customProperties);
|
|
355
|
+
Log.d(TAG, "performMarker() - converted customProperties: " + propsMap);
|
|
356
|
+
Sodyo.performMarker(markerId, activity, propsMap);
|
|
311
357
|
}
|
|
312
358
|
|
|
313
359
|
@ReactMethod
|
|
314
360
|
public void startTroubleshoot() {
|
|
315
361
|
Log.i(TAG, "startTroubleshoot()");
|
|
316
362
|
Activity activity = getCurrentActivity();
|
|
363
|
+
Log.d(TAG, "startTroubleshoot() - currentActivity: " + activity);
|
|
364
|
+
if (activity == null) {
|
|
365
|
+
Log.e(TAG, "startTroubleshoot(): current activity is null, aborting");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
317
368
|
Sodyo.startTroubleshoot(activity);
|
|
318
369
|
}
|
|
319
370
|
|
|
@@ -321,6 +372,12 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
321
372
|
public void setTroubleshootMode() {
|
|
322
373
|
Log.i(TAG, "setTroubleshootMode()");
|
|
323
374
|
Activity activity = getCurrentActivity();
|
|
375
|
+
Log.d(TAG, "setTroubleshootMode() - currentActivity: " + activity);
|
|
376
|
+
if (activity == null) {
|
|
377
|
+
Log.e(TAG, "setTroubleshootMode(): current activity is null, aborting");
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
Log.d(TAG, "setTroubleshootMode() - setting mode to Troubleshoot");
|
|
324
381
|
Sodyo.setMode(activity, SettingsHelper.ScannerViewMode.Troubleshoot);
|
|
325
382
|
}
|
|
326
383
|
|
|
@@ -328,34 +385,59 @@ public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
|
328
385
|
public void setNormalMode() {
|
|
329
386
|
Log.i(TAG, "setNormalMode()");
|
|
330
387
|
Activity activity = getCurrentActivity();
|
|
388
|
+
Log.d(TAG, "setNormalMode() - currentActivity: " + activity);
|
|
389
|
+
if (activity == null) {
|
|
390
|
+
Log.e(TAG, "setNormalMode(): current activity is null, aborting");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
Log.d(TAG, "setNormalMode() - setting mode to Normal");
|
|
331
394
|
Sodyo.setMode(activity, SettingsHelper.ScannerViewMode.Normal);
|
|
332
395
|
}
|
|
333
396
|
|
|
334
397
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
335
398
|
public String getMode() {
|
|
336
|
-
|
|
399
|
+
String mode = Sodyo.getMode().name();
|
|
400
|
+
Log.i(TAG, "getMode() - mode: " + mode);
|
|
401
|
+
return mode;
|
|
337
402
|
}
|
|
338
403
|
|
|
339
404
|
@ReactMethod
|
|
340
405
|
public void setSodyoLogoVisible(Boolean isVisible) {
|
|
341
|
-
Log.i(TAG, "setSodyoLogoVisible()");
|
|
406
|
+
Log.i(TAG, "setSodyoLogoVisible() - isVisible: " + isVisible);
|
|
342
407
|
Sodyo.setSodyoLogoVisible(isVisible);
|
|
343
408
|
}
|
|
344
409
|
|
|
410
|
+
// Issue #2 fix: validate env input, Issue #10 fix: public instead of private
|
|
345
411
|
@ReactMethod
|
|
346
|
-
|
|
347
|
-
Log.i(TAG, "setEnv:" + env);
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
412
|
+
public void setEnv(String env) {
|
|
413
|
+
Log.i(TAG, "setEnv() - env: " + env);
|
|
414
|
+
|
|
415
|
+
if (env == null) {
|
|
416
|
+
Log.e(TAG, "setEnv(): env is null, aborting");
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
try {
|
|
421
|
+
SodyoEnv sodyoEnv = SodyoEnv.valueOf(env.trim().toUpperCase());
|
|
422
|
+
Map<String, String> params = new HashMap<>();
|
|
423
|
+
params.put("webad_env", String.valueOf(sodyoEnv.getValue()));
|
|
424
|
+
params.put("scanner_QR_code_enabled", "false");
|
|
425
|
+
Log.d(TAG, "setEnv() - resolved sodyoEnv: " + sodyoEnv + " (value: " + sodyoEnv.getValue() + "), params: " + params);
|
|
426
|
+
Sodyo.setScannerParams(params);
|
|
427
|
+
} catch (IllegalArgumentException e) {
|
|
428
|
+
Log.e(TAG, "setEnv(): unknown env '" + env + "', expected DEV/QA/PROD", e);
|
|
429
|
+
}
|
|
354
430
|
}
|
|
355
431
|
|
|
432
|
+
// Issue #12 fix: check for active React instance before sending events
|
|
356
433
|
private void sendEvent(String eventName, @Nullable WritableMap params) {
|
|
357
|
-
|
|
434
|
+
Log.d(TAG, "sendEvent() - eventName: " + eventName + ", params: " + params);
|
|
435
|
+
if (!reactContext.hasActiveReactInstance()) {
|
|
436
|
+
Log.w(TAG, "sendEvent() - no active React instance, dropping event: " + eventName);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
reactContext
|
|
358
440
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
359
441
|
.emit(eventName, params);
|
|
360
442
|
}
|
|
361
|
-
}
|
|
443
|
+
}
|
|
@@ -81,11 +81,14 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
|
|
|
81
81
|
isCameraEnabled = true;
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
Activity currentActivity = mCallerContext.getCurrentActivity();
|
|
85
|
+
if (currentActivity != null) {
|
|
86
|
+
FragmentManager fragmentManager = currentActivity.getFragmentManager();
|
|
87
|
+
Fragment fragment = fragmentManager.findFragmentByTag(TAG_FRAGMENT);
|
|
88
|
+
|
|
89
|
+
if (fragment != null) {
|
|
90
|
+
fragmentManager.beginTransaction().remove(fragment).commitNowAllowingStateLoss();
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
} catch (Exception e) {
|
|
91
94
|
e.printStackTrace();
|
|
@@ -110,4 +113,4 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
|
|
|
110
113
|
sodyoFragment.stopCamera();
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
|
-
}
|
|
116
|
+
}
|