@transistorsoft/capacitor-background-geolocation 8.0.0 → 9.0.0
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/Package.swift +10 -16
- package/README.md +99 -211
- package/TransistorsoftCapacitorBackgroundGeolocation.podspec +7 -5
- package/android/build.gradle +16 -54
- package/android/src/main/java/com/transistorsoft/bggeo/capacitor/BackgroundGeolocationPlugin.java +132 -70
- package/dist/index.js +198 -189
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs.js +255 -205
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1141 -1092
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.swift +353 -306
- package/package.json +11 -12
- package/src/index.d.ts +10 -0
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar +0 -0
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.md5 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha1 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha256 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.aar.sha512 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom +0 -9
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.md5 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha1 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha256 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/3.7.0/tslocationmanager-3.7.0.pom.sha512 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml +0 -13
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar +0 -0
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.md5 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha1 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha256 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.aar.sha512 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom +0 -9
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.md5 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha1 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha256 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/3.7.0/tslocationmanager-v21-3.7.0.pom.sha512 +0 -1
- package/android/libs/com/transistorsoft/tslocationmanager-v21/maven-metadata.xml +0 -13
- package/dist/Events.js +0 -19
- package/dist/Events.js.map +0 -1
- package/dist/declarations/BackgroundGeolocation.d.ts +0 -1632
- package/dist/declarations/interfaces/Authorization.d.ts +0 -185
- package/dist/declarations/interfaces/AuthorizationEvent.d.ts +0 -34
- package/dist/declarations/interfaces/Config.d.ts +0 -2474
- package/dist/declarations/interfaces/ConnectivityChangeEvent.d.ts +0 -18
- package/dist/declarations/interfaces/CurrentPositionRequest.d.ts +0 -45
- package/dist/declarations/interfaces/DeviceInfo.d.ts +0 -33
- package/dist/declarations/interfaces/DeviceSettings.d.ts +0 -223
- package/dist/declarations/interfaces/Geofence.d.ts +0 -319
- package/dist/declarations/interfaces/GeofenceEvent.d.ts +0 -35
- package/dist/declarations/interfaces/GeofencesChangeEvent.d.ts +0 -22
- package/dist/declarations/interfaces/HeartbeatEvent.d.ts +0 -20
- package/dist/declarations/interfaces/HttpEvent.d.ts +0 -313
- package/dist/declarations/interfaces/Location.d.ts +0 -257
- package/dist/declarations/interfaces/LocationAuthorizationAlert.d.ts +0 -41
- package/dist/declarations/interfaces/Logger.d.ts +0 -359
- package/dist/declarations/interfaces/MotionActivityEvent.d.ts +0 -34
- package/dist/declarations/interfaces/MotionChangeEvent.d.ts +0 -15
- package/dist/declarations/interfaces/Notification.d.ts +0 -491
- package/dist/declarations/interfaces/PermissionRationale.d.ts +0 -31
- package/dist/declarations/interfaces/ProviderChangeEvent.d.ts +0 -74
- package/dist/declarations/interfaces/SQLQuery.d.ts +0 -60
- package/dist/declarations/interfaces/Sensors.d.ts +0 -31
- package/dist/declarations/interfaces/State.d.ts +0 -51
- package/dist/declarations/interfaces/Subscription.d.ts +0 -104
- package/dist/declarations/interfaces/TransistorAuthorizationToken.d.ts +0 -63
- package/dist/declarations/interfaces/WatchPositionRequest.d.ts +0 -45
- package/dist/declarations/types.d.ts +0 -188
- package/dist/index.d.ts +0 -3
package/android/src/main/java/com/transistorsoft/bggeo/capacitor/BackgroundGeolocationPlugin.java
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.transistorsoft.bggeo.capacitor;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
+
|
|
4
5
|
import android.content.Context;
|
|
5
6
|
import android.os.Build;
|
|
6
7
|
|
|
@@ -12,7 +13,7 @@ import com.getcapacitor.PluginMethod;
|
|
|
12
13
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
13
14
|
import com.google.android.gms.common.GoogleApiAvailability;
|
|
14
15
|
import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation;
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
import com.transistorsoft.locationmanager.adapter.callback.TSActivityChangeCallback;
|
|
17
18
|
import com.transistorsoft.locationmanager.adapter.callback.TSBackgroundTaskCallback;
|
|
18
19
|
import com.transistorsoft.locationmanager.adapter.callback.TSCallback;
|
|
@@ -39,8 +40,9 @@ import com.transistorsoft.locationmanager.adapter.callback.TSPowerSaveChangeCall
|
|
|
39
40
|
import com.transistorsoft.locationmanager.adapter.callback.TSRequestPermissionCallback;
|
|
40
41
|
import com.transistorsoft.locationmanager.adapter.callback.TSScheduleCallback;
|
|
41
42
|
import com.transistorsoft.locationmanager.adapter.callback.TSSyncCallback;
|
|
42
|
-
|
|
43
|
-
import com.transistorsoft.locationmanager.config.
|
|
43
|
+
|
|
44
|
+
import com.transistorsoft.locationmanager.config.TSConfig;
|
|
45
|
+
import com.transistorsoft.locationmanager.config.edit.Editor;
|
|
44
46
|
import com.transistorsoft.locationmanager.data.LocationModel;
|
|
45
47
|
import com.transistorsoft.locationmanager.data.SQLQuery;
|
|
46
48
|
import com.transistorsoft.locationmanager.device.DeviceInfo;
|
|
@@ -48,14 +50,18 @@ import com.transistorsoft.locationmanager.device.DeviceSettingsRequest;
|
|
|
48
50
|
import com.transistorsoft.locationmanager.event.ActivityChangeEvent;
|
|
49
51
|
import com.transistorsoft.locationmanager.event.AuthorizationEvent;
|
|
50
52
|
import com.transistorsoft.locationmanager.event.ConnectivityChangeEvent;
|
|
53
|
+
import com.transistorsoft.locationmanager.event.EventName;
|
|
51
54
|
import com.transistorsoft.locationmanager.event.GeofenceEvent;
|
|
52
55
|
import com.transistorsoft.locationmanager.event.GeofencesChangeEvent;
|
|
53
56
|
import com.transistorsoft.locationmanager.event.HeartbeatEvent;
|
|
57
|
+
import com.transistorsoft.locationmanager.event.LocationEvent;
|
|
54
58
|
import com.transistorsoft.locationmanager.event.LocationProviderChangeEvent;
|
|
55
59
|
import com.transistorsoft.locationmanager.event.TerminateEvent;
|
|
56
60
|
import com.transistorsoft.locationmanager.geofence.TSGeofence;
|
|
57
61
|
import com.transistorsoft.locationmanager.http.HttpResponse;
|
|
58
62
|
import com.transistorsoft.locationmanager.http.HttpService;
|
|
63
|
+
import com.transistorsoft.locationmanager.http.TSAuthorization;
|
|
64
|
+
import com.transistorsoft.locationmanager.http.TransistorAuthorizationToken;
|
|
59
65
|
import com.transistorsoft.locationmanager.location.TSCurrentPositionRequest;
|
|
60
66
|
import com.transistorsoft.locationmanager.location.TSLocation;
|
|
61
67
|
import com.transistorsoft.locationmanager.location.TSWatchPositionRequest;
|
|
@@ -70,7 +76,11 @@ import org.json.JSONObject;
|
|
|
70
76
|
|
|
71
77
|
import java.util.ArrayList;
|
|
72
78
|
import java.util.Arrays;
|
|
79
|
+
import java.util.HashMap;
|
|
80
|
+
import java.util.Iterator;
|
|
73
81
|
import java.util.List;
|
|
82
|
+
import java.util.Map;
|
|
83
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
74
84
|
|
|
75
85
|
@CapacitorPlugin(name = "BackgroundGeolocation")
|
|
76
86
|
public class BackgroundGeolocationPlugin extends Plugin {
|
|
@@ -79,7 +89,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
79
89
|
|
|
80
90
|
private static final String BACKGROUND_GEOLOCATION_HEADLESS_CLASSNAME = "BackgroundGeolocationHeadlessTask";
|
|
81
91
|
|
|
82
|
-
private static final
|
|
92
|
+
private static final AtomicInteger sWatchIdCounter = new AtomicInteger(0);
|
|
83
93
|
|
|
84
94
|
@Override
|
|
85
95
|
public void load() {
|
|
@@ -88,16 +98,17 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
88
98
|
TSLog.logger.debug("");
|
|
89
99
|
|
|
90
100
|
TSConfig config = TSConfig.getInstance(getContext());
|
|
91
|
-
config.
|
|
92
|
-
config.
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
config.setUseCLLocationAccuracy(true);
|
|
102
|
+
Editor ed = config.edit();
|
|
103
|
+
ed.app().setHeadlessJobService(getHeadlessJobService());
|
|
104
|
+
ed.commit();
|
|
95
105
|
|
|
96
106
|
BackgroundGeolocation bgGeo = BackgroundGeolocation.getInstance(getContext());
|
|
97
107
|
Activity activity = getActivity();
|
|
98
108
|
if (activity != null) {
|
|
99
109
|
bgGeo.setActivity(activity);
|
|
100
110
|
}
|
|
111
|
+
bgGeo.removeListeners();
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
private void handlePlayServicesConnectError(Integer errorCode) {
|
|
@@ -128,7 +139,8 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
128
139
|
setConfig(call);
|
|
129
140
|
} else {
|
|
130
141
|
TSLog.logger.warn(TSLog.warn("#ready already called. Ignored"));
|
|
131
|
-
|
|
142
|
+
JSObject state = JSObject.fromJSONObject(config.toJson(false));
|
|
143
|
+
call.resolve(state);
|
|
132
144
|
}
|
|
133
145
|
return;
|
|
134
146
|
}
|
|
@@ -144,15 +156,15 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
144
156
|
config.updateWithJSONObject(setHeadlessJobService(params));
|
|
145
157
|
} else if (params.has(TSAuthorization.NAME)) {
|
|
146
158
|
JSONObject options = params.getJSONObject(TSAuthorization.NAME);
|
|
147
|
-
config.
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
Editor ed = config.edit();
|
|
160
|
+
ed.auth().setAuthorization(jsonObjectToMap(options));
|
|
161
|
+
ed.commit();
|
|
150
162
|
}
|
|
151
163
|
}
|
|
152
164
|
adapter.ready(new TSCallback() {
|
|
153
165
|
@Override public void onSuccess() {
|
|
154
166
|
try {
|
|
155
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
167
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
156
168
|
} catch (JSONException e) {
|
|
157
169
|
call.reject(e.getMessage());
|
|
158
170
|
}
|
|
@@ -163,6 +175,8 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
163
175
|
});
|
|
164
176
|
}
|
|
165
177
|
|
|
178
|
+
|
|
179
|
+
|
|
166
180
|
@PluginMethod()
|
|
167
181
|
public void reset(PluginCall call) {
|
|
168
182
|
JSObject params = call.getObject("options");
|
|
@@ -170,7 +184,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
170
184
|
config.reset();
|
|
171
185
|
config.updateWithJSONObject(setHeadlessJobService(params));
|
|
172
186
|
try {
|
|
173
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
187
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
174
188
|
} catch (JSONException e) {
|
|
175
189
|
call.reject(e.getMessage());
|
|
176
190
|
}
|
|
@@ -181,14 +195,14 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
181
195
|
TSConfig config = TSConfig.getInstance(getContext());
|
|
182
196
|
JSObject params = call.getObject("options");
|
|
183
197
|
config.updateWithJSONObject(params);
|
|
184
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
198
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
185
199
|
}
|
|
186
200
|
|
|
187
201
|
@PluginMethod()
|
|
188
202
|
public void getState(PluginCall call) {
|
|
189
203
|
try {
|
|
190
204
|
TSConfig config = TSConfig.getInstance(getContext());
|
|
191
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
205
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
192
206
|
} catch (JSONException e) {
|
|
193
207
|
call.reject(e.getMessage());
|
|
194
208
|
}
|
|
@@ -200,7 +214,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
200
214
|
getAdapter().start(new TSCallback() {
|
|
201
215
|
@Override public void onSuccess() {
|
|
202
216
|
try {
|
|
203
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
217
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
204
218
|
} catch (JSONException e) {
|
|
205
219
|
call.reject(e.getMessage());
|
|
206
220
|
}
|
|
@@ -216,7 +230,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
216
230
|
if (getAdapter().startSchedule()) {
|
|
217
231
|
TSConfig config = TSConfig.getInstance(getContext());
|
|
218
232
|
try {
|
|
219
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
233
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
220
234
|
} catch (JSONException e) {
|
|
221
235
|
call.reject(e.getMessage());
|
|
222
236
|
}
|
|
@@ -230,7 +244,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
230
244
|
getAdapter().stopSchedule();
|
|
231
245
|
TSConfig config = TSConfig.getInstance(getContext());
|
|
232
246
|
try {
|
|
233
|
-
call.resolve(JSObject.fromJSONObject(config.toJson()));
|
|
247
|
+
call.resolve(JSObject.fromJSONObject(config.toJson(false)));
|
|
234
248
|
} catch (JSONException e) {
|
|
235
249
|
call.reject(e.getMessage());
|
|
236
250
|
}
|
|
@@ -243,7 +257,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
243
257
|
}
|
|
244
258
|
@Override public void onSuccess() {
|
|
245
259
|
try {
|
|
246
|
-
mCallback.resolve(JSObject.fromJSONObject(TSConfig.getInstance(getContext()).toJson()));
|
|
260
|
+
mCallback.resolve(JSObject.fromJSONObject(TSConfig.getInstance(getContext()).toJson(false)));
|
|
247
261
|
} catch (JSONException e) {
|
|
248
262
|
mCallback.reject(e.getMessage());
|
|
249
263
|
}
|
|
@@ -270,7 +284,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
270
284
|
}
|
|
271
285
|
@Override public void onSuccess() {
|
|
272
286
|
try {
|
|
273
|
-
mCallback.resolve(JSObject.fromJSONObject(TSConfig.getInstance(getContext()).toJson()));
|
|
287
|
+
mCallback.resolve(JSObject.fromJSONObject(TSConfig.getInstance(getContext()).toJson(false)));
|
|
274
288
|
} catch (JSONException e) {
|
|
275
289
|
mCallback.reject(e.getMessage());
|
|
276
290
|
}
|
|
@@ -359,9 +373,9 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
359
373
|
TSCurrentPositionRequest.Builder builder = new TSCurrentPositionRequest.Builder(getContext());
|
|
360
374
|
|
|
361
375
|
builder.setCallback(new TSLocationCallback() {
|
|
362
|
-
@Override public void onLocation(
|
|
376
|
+
@Override public void onLocation(LocationEvent event) {
|
|
363
377
|
try {
|
|
364
|
-
call.resolve(JSObject.fromJSONObject(
|
|
378
|
+
call.resolve(JSObject.fromJSONObject(event.toJson()));
|
|
365
379
|
} catch (JSONException e) {
|
|
366
380
|
call.reject(e.getMessage());
|
|
367
381
|
}
|
|
@@ -403,16 +417,16 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
403
417
|
TSWatchPositionRequest.Builder builder = new TSWatchPositionRequest.Builder(getContext());
|
|
404
418
|
|
|
405
419
|
builder.setCallback(new TSLocationCallback() {
|
|
406
|
-
@Override public void onLocation(
|
|
420
|
+
@Override public void onLocation(LocationEvent event) {
|
|
407
421
|
try {
|
|
408
|
-
if (!hasListeners(
|
|
422
|
+
if (!hasListeners(EventName.WATCH_POSITION)) {
|
|
409
423
|
getAdapter().stopWatchPosition(new TSCallback() {
|
|
410
424
|
@Override public void onSuccess() { }
|
|
411
425
|
@Override public void onFailure(String s) { }
|
|
412
426
|
});
|
|
413
427
|
return;
|
|
414
428
|
}
|
|
415
|
-
notifyListeners(
|
|
429
|
+
notifyListeners(EventName.WATCH_POSITION, JSObject.fromJSONObject(event.toJson()));
|
|
416
430
|
} catch (JSONException e) {
|
|
417
431
|
/// This will probably never fire, but...
|
|
418
432
|
e.printStackTrace();
|
|
@@ -420,7 +434,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
420
434
|
JSObject error = new JSObject();
|
|
421
435
|
error.put("code", -1);
|
|
422
436
|
result.put("error", error);
|
|
423
|
-
notifyListeners(
|
|
437
|
+
notifyListeners(EventName.WATCH_POSITION, error);
|
|
424
438
|
}
|
|
425
439
|
}
|
|
426
440
|
@Override public void onError(Integer code) {
|
|
@@ -428,7 +442,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
428
442
|
JSObject error = new JSObject();
|
|
429
443
|
error.put("code", code);
|
|
430
444
|
result.put("error", error);
|
|
431
|
-
notifyListeners(
|
|
445
|
+
notifyListeners(EventName.WATCH_POSITION, result);
|
|
432
446
|
}
|
|
433
447
|
});
|
|
434
448
|
|
|
@@ -445,8 +459,11 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
445
459
|
if (options.has("desiredAccuracy")) {
|
|
446
460
|
builder.setDesiredAccuracy(options.getInt("desiredAccuracy"));
|
|
447
461
|
}
|
|
462
|
+
int watchId = sWatchIdCounter.incrementAndGet();
|
|
448
463
|
getAdapter().watchPosition(builder.build());
|
|
449
|
-
|
|
464
|
+
JSObject result = new JSObject();
|
|
465
|
+
result.put("watchId", watchId);
|
|
466
|
+
call.resolve(result);
|
|
450
467
|
} catch (JSONException e) {
|
|
451
468
|
e.printStackTrace();
|
|
452
469
|
call.reject(e.getMessage());
|
|
@@ -455,6 +472,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
455
472
|
|
|
456
473
|
@PluginMethod()
|
|
457
474
|
public void stopWatchPosition(final PluginCall call) {
|
|
475
|
+
// watchId is accepted for API parity with iOS but Android stops all watches globally.
|
|
458
476
|
getAdapter().stopWatchPosition(new TSCallback() {
|
|
459
477
|
@Override public void onSuccess() { call.resolve(); }
|
|
460
478
|
@Override public void onFailure(String error) {
|
|
@@ -480,7 +498,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
480
498
|
@PluginMethod()
|
|
481
499
|
public void addGeofences(final PluginCall call) {
|
|
482
500
|
JSArray data = call.getArray("options");
|
|
483
|
-
List<TSGeofence> geofences = new ArrayList
|
|
501
|
+
List<TSGeofence> geofences = new ArrayList<>();
|
|
484
502
|
for (int i = 0; i < data.length(); i++) {
|
|
485
503
|
try {
|
|
486
504
|
geofences.add(buildGeofence(data.getJSONObject(i)));
|
|
@@ -546,6 +564,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
546
564
|
@PluginMethod()
|
|
547
565
|
public void getGeofence(final PluginCall call) {
|
|
548
566
|
String identifier = call.getString("identifier");
|
|
567
|
+
if (identifier == null) { call.reject("Missing required parameter: identifier"); return; }
|
|
549
568
|
getAdapter().getGeofence(identifier, new TSGetGeofenceCallback() {
|
|
550
569
|
@Override public void onSuccess(TSGeofence geofence) {
|
|
551
570
|
try {
|
|
@@ -564,6 +583,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
564
583
|
@PluginMethod()
|
|
565
584
|
public void geofenceExists(final PluginCall call) {
|
|
566
585
|
String identifier = call.getString("identifier");
|
|
586
|
+
if (identifier == null) { call.reject("Missing required parameter: identifier"); return; }
|
|
567
587
|
getAdapter().geofenceExists(identifier, new TSGeofenceExistsCallback() {
|
|
568
588
|
@Override public void onResult(boolean exists) {
|
|
569
589
|
JSObject result = new JSObject();
|
|
@@ -576,6 +596,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
576
596
|
@PluginMethod()
|
|
577
597
|
public void removeGeofence(final PluginCall call) {
|
|
578
598
|
String identifier = call.getString("identifier");
|
|
599
|
+
if (identifier == null) { call.reject("Missing required parameter: identifier"); return; }
|
|
579
600
|
getAdapter().removeGeofence(identifier, new TSCallback() {
|
|
580
601
|
@Override public void onSuccess() {
|
|
581
602
|
call.resolve();
|
|
@@ -591,8 +612,10 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
591
612
|
final JSArray identifiers = call.getArray("identifiers");
|
|
592
613
|
List<String> rs = new ArrayList<String>();
|
|
593
614
|
try {
|
|
594
|
-
|
|
595
|
-
|
|
615
|
+
if (identifiers != null) {
|
|
616
|
+
for (int i = 0; i < identifiers.length(); i++) {
|
|
617
|
+
rs.add(identifiers.getString(i));
|
|
618
|
+
}
|
|
596
619
|
}
|
|
597
620
|
getAdapter().removeGeofences(rs, new TSCallback() {
|
|
598
621
|
@Override public void onSuccess() {
|
|
@@ -617,11 +640,11 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
617
640
|
|
|
618
641
|
@PluginMethod()
|
|
619
642
|
public void setOdometer(final PluginCall call) {
|
|
620
|
-
|
|
643
|
+
Double value = call.getDouble("odometer");
|
|
621
644
|
getAdapter().setOdometer(value, new TSLocationCallback() {
|
|
622
|
-
@Override public void onLocation(
|
|
645
|
+
@Override public void onLocation(LocationEvent event) {
|
|
623
646
|
try {
|
|
624
|
-
call.resolve(JSObject.fromJSONObject(
|
|
647
|
+
call.resolve(JSObject.fromJSONObject(event.toJson()));
|
|
625
648
|
} catch (JSONException e) {
|
|
626
649
|
e.printStackTrace();
|
|
627
650
|
call.reject(e.getMessage());
|
|
@@ -698,6 +721,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
698
721
|
@PluginMethod()
|
|
699
722
|
public void destroyLocation(final PluginCall call) {
|
|
700
723
|
String uuid = call.getString("uuid");
|
|
724
|
+
if (uuid == null) { call.reject("Missing required parameter: uuid"); return; }
|
|
701
725
|
getAdapter().destroyLocation(uuid, new TSCallback() {
|
|
702
726
|
@Override public void onSuccess() {
|
|
703
727
|
call.resolve();
|
|
@@ -723,7 +747,8 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
723
747
|
|
|
724
748
|
@PluginMethod()
|
|
725
749
|
public void stopBackgroundTask(PluginCall call) {
|
|
726
|
-
|
|
750
|
+
Integer taskId = call.getInt("taskId");
|
|
751
|
+
if (taskId == null) { call.reject("Missing required parameter: taskId"); return; }
|
|
727
752
|
getAdapter().stopBackgroundTask(taskId);
|
|
728
753
|
call.resolve();
|
|
729
754
|
}
|
|
@@ -768,6 +793,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
768
793
|
@PluginMethod()
|
|
769
794
|
public void emailLog(final PluginCall call) {
|
|
770
795
|
String email = call.getString("email");
|
|
796
|
+
if (email == null) { call.reject("Missing required parameter: email"); return; }
|
|
771
797
|
JSONObject query = call.getObject("query");
|
|
772
798
|
|
|
773
799
|
try {
|
|
@@ -791,6 +817,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
791
817
|
@PluginMethod()
|
|
792
818
|
public void uploadLog(final PluginCall call) {
|
|
793
819
|
String url = call.getString("url");
|
|
820
|
+
if (url == null) { call.reject("Missing required parameter: url"); return; }
|
|
794
821
|
JSONObject query = call.getObject("query");
|
|
795
822
|
try {
|
|
796
823
|
TSLog.uploadLog(getContext().getApplicationContext(), url, parseSQLQuery(query), new TSCallback() {
|
|
@@ -938,6 +965,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
938
965
|
@PluginMethod()
|
|
939
966
|
public void destroyTransistorToken(PluginCall call) {
|
|
940
967
|
String url = call.getString("url");
|
|
968
|
+
if (url == null) { call.reject("Missing required parameter: url"); return; }
|
|
941
969
|
Context context = getContext();
|
|
942
970
|
TransistorAuthorizationToken.destroyTokenForUrl(context, url, new TSCallback() {
|
|
943
971
|
@Override public void onSuccess() {
|
|
@@ -965,7 +993,7 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
965
993
|
}
|
|
966
994
|
|
|
967
995
|
private String getHeadlessJobService() {
|
|
968
|
-
return
|
|
996
|
+
return getContext().getPackageName() + "." + BACKGROUND_GEOLOCATION_HEADLESS_CLASSNAME;
|
|
969
997
|
}
|
|
970
998
|
|
|
971
999
|
protected void handleOnPause() {
|
|
@@ -999,9 +1027,9 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
999
1027
|
|
|
1000
1028
|
bgGeo.onLocation(new TSLocationCallback() {
|
|
1001
1029
|
@Override
|
|
1002
|
-
public void onLocation(
|
|
1030
|
+
public void onLocation(LocationEvent event) {
|
|
1003
1031
|
try {
|
|
1004
|
-
handleEvent(
|
|
1032
|
+
handleEvent(EventName.LOCATION, event.toJson());
|
|
1005
1033
|
} catch (JSONException e) {
|
|
1006
1034
|
TSLog.logger.error(e.getMessage(), e);
|
|
1007
1035
|
}
|
|
@@ -1009,129 +1037,163 @@ public class BackgroundGeolocationPlugin extends Plugin {
|
|
|
1009
1037
|
|
|
1010
1038
|
@Override
|
|
1011
1039
|
public void onError(Integer code) {
|
|
1012
|
-
if (!hasListeners(
|
|
1040
|
+
if (!hasListeners(EventName.LOCATION)) return;
|
|
1013
1041
|
JSObject result = new JSObject();
|
|
1014
1042
|
result.put("error", code);
|
|
1015
|
-
notifyListeners(
|
|
1043
|
+
notifyListeners(EventName.LOCATION, result);
|
|
1016
1044
|
}
|
|
1017
1045
|
});
|
|
1018
1046
|
|
|
1019
1047
|
bgGeo.onMotionChange(new TSLocationCallback() {
|
|
1020
|
-
@Override public void onLocation(
|
|
1021
|
-
if (!hasListeners(
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
params.put("
|
|
1026
|
-
|
|
1048
|
+
@Override public void onLocation(LocationEvent event) {
|
|
1049
|
+
if (!hasListeners(EventName.MOTIONCHANGE)) return;
|
|
1050
|
+
|
|
1051
|
+
try {
|
|
1052
|
+
JSObject params = new JSObject();
|
|
1053
|
+
params.put("isMoving", event.isMoving());
|
|
1054
|
+
params.put("location", event.toJson());
|
|
1055
|
+
|
|
1056
|
+
notifyListeners(EventName.MOTIONCHANGE, params);
|
|
1027
1057
|
} catch (JSONException e) {
|
|
1028
1058
|
TSLog.logger.error(e.getMessage(), e);
|
|
1029
1059
|
}
|
|
1030
1060
|
}
|
|
1031
1061
|
@Override public void onError(Integer integer) {
|
|
1032
|
-
if (!hasListeners(
|
|
1062
|
+
if (!hasListeners(EventName.MOTIONCHANGE)) return;
|
|
1033
1063
|
TSLog.logger.debug("onMotionChange error: " + integer);
|
|
1034
1064
|
}
|
|
1035
1065
|
});
|
|
1036
1066
|
|
|
1037
|
-
bgGeo.onActivityChange(
|
|
1038
|
-
@Override
|
|
1039
|
-
public void onActivityChange(ActivityChangeEvent event) {
|
|
1040
|
-
handleEvent(BackgroundGeolocation.EVENT_ACTIVITYCHANGE, event.toJson());
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1067
|
+
bgGeo.onActivityChange(event -> handleEvent(EventName.ACTIVITYCHANGE, event.toJson()));
|
|
1043
1068
|
|
|
1044
1069
|
bgGeo.onConnectivityChange(new TSConnectivityChangeCallback() {
|
|
1045
1070
|
@Override
|
|
1046
1071
|
public void onConnectivityChange(ConnectivityChangeEvent event) {
|
|
1047
|
-
if (!hasListeners(
|
|
1072
|
+
if (!hasListeners(EventName.CONNECTIVITYCHANGE)) return;
|
|
1048
1073
|
JSObject params = new JSObject();
|
|
1049
1074
|
params.put("connected", event.hasConnection());
|
|
1050
|
-
notifyListeners(
|
|
1075
|
+
notifyListeners(EventName.CONNECTIVITYCHANGE, params);
|
|
1051
1076
|
}
|
|
1052
1077
|
});
|
|
1053
1078
|
|
|
1054
1079
|
bgGeo.onEnabledChange(new TSEnabledChangeCallback() {
|
|
1055
1080
|
@Override
|
|
1056
1081
|
public void onEnabledChange(boolean enabled) {
|
|
1057
|
-
if (!hasListeners(
|
|
1082
|
+
if (!hasListeners(EventName.ENABLEDCHANGE)) return;
|
|
1058
1083
|
JSObject params = new JSObject();
|
|
1059
1084
|
params.put("value", enabled);
|
|
1060
|
-
notifyListeners(
|
|
1085
|
+
notifyListeners(EventName.ENABLEDCHANGE, params);
|
|
1061
1086
|
}
|
|
1062
1087
|
});
|
|
1063
1088
|
|
|
1064
1089
|
bgGeo.onGeofence(new TSGeofenceCallback() {
|
|
1065
1090
|
@Override
|
|
1066
1091
|
public void onGeofence(GeofenceEvent event) {
|
|
1067
|
-
handleEvent(
|
|
1092
|
+
handleEvent(EventName.GEOFENCE, event.toJson());
|
|
1068
1093
|
}
|
|
1069
1094
|
});
|
|
1070
1095
|
|
|
1071
1096
|
bgGeo.onGeofencesChange(new TSGeofencesChangeCallback() {
|
|
1072
1097
|
@Override
|
|
1073
1098
|
public void onGeofencesChange(GeofencesChangeEvent event) {
|
|
1074
|
-
handleEvent(
|
|
1099
|
+
handleEvent(EventName.GEOFENCESCHANGE, event.toJson());
|
|
1075
1100
|
}
|
|
1076
1101
|
});
|
|
1077
1102
|
|
|
1078
1103
|
bgGeo.onHeartbeat(new TSHeartbeatCallback() {
|
|
1079
1104
|
@Override
|
|
1080
1105
|
public void onHeartbeat(HeartbeatEvent event) {
|
|
1081
|
-
handleEvent(
|
|
1106
|
+
handleEvent(EventName.HEARTBEAT, event.toJson());
|
|
1082
1107
|
}
|
|
1083
1108
|
});
|
|
1084
1109
|
|
|
1085
1110
|
bgGeo.onHttp(new TSHttpResponseCallback() {
|
|
1086
1111
|
@Override
|
|
1087
1112
|
public void onHttpResponse(HttpResponse event) {
|
|
1088
|
-
handleEvent(
|
|
1113
|
+
handleEvent(EventName.HTTP, event.toJson());
|
|
1089
1114
|
}
|
|
1090
1115
|
});
|
|
1091
1116
|
|
|
1092
1117
|
bgGeo.onLocationProviderChange(new TSLocationProviderChangeCallback() {
|
|
1093
1118
|
@Override
|
|
1094
1119
|
public void onLocationProviderChange(LocationProviderChangeEvent event) {
|
|
1095
|
-
handleEvent(
|
|
1120
|
+
handleEvent(EventName.PROVIDERCHANGE, event.toJson());
|
|
1096
1121
|
}
|
|
1097
1122
|
});
|
|
1098
1123
|
|
|
1099
1124
|
bgGeo.onNotificationAction(new TSNotificationActionCallback() {
|
|
1100
1125
|
@Override
|
|
1101
1126
|
public void onClick(String button) {
|
|
1102
|
-
if (!hasListeners(
|
|
1127
|
+
if (!hasListeners(EventName.NOTIFICATIONACTION)) return;
|
|
1103
1128
|
JSObject params = new JSObject();
|
|
1104
1129
|
params.put("value", button);
|
|
1105
|
-
notifyListeners(
|
|
1130
|
+
notifyListeners(EventName.NOTIFICATIONACTION, params);
|
|
1106
1131
|
}
|
|
1107
1132
|
});
|
|
1108
1133
|
|
|
1109
1134
|
bgGeo.onPowerSaveChange(new TSPowerSaveChangeCallback() {
|
|
1110
1135
|
@Override
|
|
1111
1136
|
public void onPowerSaveChange(Boolean enabled) {
|
|
1112
|
-
if (!hasListeners(
|
|
1137
|
+
if (!hasListeners(EventName.POWERSAVECHANGE)) return;
|
|
1113
1138
|
JSObject params = new JSObject();
|
|
1114
1139
|
params.put("value", enabled);
|
|
1115
|
-
notifyListeners(
|
|
1140
|
+
notifyListeners(EventName.POWERSAVECHANGE, params);
|
|
1116
1141
|
}
|
|
1117
1142
|
});
|
|
1118
1143
|
|
|
1119
1144
|
bgGeo.onSchedule(new TSScheduleCallback() {
|
|
1120
1145
|
@Override
|
|
1121
1146
|
public void onSchedule(ScheduleEvent event) {
|
|
1122
|
-
handleEvent(
|
|
1147
|
+
handleEvent(EventName.SCHEDULE, event.getState());
|
|
1123
1148
|
}
|
|
1124
1149
|
});
|
|
1125
1150
|
|
|
1126
1151
|
HttpService.getInstance(getContext()).onAuthorization(new TSAuthorizationCallback() {
|
|
1127
1152
|
@Override
|
|
1128
1153
|
public void onResponse(AuthorizationEvent event) {
|
|
1129
|
-
handleEvent(
|
|
1154
|
+
handleEvent(EventName.AUTHORIZATION, event.toJson());
|
|
1130
1155
|
}
|
|
1131
1156
|
});
|
|
1132
1157
|
}
|
|
1133
1158
|
|
|
1159
|
+
private Map<String, Object> jsonObjectToMap(JSONObject json) throws JSONException {
|
|
1160
|
+
Map<String, Object> map = new HashMap<>();
|
|
1161
|
+
Iterator<String> keys = json.keys();
|
|
1162
|
+
|
|
1163
|
+
while (keys.hasNext()) {
|
|
1164
|
+
String key = keys.next();
|
|
1165
|
+
Object value = json.get(key);
|
|
1166
|
+
|
|
1167
|
+
if (value instanceof JSONObject) {
|
|
1168
|
+
value = jsonObjectToMap((JSONObject) value);
|
|
1169
|
+
} else if (value instanceof JSONArray) {
|
|
1170
|
+
value = jsonArrayToList((JSONArray) value);
|
|
1171
|
+
} else if (value == JSONObject.NULL) {
|
|
1172
|
+
value = null;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
map.put(key, value);
|
|
1176
|
+
}
|
|
1177
|
+
return map;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
private List<Object> jsonArrayToList(JSONArray array) throws JSONException {
|
|
1181
|
+
List<Object> list = new ArrayList<>();
|
|
1182
|
+
for (int i = 0; i < array.length(); i++) {
|
|
1183
|
+
Object value = array.get(i);
|
|
1184
|
+
|
|
1185
|
+
if (value instanceof JSONObject) {
|
|
1186
|
+
value = jsonObjectToMap((JSONObject) value);
|
|
1187
|
+
} else if (value instanceof JSONArray) {
|
|
1188
|
+
value = jsonArrayToList((JSONArray) value);
|
|
1189
|
+
} else if (value == JSONObject.NULL) {
|
|
1190
|
+
value = null;
|
|
1191
|
+
}
|
|
1134
1192
|
|
|
1193
|
+
list.add(value);
|
|
1194
|
+
}
|
|
1195
|
+
return list;
|
|
1196
|
+
}
|
|
1135
1197
|
|
|
1136
1198
|
private void handleEvent(String name, JSONObject event) {
|
|
1137
1199
|
if (!hasListeners(name)) return;
|