Skip to content

Commit b183816

Browse files
authored
Merge pull request #883 from transistorsoft/logger
Fix NPE in LocationService. Implement new Logger module.
2 parents d7ec0ea + bbdcb0c commit b183816

File tree

49 files changed

+1882
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1882
-593
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Change Log
22

3+
## 3.3.1 - 2019-10-23
4+
- [Fixed] Android NPE
5+
```
6+
Caused by: java.lang.NullPointerException:
7+
at com.transistorsoft.locationmanager.service.TrackingService.b (TrackingService.java:172)
8+
at com.transistorsoft.locationmanager.service.TrackingService.onStartCommand (TrackingService.java:135)
9+
```
10+
- [Added] new `uploadLog` feature for uploading logs directly to a server. This is an alternative to `emailLog`.
11+
- [Changed] Migrated logging methods `getLog`, `destroyLog`, `emailLog` to new `Logger` module available at `BackgroundGeolocation.logger`. See docs for more information. Existing log methods on `BackgroundGeolocation` are now `@deprecated`.
12+
- [Changed] All logging methods (`getLog`, `emailLog` and `uploadLog`) now accept an optional `SQLQuery`. Eg:
13+
```javascript
14+
let query = {
15+
start: Date.parse('2019-10-23 09:00'),
16+
end: Date.parse('2019-10-23 19:00'),
17+
limit: 1000,
18+
order: Logger.ORDER_ASC
19+
};
20+
let Logger = BackgroundGeolocation.logger;
21+
22+
let log = await Logger.getLog(query)
23+
Logger.emailLog('[email protected]', query);
24+
Logger.uploadLoad('http://your.server.com/logs', query);
25+
```
26+
27+
328
## 3.3.0 - 2019-10-17
429
- [Fixed] Android: Fixed issue executing `#changePace` immediately after `#start`.
530
- [Fixed] Android: Add guard against NPR in `calculateMedianAccuracy`

android/src/main/java/com/transistorsoft/rnbackgroundgeolocation/RNBackgroundGeolocationModule.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.transistorsoft.locationmanager.adapter.TSConfig;
3434
import com.transistorsoft.locationmanager.adapter.callback.*;
3535
import com.transistorsoft.locationmanager.data.LocationModel;
36+
import com.transistorsoft.locationmanager.data.SQLQuery;
3637
import com.transistorsoft.locationmanager.event.ActivityChangeEvent;
3738
import com.transistorsoft.locationmanager.event.ConnectivityChangeEvent;
3839
import com.transistorsoft.locationmanager.event.GeofenceEvent;
@@ -55,6 +56,7 @@
5556
import java.util.HashMap;
5657
import java.util.Iterator;
5758
import java.util.List;
59+
import java.util.Map;
5860

