@josuelmm/cordova-background-geolocation 4.2.3 → 4.5.2

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 (103) hide show
  1. package/.npmignore +11 -0
  2. package/CHANGELOG.md +261 -0
  3. package/README.md +306 -115
  4. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +34 -0
  5. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +61 -1
  6. package/android/common/src/main/AndroidManifest.xml +1 -1
  7. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +20 -3
  8. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +87 -1
  9. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +94 -0
  10. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
  11. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +6 -0
  12. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +5 -1
  13. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +32 -1
  14. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +12 -2
  15. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +33 -2
  16. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +15 -1
  17. package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +48 -1
  18. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +105 -6
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +336 -250
  20. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +69 -19
  21. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +246 -21
  22. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +5 -2
  23. package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +46 -13
  24. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +23 -1
  25. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +208 -70
  26. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +132 -5
  27. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +20 -0
  28. package/ios/common/BackgroundGeolocation/MAURConfig.h +7 -0
  29. package/ios/common/BackgroundGeolocation/MAURConfig.m +37 -2
  30. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +3 -0
  31. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +3 -1
  32. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +10 -1
  33. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +15 -1
  34. package/ios/common/BackgroundGeolocation/MAURLocation.h +12 -0
  35. package/ios/common/BackgroundGeolocation/MAURLocation.m +33 -4
  36. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +4 -0
  37. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +5 -1
  38. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +19 -1
  39. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +9 -0
  40. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +59 -1
  41. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +10 -1
  42. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +54 -4
  43. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +12 -0
  44. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +125 -5
  45. package/package.json +31 -1
  46. package/plugin.xml +3 -10
  47. package/www/BackgroundGeolocation.d.ts +143 -3
  48. package/www/BackgroundGeolocation.js +11 -4
  49. package/CLAUDE.md +0 -56
  50. package/HISTORY.md +0 -871
  51. package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +0 -220
  52. package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +0 -45
  53. package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +0 -570
  54. package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +0 -76
  55. package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +0 -437
  56. package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +0 -95
  57. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +0 -159
  58. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +0 -161
  59. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +0 -247
  60. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +0 -200
  61. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +0 -457
  62. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +0 -96
  63. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +0 -225
  64. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +0 -46
  65. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +0 -14
  66. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +0 -50
  67. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +0 -17
  68. package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +0 -92
  69. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +0 -107
  70. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +0 -5
  71. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +0 -82
  72. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +0 -128
  73. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +0 -191
  74. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +0 -37
  75. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +0 -216
  76. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +0 -223
  77. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +0 -50
  78. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +0 -180
  79. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +0 -16
  80. package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +0 -2
  81. package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +0 -21
  82. package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +0 -135
  83. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +0 -80
  84. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +0 -147
  85. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +0 -30
  86. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +0 -42
  87. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +0 -99
  88. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +0 -327
  89. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +0 -44
  90. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +0 -94
  91. package/ios/common/BackgroundGeolocationTests/Info.plist +0 -24
  92. package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +0 -185
  93. package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +0 -161
  94. package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +0 -102
  95. package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +0 -216
  96. package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +0 -55
  97. package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +0 -43
  98. package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +0 -102
  99. package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +0 -41
  100. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +0 -240
  101. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +0 -84
  102. package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +0 -144
  103. package/ios/common/scripts/xcode-refactor.js +0 -184
