@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.
Files changed (239) hide show
  1. package/.npmignore +23 -0
  2. package/CHANGELOG.md +787 -0
  3. package/CONTRIBUTORS.md +15 -0
  4. package/HISTORY.md +734 -0
  5. package/LICENSE +191 -0
  6. package/README.md +125 -0
  7. package/RELEASE.MD +5 -0
  8. package/android/CDVBackgroundGeolocation/src/main/AndroidManifest.xml +23 -0
  9. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
  10. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
  11. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
  12. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
  13. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
  14. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
  15. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
  16. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
  17. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
  18. package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
  19. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +148 -0
  20. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/PluginRegistry.java +25 -0
  21. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/headless/JsEvaluatorTaskRunner.java +53 -0
  22. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +603 -0
  23. package/android/CDVBackgroundGeolocation/src/main/res/values/strings.xml +4 -0
  24. package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +208 -0
  25. package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +45 -0
  26. package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +570 -0
  27. package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +76 -0
  28. package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +437 -0
  29. package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +95 -0
  30. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +159 -0
  31. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +161 -0
  32. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +247 -0
  33. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +200 -0
  34. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +457 -0
  35. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +96 -0
  36. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +225 -0
  37. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +46 -0
  38. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +14 -0
  39. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +50 -0
  40. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +17 -0
  41. package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +92 -0
  42. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +107 -0
  43. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +5 -0
  44. package/android/common/src/main/AndroidManifest.xml +72 -0
  45. package/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +523 -0
  46. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +59 -0
  47. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +652 -0
  48. package/android/common/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
  49. package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +224 -0
  50. package/android/common/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
  51. package/android/common/src/main/java/com/marianhello/bgloc/PluginDelegate.java +19 -0
  52. package/android/common/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
  53. package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +188 -0
  54. package/android/common/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
  55. package/android/common/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
  56. package/android/common/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
  57. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
  58. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +994 -0
  59. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
  60. package/android/common/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
  61. package/android/common/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
  62. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +22 -0
  63. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
  64. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +65 -0
  65. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
  66. package/android/common/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +395 -0
  67. package/android/common/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
  68. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +76 -0
  69. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +160 -0
  70. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +112 -0
  71. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +506 -0
  72. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +151 -0
  73. package/android/common/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
  74. package/android/common/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
  75. package/android/common/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
  76. package/android/common/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
  77. package/android/common/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
  78. package/android/common/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
  79. package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
  80. package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
  81. package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +171 -0
  82. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +282 -0
  83. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +610 -0
  84. package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
  85. package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
  86. package/android/common/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
  87. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +145 -0
  88. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
  89. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +749 -0
  90. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
  91. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
  92. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
  93. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +130 -0
  94. package/android/common/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
  95. package/android/common/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
  96. package/android/common/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
  97. package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +278 -0
  98. package/android/common/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
  99. package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +249 -0
  100. package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
  101. package/android/common/src/main/java/com/marianhello/logging/DBLogReader.java +203 -0
  102. package/android/common/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
  103. package/android/common/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
  104. package/android/common/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
  105. package/android/common/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
  106. package/android/common/src/main/java/com/marianhello/utils/Convert.java +56 -0
  107. package/android/common/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
  108. package/android/common/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
  109. package/android/common/src/main/java/org/apache/commons/io/Charsets.java +153 -0
  110. package/android/common/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
  111. package/android/common/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
  112. package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
  113. package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
  114. package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
  115. package/android/common/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
  116. package/android/common/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  117. package/android/common/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  118. package/android/common/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  119. package/android/common/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  120. package/android/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  121. package/android/common/src/main/res/values/strings.xml +4 -0
  122. package/android/common/src/main/res/xml/authenticator.xml +7 -0
  123. package/android/common/src/main/res/xml/syncadapter.xml +9 -0
  124. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +82 -0
  125. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +128 -0
  126. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +191 -0
  127. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +37 -0
  128. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +216 -0
  129. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +223 -0
  130. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +50 -0
  131. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +180 -0
  132. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +16 -0
  133. package/android/dependencies.gradle +13 -0
  134. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.h +41 -0
  135. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +526 -0
  136. package/ios/common/BackgroundGeolocation/CocoaLumberjack.h +1945 -0
  137. package/ios/common/BackgroundGeolocation/CocoaLumberjack.m +5255 -0
  138. package/ios/common/BackgroundGeolocation/FMDB.h +2357 -0
  139. package/ios/common/BackgroundGeolocation/FMDB.m +2672 -0
  140. package/ios/common/BackgroundGeolocation/FMDBLogger.h +42 -0
  141. package/ios/common/BackgroundGeolocation/FMDBLogger.m +264 -0
  142. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +41 -0
  143. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +68 -0
  144. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +33 -0
  145. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +178 -0
  146. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +1025 -0
  147. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +103 -0
  148. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +238 -0
  149. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +163 -0
  150. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +39 -0
  151. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +37 -0
  152. package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.h +51 -0
  153. package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.m +53 -0
  154. package/ios/common/BackgroundGeolocation/MAURActivity.h +23 -0
  155. package/ios/common/BackgroundGeolocation/MAURActivity.m +52 -0
  156. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.h +18 -0
  157. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +202 -0
  158. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +60 -0
  159. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +638 -0
  160. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +34 -0
  161. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +185 -0
  162. package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
  163. package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
  164. package/ios/common/BackgroundGeolocation/MAURConfig.h +74 -0
  165. package/ios/common/BackgroundGeolocation/MAURConfig.m +485 -0
  166. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +49 -0
  167. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +51 -0
  168. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
  169. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +514 -0
  170. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
  171. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +97 -0
  172. package/ios/common/BackgroundGeolocation/MAURLocation.h +59 -0
  173. package/ios/common/BackgroundGeolocation/MAURLocation.m +349 -0
  174. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +34 -0
  175. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +35 -0
  176. package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
  177. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +287 -0
  178. package/ios/common/BackgroundGeolocation/MAURLogReader.h +26 -0
  179. package/ios/common/BackgroundGeolocation/MAURLogReader.m +122 -0
  180. package/ios/common/BackgroundGeolocation/MAURLogging.h +19 -0
  181. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +40 -0
  182. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +250 -0
  183. package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
  184. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
  185. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +129 -0
  186. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
  187. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +278 -0
  188. package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
  189. package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
  190. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +38 -0
  191. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +380 -0
  192. package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
  193. package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
  194. package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
  195. package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
  196. package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
  197. package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
  198. package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +2 -0
  199. package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +21 -0
  200. package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +135 -0
  201. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +80 -0
  202. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +147 -0
  203. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +30 -0
  204. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +42 -0
  205. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +99 -0
  206. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +327 -0
  207. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +44 -0
  208. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +94 -0
  209. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +170 -0
  210. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +55 -0
  211. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +47 -0
  212. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +27 -0
  213. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +250 -0
  214. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +259 -0
  215. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +360 -0
  216. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +427 -0
  217. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +37 -0
  218. package/ios/common/BackgroundGeolocation.xcodeproj/project.pbxproj +760 -0
  219. package/ios/common/BackgroundGeolocationTests/Info.plist +24 -0
  220. package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +185 -0
  221. package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +161 -0
  222. package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +102 -0
  223. package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +216 -0
  224. package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +55 -0
  225. package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +43 -0
  226. package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +102 -0
  227. package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +41 -0
  228. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +240 -0
  229. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +84 -0
  230. package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +144 -0
  231. package/ios/common/CONTRIBUTORS.md +10 -0
  232. package/ios/common/LICENSE +191 -0
  233. package/ios/common/README.md +7 -0
  234. package/ios/common/scripts/xcode-refactor.js +184 -0
  235. package/package.json +44 -0
  236. package/plugin.xml +355 -0
  237. package/www/BackgroundGeolocation.d.ts +910 -0
  238. package/www/BackgroundGeolocation.js +247 -0
  239. package/www/radio.js +177 -0
