Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit a464543

Browse files
authored
Merge pull request #27 from taras-omelchuk/master
Implement ability for AppKinetics module to provide multiple app-based sevices.
2 parents 8928921 + 82a89e2 commit a464543

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

modules/BlackBerry-Dynamics-for-React-Native-AppKinetics/android/src/main/java/com/blackberry/bbd/reactnative/appkinetics/ReactNativeBbdAppKineticsModule.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2022 BlackBerry Limited. All Rights Reserved.
2+
* Copyright (c) 2023 BlackBerry Limited. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -173,6 +173,7 @@ public void readyToProvideService(final ReadableMap arguments, final Promise pro
173173
final String serviceId = arguments.getString("serviceId");
174174
final String version = arguments.getString("version");
175175

176+
serviceHelper.setService(serviceId, version);
176177
serviceHelper.setServiceId(serviceId);
177178
serviceHelper.setServiceVersion(version);
178179

modules/BlackBerry-Dynamics-for-React-Native-Base/android/src/main/java/com/blackberry/bbd/reactnative/helpers/RNBbdServiceHelper.java

+52-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 BlackBerry Limited. All Rights Reserved.
2+
* Copyright (c) 2023 BlackBerry Limited. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,10 @@
3838
import org.json.JSONException;
3939
import org.json.JSONObject;
4040

41+
import java.util.ArrayList;
42+
import java.util.HashMap;
4143
import java.util.Iterator;
44+
import java.util.List;
4245

4346
/**
4447
* Helper class to interact with GDService and GDServiceClient.
@@ -61,6 +64,8 @@ public class RNBbdServiceHelper implements GDServiceListener, GDServiceClientLis
6164
private static RNBbdServiceHelper instance = null;
6265
private Promise promise = null;
6366
private ReactApplicationContext reactContext = null;
67+
68+
private List<AppBasedService> providedServices = new ArrayList<AppBasedService>();
6469
private String serviceId = null;
6570
private String serviceVersion = null;
6671

@@ -72,6 +77,16 @@ public static RNBbdServiceHelper getInstance() {
7277
return instance;
7378
}
7479

80+
private class AppBasedService {
81+
String serviceId;
82+
String serviceVersion;
83+
84+
AppBasedService(String service, String version) {
85+
this.serviceId = service;
86+
this.serviceVersion = version;
87+
}
88+
}
89+
7590
/**
7691
* Constructs RNBbdServiceHelper.
7792
*/
@@ -105,6 +120,16 @@ public void setRNContext(final ReactApplicationContext reactContext) {
105120
RNBbdServiceSpoolHelper.getInstance().setRNContext(reactContext);
106121
}
107122

123+
/**
124+
* Sets service to proceed with.
125+
*
126+
* @param serviceId serviceId to proceed with.
127+
* @param serviceVersion serviceVersion to proceed with.
128+
*/
129+
public void setService(final String serviceId, final String serviceVersion) {
130+
providedServices.add(new AppBasedService(serviceId, serviceVersion));
131+
}
132+
108133
/**
109134
* Sets serviceId to proceed with.
110135
*
@@ -187,34 +212,35 @@ public void onReceiveMessage(final String application,
187212
RNBbdServiceSpoolHelper.getInstance().proceedSimpleReceive(service, version, attachments);
188213
return;
189214
}
190-
if (serviceId.equals(service) && serviceVersion.equals(version)) {
191-
192-
final JSONObject resultObject = new JSONObject();
193-
194-
try {
195-
resultObject.put(APP_KINETICS_APPLICATION_NAME_KEY, application);
196-
resultObject.put(APP_KINETICS_SERVICE_NAME_KEY, service);
197-
resultObject.put(APP_KINETICS_VERSION_KEY, version);
198-
resultObject.put(APP_KINETICS_METHOD_KEY, method);
199-
200-
if (attachments != null) {
201-
resultObject.put(APP_KINETICS_ATTACHMENT_KEY, attachments);
202-
}
203-
204-
if (params != null) {
205-
resultObject.put(APP_KINETICS_PARAMETERS_KEY, params);
206-
}
207215

208-
if (reactContext != null) {
209-
reactContext
210-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
211-
.emit("onReceivedMessage", convertJsonToMap(resultObject));
216+
providedServices.forEach((AppBasedService providedService) -> {
217+
if (providedService.serviceId.equals(service) && providedService.serviceVersion.equals(version)) {
218+
final JSONObject resultObject = new JSONObject();
219+
220+
try {
221+
resultObject.put(APP_KINETICS_APPLICATION_NAME_KEY, application);
222+
resultObject.put(APP_KINETICS_SERVICE_NAME_KEY, service);
223+
resultObject.put(APP_KINETICS_VERSION_KEY, version);
224+
resultObject.put(APP_KINETICS_METHOD_KEY, method);
225+
226+
if (attachments != null) {
227+
resultObject.put(APP_KINETICS_ATTACHMENT_KEY, attachments);
228+
}
229+
230+
if (params != null) {
231+
resultObject.put(APP_KINETICS_PARAMETERS_KEY, params);
232+
}
233+
234+
if (reactContext != null) {
235+
reactContext
236+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
237+
.emit("onReceivedMessage", convertJsonToMap(resultObject));
238+
}
239+
} catch (final JSONException exception) {
240+
// Should not get here
212241
}
213-
} catch (final JSONException exception) {
214-
// Should not get here
215242
}
216-
217-
}
243+
});
218244
} catch (final NullPointerException nullPointerException) {
219245
if (reactContext != null) {
220246
reactContext

modules/BlackBerry-Dynamics-for-React-Native-Base/scripts/react_native_info/development-tools-info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"framework": {
33
"name": "ReactNative",
4-
"bbdSdkForReactNativeVersion": "11.1.0.5",
4+
"bbdSdkForReactNativeVersion": "11.1.1.6",
55
"react-native": "",
66
"react": "",
77
"system": {

0 commit comments

Comments
 (0)