@josuelmm/cordova-background-geolocation 2.3.5
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/.npmignore +23 -0
- package/CHANGELOG.md +787 -0
- package/CONTRIBUTORS.md +15 -0
- package/HISTORY.md +734 -0
- package/LICENSE +191 -0
- package/README.md +125 -0
- package/RELEASE.MD +5 -0
- package/android/CDVBackgroundGeolocation/src/main/AndroidManifest.xml +23 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +148 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/PluginRegistry.java +25 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/headless/JsEvaluatorTaskRunner.java +53 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +603 -0
- package/android/CDVBackgroundGeolocation/src/main/res/values/strings.xml +4 -0
- package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +208 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +45 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +570 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +76 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +437 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +95 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +159 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +161 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +247 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +200 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +457 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +96 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +225 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +46 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +14 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +50 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +17 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +92 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +107 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +5 -0
- package/android/common/src/main/AndroidManifest.xml +72 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +523 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +59 -0
- package/android/common/src/main/java/com/marianhello/bgloc/Config.java +652 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +224 -0
- package/android/common/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginDelegate.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +188 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +994 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +22 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +65 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +395 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +76 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +160 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +112 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +506 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +151 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +171 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +282 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +610 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +145 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +749 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +130 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +278 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +249 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
- package/android/common/src/main/java/com/marianhello/logging/DBLogReader.java +203 -0
- package/android/common/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
- package/android/common/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
- package/android/common/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
- package/android/common/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
- package/android/common/src/main/java/com/marianhello/utils/Convert.java +56 -0
- package/android/common/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
- package/android/common/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
- package/android/common/src/main/java/org/apache/commons/io/Charsets.java +153 -0
- package/android/common/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
- package/android/common/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
- package/android/common/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
- package/android/common/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/values/strings.xml +4 -0
- package/android/common/src/main/res/xml/authenticator.xml +7 -0
- package/android/common/src/main/res/xml/syncadapter.xml +9 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +82 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +128 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +191 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +37 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +216 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +223 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +50 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +180 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +16 -0
- package/android/dependencies.gradle +13 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.h +41 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +526 -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 +202 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +60 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +638 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +185 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +74 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +485 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +49 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +51 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +514 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +97 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.h +59 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +349 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +35 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +287 -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 +40 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +250 -0
- package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +129 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +278 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +38 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +380 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
- package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
- package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +2 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +21 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +135 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +80 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +147 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +30 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +42 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +99 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +327 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +44 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +94 -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.xcodeproj/project.pbxproj +760 -0
- package/ios/common/BackgroundGeolocationTests/Info.plist +24 -0
- package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +185 -0
- package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +161 -0
- package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +216 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +55 -0
- package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +43 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +41 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +240 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +84 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +144 -0
- package/ios/common/CONTRIBUTORS.md +10 -0
- package/ios/common/LICENSE +191 -0
- package/ios/common/README.md +7 -0
- package/ios/common/scripts/xcode-refactor.js +184 -0
- package/package.json +44 -0
- package/plugin.xml +355 -0
- package/www/BackgroundGeolocation.d.ts +910 -0
- package/www/BackgroundGeolocation.js +247 -0
- package/www/radio.js +177 -0
package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.IntentFilter;
|
|
7
|
+
import android.os.Bundle;
|
|
8
|
+
import android.os.IBinder;
|
|
9
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
10
|
+
import androidx.test.rule.ServiceTestRule;
|
|
11
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
12
|
+
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
13
|
+
|
|
14
|
+
import com.marianhello.bgloc.provider.TestLocationProviderFactory;
|
|
15
|
+
import com.marianhello.bgloc.service.LocationServiceImpl;
|
|
16
|
+
import com.marianhello.bgloc.service.LocationServiceProxy;
|
|
17
|
+
|
|
18
|
+
import org.junit.After;
|
|
19
|
+
import org.junit.Before;
|
|
20
|
+
import org.junit.Ignore;
|
|
21
|
+
import org.junit.Rule;
|
|
22
|
+
import org.junit.Test;
|
|
23
|
+
import org.junit.runner.RunWith;
|
|
24
|
+
|
|
25
|
+
import java.util.concurrent.CountDownLatch;
|
|
26
|
+
import java.util.concurrent.TimeoutException;
|
|
27
|
+
|
|
28
|
+
import static org.hamcrest.core.Is.is;
|
|
29
|
+
import static org.hamcrest.core.IsEqual.equalTo;
|
|
30
|
+
import static org.junit.Assert.assertThat;
|
|
31
|
+
|
|
32
|
+
@RunWith(AndroidJUnit4.class)
|
|
33
|
+
public class LocationServiceProxyTest {
|
|
34
|
+
|
|
35
|
+
@Rule
|
|
36
|
+
public final ServiceTestRule mServiceRule = new ServiceTestRule();
|
|
37
|
+
|
|
38
|
+
private LocationServiceProxy proxy;
|
|
39
|
+
|
|
40
|
+
@Before
|
|
41
|
+
public void setUp() {
|
|
42
|
+
LocationServiceImpl.setLocationProviderFactory(new TestLocationProviderFactory());
|
|
43
|
+
proxy = new LocationServiceProxy(InstrumentationRegistry.getTargetContext());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@After
|
|
47
|
+
public void tearDown() {
|
|
48
|
+
LocationServiceImpl.setLocationProviderFactory(null);
|
|
49
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
50
|
+
ctx.stopService(new Intent(ctx, LocationServiceImpl.class));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Test(timeout = 5000)
|
|
54
|
+
public void testStart() throws InterruptedException {
|
|
55
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
|
56
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
57
|
+
@Override
|
|
58
|
+
public void onReceive(Context context, Intent intent) {
|
|
59
|
+
Bundle bundle = intent.getExtras();
|
|
60
|
+
int action = bundle.getInt("action");
|
|
61
|
+
|
|
62
|
+
if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) {
|
|
63
|
+
latch.countDown();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
|
|
69
|
+
lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
70
|
+
|
|
71
|
+
proxy.start();
|
|
72
|
+
latch.await();
|
|
73
|
+
lbm.unregisterReceiver(serviceBroadcastReceiver);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Test(timeout = 5000)
|
|
77
|
+
public void testStop() throws InterruptedException {
|
|
78
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
|
79
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
80
|
+
@Override
|
|
81
|
+
public void onReceive(Context context, Intent intent) {
|
|
82
|
+
Bundle bundle = intent.getExtras();
|
|
83
|
+
int action = bundle.getInt("action");
|
|
84
|
+
|
|
85
|
+
if (action == LocationServiceImpl.MSG_ON_SERVICE_STOPPED) {
|
|
86
|
+
latch.countDown();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
|
|
92
|
+
lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
93
|
+
|
|
94
|
+
proxy.start();
|
|
95
|
+
proxy.stop();
|
|
96
|
+
latch.await();
|
|
97
|
+
lbm.unregisterReceiver(serviceBroadcastReceiver);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Test(timeout = 5000)
|
|
101
|
+
public void testConfigure() throws TimeoutException, InterruptedException {
|
|
102
|
+
Context context = InstrumentationRegistry.getTargetContext();
|
|
103
|
+
// Create the service Intent.
|
|
104
|
+
Intent serviceIntent = new Intent(context, LocationServiceImpl.class);
|
|
105
|
+
// Bind the service and grab a reference to the binder.
|
|
106
|
+
IBinder binder = mServiceRule.bindService(serviceIntent);
|
|
107
|
+
// Get the reference to the service, or you can call
|
|
108
|
+
// public methods on the binder directly.
|
|
109
|
+
LocationServiceImpl service = ((LocationServiceImpl.LocalBinder) binder).getService();
|
|
110
|
+
|
|
111
|
+
Config config = Config.getDefault();
|
|
112
|
+
config.setUrl("http://locationserviceproxy.net/");
|
|
113
|
+
|
|
114
|
+
proxy.start();
|
|
115
|
+
proxy.configure(config);
|
|
116
|
+
Thread.sleep(4000);
|
|
117
|
+
assertThat(service.getConfig().getUrl(), equalTo("http://locationserviceproxy.net/"));
|
|
118
|
+
|
|
119
|
+
mServiceRule.unbindService();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Test(timeout = 5000)
|
|
123
|
+
public void testShouldNotBeRunningAfterConfigure() throws TimeoutException, InterruptedException {
|
|
124
|
+
assertThat(proxy.isStarted(), is(false));
|
|
125
|
+
assertThat(proxy.isRunning(), is(false));
|
|
126
|
+
proxy.configure(Config.getDefault());
|
|
127
|
+
assertThat(proxy.isStarted(), is(false));
|
|
128
|
+
assertThat(proxy.isRunning(), is(false));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@Ignore
|
|
133
|
+
@Test(timeout = 5000)
|
|
134
|
+
public void testRegisterHeadlessTask() {
|
|
135
|
+
// TODO
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Ignore
|
|
139
|
+
@Test(timeout = 5000)
|
|
140
|
+
public void testStartHeadlessTask() {
|
|
141
|
+
// TODO
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@Ignore
|
|
145
|
+
@Test(timeout = 5000)
|
|
146
|
+
public void testExecuteProviderCommand() {
|
|
147
|
+
// TODO
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Ignore
|
|
151
|
+
@Test(timeout = 5000)
|
|
152
|
+
public void testStartForeground() {
|
|
153
|
+
// TODO
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@Ignore
|
|
157
|
+
@Test(timeout = 5000)
|
|
158
|
+
public void testStopForeground() {
|
|
159
|
+
// TODO
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.IntentFilter;
|
|
7
|
+
import android.location.Location;
|
|
8
|
+
import android.os.Bundle;
|
|
9
|
+
import android.os.IBinder;
|
|
10
|
+
import androidx.annotation.NonNull;
|
|
11
|
+
import androidx.annotation.Nullable;
|
|
12
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
13
|
+
import androidx.test.rule.ServiceTestRule;
|
|
14
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
15
|
+
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
16
|
+
|
|
17
|
+
import com.marianhello.bgloc.data.BackgroundLocation;
|
|
18
|
+
import com.marianhello.bgloc.provider.MockLocationProvider;
|
|
19
|
+
import com.marianhello.bgloc.provider.TestLocationProviderFactory;
|
|
20
|
+
import com.marianhello.bgloc.service.LocationServiceImpl;
|
|
21
|
+
import com.marianhello.bgloc.service.LocationServiceIntentBuilder;
|
|
22
|
+
import com.marianhello.bgloc.data.LocationTransform;
|
|
23
|
+
|
|
24
|
+
import org.junit.After;
|
|
25
|
+
import org.junit.Before;
|
|
26
|
+
import org.junit.Rule;
|
|
27
|
+
import org.junit.Test;
|
|
28
|
+
import org.junit.runner.RunWith;
|
|
29
|
+
|
|
30
|
+
import java.util.Arrays;
|
|
31
|
+
import java.util.concurrent.CountDownLatch;
|
|
32
|
+
import java.util.concurrent.TimeUnit;
|
|
33
|
+
import java.util.concurrent.TimeoutException;
|
|
34
|
+
|
|
35
|
+
import static org.hamcrest.core.Is.is;
|
|
36
|
+
import static org.hamcrest.core.Is.isA;
|
|
37
|
+
import static org.hamcrest.core.IsEqual.equalTo;
|
|
38
|
+
import static org.hamcrest.core.IsInstanceOf.any;
|
|
39
|
+
import static org.junit.Assert.assertThat;
|
|
40
|
+
|
|
41
|
+
@RunWith(AndroidJUnit4.class)
|
|
42
|
+
public class LocationServiceTest {
|
|
43
|
+
|
|
44
|
+
@Rule
|
|
45
|
+
public final ServiceTestRule mServiceRule = new ServiceTestRule();
|
|
46
|
+
|
|
47
|
+
private LocationServiceImpl mService;
|
|
48
|
+
private TestLocationProviderFactory mLocationProviderFactory = new TestLocationProviderFactory();
|
|
49
|
+
|
|
50
|
+
@Before
|
|
51
|
+
public void setUp() {
|
|
52
|
+
mLocationProviderFactory.setProvider(new MockLocationProvider());
|
|
53
|
+
LocationServiceImpl.setLocationProviderFactory(mLocationProviderFactory);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
Context context = InstrumentationRegistry.getTargetContext();
|
|
57
|
+
// Create the mService Intent.
|
|
58
|
+
Intent serviceIntent = new Intent(context, LocationServiceImpl.class);
|
|
59
|
+
// Bind the mService and grab a reference to the binder.
|
|
60
|
+
IBinder binder = mServiceRule.bindService(serviceIntent);
|
|
61
|
+
// Get the reference to the mService, or you can call
|
|
62
|
+
// public methods on the binder directly.
|
|
63
|
+
mService = ((LocationServiceImpl.LocalBinder) binder).getService();
|
|
64
|
+
} catch (TimeoutException e) {
|
|
65
|
+
throw new RuntimeException(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@After
|
|
70
|
+
public void tearDown() {
|
|
71
|
+
LocationServiceImpl.setLocationProviderFactory(null);
|
|
72
|
+
LocationServiceImpl.setLocationTransform(null);
|
|
73
|
+
mService.stop();
|
|
74
|
+
mServiceRule.unbindService();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Test(timeout = 5000)
|
|
78
|
+
public void testWithStartedService() throws TimeoutException, InterruptedException {
|
|
79
|
+
final Context context = InstrumentationRegistry.getTargetContext();
|
|
80
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
|
81
|
+
|
|
82
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
83
|
+
@Override
|
|
84
|
+
public void onReceive(Context context, Intent intent) {
|
|
85
|
+
Bundle bundle = intent.getExtras();
|
|
86
|
+
int action = bundle.getInt("action");
|
|
87
|
+
|
|
88
|
+
if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) {
|
|
89
|
+
latch.countDown();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
LocalBroadcastManager.getInstance(context)
|
|
94
|
+
.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
//assertThat(mService.isBound(), is(false));
|
|
98
|
+
assertThat(mService.isRunning(), is(false));
|
|
99
|
+
Intent intent = LocationServiceIntentBuilder
|
|
100
|
+
.getInstance(context)
|
|
101
|
+
.setCommand(0)
|
|
102
|
+
.build();
|
|
103
|
+
mServiceRule.startService(intent);
|
|
104
|
+
|
|
105
|
+
latch.await(5, TimeUnit.SECONDS);
|
|
106
|
+
assertThat(mService.isRunning(), is(true));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Test(timeout = 5000)
|
|
110
|
+
public void testWithBoundService() {
|
|
111
|
+
// Verify that the mService is working correctly.
|
|
112
|
+
assertThat(mService.isRunning(), is(false));
|
|
113
|
+
assertThat(mService.isBound(), is(true));
|
|
114
|
+
assertThat(mService.getConfig(), is(any(Config.class)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Test(timeout = 5000)
|
|
118
|
+
public void testStartStop() {
|
|
119
|
+
assertThat(mService.isRunning(), is(false));
|
|
120
|
+
mService.start();
|
|
121
|
+
assertThat(mService.isRunning(), is(true));
|
|
122
|
+
mService.stop();
|
|
123
|
+
assertThat(mService.isRunning(), is(false));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Test(timeout = 5000)
|
|
127
|
+
public void testOnLocation() throws InterruptedException {
|
|
128
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
|
129
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
130
|
+
@Override
|
|
131
|
+
public void onReceive(Context context, Intent intent) {
|
|
132
|
+
Bundle bundle = intent.getExtras();
|
|
133
|
+
int action = bundle.getInt("action");
|
|
134
|
+
|
|
135
|
+
if (action == LocationServiceImpl.MSG_ON_LOCATION) {
|
|
136
|
+
bundle.setClassLoader(LocationServiceImpl.class.getClassLoader());
|
|
137
|
+
BackgroundLocation location = bundle.getParcelable("payload");
|
|
138
|
+
|
|
139
|
+
assertThat(location, isA(BackgroundLocation.class));
|
|
140
|
+
assertThat(location.getAltitude(), equalTo(666.0));
|
|
141
|
+
latch.countDown();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
|
|
147
|
+
lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
148
|
+
|
|
149
|
+
mService.start();
|
|
150
|
+
BackgroundLocation location = new BackgroundLocation();
|
|
151
|
+
location.setAltitude(666.0);
|
|
152
|
+
mService.onLocation(location);
|
|
153
|
+
|
|
154
|
+
latch.await();
|
|
155
|
+
lbm.unregisterReceiver(serviceBroadcastReceiver);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@Test(timeout = 5000)
|
|
159
|
+
public void testOnLocationOnStoppedService() throws InterruptedException {
|
|
160
|
+
final CountDownLatch latch = new CountDownLatch(3);
|
|
161
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
162
|
+
@Override
|
|
163
|
+
public void onReceive(Context context, Intent intent) {
|
|
164
|
+
Bundle bundle = intent.getExtras();
|
|
165
|
+
int action = bundle.getInt("action");
|
|
166
|
+
|
|
167
|
+
if (action == LocationServiceImpl.MSG_ON_SERVICE_STARTED) {
|
|
168
|
+
latch.countDown();
|
|
169
|
+
mService.stop();
|
|
170
|
+
//mService.onDestroy();
|
|
171
|
+
}
|
|
172
|
+
if (action == LocationServiceImpl.MSG_ON_SERVICE_STOPPED) {
|
|
173
|
+
latch.countDown();
|
|
174
|
+
mService.onLocation(new BackgroundLocation());
|
|
175
|
+
}
|
|
176
|
+
if (action == LocationServiceImpl.MSG_ON_LOCATION) {
|
|
177
|
+
latch.countDown();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
|
|
183
|
+
lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
184
|
+
|
|
185
|
+
Config config = Config.getDefault();
|
|
186
|
+
config.setStartForeground(false);
|
|
187
|
+
|
|
188
|
+
MockLocationProvider provider = new MockLocationProvider();
|
|
189
|
+
Location location = new Location("gps");
|
|
190
|
+
location.setProvider("mock");
|
|
191
|
+
location.setElapsedRealtimeNanos(2000000000L);
|
|
192
|
+
location.setAltitude(100);
|
|
193
|
+
location.setLatitude(49);
|
|
194
|
+
location.setLongitude(5);
|
|
195
|
+
location.setAccuracy(105);
|
|
196
|
+
location.setSpeed(50);
|
|
197
|
+
location.setBearing(1);
|
|
198
|
+
|
|
199
|
+
provider.setMockLocations(Arrays.asList(location));
|
|
200
|
+
mLocationProviderFactory.setProvider(provider);
|
|
201
|
+
|
|
202
|
+
mService.setLocationProviderFactory(mLocationProviderFactory);
|
|
203
|
+
mService.configure(config);
|
|
204
|
+
mService.start();
|
|
205
|
+
|
|
206
|
+
latch.await();
|
|
207
|
+
lbm.unregisterReceiver(serviceBroadcastReceiver);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@Test(timeout = 5000)
|
|
211
|
+
public void testTransform() throws InterruptedException {
|
|
212
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
|
213
|
+
BroadcastReceiver serviceBroadcastReceiver = new BroadcastReceiver() {
|
|
214
|
+
@Override
|
|
215
|
+
public void onReceive(Context context, Intent intent) {
|
|
216
|
+
Bundle bundle = intent.getExtras();
|
|
217
|
+
int action = bundle.getInt("action");
|
|
218
|
+
|
|
219
|
+
if (action == LocationServiceImpl.MSG_ON_LOCATION) {
|
|
220
|
+
latch.countDown();
|
|
221
|
+
|
|
222
|
+
bundle.setClassLoader(LocationServiceImpl.class.getClassLoader());
|
|
223
|
+
BackgroundLocation location = (BackgroundLocation) bundle.getParcelable("payload");
|
|
224
|
+
|
|
225
|
+
assertThat(location.getAltitude(), equalTo(8848.0));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(InstrumentationRegistry.getTargetContext());
|
|
231
|
+
lbm.registerReceiver(serviceBroadcastReceiver, new IntentFilter(LocationServiceImpl.ACTION_BROADCAST));
|
|
232
|
+
|
|
233
|
+
LocationServiceImpl.setLocationTransform(new LocationTransform() {
|
|
234
|
+
@Nullable
|
|
235
|
+
@Override
|
|
236
|
+
public BackgroundLocation transformLocationBeforeCommit(@NonNull Context context, @NonNull BackgroundLocation location) {
|
|
237
|
+
location.setAltitude(8848.0);
|
|
238
|
+
return location;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
mService.onLocation(new BackgroundLocation());
|
|
243
|
+
latch.await();
|
|
244
|
+
lbm.unregisterReceiver(serviceBroadcastReceiver);
|
|
245
|
+
LocationServiceImpl.setLocationTransform(null);
|
|
246
|
+
}
|
|
247
|
+
}
|
package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
package com.marianhello.bgloc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.database.Cursor;
|
|
5
|
+
import android.database.sqlite.SQLiteDatabase;
|
|
6
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
7
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
8
|
+
import androidx.test.filters.SmallTest;
|
|
9
|
+
|
|
10
|
+
import com.marianhello.bgloc.data.HashMapLocationTemplate;
|
|
11
|
+
import com.marianhello.bgloc.data.LocationTemplate;
|
|
12
|
+
import com.marianhello.bgloc.data.LocationTemplateFactory;
|
|
13
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteConfigurationContract;
|
|
14
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteConfigurationDAO;
|
|
15
|
+
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
|
|
16
|
+
|
|
17
|
+
import org.json.JSONException;
|
|
18
|
+
import org.json.JSONObject;
|
|
19
|
+
import org.junit.Assert;
|
|
20
|
+
import org.junit.Before;
|
|
21
|
+
import org.junit.Test;
|
|
22
|
+
import org.junit.runner.RunWith;
|
|
23
|
+
|
|
24
|
+
import java.util.ArrayList;
|
|
25
|
+
import java.util.HashMap;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Created by finch on 13/07/16.
|
|
29
|
+
*/
|
|
30
|
+
@RunWith(AndroidJUnit4.class)
|
|
31
|
+
@SmallTest
|
|
32
|
+
public class SQLiteConfigurationDAOTest {
|
|
33
|
+
@Before
|
|
34
|
+
public void deleteDatabase() {
|
|
35
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
36
|
+
SQLiteOpenHelper.getHelper(ctx).close();
|
|
37
|
+
ctx.deleteDatabase(SQLiteOpenHelper.SQLITE_DATABASE_NAME);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
public void persistConfiguration() {
|
|
42
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
43
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
44
|
+
SQLiteConfigurationDAO dao = new SQLiteConfigurationDAO(db);
|
|
45
|
+
|
|
46
|
+
Config config = new Config();
|
|
47
|
+
config.setActivitiesInterval(1000);
|
|
48
|
+
config.setDesiredAccuracy(200);
|
|
49
|
+
config.setDistanceFilter(300);
|
|
50
|
+
config.setFastestInterval(5000);
|
|
51
|
+
config.setInterval(10000);
|
|
52
|
+
config.setLocationProvider(0);
|
|
53
|
+
config.setMaxLocations(15000);
|
|
54
|
+
config.setUrl("http://server:1234/locations");
|
|
55
|
+
config.setSyncUrl("http://server:1234/syncLocations");
|
|
56
|
+
config.setSyncThreshold(200);
|
|
57
|
+
config.setStopOnTerminate(false);
|
|
58
|
+
config.setStopOnStillActivity(false);
|
|
59
|
+
config.setStationaryRadius(50);
|
|
60
|
+
config.setStartOnBoot(true);
|
|
61
|
+
config.setStartForeground(true);
|
|
62
|
+
config.setSmallNotificationIcon("smallico");
|
|
63
|
+
config.setLargeNotificationIcon("largeico");
|
|
64
|
+
config.setNotificationTitle("test");
|
|
65
|
+
config.setNotificationText("in progress");
|
|
66
|
+
config.setNotificationIconColor("yellow");
|
|
67
|
+
config.setNotificationsEnabled(true);
|
|
68
|
+
|
|
69
|
+
dao.persistConfiguration(config);
|
|
70
|
+
dao.persistConfiguration(config); // try once more
|
|
71
|
+
|
|
72
|
+
Cursor cursor = db.query(SQLiteConfigurationContract.ConfigurationEntry.TABLE_NAME, null, null, null, null, null, null);
|
|
73
|
+
Assert.assertEquals(1, cursor.getCount());
|
|
74
|
+
cursor.close();
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
Config storedConfig = dao.retrieveConfiguration();
|
|
78
|
+
Assert.assertEquals(1000, storedConfig.getActivitiesInterval().intValue());
|
|
79
|
+
Assert.assertEquals(200, storedConfig.getDesiredAccuracy().intValue());
|
|
80
|
+
Assert.assertEquals(300, storedConfig.getDistanceFilter().intValue());
|
|
81
|
+
Assert.assertEquals(5000, storedConfig.getFastestInterval().intValue());
|
|
82
|
+
Assert.assertEquals(10000, storedConfig.getInterval().intValue());
|
|
83
|
+
Assert.assertEquals(0, storedConfig.getLocationProvider().intValue());
|
|
84
|
+
Assert.assertEquals(15000, storedConfig.getMaxLocations().intValue());
|
|
85
|
+
Assert.assertEquals("http://server:1234/locations", storedConfig.getUrl());
|
|
86
|
+
Assert.assertEquals("http://server:1234/syncLocations", storedConfig.getSyncUrl());
|
|
87
|
+
Assert.assertEquals(200, storedConfig.getSyncThreshold().intValue());
|
|
88
|
+
Assert.assertEquals(Boolean.FALSE, storedConfig.getStopOnTerminate());
|
|
89
|
+
Assert.assertEquals(Boolean.FALSE, storedConfig.getStopOnStillActivity());
|
|
90
|
+
Assert.assertEquals(50, storedConfig.getStationaryRadius(), 0);
|
|
91
|
+
Assert.assertEquals(Boolean.TRUE, storedConfig.getStartOnBoot());
|
|
92
|
+
Assert.assertEquals(Boolean.TRUE, storedConfig.getStartForeground());
|
|
93
|
+
Assert.assertEquals("smallico", storedConfig.getSmallNotificationIcon());
|
|
94
|
+
Assert.assertEquals("largeico", storedConfig.getLargeNotificationIcon());
|
|
95
|
+
Assert.assertEquals("test", storedConfig.getNotificationTitle());
|
|
96
|
+
Assert.assertEquals("in progress", storedConfig.getNotificationText());
|
|
97
|
+
Assert.assertEquals("yellow", storedConfig.getNotificationIconColor());
|
|
98
|
+
|
|
99
|
+
} catch (JSONException e) {
|
|
100
|
+
Assert.fail(e.getMessage());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Test
|
|
105
|
+
public void persistConfigurationWithArrayListTemplate() {
|
|
106
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
107
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
108
|
+
SQLiteConfigurationDAO dao = new SQLiteConfigurationDAO(db);
|
|
109
|
+
|
|
110
|
+
Config config = Config.getDefault();
|
|
111
|
+
ArrayList props = new ArrayList();
|
|
112
|
+
props.add("@id");
|
|
113
|
+
props.add("@provider");
|
|
114
|
+
props.add("@time");
|
|
115
|
+
props.add("@altitude");
|
|
116
|
+
props.add("@latitude");
|
|
117
|
+
props.add("@longitude");
|
|
118
|
+
props.add("foo");
|
|
119
|
+
props.add("@locationProvider");
|
|
120
|
+
props.add("@accuracy");
|
|
121
|
+
props.add("@speed");
|
|
122
|
+
props.add("@bearing");
|
|
123
|
+
|
|
124
|
+
config.setTemplate(LocationTemplateFactory.fromArrayList(props));
|
|
125
|
+
dao.persistConfiguration(config);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
Config storedConfig = dao.retrieveConfiguration();
|
|
129
|
+
Assert.assertEquals(config.getTemplate(), storedConfig.getTemplate());
|
|
130
|
+
} catch (JSONException e) {
|
|
131
|
+
Assert.fail(e.getMessage());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Test
|
|
136
|
+
public void persistConfigurationWithHashMapTemplate() {
|
|
137
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
138
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
139
|
+
SQLiteConfigurationDAO dao = new SQLiteConfigurationDAO(db);
|
|
140
|
+
|
|
141
|
+
Config config = Config.getDefault();
|
|
142
|
+
HashMap props = new HashMap<String, String>();
|
|
143
|
+
props.put("@id", "Id");
|
|
144
|
+
props.put("@provider", "Provider");
|
|
145
|
+
props.put("@time", "Time");
|
|
146
|
+
props.put("@altitude", "Altitude");
|
|
147
|
+
props.put("@latitude", "Latitude");
|
|
148
|
+
props.put("@longitude", "Longitude");
|
|
149
|
+
props.put("Bar", "Foo");
|
|
150
|
+
props.put("@locationProvider", "LocationProvider");
|
|
151
|
+
props.put("@accuracy", "Accuracy");
|
|
152
|
+
props.put("@speed", "Speed");
|
|
153
|
+
props.put("@bearing", "Bearing");
|
|
154
|
+
|
|
155
|
+
config.setTemplate(new HashMapLocationTemplate(props));
|
|
156
|
+
dao.persistConfiguration(config);
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
Config storedConfig = dao.retrieveConfiguration();
|
|
160
|
+
Assert.assertEquals(config.getTemplate(), storedConfig.getTemplate());
|
|
161
|
+
} catch (JSONException e) {
|
|
162
|
+
Assert.fail(e.getMessage());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@Test
|
|
167
|
+
public void persistConfigurationWithComplexTemplate() throws JSONException {
|
|
168
|
+
Context ctx = InstrumentationRegistry.getTargetContext();
|
|
169
|
+
SQLiteDatabase db = new SQLiteOpenHelper(ctx).getWritableDatabase();
|
|
170
|
+
SQLiteConfigurationDAO dao = new SQLiteConfigurationDAO(db);
|
|
171
|
+
|
|
172
|
+
Config config = Config.getDefault();
|
|
173
|
+
JSONObject template = new JSONObject(
|
|
174
|
+
"{\"data\":{\"Id\":\"@id\"," +
|
|
175
|
+
"\"Provider\":\"@provider\"," +
|
|
176
|
+
"\"Time\":\"@time\"," +
|
|
177
|
+
"\"Altitude\":\"@altitude\"," +
|
|
178
|
+
"\"Latitude\":\"@latitude\"," +
|
|
179
|
+
"\"Longitude\":\"@longitude\"," +
|
|
180
|
+
"\"Foo\":\"bar\"," +
|
|
181
|
+
"\"LocationProvider\":\"@locationProvider\"," +
|
|
182
|
+
"\"Accuracy\":\"@accuracy\"," +
|
|
183
|
+
"\"Speed\":\"@speed\"," +
|
|
184
|
+
"\"Bearing\":\"@bearing\"}" +
|
|
185
|
+
"}"
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
LocationTemplate tpl = LocationTemplateFactory.fromJSON(template);
|
|
189
|
+
config.setTemplate(tpl);
|
|
190
|
+
dao.persistConfiguration(config);
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
Config storedConfig = dao.retrieveConfiguration();
|
|
194
|
+
Assert.assertEquals(config.getTemplate(), storedConfig.getTemplate());
|
|
195
|
+
} catch (JSONException e) {
|
|
196
|
+
Assert.fail(e.getMessage());
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|