@josuelmm/capacitor-background-geolocation 1.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/JosuelmmCapacitorBackgroundGeolocation.podspec +34 -0
- package/LICENSE +17 -0
- package/NOTICE.md +32 -0
- package/Package.swift +45 -0
- package/README.md +402 -0
- package/android/build.gradle +79 -0
- package/android/proguard-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +83 -0
- package/android/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
- package/android/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/BackgroundGeolocationPlugin.java +898 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/ConfigMapper.java +303 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/HeadlessTaskRegistry.java +34 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/JsEvaluatorTaskRunner.java +63 -0
- package/android/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +699 -0
- package/android/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +103 -0
- package/android/src/main/java/com/marianhello/bgloc/Config.java +1155 -0
- package/android/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
- package/android/src/main/java/com/marianhello/bgloc/HttpPostService.java +362 -0
- package/android/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
- package/android/src/main/java/com/marianhello/bgloc/PluginDelegate.java +45 -0
- package/android/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
- package/android/src/main/java/com/marianhello/bgloc/PostLocationTask.java +238 -0
- package/android/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
- package/android/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
- package/android/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
- package/android/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +1088 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
- package/android/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
- package/android/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +27 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +71 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
- package/android/src/main/java/com/marianhello/bgloc/data/SessionLocationDAO.java +18 -0
- package/android/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +406 -0
- package/android/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +94 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +227 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +122 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +550 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +189 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionContract.java +74 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionLocationDAO.java +169 -0
- package/android/src/main/java/com/marianhello/bgloc/driving/DrivingEventsDetector.java +265 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
- package/android/src/main/java/com/marianhello/bgloc/http/UrlTemplateResolver.java +115 -0
- package/android/src/main/java/com/marianhello/bgloc/oem/BatteryOemHelper.java +214 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +218 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +385 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +685 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +175 -0
- package/android/src/main/java/com/marianhello/bgloc/sensor/SensorFusionDetector.java +199 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +1531 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +156 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +311 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +301 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
- package/android/src/main/java/com/marianhello/logging/DBLogReader.java +208 -0
- package/android/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
- package/android/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
- package/android/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
- package/android/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
- package/android/src/main/java/com/marianhello/utils/Convert.java +56 -0
- package/android/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
- package/android/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
- package/android/src/main/java/org/apache/commons/io/Charsets.java +153 -0
- package/android/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
- package/android/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
- package/android/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/values/strings.xml +15 -0
- package/android/src/main/res/xml/authenticator.xml +7 -0
- package/android/src/main/res/xml/syncadapter.xml +9 -0
- package/dist/esm/definitions.d.ts +1052 -0
- package/dist/esm/definitions.js +142 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +92 -0
- package/dist/esm/web.js +242 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +415 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +418 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin-Bridging-Header.h +18 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.m +52 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.swift +750 -0
- package/ios/Tests/BackgroundGeolocationPluginTests/BackgroundGeolocationPluginTests.swift +12 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.h +1945 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.m +5255 -0
- package/ios/common/BackgroundGeolocation/FMDB.h +2357 -0
- package/ios/common/BackgroundGeolocation/FMDB.m +2672 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.h +42 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.m +264 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +41 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +68 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +33 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +178 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +1025 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +103 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +238 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +163 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +39 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +37 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.h +51 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.m +53 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.h +23 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.m +52 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +340 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +88 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +1193 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +46 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +283 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +99 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +636 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +54 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +550 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +124 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.h +73 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +392 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +38 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +39 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +305 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.m +122 -0
- package/ios/common/BackgroundGeolocation/MAURLogging.h +19 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +367 -0
- package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +138 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +335 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +520 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
- package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.h +41 -0
- package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.m +137 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.h +29 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.m +31 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.m +153 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
- package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.h +31 -0
- package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.m +107 -0
- package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
- package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +170 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +55 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +47 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +27 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +250 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +259 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +360 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +427 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +37 -0
- package/ios/common/BackgroundGeolocation/module.modulemap +16 -0
- package/package.json +82 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
4
|
+
import com.marianhello.bgloc.data.LocationDAO;
|
|
5
|
+
import com.marianhello.bgloc.data.SessionLocationDAO;
|
|
6
|
+
import com.marianhello.bgloc.http.UrlTemplateResolver;
|
|
7
|
+
import com.marianhello.logging.LoggerManager;
|
|
8
|
+
|
|
9
|
+
import org.json.JSONArray;
|
|
10
|
+
import org.json.JSONException;
|
|
11
|
+
import org.json.JSONObject;
|
|
12
|
+
|
|
13
|
+
import java.util.concurrent.ExecutorService;
|
|
14
|
+
import java.util.concurrent.Executors;
|
|
15
|
+
import java.util.concurrent.RejectedExecutionException;
|
|
16
|
+
import java.util.concurrent.TimeUnit;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Location task to post/sync locations from location providers
|
|
20
|
+
*
|
|
21
|
+
* All locations updates are recorded in local db at all times.
|
|
22
|
+
* Also location is also send to all messenger clients.
|
|
23
|
+
*
|
|
24
|
+
* If option.url is defined, each location is also immediately posted.
|
|
25
|
+
* If post is successful, the location is deleted from local db.
|
|
26
|
+
* All failed to post locations are coalesced and send in some time later in one single batch.
|
|
27
|
+
* Batch sync takes place only when number of failed to post locations reaches syncTreshold.
|
|
28
|
+
*
|
|
29
|
+
* If only option.syncUrl is defined, locations are send only in single batch,
|
|
30
|
+
* when number of locations reaches syncTreshold.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
public class PostLocationTask {
|
|
34
|
+
private final LocationDAO mLocationDAO;
|
|
35
|
+
private final SessionLocationDAO mSessionDAO;
|
|
36
|
+
private final PostLocationTaskListener mTaskListener;
|
|
37
|
+
private final ConnectivityListener mConnectivityListener;
|
|
38
|
+
|
|
39
|
+
private final ExecutorService mExecutor;
|
|
40
|
+
|
|
41
|
+
private volatile boolean mHasConnectivity = true;
|
|
42
|
+
private volatile Config mConfig;
|
|
43
|
+
|
|
44
|
+
private org.slf4j.Logger logger;
|
|
45
|
+
|
|
46
|
+
public interface PostLocationTaskListener
|
|
47
|
+
{
|
|
48
|
+
void onSyncRequested();
|
|
49
|
+
void onRequestedAbortUpdates();
|
|
50
|
+
void onHttpAuthorizationUpdates();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public PostLocationTask(LocationDAO dao, PostLocationTaskListener taskListener,
|
|
54
|
+
ConnectivityListener connectivityListener) {
|
|
55
|
+
this(dao, null, taskListener, connectivityListener);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public PostLocationTask(LocationDAO dao, SessionLocationDAO sessionDAO,
|
|
59
|
+
PostLocationTaskListener taskListener,
|
|
60
|
+
ConnectivityListener connectivityListener) {
|
|
61
|
+
logger = LoggerManager.getLogger(PostLocationTask.class);
|
|
62
|
+
logger.info("Creating PostLocationTask");
|
|
63
|
+
|
|
64
|
+
mLocationDAO = dao;
|
|
65
|
+
mSessionDAO = sessionDAO;
|
|
66
|
+
mTaskListener = taskListener;
|
|
67
|
+
mConnectivityListener = connectivityListener;
|
|
68
|
+
|
|
69
|
+
mExecutor = Executors.newSingleThreadExecutor();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public void setConfig(Config config) {
|
|
73
|
+
mConfig = config;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public void setHasConnectivity(boolean hasConnectivity) {
|
|
77
|
+
mHasConnectivity = hasConnectivity;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public void clearQueue() {
|
|
81
|
+
mExecutor.execute(new Runnable() {
|
|
82
|
+
@Override
|
|
83
|
+
public void run() {
|
|
84
|
+
mLocationDAO.deleteUnpostedLocations();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public void add(final BackgroundLocation location) {
|
|
90
|
+
if (mConfig == null) {
|
|
91
|
+
logger.warn("PostLocationTask has no config. Did you called setConfig? Skipping location.");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// v3.5 Phase 4: mock location policy. Detection is already in BackgroundLocation
|
|
96
|
+
// (isFromMockProvider). Here we apply the policy.
|
|
97
|
+
if (location != null && location.isFromMockProvider()) {
|
|
98
|
+
String policy = mConfig.getMockLocationPolicy(); // "allow" | "flag" | "drop"
|
|
99
|
+
if ("drop".equals(policy)) {
|
|
100
|
+
logger.info("Mock location dropped (mockLocationPolicy=drop)");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// "flag": leave it but caller can read isFromMockProvider() / mocked field.
|
|
104
|
+
// "allow": no-op.
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
long locationId = mLocationDAO.persistLocation(location);
|
|
108
|
+
location.setLocationId(locationId);
|
|
109
|
+
|
|
110
|
+
if (mSessionDAO != null && mSessionDAO.isSessionActive()) {
|
|
111
|
+
mSessionDAO.persistSessionLocation(location);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
mExecutor.execute(new Runnable() {
|
|
116
|
+
@Override
|
|
117
|
+
public void run() {
|
|
118
|
+
post(location);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
} catch (RejectedExecutionException ex) {
|
|
122
|
+
mLocationDAO.updateLocationForSync(locationId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public void shutdown() {
|
|
127
|
+
shutdown(60);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public void shutdown(int waitSeconds) {
|
|
131
|
+
mExecutor.shutdown();
|
|
132
|
+
try {
|
|
133
|
+
if (!mExecutor.awaitTermination(waitSeconds, TimeUnit.SECONDS)) {
|
|
134
|
+
mExecutor.shutdownNow();
|
|
135
|
+
mLocationDAO.deleteUnpostedLocations();
|
|
136
|
+
}
|
|
137
|
+
} catch (InterruptedException e) {
|
|
138
|
+
mExecutor.shutdownNow();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private void post(final BackgroundLocation location) {
|
|
143
|
+
long locationId = location.getLocationId();
|
|
144
|
+
|
|
145
|
+
if (mHasConnectivity && mConfig.hasValidUrl()) {
|
|
146
|
+
if (postLocation(location)) {
|
|
147
|
+
mLocationDAO.deleteLocationById(locationId);
|
|
148
|
+
|
|
149
|
+
return; // if posted successfully do nothing more
|
|
150
|
+
} else {
|
|
151
|
+
mLocationDAO.updateLocationForSync(locationId);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
mLocationDAO.updateLocationForSync(locationId);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (mConfig.hasValidSyncUrl()) {
|
|
158
|
+
Integer configThreshold = mConfig.getSyncThreshold();
|
|
159
|
+
int threshold = (configThreshold != null) ? configThreshold : 100;
|
|
160
|
+
long syncLocationsCount = mLocationDAO.getLocationsForSyncCount(System.currentTimeMillis());
|
|
161
|
+
if (syncLocationsCount >= threshold) {
|
|
162
|
+
logger.debug("Attempt to sync locations: {} threshold: {}", syncLocationsCount, threshold);
|
|
163
|
+
mTaskListener.onSyncRequested();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private boolean postLocation(BackgroundLocation location) {
|
|
169
|
+
logger.debug("Executing PostLocationTask#postLocation");
|
|
170
|
+
|
|
171
|
+
// LocationTemplate.locationToJson returns Object (JSONObject for HashMapLocationTemplate,
|
|
172
|
+
// JSONArray for ArrayListLocationTemplate). Resolve to the concrete type before calling
|
|
173
|
+
// the matching HttpPostService.postJSON overload.
|
|
174
|
+
Object jsonLocation;
|
|
175
|
+
try {
|
|
176
|
+
jsonLocation = mConfig.getTemplate().locationToJson(location);
|
|
177
|
+
} catch (JSONException e) {
|
|
178
|
+
logger.warn("Location to json failed: {}", location.toString());
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
String urlTemplate = mConfig.getUrl();
|
|
183
|
+
// URL templating: substitute {lat}, {lon}, {timestamp_iso}, {device_id}, ... using the
|
|
184
|
+
// current location plus any static queryParams. For "single" mode this is per-location;
|
|
185
|
+
// for "batch" mode only static queryParams placeholders apply (location-derived ones
|
|
186
|
+
// would not make sense for an array).
|
|
187
|
+
String resolvedUrl = UrlTemplateResolver.resolve(urlTemplate, location, mConfig.getQueryParams());
|
|
188
|
+
|
|
189
|
+
String method = mConfig.getHttpMethod();
|
|
190
|
+
String mode = mConfig.getHttpMode();
|
|
191
|
+
logger.debug("Posting to url: {} method: {} mode: {} headers: {}",
|
|
192
|
+
resolvedUrl, method, mode, mConfig.getHttpHeaders());
|
|
193
|
+
int responseCode;
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
if ("single".equals(mode) || "GET".equals(method)) {
|
|
197
|
+
// GET cannot carry a JSON array body; force per-location request.
|
|
198
|
+
if (jsonLocation instanceof JSONArray) {
|
|
199
|
+
responseCode = HttpPostService.postJSON(resolvedUrl, (JSONArray) jsonLocation, mConfig.getHttpHeaders(), method);
|
|
200
|
+
} else {
|
|
201
|
+
responseCode = HttpPostService.postJSON(resolvedUrl, (JSONObject) jsonLocation, mConfig.getHttpHeaders(), method);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
JSONArray jsonLocations = new JSONArray();
|
|
205
|
+
jsonLocations.put(jsonLocation);
|
|
206
|
+
responseCode = HttpPostService.postJSON(resolvedUrl, jsonLocations, mConfig.getHttpHeaders(), method);
|
|
207
|
+
}
|
|
208
|
+
} catch (Exception e) {
|
|
209
|
+
mHasConnectivity = mConnectivityListener.hasConnectivity();
|
|
210
|
+
logger.warn("Error while posting locations: {}", e.getMessage());
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (responseCode == 285) {
|
|
215
|
+
// Okay, but we don't need to continue sending these
|
|
216
|
+
|
|
217
|
+
logger.debug("Location was sent to the server, and received an \"HTTP 285 Updates Not Required\"");
|
|
218
|
+
|
|
219
|
+
if (mTaskListener != null)
|
|
220
|
+
mTaskListener.onRequestedAbortUpdates();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (responseCode == 401) {
|
|
224
|
+
if (mTaskListener != null)
|
|
225
|
+
mTaskListener.onHttpAuthorizationUpdates();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// All 2xx statuses are okay
|
|
229
|
+
boolean isStatusOkay = responseCode >= 200 && responseCode < 300;
|
|
230
|
+
|
|
231
|
+
if (!isStatusOkay) {
|
|
232
|
+
logger.warn("Server error while posting locations responseCode: {}", responseCode);
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Created by finch on 19/07/16.
|
|
7
|
+
*/
|
|
8
|
+
public class ResourceResolver {
|
|
9
|
+
|
|
10
|
+
private static final String RESOURCE_PREFIX = "plugin_bgloc_";
|
|
11
|
+
private static final String ACCOUNT_NAME_RESOURCE = RESOURCE_PREFIX + "account_name";
|
|
12
|
+
private static final String ACCOUNT_TYPE_RESOURCE = RESOURCE_PREFIX + "account_type";
|
|
13
|
+
private static final String AUTHORITY_TYPE_RESOURCE = RESOURCE_PREFIX + "content_authority";
|
|
14
|
+
|
|
15
|
+
private Context mContext;
|
|
16
|
+
|
|
17
|
+
protected ResourceResolver() {}
|
|
18
|
+
|
|
19
|
+
private ResourceResolver(Context context) {
|
|
20
|
+
mContext = context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private Context getApplicationContext() {
|
|
24
|
+
return mContext.getApplicationContext();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public int getAppResource(String name, String type) {
|
|
28
|
+
Context appContext = getApplicationContext();
|
|
29
|
+
return appContext.getResources().getIdentifier(name, type, appContext.getPackageName());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public Integer getDrawable(String resourceName) {
|
|
33
|
+
return getAppResource(resourceName, "drawable");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public String getString(String name) {
|
|
37
|
+
return getApplicationContext().getString(getAppResource(name, "string"));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public String getAccountName() {
|
|
41
|
+
return getString(ACCOUNT_NAME_RESOURCE);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public String getAccountType() {
|
|
45
|
+
return getString(ACCOUNT_TYPE_RESOURCE);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public String getAuthority() {
|
|
49
|
+
return getString(AUTHORITY_TYPE_RESOURCE);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static ResourceResolver newInstance(Context context) {
|
|
53
|
+
return new ResourceResolver(context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package com.marianhello.bgloc.data;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONArray;
|
|
4
|
+
import org.json.JSONException;
|
|
5
|
+
import org.json.JSONObject;
|
|
6
|
+
|
|
7
|
+
import java.io.Serializable;
|
|
8
|
+
import java.util.Iterator;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Created by finch on 9.12.2017.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
abstract public class AbstractLocationTemplate implements LocationTemplate, Serializable {
|
|
17
|
+
public static final String BUNDLE_KEY = "template";
|
|
18
|
+
public abstract LocationTemplate clone();
|
|
19
|
+
|
|
20
|
+
static class LocationMapper {
|
|
21
|
+
private BackgroundLocation location;
|
|
22
|
+
|
|
23
|
+
private LocationMapper() {}
|
|
24
|
+
|
|
25
|
+
private Object mapValue(Object value) throws JSONException {
|
|
26
|
+
if (value instanceof String) {
|
|
27
|
+
Object locationValue = location.getValueForKey((String) value);
|
|
28
|
+
return locationValue != null ? locationValue : value;
|
|
29
|
+
} else if (value instanceof Map) {
|
|
30
|
+
return withMap((Map) value);
|
|
31
|
+
} else if (value instanceof List) {
|
|
32
|
+
return withList((List) value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public JSONArray withList(List values) throws JSONException {
|
|
39
|
+
JSONArray result = new JSONArray();
|
|
40
|
+
Iterator<?> it = values.iterator();
|
|
41
|
+
while (it.hasNext()) {
|
|
42
|
+
Object value = it.next();
|
|
43
|
+
result.put(mapValue(value));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public JSONObject withMap(Map values) throws JSONException {
|
|
51
|
+
JSONObject result = new JSONObject();
|
|
52
|
+
Iterator<?> it = values.entrySet().iterator();
|
|
53
|
+
while (it.hasNext()) {
|
|
54
|
+
Map.Entry<String, Object> pair = (Map.Entry) it.next();
|
|
55
|
+
String key = pair.getKey();
|
|
56
|
+
Object value = pair.getValue();
|
|
57
|
+
result.put(key, mapValue(value));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static LocationMapper map(BackgroundLocation location) {
|
|
64
|
+
LocationMapper instance = new LocationMapper();
|
|
65
|
+
instance.location = location;
|
|
66
|
+
return instance;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
package com.marianhello.bgloc.data;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONArray;
|
|
4
|
+
import org.json.JSONException;
|
|
5
|
+
|
|
6
|
+
import java.io.Serializable;
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.Iterator;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Created by finch on 15.12.2017.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
public class ArrayListLocationTemplate extends AbstractLocationTemplate implements Serializable {
|
|
16
|
+
private ArrayList mList;
|
|
17
|
+
private static final long serialVersionUID = 1234L;
|
|
18
|
+
|
|
19
|
+
// copy constructor
|
|
20
|
+
public ArrayListLocationTemplate(ArrayListLocationTemplate tpl) {
|
|
21
|
+
if (tpl == null || tpl.mList == null) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
mList = new ArrayList();
|
|
26
|
+
Iterator it = tpl.mList.iterator();
|
|
27
|
+
while (it.hasNext()) {
|
|
28
|
+
mList.add(it.next());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public ArrayListLocationTemplate(ArrayList list) {
|
|
33
|
+
this.mList = list;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Override
|
|
37
|
+
public Object locationToJson(BackgroundLocation location) throws JSONException {
|
|
38
|
+
return LocationMapper.map(location).withList(mList);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public Iterator iterator() {
|
|
42
|
+
return mList.iterator();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public boolean containsKey(String key) {
|
|
46
|
+
return mList.contains(key);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public boolean isEmpty() {
|
|
51
|
+
return mList == null || mList.isEmpty();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Override
|
|
55
|
+
public boolean equals(Object other) {
|
|
56
|
+
if (other == null) return false;
|
|
57
|
+
if (other == this) return true;
|
|
58
|
+
if (!(other instanceof ArrayListLocationTemplate)) return false;
|
|
59
|
+
return ((ArrayListLocationTemplate) other).mList.equals(this.mList);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Override
|
|
63
|
+
public String toString() {
|
|
64
|
+
if (mList == null) {
|
|
65
|
+
return "null";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
JSONArray jArray = new JSONArray(mList);
|
|
69
|
+
return jArray.toString();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public Object[] toArray() {
|
|
73
|
+
if (mList == null) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return mList.toArray();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public List toList() {
|
|
81
|
+
return mList;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public LocationTemplate clone() {
|
|
86
|
+
return new ArrayListLocationTemplate(this);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package com.marianhello.bgloc.data;
|
|
2
|
+
|
|
3
|
+
import android.os.Parcel;
|
|
4
|
+
import android.os.Parcelable;
|
|
5
|
+
|
|
6
|
+
import com.google.android.gms.location.DetectedActivity;
|
|
7
|
+
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Created by finch on 5.12.2017.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
public class BackgroundActivity implements Parcelable {
|
|
16
|
+
private int confidence;
|
|
17
|
+
private int type;
|
|
18
|
+
|
|
19
|
+
public BackgroundActivity(Integer locationProvider, DetectedActivity activity) {
|
|
20
|
+
confidence = activity.getConfidence();
|
|
21
|
+
type = activity.getType();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private BackgroundActivity(Parcel in) {
|
|
25
|
+
confidence = in.readInt();
|
|
26
|
+
type = in.readInt();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns location as JSON object.
|
|
31
|
+
* @throws JSONException
|
|
32
|
+
*/
|
|
33
|
+
public JSONObject toJSONObject() throws JSONException {
|
|
34
|
+
JSONObject json = new JSONObject();
|
|
35
|
+
json.put("confidence", confidence);
|
|
36
|
+
json.put("type", getActivityString(type));
|
|
37
|
+
return json;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static String getActivityString(int detectedActivityType) {
|
|
41
|
+
switch(detectedActivityType) {
|
|
42
|
+
case DetectedActivity.IN_VEHICLE:
|
|
43
|
+
return "IN_VEHICLE";
|
|
44
|
+
case DetectedActivity.ON_BICYCLE:
|
|
45
|
+
return "ON_BICYCLE";
|
|
46
|
+
case DetectedActivity.ON_FOOT:
|
|
47
|
+
return "ON_FOOT";
|
|
48
|
+
case DetectedActivity.RUNNING:
|
|
49
|
+
return "RUNNING";
|
|
50
|
+
case DetectedActivity.STILL:
|
|
51
|
+
return "STILL";
|
|
52
|
+
case DetectedActivity.TILTING:
|
|
53
|
+
return "TILTING";
|
|
54
|
+
case DetectedActivity.UNKNOWN:
|
|
55
|
+
return "UNKNOWN";
|
|
56
|
+
case DetectedActivity.WALKING:
|
|
57
|
+
return "WALKING";
|
|
58
|
+
default:
|
|
59
|
+
return "UNKNOWN";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public int getConfidence() {
|
|
64
|
+
return confidence;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public void setConfidence(int confidence) {
|
|
68
|
+
this.confidence = confidence;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public int getType() {
|
|
72
|
+
return type;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public void setType(int type) {
|
|
76
|
+
this.type = type;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static final Parcelable.Creator<BackgroundActivity> CREATOR
|
|
80
|
+
= new Parcelable.Creator<BackgroundActivity>() {
|
|
81
|
+
public BackgroundActivity createFromParcel(Parcel in) {
|
|
82
|
+
return new BackgroundActivity(in);
|
|
83
|
+
}
|
|
84
|
+
public BackgroundActivity[] newArray(int size) {
|
|
85
|
+
return new BackgroundActivity[size];
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public int describeContents() {
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Override
|
|
95
|
+
public void writeToParcel(Parcel dest, int i) {
|
|
96
|
+
dest.writeInt(confidence);
|
|
97
|
+
dest.writeInt(type);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Override
|
|
101
|
+
public String toString () {
|
|
102
|
+
return new StringBuffer()
|
|
103
|
+
.append("BackgroundActivity[confidence=").append(confidence)
|
|
104
|
+
.append(" type=").append(getActivityString(type))
|
|
105
|
+
.append("]")
|
|
106
|
+
.toString();
|
|
107
|
+
}
|
|
108
|
+
}
|