@@ -0,0 +1,216 @@
1
+ package com.marianhello.backgroundgeolocation;
2
+
3
+ import com.marianhello.bgloc.Config;
4
+ import com.marianhello.bgloc.data.BackgroundLocation;
5
+ import com.marianhello.bgloc.data.HashMapLocationTemplate;
6
+ import com.marianhello.bgloc.data.LocationTemplate;
7
+ import com.marianhello.bgloc.data.LocationTemplateFactory;
8
+
9
+ import junit.framework.Assert;
10
+
11
+ import org.json.JSONArray;
12
+ import org.json.JSONException;
13
+ import org.json.JSONObject;
14
+ import org.junit.Test;
15
+
16
+ import java.util.HashMap;
17
+
18
+ /**
19
+ * Created by finch on 9.12.2017.
20
+ */
21
+
22
+ public class HashMapLocationTemplateTest {
23
+ @Test
24
+ public void testObjectTemplateToString() {
25
+ HashMap props = new HashMap();
26
+ props.put("foo", "bar");
27
+ props.put("pretzels", 123);
28
+ HashMapLocationTemplate tpl = new HashMapLocationTemplate(props);
29
+
30
+ Assert.assertEquals("{\"foo\":\"bar\",\"pretzels\":123}" , tpl.toString());
31
+ }
32
+
33
+ @Test
34
+ public void testLocationToJSONObject() throws JSONException {
35
+ BackgroundLocation location = new BackgroundLocation();
36
+ location.setLocationId(11L);
37
+ location.setProvider("test");
38
+ location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
39
+ location.setAltitude(100);
40
+ location.setLatitude(49);
41
+ location.setLongitude(5);
42
+ location.setLocationProvider(1);
43
+ location.setAccuracy(105);
44
+ location.setSpeed(50);
45
+ location.setBearing(1);
46
+
47
+ HashMap map = new HashMap<String, String>();
48
+ map.put("Id", "@id");
49
+ map.put("Provider", "@provider");
50
+ map.put("Time", "@time");
51
+ map.put("Altitude", "@altitude");
52
+ map.put("Latitude", "@latitude");
53
+ map.put("Longitude", "@longitude");
54
+ map.put("Foo", "bar");
55
+ map.put("LocationProvider", "@locationProvider");
56
+ map.put("Accuracy", "@accuracy");
57
+ map.put("Speed", "@speed");
58
+ map.put("Bearing", "@bearing");
59
+ map.put("Pretzels", 123);
60
+
61
+ LocationTemplate tpl = new HashMapLocationTemplate(map);
62
+ JSONObject expected = (JSONObject) tpl.locationToJson(location);
63
+
64
+ Assert.assertEquals(expected.get("Id"), location.getLocationId());
65
+ Assert.assertEquals(expected.get("Provider"), location.getProvider());
66
+ Assert.assertEquals(expected.get("Time"), location.getTime());
67
+ Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
68
+ Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
69
+ Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
70
+ Assert.assertEquals(expected.get("Foo"), "bar");
71
+ Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
72
+ Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
73
+ Assert.assertEquals(expected.get("Speed"), location.getSpeed());
74
+ Assert.assertEquals(expected.get("Bearing"), location.getBearing());
75
+ Assert.assertEquals(expected.get("Pretzels"), 123);
76
+ }
77
+
78
+ @Test
79
+ public void testLocationToJSONObjectFactory() throws JSONException {
80
+ BackgroundLocation location = new BackgroundLocation();
81
+ location.setLocationId(11L);
82
+ location.setProvider("test");
83
+ location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
84
+ location.setAltitude(100);
85
+ location.setLatitude(49);
86
+ location.setLongitude(5);
87
+ location.setLocationProvider(1);
88
+ location.setAccuracy(105);
89
+ location.setSpeed(50);
90
+ location.setBearing(1);
91
+
92
+ HashMap map = new HashMap();
93
+ map.put("Id", "@id");
94
+ map.put("Provider", "@provider");
95
+ map.put("Time", "@time");
96
+ map.put("Altitude", "@altitude");
97
+ map.put("Latitude", "@latitude");
98
+ map.put("Longitude", "@longitude");
99
+ map.put("Foo", "bar");
100
+ map.put("LocationProvider", "@locationProvider");
101
+ map.put("Accuracy", "@accuracy");
102
+ map.put("Speed", "@speed");
103
+ map.put("Bearing", "@bearing");
104
+ map.put("Pretzels", 123);
105
+
106
+ JSONObject json = new JSONObject(map);
107
+ LocationTemplate tpl = LocationTemplateFactory.fromJSON(json);
108
+
109
+ JSONObject expected = (JSONObject) tpl.locationToJson(location);
110
+
111
+ Assert.assertEquals(expected.get("Id"), location.getLocationId());
112
+ Assert.assertEquals(expected.get("Provider"), location.getProvider());
113
+ Assert.assertEquals(expected.get("Time"), location.getTime());
114
+ Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
115
+ Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
116
+ Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
117
+ Assert.assertEquals(expected.get("Foo"), "bar");
118
+ Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
119
+ Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
120
+ Assert.assertEquals(expected.get("Speed"), location.getSpeed());
121
+ Assert.assertEquals(expected.get("Bearing"), location.getBearing());
122
+ }
123
+
124
+ @Test
125
+ public void testNullToString() {
126
+ HashMapLocationTemplate tpl = new HashMapLocationTemplate((HashMap)null);
127
+ Assert.assertEquals("null", tpl.toString());
128
+ }
129
+
130
+ @Test
131
+ public void testNestedObjectTemplate() throws JSONException {
132
+ BackgroundLocation location = new BackgroundLocation();
133
+ location.setLocationId(11L);
134
+ location.setProvider("test");
135
+ location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
136
+ location.setAltitude(100);
137
+ location.setLatitude(49);
138
+ location.setLongitude(5);
139
+ location.setLocationProvider(1);
140
+ location.setAccuracy(105);
141
+ location.setSpeed(50);
142
+ location.setBearing(1);
143
+
144
+ JSONObject template = new JSONObject(
145
+ "{\"data\":{\"Id\":\"@id\"," +
146
+ "\"Provider\":\"@provider\"," +
147
+ "\"Time\":\"@time\"," +
148
+ "\"Altitude\":\"@altitude\"," +
149
+ "\"Latitude\":\"@latitude\"," +
150
+ "\"Longitude\":\"@longitude\"," +
151
+ "\"Foo\":\"bar\"," +
152
+ "\"LocationProvider\":\"@locationProvider\"," +
153
+ "\"Accuracy\":\"@accuracy\"," +
154
+ "\"Speed\":\"@speed\"," +
155
+ "\"Bearing\":\"@bearing\"}" +
156
+ "}"
157
+ );
158
+ LocationTemplate tpl = LocationTemplateFactory.fromJSON(template);
159
+
160
+ JSONObject json = ((JSONObject) tpl.locationToJson(location));
161
+ JSONObject expected = json.getJSONObject("data");
162
+
163
+ Assert.assertEquals(expected.get("Id"), location.getLocationId());
164
+ Assert.assertEquals(expected.get("Provider"), location.getProvider());
165
+ Assert.assertEquals(expected.get("Time"), location.getTime());
166
+ Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
167
+ Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
168
+ Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
169
+ Assert.assertEquals(expected.get("Foo"), "bar");
170
+ Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
171
+ Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
172
+ Assert.assertEquals(expected.get("Speed"), location.getSpeed());
173
+ Assert.assertEquals(expected.get("Bearing"), location.getBearing());
174
+ }
175
+
176
+
177
+ @Test
178
+ public void testNestedArrayTemplate() throws JSONException {
179
+ BackgroundLocation location = new BackgroundLocation();
180
+ location.setLocationId(11L);
181
+ location.setProvider("test");
182
+ location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
183
+ location.setAltitude(100);
184
+ location.setLatitude(49);
185
+ location.setLongitude(5);
186
+ location.setLocationProvider(1);
187
+ location.setAccuracy(105);
188
+ location.setSpeed(50);
189
+ location.setBearing(1);
190
+
191
+ JSONObject template = new JSONObject(
192
+ "{\"data\":[\"@id\",\"@provider\",\"@time\",\"@altitude\",\"@latitude\"," +
193
+ "\"@longitude\",\"foo\",\"@locationProvider\",\"@accuracy\",\"@speed\"," +
194
+ "\"@bearing\",123]}"
195
+ );
196
+ LocationTemplate tpl = LocationTemplateFactory.fromJSON(template);
197
+
198
+ JSONObject json = ((JSONObject) tpl.locationToJson(location));
199
+ JSONArray expected = json.getJSONArray("data");
200
+
201
+ Assert.assertEquals(expected.get(0), location.getLocationId());
202
+ Assert.assertEquals(expected.get(1), location.getProvider());
203
+ Assert.assertEquals(expected.get(2), location.getTime());
204
+ Assert.assertEquals(expected.get(3), location.getAltitude());
205
+ Assert.assertEquals(expected.get(4), location.getLatitude());
206
+ Assert.assertEquals(expected.get(5), location.getLongitude());
207
+ Assert.assertEquals(expected.get(6), "foo");
208
+ Assert.assertEquals(expected.get(7), location.getLocationProvider());
209
+ Assert.assertEquals(expected.get(8), location.getAccuracy());
210
+ Assert.assertEquals(expected.get(9), location.getSpeed());
211
+ Assert.assertEquals(expected.get(10), location.getBearing());
212
+ Assert.assertEquals(expected.get(11), 123);
213
+
214
+ }
215
+
216
+ }
@@ -0,0 +1,223 @@
1
+ package com.marianhello.backgroundgeolocation;
2
+
3
+ import android.os.Build;
4
+
5
+ import com.marianhello.bgloc.HttpPostService;
6
+ import com.marianhello.bgloc.HttpPostService.UploadingProgressListener;
7
+
8
+ import org.json.JSONArray;
9
+ import org.json.JSONObject;
10
+ import org.junit.After;
11
+ import org.junit.Before;
12
+ import org.junit.Rule;
13
+ import org.junit.Test;
14
+ import org.junit.rules.ExpectedException;
15
+ import org.junit.runner.RunWith;
16
+ import org.mockito.InOrder;
17
+ import org.mockito.Mock;
18
+ import org.mockito.MockitoAnnotations;
19
+ import org.robolectric.RobolectricTestRunner;
20
+
21
+ import java.io.ByteArrayInputStream;
22
+ import java.io.ByteArrayOutputStream;
23
+ import java.io.File;
24
+ import java.io.IOException;
25
+ import java.io.InputStream;
26
+ import java.net.HttpURLConnection;
27
+ import java.net.MalformedURLException;
28
+ import java.net.UnknownHostException;
29
+ import java.util.HashMap;
30
+ import java.util.Random;
31
+
32
+ import static org.hamcrest.core.Is.is;
33
+ import static org.junit.Assert.assertThat;
34
+ import static org.mockito.Mockito.inOrder;
35
+ import static org.mockito.Mockito.mock;
36
+ import static org.mockito.Mockito.verify;
37
+ import static org.mockito.Mockito.when;
38
+
39
+ @RunWith(RobolectricTestRunner.class)
40
+ public class HttpPostServiceTest {
41
+ @Mock
42
+ HttpURLConnection mockHttpURLConnection;
43
+
44
+ private static final int DEFAULT_SDK_INT = Build.VERSION.SDK_INT;
45
+
46
+ @Rule
47
+ public final ExpectedException exception = ExpectedException.none();
48
+
49
+ @Before
50
+ public void setUp() {
51
+ MockitoAnnotations.initMocks(this);
52
+ }
53
+
54
+ @After
55
+ public void cleanUp() {
56
+ try {
57
+ TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), DEFAULT_SDK_INT);
58
+ } catch (Exception e) {
59
+ e.printStackTrace();
60
+ }
61
+ }
62
+
63
+ @Test
64
+ public void testPostJSONThrowsMalformedURLException() throws IOException {
65
+ exception.expect(MalformedURLException.class);
66
+ HttpPostService.postJSON(null, (JSONObject) null, null);
67
+ }
68
+
69
+ @Test
70
+ public void testPostJSONThrowsUnknownHostException() throws IOException {
71
+ exception.expect(UnknownHostException.class);
72
+ HttpPostService.postJSON("http://unknown/json", (JSONObject) null, null);
73
+ }
74
+
75
+ @Test
76
+ public void testPostJSONResult() throws IOException {
77
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
78
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
79
+ when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
80
+
81
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
82
+ assertThat(service.postJSON((JSONObject) new JSONObject(), null), is(200));
83
+ verify(mockHttpURLConnection).setRequestMethod("POST");
84
+ }
85
+
86
+
87
+ @Test
88
+ public void testPostJSONShouldPostHeaders() throws IOException {
89
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
90
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
91
+
92
+ HashMap headers = new HashMap();
93
+ headers.put("foo", "bar");
94
+
95
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
96
+ service.postJSON((JSONObject) null, headers);
97
+ verify(mockHttpURLConnection).setRequestMethod("POST");
98
+ verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
99
+ verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
100
+ }
101
+
102
+ @Test
103
+ public void testPostJSONObject() throws IOException {
104
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
105
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
106
+
107
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
108
+ service.postJSON(new JSONObject(), null);
109
+ verify(mockHttpURLConnection).setRequestMethod("POST");
110
+ assertThat(outputStream.toString(), is("{}"));
111
+ }
112
+
113
+ @Test
114
+ public void testPostJSONArray() throws IOException {
115
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
116
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
117
+
118
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
119
+ service.postJSON(new JSONArray(), null);
120
+ verify(mockHttpURLConnection).setRequestMethod("POST");
121
+ assertThat(outputStream.toString(), is("[]"));
122
+ }
123
+
124
+ @Test
125
+ public void testPostJSONObjectNull() throws IOException {
126
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
127
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
128
+
129
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
130
+ service.postJSON((JSONObject) null, null);
131
+ verify(mockHttpURLConnection).setRequestMethod("POST");
132
+ assertThat(outputStream.toString(), is("null"));
133
+ }
134
+
135
+ @Test
136
+ public void testPostJSONArrayNull() throws IOException {
137
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
138
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
139
+
140
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
141
+ service.postJSON((JSONArray) null, null);
142
+ verify(mockHttpURLConnection).setRequestMethod("POST");
143
+ assertThat(outputStream.toString(), is("null"));
144
+ }
145
+
146
+ @Test
147
+ public void testPostString() throws IOException {
148
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
149
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
150
+
151
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
152
+ service.postJSONString("test", null);
153
+ verify(mockHttpURLConnection).setRequestMethod("POST");
154
+ verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
155
+ assertThat(outputStream.toString(), is("test"));
156
+ }
157
+
158
+ @Test
159
+ public void testPostStream() throws Exception {
160
+ TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.KITKAT);
161
+
162
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
163
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
164
+ when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
165
+
166
+ String body = "test";
167
+ InputStream inputStream = new ByteArrayInputStream(body.getBytes());
168
+ HashMap headers = new HashMap();
169
+ headers.put("foo", "bar");
170
+
171
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
172
+ assertThat(service.postJSONFile(inputStream, headers, null), is(200));
173
+ verify(mockHttpURLConnection).setRequestMethod("POST");
174
+ verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
175
+ verify(mockHttpURLConnection).setFixedLengthStreamingMode((long) body.length());
176
+ //verify(mockHttpURLConnection).setChunkedStreamingMode(0);
177
+ assertThat(outputStream.toString(), is("test"));
178
+ }
179
+
180
+ @Test
181
+ public void testJSONPostFile() throws Exception {
182
+ TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.KITKAT);
183
+
184
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
185
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
186
+ when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
187
+
188
+ File file = new File("./README.md");
189
+
190
+ HashMap headers = new HashMap();
191
+ headers.put("foo", "bar");
192
+
193
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
194
+ assertThat(service.postJSONFile(file, headers, null), is(200));
195
+ verify(mockHttpURLConnection).setRequestMethod("POST");
196
+ verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
197
+ verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
198
+ verify(mockHttpURLConnection).setFixedLengthStreamingMode((long) file.length());
199
+ //verify(mockHttpURLConnection).setChunkedStreamingMode(0);
200
+ }
201
+
202
+ @Test
203
+ public void testJSONPostFileProgressListener() throws IOException {
204
+ HttpPostService service = new HttpPostService(mockHttpURLConnection);
205
+ UploadingProgressListener mockListener = mock(UploadingProgressListener.class);
206
+
207
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
208
+ when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
209
+
210
+ int bodySize = HttpPostService.BUFFER_SIZE * 5;
211
+ byte[] body = new byte[bodySize];
212
+ new Random().nextBytes(body);
213
+ InputStream inputStream = new ByteArrayInputStream(body);
214
+
215
+ service.postJSONFile(inputStream, null, mockListener);
216
+ InOrder inOrder = inOrder(mockListener);
217
+ inOrder.verify(mockListener).onProgress(20);
218
+ inOrder.verify(mockListener).onProgress(40);
219
+ inOrder.verify(mockListener).onProgress(60);
220
+ inOrder.verify(mockListener).onProgress(80);
221
+ inOrder.verify(mockListener).onProgress(100);
222
+ }
223
+ }
@@ -0,0 +1,50 @@
1
+ package com.marianhello.backgroundgeolocation;
2
+
3
+ import com.marianhello.bgloc.data.LocationTemplate;
4
+ import com.marianhello.bgloc.data.LocationTemplateFactory;
5
+
6
+ import junit.framework.Assert;
7
+
8
+ import org.json.JSONArray;
9
+ import org.json.JSONException;
10
+ import org.json.JSONObject;
11
+ import org.json.JSONTokener;
12
+ import org.junit.Test;
13
+
14
+ /**
15
+ * Created by finch on 9.12.2017.
16
+ */
17
+
18
+ public class LocationTemplateFactoryTest {
19
+ @Test
20
+ public void testTemplateFromJsonArray() {
21
+ String jsonString = "[\"foo\",\"bar\",123]";
22
+
23
+ try {
24
+ LocationTemplate tpl = LocationTemplateFactory.fromJSONString(jsonString);
25
+ JSONArray expected = new JSONArray();
26
+ expected.put("foo");
27
+ expected.put("bar");
28
+ expected.put(123);
29
+ Assert.assertEquals(expected.toString(), tpl.toString());
30
+ } catch (JSONException e) {
31
+ org.junit.Assert.fail(e.getMessage());
32
+ }
33
+ }
34
+
35
+ @Test
36
+ public void testTemplateFromJsonObject() {
37
+ String jsonString = "{\"foo\":\"bar\",\"pretzels\":123}";
38
+
39
+ try {
40
+ LocationTemplate tpl = LocationTemplateFactory.fromJSONString(jsonString);
41
+ JSONObject expected = new JSONObject();
42
+ expected.put("foo", "bar");
43
+ expected.put("pretzels", 123);
44
+ Assert.assertEquals(expected.toString(), tpl.toString());
45
+ } catch (JSONException e) {
46
+ org.junit.Assert.fail(e.getMessage());
47
+ }
48
+ }
49
+
50
+ }
@@ -0,0 +1,180 @@
1
+ package com.marianhello.backgroundgeolocation;
2
+
3
+ import com.marianhello.bgloc.Config;
4
+ import com.marianhello.bgloc.ConnectivityListener;
5
+ import com.marianhello.bgloc.PostLocationTask;
6
+ import com.marianhello.bgloc.PostLocationTask.PostLocationTaskListener;
7
+ import com.marianhello.bgloc.data.BackgroundLocation;
8
+ import com.marianhello.bgloc.data.LocationDAO;
9
+
10
+ import org.junit.After;
11
+ import org.junit.Before;
12
+ import org.junit.BeforeClass;
13
+ import org.junit.Ignore;
14
+ import org.junit.Rule;
15
+ import org.junit.Test;
16
+ import org.junit.rules.ExpectedException;
17
+ import org.junit.runner.RunWith;
18
+ import org.mockito.MockitoAnnotations;
19
+ import org.robolectric.RobolectricTestRunner;
20
+
21
+ import java.io.IOException;
22
+ import java.net.HttpURLConnection;
23
+ import java.net.ProtocolException;
24
+ import java.net.URL;
25
+ import java.net.URLConnection;
26
+ import java.net.URLStreamHandler;
27
+ import java.net.URLStreamHandlerFactory;
28
+ import java.util.concurrent.RejectedExecutionException;
29
+
30
+ import static org.mockito.Mockito.mock;
31
+ import static org.mockito.Mockito.reset;
32
+ import static org.mockito.Mockito.times;
33
+ import static org.mockito.Mockito.verify;
34
+
35
+ /**
36
+ * Test inspired by
37
+ * https://github.com/google/agera/blob/master/extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
38
+ */
39
+ @RunWith(RobolectricTestRunner.class)
40
+ public class PostLocationTaskTest {
41
+ private static final String TEST_PROTOCOL = "httptest";
42
+ private static final String SLOW_PROTOCOL = "httpslow";
43
+
44
+ private static HttpURLConnection mockHttpURLConnection;
45
+
46
+ private ConnectivityListener connectivityListener = new ConnectivityListener() {
47
+ @Override
48
+ public boolean hasConnectivity() {
49
+ return true;
50
+ }
51
+ };
52
+
53
+ @Rule
54
+ public final ExpectedException exception = ExpectedException.none();
55
+
56
+ @BeforeClass
57
+ public static void onlyOnce() throws Throwable {
58
+ mockHttpURLConnection = mock(HttpURLConnection.class);
59
+ URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
60
+ @Override
61
+ public URLStreamHandler createURLStreamHandler(final String s) {
62
+ if (TEST_PROTOCOL.equals(s)) {
63
+ return new URLStreamHandler() {
64
+ @Override
65
+ protected URLConnection openConnection(final URL url) throws IOException {
66
+ return mockHttpURLConnection;
67
+ }
68
+ };
69
+ }
70
+ if (SLOW_PROTOCOL.equals(s)) {
71
+ return new URLStreamHandler() {
72
+ @Override
73
+ protected URLConnection openConnection(final URL url) throws IOException {
74
+ try {
75
+ Thread.sleep(100);
76
+ } catch (InterruptedException e) { /* noop */ }
77
+ return mockHttpURLConnection;
78
+ }
79
+ };
80
+ }
81
+
82
+ return null;
83
+ }
84
+ });
85
+ }
86
+
87
+ @Before
88
+ public void setUp() {
89
+ MockitoAnnotations.initMocks(this);
90
+ }
91
+
92
+ @After
93
+ public void tearDown() {
94
+ reset(mockHttpURLConnection);
95
+ }
96
+
97
+ @Test
98
+ public void persistTask() throws ProtocolException, InterruptedException {
99
+ LocationDAO mockDAO = mock(LocationDAO.class);
100
+
101
+ PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
102
+ PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
103
+
104
+ Config config = Config.getDefault();
105
+ config.setUrl(TEST_PROTOCOL + "://localhost:3000/locations");
106
+ config.setSyncUrl(TEST_PROTOCOL + "://localhost:3000/sync");
107
+ task.setConfig(config);
108
+
109
+ for (int i = 0; i < 10; i++) {
110
+ task.add(new BackgroundLocation());
111
+ }
112
+
113
+ Thread.sleep(3000);
114
+ verify(mockHttpURLConnection, times(10)).setRequestMethod("POST");
115
+ }
116
+
117
+ @Test
118
+ public void persistTaskShouldRejectAfterShutdown() {
119
+ LocationDAO mockDAO = mock(LocationDAO.class);
120
+
121
+ PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
122
+ PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
123
+
124
+ Config config = Config.getDefault();
125
+ config.setUrl(TEST_PROTOCOL + "://localhost:3000/locations");
126
+ config.setSyncUrl(TEST_PROTOCOL + "://localhost:3000/sync");
127
+ task.setConfig(config);
128
+
129
+ for (int i = 0; i < 10; i++) {
130
+ task.add(new BackgroundLocation());
131
+ }
132
+
133
+ task.shutdown();
134
+ task.add(new BackgroundLocation());
135
+ }
136
+
137
+ @Test
138
+ public void persistTaskOnShutdown() throws ProtocolException, InterruptedException {
139
+ LocationDAO mockDAO = mock(LocationDAO.class);
140
+
141
+ PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
142
+ PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
143
+
144
+ Config config = Config.getDefault();
145
+ config.setUrl(SLOW_PROTOCOL + "://localhost:3000/locations");
146
+ config.setSyncUrl(SLOW_PROTOCOL + "://localhost:3000/sync");
147
+ task.setConfig(config);
148
+
149
+ for (int i = 0; i < 10; i++) {
150
+ task.add(new BackgroundLocation());
151
+ }
152
+
153
+ task.shutdown(600);
154
+
155
+ Thread.sleep(3000);
156
+ verify(mockHttpURLConnection, times(10)).setRequestMethod("POST");
157
+ }
158
+
159
+ @Test
160
+ public void persistTaskSetUnsyncedOnShutdown() throws InterruptedException {
161
+ LocationDAO mockDAO = mock(LocationDAO.class);
162
+
163
+ PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
164
+ PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
165
+
166
+ Config config = Config.getDefault();
167
+ config.setUrl(SLOW_PROTOCOL + "://localhost:3000/locations");
168
+ config.setSyncUrl(SLOW_PROTOCOL + "://localhost:3000/sync");
169
+ task.setConfig(config);
170
+
171
+ for (int i = 0; i < 10; i++) {
172
+ task.add(new BackgroundLocation());
173
+ }
174
+
175
+ task.shutdown(1);
176
+
177
+ Thread.sleep(3000);
178
+ verify(mockDAO).deleteUnpostedLocations();
179
+ }
180
+ }
@@ -0,0 +1,16 @@
1
+ package com.marianhello.backgroundgeolocation;
2
+
3
+ import java.lang.reflect.Field;
4
+ import java.lang.reflect.Modifier;
5
+
6
+ public class TestHelper {
7
+ static void setFinalStatic(Field field, Object newValue) throws Exception {
8
+ field.setAccessible(true);
9
+
10
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
11
+ modifiersField.setAccessible(true);
12
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
13
+
14
+ field.set(null, newValue);
15
+ }
16
+ }