Skip to content

Commit 5830d05

Browse files
committed
[Added] new Authorization feature. [Added] Encryption. [Added] Demo server JWT support as well as local helper methods to request JWT from demo server. [Added] New DeviceInfo module for providing simple device-info without need of 3rd party library
1 parent b311a25 commit 5830d05

File tree

78 files changed

+4710
-965
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4710
-965
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 3.4.0 - 2019-12-02
4+
- [Added] New `Config.authorization` option for automated authorization-token support. If the SDK receives an HTTP response status `401 Unauthorized` and you've provided an `authorization` config, the plugin will automatically send a request to your configured `refreshUrl` to request a new token. The SDK will take care of adding the required `Authorization` HTTP header with `Bearer accessToken`. In the past, one would manage token-refresh by listening to the SDK's `onHttp` listener for HTTP `401`. This can now all be managed by the SDK by providing a `Config.authorization`.
5+
- [Added] Implemented strong encryption support via `Config.encrypt`. When enabled, the SDK will encrypt location data in its SQLite datbase, as well as the payload in HTTP requests. See API docs `Config.encrypt` for more information, including the configuration of encryption password.
6+
- [Added] New JSON Web Token API for the Demo server at http://tracker.transistorsoft.com. It's now easier than ever to configure the plugin to post to the demo server. See API docs `Config.transistorAuthorizationToken`. The old method using `BackgroundGeolocation.transistorTrackerParams` is now deprecated.
7+
- [Added] New `DeviceInfo` module for providing simple device-info (`model`, `manufacturer`, `version`, `platform`).
8+
39
## 3.3.2 - 2019-10-25
410
- [Fixed] Android bug in params order to getLog. Thanks @mikehardy.
511
- [Fixed] Typo in Javascript API callback in `destroyLog`. Thanks @mikehardy.

android/src/main/java/com/transistorsoft/rnbackgroundgeolocation/RNBackgroundGeolocationModule.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,21 @@
3232
import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation;
3333
import com.transistorsoft.locationmanager.adapter.TSConfig;
3434
import com.transistorsoft.locationmanager.adapter.callback.*;
35+
import com.transistorsoft.locationmanager.config.TransistorAuthorizationToken;
36+
import com.transistorsoft.locationmanager.config.TSAuthorization;
3537
import com.transistorsoft.locationmanager.data.LocationModel;
3638
import com.transistorsoft.locationmanager.data.SQLQuery;
39+
import com.transistorsoft.locationmanager.device.DeviceInfo;
3740
import com.transistorsoft.locationmanager.event.ActivityChangeEvent;
41+
import com.transistorsoft.locationmanager.event.AuthorizationEvent;
3842
import com.transistorsoft.locationmanager.event.ConnectivityChangeEvent;
3943
import com.transistorsoft.locationmanager.event.GeofenceEvent;
4044
import com.transistorsoft.locationmanager.event.GeofencesChangeEvent;
4145
import com.transistorsoft.locationmanager.event.HeartbeatEvent;
4246
import com.transistorsoft.locationmanager.event.LocationProviderChangeEvent;
4347
import com.transistorsoft.locationmanager.geofence.TSGeofence;
4448
import com.transistorsoft.locationmanager.http.HttpResponse;
49+
import com.transistorsoft.locationmanager.http.HttpService;
4550
import com.transistorsoft.locationmanager.location.TSCurrentPositionRequest;
4651
import com.transistorsoft.locationmanager.location.TSLocation;
4752
import com.transistorsoft.locationmanager.location.TSWatchPositionRequest;
@@ -107,6 +112,7 @@ public RNBackgroundGeolocationModule(ReactApplicationContext reactContext) {
107112
mEvents.add(BackgroundGeolocation.EVENT_CONNECTIVITYCHANGE);
108113
mEvents.add(BackgroundGeolocation.EVENT_ENABLEDCHANGE);
109114
mEvents.add(BackgroundGeolocation.EVENT_NOTIFICATIONACTION);
115+
mEvents.add(TSAuthorization.NAME);
110116

111117
reactContext.addLifecycleEventListener(this);
112118
}
@@ -287,6 +293,18 @@ private class PowerSaveChangeCallack implements TSPowerSaveChangeCallback {
287293
}
288294
}
289295

