@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,41 @@
|
|
|
1
|
+
package com.marianhello.bgloc.service;
|
|
2
|
+
|
|
3
|
+
import android.app.ActivityManager;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
|
|
6
|
+
public class LocationServiceInfoImpl implements LocationServiceInfo {
|
|
7
|
+
private Context mContext;
|
|
8
|
+
|
|
9
|
+
public LocationServiceInfoImpl(Context context) {
|
|
10
|
+
mContext = context;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Override
|
|
14
|
+
public boolean isStarted() {
|
|
15
|
+
ActivityManager.RunningServiceInfo info = getRunningServiceInfo();
|
|
16
|
+
if (info != null) {
|
|
17
|
+
return info.started;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public boolean isBound() {
|
|
24
|
+
ActivityManager.RunningServiceInfo info = getRunningServiceInfo();
|
|
25
|
+
if (info != null) {
|
|
26
|
+
return info.clientCount > 0;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public ActivityManager.RunningServiceInfo getRunningServiceInfo() {
|
|
32
|
+
String serviceName = LocationServiceImpl.class.getName();
|
|
33
|
+
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
|
34
|
+
for (ActivityManager.RunningServiceInfo info : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
35
|
+
if (serviceName.equals(info.service.getClassName())) {
|
|
36
|
+
return info;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017 R3BL LLC.
|
|
3
|
+
*
|
|
4
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
|
5
|
+
* license agreements. See the NOTICE file distributed with this work for additional
|
|
6
|
+
* information regarding copyright ownership. The ASF licenses this file to you under
|
|
7
|
+
* the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
8
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed
|
|
13
|
+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
14
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
package com.marianhello.bgloc.service;
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import android.content.Intent;
|
|
22
|
+
import android.os.Bundle;
|
|
23
|
+
import android.os.Parcelable;
|
|
24
|
+
import androidx.annotation.IntDef;
|
|
25
|
+
|
|
26
|
+
import java.lang.annotation.Retention;
|
|
27
|
+
import java.lang.annotation.RetentionPolicy;
|
|
28
|
+
|
|
29
|
+
// CommandId enumeration
|
|
30
|
+
// more info - http://blog.shamanland.com/2016/02/int-string-enum.html
|
|
31
|
+
@IntDef({
|
|
32
|
+
CommandId.INVALID,
|
|
33
|
+
CommandId.START,
|
|
34
|
+
CommandId.START_FOREGROUND_SERVICE,
|
|
35
|
+
CommandId.STOP,
|
|
36
|
+
CommandId.STOP_FOREGROUND,
|
|
37
|
+
CommandId.START_FOREGROUND,
|
|
38
|
+
CommandId.CONFIGURE,
|
|
39
|
+
CommandId.REGISTER_HEADLESS_TASK,
|
|
40
|
+
CommandId.START_HEADLESS_TASK,
|
|
41
|
+
CommandId.STOP_HEADLESS_TASK
|
|
42
|
+
})
|
|
43
|
+
@Retention(RetentionPolicy.SOURCE)
|
|
44
|
+
@interface CommandId {
|
|
45
|
+
int INVALID = -1;
|
|
46
|
+
int START = 0;
|
|
47
|
+
int START_FOREGROUND_SERVICE = 1;
|
|
48
|
+
int STOP = 2;
|
|
49
|
+
int STOP_FOREGROUND = 3;
|
|
50
|
+
int START_FOREGROUND = 4;
|
|
51
|
+
int CONFIGURE = 5;
|
|
52
|
+
int REGISTER_HEADLESS_TASK = 6;
|
|
53
|
+
int START_HEADLESS_TASK = 7;
|
|
54
|
+
int STOP_HEADLESS_TASK = 8;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public class LocationServiceIntentBuilder {
|
|
58
|
+
|
|
59
|
+
private static final String KEY_MESSAGE = "msg";
|
|
60
|
+
private static final String KEY_COMMAND = "cmd";
|
|
61
|
+
|
|
62
|
+
private Context mContext;
|
|
63
|
+
private String mMessage;
|
|
64
|
+
private Command mCommand;
|
|
65
|
+
|
|
66
|
+
public static class Command {
|
|
67
|
+
private static final String KEY_COMMAND_ID = "cmd_id";
|
|
68
|
+
private static final String KEY_COMMAND_ARGUMENT = "cmd_arg";
|
|
69
|
+
private static final String KEY_COMMAND_ARGUMENT_TYPE = "cmd_arg_type";
|
|
70
|
+
private static final int ARGUMENT_TYPE_MISSING = 0;
|
|
71
|
+
private static final int ARGUMENT_TYPE_STRING = 1;
|
|
72
|
+
private static final int ARGUMENT_TYPE_PARCELABLE = 2;
|
|
73
|
+
|
|
74
|
+
private final @CommandId int mCommandId;
|
|
75
|
+
private Parcelable mParcelableArg;
|
|
76
|
+
private String mStringArg;
|
|
77
|
+
private int mArgType = 0;
|
|
78
|
+
|
|
79
|
+
public Command(int id) {
|
|
80
|
+
this.mCommandId = id;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public Command(int id, String argument) {
|
|
84
|
+
mCommandId = id;
|
|
85
|
+
mStringArg = argument;
|
|
86
|
+
mArgType = ARGUMENT_TYPE_STRING;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public Command(int id, Parcelable argument) {
|
|
90
|
+
mCommandId = id;
|
|
91
|
+
mParcelableArg = argument;
|
|
92
|
+
mArgType = ARGUMENT_TYPE_PARCELABLE;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public int getId() {
|
|
96
|
+
return mCommandId;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public Object getArgument() {
|
|
100
|
+
switch (mArgType) {
|
|
101
|
+
case ARGUMENT_TYPE_STRING:
|
|
102
|
+
return mStringArg;
|
|
103
|
+
case ARGUMENT_TYPE_PARCELABLE:
|
|
104
|
+
return mParcelableArg;
|
|
105
|
+
default:
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public Bundle toBundle() {
|
|
111
|
+
Bundle bundle = new Bundle();
|
|
112
|
+
bundle.putInt(KEY_COMMAND_ID, mCommandId);
|
|
113
|
+
|
|
114
|
+
if (mStringArg != null) {
|
|
115
|
+
bundle.putInt(KEY_COMMAND_ARGUMENT_TYPE, ARGUMENT_TYPE_STRING);
|
|
116
|
+
bundle.putString(KEY_COMMAND_ARGUMENT, mStringArg);
|
|
117
|
+
} else if (mParcelableArg != null) {
|
|
118
|
+
bundle.putInt(KEY_COMMAND_ARGUMENT_TYPE, ARGUMENT_TYPE_PARCELABLE);
|
|
119
|
+
bundle.putParcelable(KEY_COMMAND_ARGUMENT, mParcelableArg);
|
|
120
|
+
} else {
|
|
121
|
+
bundle.putInt(KEY_COMMAND_ARGUMENT_TYPE, ARGUMENT_TYPE_MISSING);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return bundle;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static Command from(Bundle bundle) {
|
|
128
|
+
@CommandId int commandId = bundle.getInt(KEY_COMMAND_ID);
|
|
129
|
+
int argumentType = bundle.getInt(KEY_COMMAND_ARGUMENT_TYPE);
|
|
130
|
+
|
|
131
|
+
if (argumentType == ARGUMENT_TYPE_STRING) {
|
|
132
|
+
return new Command(commandId, bundle.getString(KEY_COMMAND_ARGUMENT));
|
|
133
|
+
} else if (argumentType == ARGUMENT_TYPE_PARCELABLE) {
|
|
134
|
+
// Important: don't remove Parcelable cast
|
|
135
|
+
// required for Java 1.8 compatibility
|
|
136
|
+
return new Command(commandId, (Parcelable) bundle.getParcelable(KEY_COMMAND_ARGUMENT));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return new Command(commandId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public static LocationServiceIntentBuilder getInstance(Context context) {
|
|
144
|
+
return new LocationServiceIntentBuilder(context);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public LocationServiceIntentBuilder(Context context) {
|
|
148
|
+
mContext = context;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public LocationServiceIntentBuilder setMessage(String message) {
|
|
152
|
+
mMessage = message;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param commandId Don't use {@link CommandId#INVALID} as a param. If you do then this method does
|
|
158
|
+
* nothing.
|
|
159
|
+
*/
|
|
160
|
+
public LocationServiceIntentBuilder setCommand(@CommandId int commandId) {
|
|
161
|
+
mCommand = new Command(commandId);
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public LocationServiceIntentBuilder setCommand(@CommandId int commandId, String arg) {
|
|
166
|
+
mCommand = new Command(commandId, arg);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public LocationServiceIntentBuilder setCommand(@CommandId int commandId, Parcelable arg) {
|
|
171
|
+
mCommand = new Command(commandId, arg);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public Intent build() {
|
|
176
|
+
assert mContext != null : "Context can not be null!";
|
|
177
|
+
Intent intent = new Intent(mContext, LocationServiceImpl.class);
|
|
178
|
+
if (mCommand != null) {
|
|
179
|
+
intent.putExtra(KEY_COMMAND, mCommand.toBundle());
|
|
180
|
+
}
|
|
181
|
+
if (mMessage != null) {
|
|
182
|
+
intent.putExtra(KEY_MESSAGE, mMessage);
|
|
183
|
+
}
|
|
184
|
+
return intent;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public static boolean containsCommand(Intent intent) {
|
|
188
|
+
return intent.hasExtra(KEY_COMMAND);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public static boolean containsMessage(Intent intent) {
|
|
192
|
+
return intent.hasExtra(KEY_MESSAGE);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public static Command getCommand(Intent intent) {
|
|
196
|
+
Bundle bundle = intent.getBundleExtra(KEY_COMMAND);
|
|
197
|
+
return Command.from(bundle);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public static String getMessage(Intent intent) {
|
|
201
|
+
return intent.getStringExtra(KEY_MESSAGE);
|
|
202
|
+
}
|
|
203
|
+
} //end class LocationServiceIntentBuilder
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
package com.marianhello.bgloc.service;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.pm.PackageManager;
|
|
7
|
+
import android.os.Build;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
|
|
10
|
+
import androidx.core.content.ContextCompat;
|
|
11
|
+
|
|
12
|
+
import com.marianhello.bgloc.Config;
|
|
13
|
+
|
|
14
|
+
public class LocationServiceProxy implements LocationService, LocationServiceInfo {
|
|
15
|
+
private static final String TAG = LocationServiceProxy.class.getSimpleName();
|
|
16
|
+
private final Context mContext;
|
|
17
|
+
private final LocationServiceIntentBuilder mIntentBuilder;
|
|
18
|
+
|
|
19
|
+
public LocationServiceProxy(Context context) {
|
|
20
|
+
mContext = context;
|
|
21
|
+
mIntentBuilder = new LocationServiceIntentBuilder(context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void configure(Config config) {
|
|
26
|
+
// do not start service if it was not already started
|
|
27
|
+
// FIXES:
|
|
28
|
+
// https://github.com/mauron85/react-native-background-geolocation/issues/360
|
|
29
|
+
// https://github.com/mauron85/cordova-plugin-background-geolocation/issues/551
|
|
30
|
+
// https://github.com/mauron85/cordova-plugin-background-geolocation/issues/552
|
|
31
|
+
if (!isStarted()) { return; }
|
|
32
|
+
|
|
33
|
+
Intent intent = mIntentBuilder
|
|
34
|
+
.setCommand(CommandId.CONFIGURE, config)
|
|
35
|
+
.build();
|
|
36
|
+
executeIntentCommand(intent);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public void registerHeadlessTask(String taskRunnerClass) {
|
|
41
|
+
Intent intent = mIntentBuilder
|
|
42
|
+
.setCommand(CommandId.REGISTER_HEADLESS_TASK, taskRunnerClass)
|
|
43
|
+
.build();
|
|
44
|
+
executeIntentCommand(intent);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
public void startHeadlessTask() {
|
|
49
|
+
if (!isStarted()) { return; }
|
|
50
|
+
|
|
51
|
+
Intent intent = mIntentBuilder
|
|
52
|
+
.setCommand(CommandId.START_HEADLESS_TASK)
|
|
53
|
+
.build();
|
|
54
|
+
executeIntentCommand(intent);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public void stopHeadlessTask() {
|
|
59
|
+
if (!isStarted()) { return; }
|
|
60
|
+
|
|
61
|
+
Intent intent = mIntentBuilder
|
|
62
|
+
.setCommand(CommandId.STOP_HEADLESS_TASK)
|
|
63
|
+
.build();
|
|
64
|
+
executeIntentCommand(intent);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Override
|
|
68
|
+
public void executeProviderCommand(int command, int arg) {
|
|
69
|
+
// TODO
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Override
|
|
73
|
+
public void start() {
|
|
74
|
+
Intent intent = mIntentBuilder.setCommand(CommandId.START).build();
|
|
75
|
+
// intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
|
76
|
+
// start service to keep service running even if no clients are bound to it
|
|
77
|
+
executeIntentCommand(intent);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Override
|
|
81
|
+
public void startForegroundService() {
|
|
82
|
+
Intent intent = mIntentBuilder.setCommand(CommandId.START_FOREGROUND_SERVICE).build();
|
|
83
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
84
|
+
if (!hasLocationPermission()) {
|
|
85
|
+
// Do NOT fall back to startService(): would create a non-foreground service that crashes
|
|
86
|
+
// on first location update. Caller must request the permission first.
|
|
87
|
+
Log.w(TAG, "Cannot start foreground service: ACCESS_FINE_LOCATION/COARSE_LOCATION not granted");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Note: ACCESS_BACKGROUND_LOCATION is only required when the service is started from
|
|
91
|
+
// background (e.g. BootCompletedReceiver). When called from foreground, the OS allows
|
|
92
|
+
// a location-typed FGS to run with only fine/coarse location and inherit "while-in-use".
|
|
93
|
+
try {
|
|
94
|
+
mContext.startForegroundService(intent);
|
|
95
|
+
} catch (Exception e) {
|
|
96
|
+
// Android 12+ may throw ForegroundServiceStartNotAllowedException.
|
|
97
|
+
Log.e(TAG, "startForegroundService blocked: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
mContext.startService(intent);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private boolean hasLocationPermission() {
|
|
105
|
+
// v4.5.1 — ContextCompat handles API < 23 safely.
|
|
106
|
+
return ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
|
107
|
+
|| ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Override
|
|
111
|
+
public void stop() {
|
|
112
|
+
if (!isStarted()) { return; }
|
|
113
|
+
|
|
114
|
+
Intent intent = mIntentBuilder.setCommand(CommandId.STOP).build();
|
|
115
|
+
executeIntentCommand(intent);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Override
|
|
119
|
+
public void stopForeground() {
|
|
120
|
+
if (!isStarted()) { return; }
|
|
121
|
+
|
|
122
|
+
Intent intent = mIntentBuilder.setCommand(CommandId.STOP_FOREGROUND).build();
|
|
123
|
+
executeIntentCommand(intent);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Override
|
|
127
|
+
public void startForeground() {
|
|
128
|
+
if (!isStarted()) { return; }
|
|
129
|
+
|
|
130
|
+
Intent intent = mIntentBuilder.setCommand(CommandId.START_FOREGROUND).build();
|
|
131
|
+
executeIntentCommand(intent);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Override
|
|
135
|
+
public boolean isStarted() {
|
|
136
|
+
LocationServiceInfo serviceInfo = new LocationServiceInfoImpl(mContext);
|
|
137
|
+
return serviceInfo.isStarted();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public boolean isRunning() {
|
|
141
|
+
if (isStarted()) {
|
|
142
|
+
return LocationServiceImpl.isRunning();
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@Override
|
|
148
|
+
public boolean isBound() {
|
|
149
|
+
LocationServiceInfo serviceInfo = new LocationServiceInfoImpl(mContext);
|
|
150
|
+
return serviceInfo.isBound();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private void executeIntentCommand(Intent intent) {
|
|
154
|
+
mContext.startService(intent);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.marianhello.bgloc.sync;
|
|
2
|
+
|
|
3
|
+
import android.accounts.Account;
|
|
4
|
+
import android.accounts.AccountManager;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Created by finch on 19/07/16.
|
|
9
|
+
*/
|
|
10
|
+
public class AccountHelper {
|
|
11
|
+
/**
|
|
12
|
+
* Create a new dummy account for the sync adapter
|
|
13
|
+
*
|
|
14
|
+
* @param context The application context
|
|
15
|
+
*/
|
|
16
|
+
public static android.accounts.Account CreateSyncAccount(Context context, String accountName, String accountType) {
|
|
17
|
+
Account account = new Account(accountName, accountType);
|
|
18
|
+
// Get an instance of the Android account manager
|
|
19
|
+
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
|
|
20
|
+
/*
|
|
21
|
+
* Add the account and account type, no password or user data
|
|
22
|
+
* If successful, return the Account object, otherwise report an error.
|
|
23
|
+
*/
|
|
24
|
+
if (accountManager.addAccountExplicitly(account, null, null)) {
|
|
25
|
+
/*
|
|
26
|
+
* If you don't set android:syncable="true" in
|
|
27
|
+
* in your <provider> element in the manifest,
|
|
28
|
+
* then call context.setIsSyncable(account, AUTHORITY, 1)
|
|
29
|
+
* here.
|
|
30
|
+
*/
|
|
31
|
+
} else {
|
|
32
|
+
/*
|
|
33
|
+
* The account exists or some other error occurred. Log this, report it,
|
|
34
|
+
* or handle it internally.
|
|
35
|
+
*/
|
|
36
|
+
}
|
|
37
|
+
return account;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package com.marianhello.bgloc.sync;
|
|
2
|
+
|
|
3
|
+
import android.accounts.AbstractAccountAuthenticator;
|
|
4
|
+
import android.accounts.Account;
|
|
5
|
+
import android.accounts.AccountAuthenticatorResponse;
|
|
6
|
+
import android.accounts.NetworkErrorException;
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.os.Bundle;
|
|
9
|
+
|
|
10
|
+
public class Authenticator extends AbstractAccountAuthenticator {
|
|
11
|
+
// Simple constructor
|
|
12
|
+
public Authenticator(Context context) {
|
|
13
|
+
super(context);
|
|
14
|
+
}
|
|
15
|
+
// Editing properties is not supported
|
|
16
|
+
@Override
|
|
17
|
+
public Bundle editProperties(
|
|
18
|
+
AccountAuthenticatorResponse r, String s) {
|
|
19
|
+
throw new UnsupportedOperationException();
|
|
20
|
+
}
|
|
21
|
+
// Don't add additional accounts
|
|
22
|
+
@Override
|
|
23
|
+
public Bundle addAccount(
|
|
24
|
+
AccountAuthenticatorResponse r,
|
|
25
|
+
String s,
|
|
26
|
+
String s2,
|
|
27
|
+
String[] strings,
|
|
28
|
+
Bundle bundle) throws NetworkErrorException {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
// Ignore attempts to confirm credentials
|
|
32
|
+
@Override
|
|
33
|
+
public Bundle confirmCredentials(
|
|
34
|
+
AccountAuthenticatorResponse r,
|
|
35
|
+
Account account,
|
|
36
|
+
Bundle bundle) throws NetworkErrorException {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Getting an authentication token is not supported
|
|
40
|
+
@Override
|
|
41
|
+
public Bundle getAuthToken(
|
|
42
|
+
AccountAuthenticatorResponse r,
|
|
43
|
+
Account account,
|
|
44
|
+
String s,
|
|
45
|
+
Bundle bundle) throws NetworkErrorException {
|
|
46
|
+
throw new UnsupportedOperationException();
|
|
47
|
+
}
|
|
48
|
+
// Getting a label for the auth token is not supported
|
|
49
|
+
@Override
|
|
50
|
+
public String getAuthTokenLabel(String s) {
|
|
51
|
+
throw new UnsupportedOperationException();
|
|
52
|
+
}
|
|
53
|
+
// Updating user credentials is not supported
|
|
54
|
+
@Override
|
|
55
|
+
public Bundle updateCredentials(
|
|
56
|
+
AccountAuthenticatorResponse r,
|
|
57
|
+
Account account,
|
|
58
|
+
String s, Bundle bundle) throws NetworkErrorException {
|
|
59
|
+
throw new UnsupportedOperationException();
|
|
60
|
+
}
|
|
61
|
+
// Checking features for the account is not supported
|
|
62
|
+
@Override
|
|
63
|
+
public Bundle hasFeatures(
|
|
64
|
+
AccountAuthenticatorResponse r,
|
|
65
|
+
Account account, String[] strings) throws NetworkErrorException {
|
|
66
|
+
throw new UnsupportedOperationException();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.marianhello.bgloc.sync;
|
|
2
|
+
|
|
3
|
+
import android.app.Service;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.os.IBinder;
|
|
6
|
+
|
|
7
|
+
public class AuthenticatorService extends Service {
|
|
8
|
+
|
|
9
|
+
private Authenticator mAuthenticator;
|
|
10
|
+
|
|
11
|
+
public AuthenticatorService() {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Override
|
|
15
|
+
public void onCreate() {
|
|
16
|
+
// Create a new authenticator object
|
|
17
|
+
mAuthenticator = new Authenticator(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* When the system binds to this Service to make the RPC call
|
|
22
|
+
* return the authenticator's IBinder.
|
|
23
|
+
*/
|
|
24
|
+
@Override
|
|
25
|
+
public IBinder onBind(Intent intent) {
|
|
26
|
+
return mAuthenticator.getIBinder();
|
|
27
|
+
}
|
|
28
|
+
}
|