5961
/**
6062
* Created by chris on 2015-10-30.
@@ -484,7 +486,7 @@ public void destroyLocations(final Callback success, final Callback failure) {
484486
public void destroyLog(final Callback success, final Callback failure) {
485487
getAdapter().destroyLog(new TSCallback() {
486488
@Override public void onSuccess() {
487-
success.invoke();
489+
success.invoke(true);
488490
}
489491
@Override public void onFailure(String error) {
490492
failure.invoke(error);
@@ -760,8 +762,10 @@ public void playSound(String soundId) {
760762
}
761763

762764
@ReactMethod
763-
public void getLog(final Callback success, final Callback failure) {
764-
getAdapter().getLog(new TSGetLogCallback() {
765+
public void getLog(final Callback success, ReadableMap params, final Callback failure) {
766+
SQLQuery query = parseSQLQuery(params);
767+
768+
TSLog.getLog(query, new TSGetLogCallback() {
765769
@Override public void onSuccess(String log) {
766770
success.invoke(log);
767771
}
@@ -772,8 +776,24 @@ public void getLog(final Callback success, final Callback failure) {
772776
}
773777

774778
@ReactMethod
775-
public void emailLog(String email, final Callback success, final Callback failure) {
776-
getAdapter().emailLog(email, getCurrentActivity(), new TSEmailLogCallback() {
779+
public void emailLog(String email, ReadableMap params, final Callback success, final Callback failure) {
780+
SQLQuery query = parseSQLQuery(params);
781+
782+
TSLog.emailLog(getCurrentActivity(), email, query, new TSEmailLogCallback() {
783+
@Override public void onSuccess() {
784+
success.invoke();
785+
}
786+
@Override public void onFailure(String error) {
787+
failure.invoke(error);
788+
}
789+
});
790+
}
791+
792+
@ReactMethod
793+
public void uploadLog(String url, ReadableMap params, final Callback success, final Callback failure) {
794+
SQLQuery query = parseSQLQuery(params);
795+
796+
TSLog.uploadLog(getReactApplicationContext(), url, query, new TSCallback() {
777797
@Override public void onSuccess() {
778798
success.invoke();
779799
}
@@ -788,6 +808,25 @@ public void log(String level, String message) throws JSONException {
788808
TSLog.log(level, message);
789809
}
790810

811+
private SQLQuery parseSQLQuery(ReadableMap params) {
812+
SQLQuery query = SQLQuery.create();
813+
if (params.hasKey("start")) {
814+
Double start = params.getDouble("start");
815+
query.setStart(start.longValue());
816+
}
817+
if (params.hasKey("end")) {
818+
Double end = params.getDouble("end");
819+
query.setEnd(end.longValue());
820+
}
821+
if (params.hasKey("order")) {
822+
query.setOrder(params.getInt("order"));
823+
}
824+
if (params.hasKey("limit")) {
825+
query.setLimit(params.getInt("limit"));
826+
}
827+
return query;
828+
}
829+
791830
@ReactMethod
792831
public void getSensors(Callback success, Callback error) {
793832
Sensors sensors = Sensors.getInstance(getReactApplicationContext());

docs/assets/js/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/_react_native_background_geolocation_.backgroundgeolocation.html

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li class="state loading">Preparing search index...</li>
2424
<li class="state failure">The search index is not available</li>
2525
</ul>
26-
<a href="../globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.0</span>
26+
<a href="../globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.1</span>
2727
</div>
2828
<div class="" id="tsd-widgets">
2929
<a class="github" href="https://github.com/transistorsoft/react-native-background-geolocation">Github</a>
@@ -1342,6 +1342,11 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> logger</h3>
13421342
<div class="tsd-signature tsd-kind-icon">logger<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_react_native_background_geolocation_.logger.html" class="tsd-signature-type">Logger</a></div>
13431343
<aside class="tsd-sources">
13441344
</aside>
1345+
<div class="tsd-comment tsd-typography">
1346+
<div class="lead">
1347+
<p><a href="../interfaces/_react_native_background_geolocation_.logger.html">Logger</a> API</p>
1348+
</div>
1349+
</div>
13451350
</section>
13461351
</section>
13471352
<section class="tsd-panel-group tsd-member-group ">
@@ -1581,19 +1586,9 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> destroy<wbr>Log</h3>
15811586
<aside class="tsd-sources">
15821587
</aside>
15831588
<div class="tsd-comment tsd-typography">
1584-
<div class="lead">
1585-
<p>Destroy the entire contents of plugin&#39;s log database.</p>
1586-
</div>
15871589
<dl class="tsd-comment-tags">
1588-
<dt class="tsd-comment-tag-example">example</dt>
1589-
<dd><pre><code class="language-javascript">BackgroundGeolocation.destroyLog();</code></pre>
1590-
<h3 id="-see-also-">ℹ️ See also:</h3>
1591-
<ul>
1592-
<li><a href="../interfaces/_react_native_background_geolocation_.config.html#loglevel">logLevel</a></li>
1593-
<li><a href="_react_native_background_geolocation_.backgroundgeolocation.html#getlog">getLog</a></li>
1594-
<li><a href="_react_native_background_geolocation_.backgroundgeolocation.html#emaillog">emailLog</a></li>
1595-
<li>📘<a href="https://github.com/transistorsoft/react-native-background-geolocation/wiki/Debugging">Debugging Guide</a></li>
1596-
</ul>
1590+
<dt class="tsd-comment-tag-deprecated">deprecated</dt>
1591+
<dd><p>Use <a href="../interfaces/_react_native_background_geolocation_.logger.html#destroylog">Logger.destroyLog</a>.</p>
15971592
</dd>
15981593
</dl>
15991594
</div>
@@ -1621,22 +1616,9 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> email<wbr>Log</h3>
16211616
<aside class="tsd-sources">
16221617
</aside>
16231618
<div class="tsd-comment tsd-typography">
1624-
<div class="lead">
1625-
<p>Email the result of <a href="_react_native_background_geolocation_.backgroundgeolocation.html#getlog">getLog</a> using device&#39;s mail client.</p>
1626-
</div>
16271619
<dl class="tsd-comment-tags">
1628-
<dt class="tsd-comment-tag-example">example</dt>
1629-
<dd><pre><code class="language-javascript">BackgroundGeolocation.emailLog(<span class="hljs-string">'[email protected]'</span>).then(<span class="hljs-function">(<span class="hljs-params">success</span>) =&gt;</span> {
1630-
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'[emailLog] success'</span>);
1631-
}).catch(<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
1632-
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'[emailLog] FAILURE: '</span>, error);
1633-
});</code></pre>
1634-
<h3 id="-see-also-">ℹ️ See also:</h3>
1635-
<ul>
1636-
<li><a href="../interfaces/_react_native_background_geolocation_.config.html#loglevel">logLevel</a></li>
1637-
<li><a href="_react_native_background_geolocation_.backgroundgeolocation.html#getlog">getLog</a></li>
1638-
<li>📘<a href="https://github.com/transistorsoft/react-native-background-geolocation/wiki/Debugging">Debugging Guide</a>.</li>
1639-
</ul>
1620+
<dt class="tsd-comment-tag-deprecated">deprecated</dt>
1621+
<dd><p>Use <a href="../interfaces/_react_native_background_geolocation_.logger.html#emaillog">Logger.emailLog</a>.</p>
16401622
</dd>
16411623
</dl>
16421624
</div>
@@ -2123,71 +2105,10 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> get<wbr>Log</h3>
21232105
<aside class="tsd-sources">
21242106
</aside>
21252107
<div class="tsd-comment tsd-typography">
2126-
<div class="lead">
2127-
<p>Returns the entire contents of the log database.</p>
2128-
</div>
21292108
<dl class="tsd-comment-tags">
2130-
<dt class="tsd-comment-tag-break">break</dt>
2131-
<dd><p>Depending on the configured <a href="../interfaces/_react_native_background_geolocation_.config.html#loglevel">logLevel</a>, the plugin can store an <em>immense</em> amount of helpful logging information for debugging location-tracking
2132-
problems.</p>
2133-
<h3 id="-see-also-">ℹ️ See also:</h3>
2134-
<ul>
2135-
<li><a href="../interfaces/_react_native_background_geolocation_.config.html#logmaxdays">logMaxDays</a> (default <code>3</code> days)</li>
2136-
<li><a href="../interfaces/_react_native_background_geolocation_.config.html#loglevel">logLevel</a> (default <a href="_react_native_background_geolocation_.backgroundgeolocation.html#log_level_off">LOG_LEVEL_OFF</a>)</li>
2137-
<li><a href="_react_native_background_geolocation_.backgroundgeolocation.html#emaillog">emailLog</a></li>
2138-
<li>📘<a href="https://github.com/transistorsoft/react-native-background-geolocation/wiki/Debugging">Debugging Guide</a>
2139-
log data:</li>
2140-
</ul>
2109+
<dt class="tsd-comment-tag-deprecated">deprecated</dt>
2110+
<dd><p>Use <a href="../interfaces/_react_native_background_geolocation_.logger.html#getlog">Logger.getLog</a>.</p>
21412111
</dd>
2142-
<dt class="tsd-comment-tag-example">example</dt>
2143-
<dd><pre><code class="language-javascript">BackgroundGeolocation.getLog.then(<span class="hljs-function">(<span class="hljs-params">log</span>) =&gt;</span> {
2144-
<span class="hljs-comment">// Warning: this string could be several megabytes.</span>
2145-
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'[log] success: '</span>, log);
2146-
});</code></pre>
2147-
<pre><code>09-19 11:12:18.716 ╔═════════════════════════════════════════════
2148-
09-19 11:12:18.716 ║ BackgroundGeolocation<span class="hljs-built_in"> Service </span>started
2149-
09-19 11:12:18.716 ╠═════════════════════════════════════════════
2150-
09-19 11:12:18.723 [c.t.l.BackgroundGeolocationService d]
2151-
09-19 11:12:18.723 ✅ Started <span class="hljs-keyword">in</span> foreground
2152-
09-19 11:12:18.737 [c.t.l.ActivityRecognitionService a]
2153-
09-19 11:12:18.737 🎾 Start activity updates: 10000
2154-
09-19 11:12:18.761 [c.t.l.BackgroundGeolocationService k]
2155-
09-19 11:12:18.761 🔴 Stop heartbeat
2156-
09-19 11:12:18.768 [c.t.l.BackgroundGeolocationService a]
2157-
09-19 11:12:18.768 🎾 Start heartbeat (60)
2158-
09-19 11:12:18.778 [c.t.l.BackgroundGeolocationService a]
2159-
09-19 11:12:18.778 🔵 setPace: <span class="hljs-literal">null</span><span class="hljs-literal">false</span>
2160-
09-19 11:12:18.781 [c.t.l.adapter.TSConfig c] ℹ️ Persist<span class="hljs-built_in"> config
2161-
</span>09-19 11:12:18.794 [c.t.locationmanager.util.b a]
2162-
09-19 11:12:18.794 ℹ️ LocationAuthorization: Permission granted
2163-
09-19 11:12:18.842 [c.t.l.http.HttpService flush]
2164-
09-19 11:12:18.842 ╔═════════════════════════════════════════════
2165-
09-19 11:12:18.842 ║ HTTP<span class="hljs-built_in"> Service
2166-
</span>09-19 11:12:18.842 ╠═════════════════════════════════════════════
2167-
09-19 11:12:19.000 [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] still (100%)
2168-
09-19 11:12:21.314 [c.t.l.l.SingleLocationRequest<span class="hljs-variable">$2</span> onLocationResult]
2169-
09-19 11:12:21.314 ╔═════════════════════════════════════════════
2170-
09-19 11:12:21.314 ║ SingleLocationRequest: 1
2171-
09-19 11:12:21.314 ╠═════════════════════════════════════════════
2172-
09-19 11:12:21.314 ╟─ 📍 Location[fused 45.519239,-73.617058 <span class="hljs-attribute">hAcc</span>=15]999923706055 <span class="hljs-attribute">vAcc</span>=2 <span class="hljs-attribute">sAcc</span>=??? <span class="hljs-attribute">bAcc</span>=???
2173-
09-19 11:12:21.327 [c.t.l.l.TSLocationManager onSingleLocationResult]
2174-
09-19 11:12:21.327 🔵 Acquired motionchange position, isMoving: <span class="hljs-literal">false</span>
2175-
09-19 11:12:21.342 [c.t.l.l.TSLocationManager a] 15.243
2176-
09-19 11:12:21.405 [c.t.locationmanager.data.a.c persist]
2177-
09-19 11:12:21.405 ✅ INSERT: bca5acc8-e358-4d8f-827f-b8c0d556b7bb
2178-
09-19 11:12:21.423 [c.t.l.http.HttpService flush]
2179-
09-19 11:12:21.423 ╔═════════════════════════════════════════════
2180-
09-19 11:12:21.423 ║ HTTP<span class="hljs-built_in"> Service
2181-
</span>09-19 11:12:21.423 ╠═════════════════════════════════════════════
2182-
09-19 11:12:21.446 [c.t.locationmanager.data.a.c first]
2183-
09-19 11:12:21.446 ✅ Locked 1 records
2184-
09-19 11:12:21.454 [c.t.l.http.HttpService a]
2185-
09-19 11:12:21.454 🔵 HTTP POST: bca5acc8-e358-4d8f-827f-b8c0d556b7bb
2186-
09-19 11:12:22.083 [c.t.l.http.HttpService<span class="hljs-variable">$a</span> onResponse]
2187-
09-19 11:12:22.083 🔵 Response: 200
2188-
09-19 11:12:22.100 [c.t.locationmanager.data.a.c destroy]
2189-
09-19 11:12:22.100 ✅ DESTROY: bca5acc8-e358-4d8f-827f-b8c0d556b7bb
2190-
09-19 11:12:55.226 [c.t.l.BackgroundGeolocationService onActivityRecognitionResult] still (100%)</code></pre></dd>
21912112
</dl>
21922113
</div>
21932114
<h4 class="tsd-parameters-title">Parameters</h4>
@@ -4555,6 +4476,9 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
45554476
<li class=" tsd-kind-interface tsd-parent-kind-module tsd-is-not-exported">
45564477
<a href="../interfaces/_react_native_background_geolocation_.providerchangeevent.html" class="tsd-kind-icon">Provider<wbr>Change<wbr>Event</a>
45574478
</li>
4479+
<li class=" tsd-kind-interface tsd-parent-kind-module tsd-is-not-exported">
4480+
<a href="../interfaces/_react_native_background_geolocation_.sqlquery.html" class="tsd-kind-icon">SQLQuery</a>
4481+
</li>
45584482
<li class=" tsd-kind-interface tsd-parent-kind-module tsd-is-not-exported">
45594483
<a href="../interfaces/_react_native_background_geolocation_.sensors.html" class="tsd-kind-icon">Sensors</a>
45604484
</li>
@@ -4594,6 +4518,9 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
45944518
<li class=" tsd-kind-type-alias tsd-parent-kind-module tsd-is-not-exported">
45954519
<a href="../modules/_react_native_background_geolocation_.html#persistmode" class="tsd-kind-icon">Persist<wbr>Mode</a>
45964520
</li>
4521+
<li class=" tsd-kind-type-alias tsd-parent-kind-module tsd-is-not-exported">
4522+
<a href="../modules/_react_native_background_geolocation_.html#sqlqueryorder" class="tsd-kind-icon">SQLQuery<wbr>Order</a>
4523+
</li>
45974524
<li class=" tsd-kind-type-alias tsd-parent-kind-module tsd-is-not-exported">
45984525
<a href="../modules/_react_native_background_geolocation_.html#trackingmode" class="tsd-kind-icon">Tracking<wbr>Mode</a>
45994526
</li>

docs/globals.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li class="state loading">Preparing search index...</li>
2424
<li class="state failure">The search index is not available</li>
2525
</ul>
26-
<a href="globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.0</span>
26+
<a href="globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.1</span>
2727
</div>
2828
<div class="" id="tsd-widgets">
2929
<a class="github" href="https://github.com/transistorsoft/react-native-background-geolocation">Github</a>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li class="state loading">Preparing search index...</li>
2424
<li class="state failure">The search index is not available</li>
2525
</ul>
26-
<a href="globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.0</span>
26+
<a href="globals.html" class="title">[API Docs] React Native Background Geolocation</a>&nbsp;<span class="tsd-flag ts-flagOptional ts-flagVersion">v 3.3.1</span>
2727
</div>
2828
<div class="" id="tsd-widgets">
2929
<a class="github" href="https://github.com/transistorsoft/react-native-background-geolocation">Github</a>

0 commit comments

Comments
 (0)