296+
/**
297+
* authorization event callback
298+
*/
299+
private class AuthorizationCallback implements TSAuthorizationCallback {
300+
@Override public void onResponse(AuthorizationEvent event) {
301+
try {
302+
sendEvent(TSAuthorization.NAME, jsonToMap(event.toJson()));
303+
} catch (JSONException e) {
304+
TSLog.logger.error(TSLog.error(e.getMessage()), e);
305+
}
306+
}
307+
}
290308
@Override
291309
public void onHostResume() {
292310
if (!mInitialized) {
@@ -343,6 +361,17 @@ public void ready(ReadableMap params, final Callback success, final Callback fai
343361
if (reset) {
344362
config.reset();
345363
config.updateWithJSONObject(mapToJson(setHeadlessJobService(params)));
364+
} else if (params.hasKey(TSAuthorization.NAME)) {
365+
ReadableMap readableMap = params.getMap(TSAuthorization.NAME);
366+
if (readableMap != null) {
367+
Map<String, Object> options = readableMap.toHashMap();
368+
// Have to be careful with expires: ReadadbleMap#toHashMap converts it to Double.
369+
options.put(TSAuthorization.FIELD_EXPIRES, readableMap.getInt(TSAuthorization.FIELD_EXPIRES));
370+
371+
config.updateWithBuilder()
372+
.setAuthorization(new TSAuthorization(options))
373+
.commit();
374+
}
346375
}
347376
}
348377
getAdapter().ready(new TSCallback() {
@@ -755,6 +784,34 @@ public void finish(int taskId, Callback success, Callback failure) {
755784
success.invoke(taskId);
756785
}
757786

787+
@ReactMethod
788+
public void getTransistorToken(String orgname, String username, String url, final Callback success, final Callback failure) {
789+
790+
TransistorAuthorizationToken.findOrCreate(getReactApplicationContext(), orgname, username, url, new TransistorAuthorizationToken.Callback() {
791+
@Override public void onSuccess(TransistorAuthorizationToken token) {
792+
try {
793+
success.invoke(jsonToMap(token.toJson()));
794+
} catch (JSONException e) {
795+
failure.invoke(e.getMessage());
796+
}
797+
}
798+
@Override public void onFailure(String error) {
799+
failure.invoke(error);
800+
}
801+
});
802+
}
803+
804+
@ReactMethod
805+
public void destroyTransistorToken(String url, final Callback success, final Callback failure) {
806+
TransistorAuthorizationToken.destroyTokenForUrl(getReactApplicationContext(), url, new TSCallback() {
807+
@Override public void onSuccess() {
808+
success.invoke(true);
809+
}
810+
@Override public void onFailure(String error) {
811+
failure.invoke(error);
812+
}
813+
});
814+
}
758815

759816
@ReactMethod
760817
public void playSound(String soundId) {
@@ -839,6 +896,19 @@ public void getSensors(Callback success, Callback error) {
839896
success.invoke(params);
840897
}
841898

899+
@ReactMethod
900+
public void getDeviceInfo(Callback success, Callback error) {
901+
DeviceInfo deviceInfo = DeviceInfo.getInstance(getReactApplicationContext());
902+
903+
WritableMap params = new WritableNativeMap();
904+
params.putString("manufacturer", deviceInfo.getManufacturer());
905+
params.putString("model", deviceInfo.getModel());
906+
params.putString("version", deviceInfo.getVersion());
907+
params.putString("platform", deviceInfo.getPlatform());
908+
params.putString("framework", "react-native");
909+
success.invoke(params);
910+
}
911+
842912
@ReactMethod
843913
public void isPowerSaveMode(Callback success, Callback error) {
844914
success.invoke(getAdapter().isPowerSaveMode());
@@ -897,8 +967,9 @@ public void requestPermission(final Callback success, final Callback error) {
897967

898968
@ReactMethod
899969
public void addEventListener(String event) {
970+
900971
if (!mEvents.contains(event)) {
901-
Log.e(TAG, "[RNBackgroundGeolocation addListener] Unknown event: " + event);
972+
TSLog.logger.warn(TSLog.warn("[RNBackgroundGeolocation addListener] Unknown event: " + event));
902973
return;
903974
}
904975
BackgroundGeolocation adapter = getAdapter();
@@ -941,6 +1012,8 @@ public void addEventListener(String event) {
9411012
adapter.onEnabledChange(new EnabledChangeCallback());
9421013
} else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_NOTIFICATIONACTION)) {
9431014
adapter.onNotificationAction(new NotificationActionCallback());
1015+
} else if (event.equalsIgnoreCase(TSAuthorization.NAME)) {
1016+
HttpService.getInstance(getReactApplicationContext()).onAuthorization(new AuthorizationCallback());
9441017
}
9451018
}
9461019
}

docs/assets/js/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)