Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 33e80b1

Browse files
committed
[[ Bug 16296 ]] Fix crash when restarting location tracker on Android
This patch fixes a bug where starting the location tracker on Android would cause a crash if the tracker had already been started. This was caused by posting a location update to the engine while in a Java method called from the engine and is fixed by deferring the location update until after the method has returned.
1 parent fe4853d commit 33e80b1

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

engine/src/java/com/runrev/android/SensorModule.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,37 @@ protected void onLocationChanged(Location location)
358358
public double getLongitude() { return m_last_location.getLongitude(); }
359359
public double getAltitude() { return m_last_location.getAltitude(); }
360360

361-
//override to make sure currently known location is sent if already started by heading tracker
362-
public boolean startTracking(boolean p_loosely)
363-
{
364-
boolean t_result;
365-
t_result = super.startTracking(p_loosely);
366-
if (t_result && m_last_location != null)
367-
onLocationChanged(m_last_location);
368-
return t_result;
369-
}
370-
}
371-
361+
//override to make sure currently known location is sent if already started by internal tracking
362+
public boolean startTracking(boolean p_loosely)
363+
{
364+
// Check if already tracking at the requested level
365+
int t_tracking_requested = p_loosely ? COARSE_TRACKING : FINE_TRACKING;
366+
367+
if (m_tracking_requested == t_tracking_requested)
368+
return true;
369+
370+
boolean t_result;
371+
t_result = super.startTracking(p_loosely);
372+
if (t_result && m_last_location != null)
373+
m_engine.post(new Runnable() {
374+
public void run() {
375+
onLocationChanged(m_last_location);
376+
}
377+
});
378+
return t_result;
379+
}
380+
381+
// override to clear cached last location if not tracking internallly
382+
public boolean stopTracking()
383+
{
384+
boolean t_result;
385+
t_result = super.stopTracking();
386+
if (t_result && !isTracking())
387+
m_last_location = null;
388+
return t_result;
389+
}
390+
}
391+
372392
class HeadingTracker extends Tracker implements SensorEventListener
373393
{
374394
private Sensor m_magnetometer;

0 commit comments

Comments
 (0)