@@ -1,223 +0,0 @@
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
- }
@@ -1,50 +0,0 @@
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
- }
@@ -1,180 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- SOMotionDetector
2
- ===========
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 SocialObject Sofware
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,135 +0,0 @@
1
- SOMotionDetector
2
- ================
3
-
4
- Simple library to detect motion for iOS by <b> <a href="https://github.com/arturdev">arturdev</a> </b>.
5
-
6
- Based on location updates and acceleration.
7
-
8
- ###Requierments
9
- iOS > 6.0
10
-
11
- Compatible with <b>iOS 9</b>
12
-
13
- <b>Works on all iOS devices (i.e. not need M7 chip)</b>
14
-
15
- <img src="https://raw.github.com/SocialObjects-Software/SOMotionDetector/master/MotionDetection/screenshot.PNG" width=320>
16
-
17
- This demo project also demonstrates how to use this library to relaunch the app from killed state.
18
-
19
- USAGE
20
- =====
21
- Copy <b>SOMotionDetector</b> folder to your project.
22
-
23
- Link <b>CoreMotion.framework</b>, <b>CoreLocation.framework</b>.
24
-
25
- Import <b>"SOMotionDetector.h"</b> file and set SOMotionDetector's callbacks
26
-
27
- ```ObjC
28
- #import "SOMotionDetector.h
29
-
30
- //...
31
-
32
- [SOMotionDetector sharedInstance].motionTypeChangedBlock = ^(SOMotionType motionType) {
33
- //...
34
- };
35
-
36
- [SOMotionDetector sharedInstance].locationChangedBlock = ^(CLLocation *location) {
37
- //...
38
- };
39
-
40
- [SOMotionDetector sharedInstance].accelerationChangedBlock = ^(CMAcceleration acceleration) {
41
- //...
42
- };
43
- ```
44
-
45
- If you need to know when location updates were automatically paused due to your app running in the background...
46
-
47
- ```ObjC
48
- [SOMotionDetector sharedInstance].locationWasPausedBlock = ^(BOOL changed) {
49
- //...
50
- };
51
- ```
52
-
53
- ###NOTE!
54
- To Support iOS > 8.0 you must add in your info.plist file one of the following keys: <br>
55
- `NSLocationAlwaysUsageDescription`<br> `NSLocationWhenInUseUsageDescription`
56
-
57
- To enable background location updates in iOS > 9.0 you must set `allowsBackgroundLocationUpdates` to `YES` <br>
58
- ```ObjC
59
- [SOLocationManager sharedInstance].allowsBackgroundLocationUpdates = YES;
60
- ```
61
-
62
- You are done!
63
-
64
- Now to start motion detection just call
65
- ```ObjC
66
- [[SOMotionDetector sharedInstance] startDetection];
67
- ```
68
-
69
- To stop detection call
70
- ```ObjC
71
- [[SOMotionDetector sharedInstance] stopDetection];
72
- ```
73
-
74
- To start step counter call
75
- ```ObjC
76
- [[SOStepDetector sharedInstance] startDetectionWithUpdateBlock:^(NSError *error) {
77
- //...
78
- }];
79
- ```
80
- ###Detecting motion types
81
- ```ObjC
82
- typedef enum
83
- {
84
- MotionTypeNotMoving = 1,
85
- MotionTypeWalking,
86
- MotionTypeRunning,
87
- MotionTypeAutomotive
88
- } SOMotionType;
89
- ```
90
-
91
- CUSTOMIZATION
92
- =============
93
- ```ObjC
94
-
95
- /**
96
- * Set this parameter to YES if you want to use M7 chip to detect more exact motion type. By default is No.
97
- * Set this parameter before calling startDetection method.
98
- * Available only on devices that have M7 chip. At this time only the iPhone 5S, the iPad Air and iPad mini with retina display have the M7 coprocessor.
99
- */
100
- @property (nonatomic) BOOL useM7IfAvailable;
101
-
102
- /**
103
- *@param speed The minimum speed value less than which will be considered as not moving state
104
- */
105
- - (void)setMinimumSpeed:(CGFloat)speed;
106
-
107
- /**
108
- *@param speed The maximum speed value more than which will be considered as running state
109
- */
110
- - (void)setMaximumWalkingSpeed:(CGFloat)speed;
111
-
112
- /**
113
- *@param speed The maximum speed value more than which will be considered as automotive state
114
- */
115
- - (void)setMaximumRunningSpeed:(CGFloat)speed;
116
-
117
- /**
118
- *@param acceleration The minimum acceleration value less than which will be considered as non shaking state
119
- */
120
- - (void)setMinimumRunningAcceleration:(CGFloat)acceleration;
121
-
122
- ```
123
-
124
- ### Installation with CocoaPods
125
-
126
- [CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries installation in your projects.
127
-
128
- #### Podfile
129
-
130
- ```ruby
131
- pod "SOMotionDetector"
132
- ```
133
-
134
- <h2>LICENSE</h2>
135
- SOMotionDetector is under MIT License (see LICENSE file)