Skip to content

Commit 9f8ab42

Browse files
committed
Use the 2nd network location changed as a trigger for movement
1 parent c651075 commit 9f8ab42

File tree

1 file changed

+15
-3
lines changed
  • libraries/stumbler/src/main/java/org/mozilla/mozstumbler/service/stumblerthread/motiondetection

1 file changed

+15
-3
lines changed

Diff for: libraries/stumbler/src/main/java/org/mozilla/mozstumbler/service/stumblerthread/motiondetection/MotionSensor.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,26 @@ static class NetworkLocationChangeDetector {
143143
private LocationListener mNetworkLocationListener = new LocationListener() {
144144
public void onLocationChanged(Location location) {
145145
if (mLastLocation == null) {
146+
// Use the first location change to init the location. This means an initial movement
147+
// can be missed, and a subsequent movement is required. However this is the most reliable
148+
// means of initializing the location.
146149
mLastLocation = location;
147150
return;
148151
}
149152

150-
AppGlobals.guiLogInfo("MotionSensor.NetworkLocationChangeDetector triggered. (" +
151-
Math.round(location.distanceTo(mLastLocation)) + "m)");
153+
final int distanceMeters = Math.round(location.distanceTo(mLastLocation));
154+
if (distanceMeters < DIST_THRESHOLD_M) {
155+
// The threshold set in requestLocationUpdates is unreliable, I have seen false triggers, check here instead
156+
return;
157+
}
158+
159+
AppGlobals.guiLogInfo("MotionSensor.NetworkLocationChangeDetector triggered. (" + distanceMeters + "m)");
152160
Intent sendIntent = new Intent(ACTION_USER_MOTION_DETECTED);
153161
LocalBroadcastManager.getInstance(mContext).sendBroadcastSync(sendIntent);
162+
163+
// Under expected usage, after the motion detection broadcast, this class goes through a stop()/start() cycle,
164+
// which sets mLastLocation to null. In case someone wants to use this class differently, we update mLastLocation here.
165+
mLastLocation = location;
154166
}
155167

156168
public void onStatusChanged(String provider, int status, Bundle extras) {}
@@ -166,7 +178,7 @@ public void start(Context c) {
166178
return;
167179
}
168180

169-
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TIME_INTERVAL_MS, DIST_THRESHOLD_M, mNetworkLocationListener);
181+
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TIME_INTERVAL_MS, 0, mNetworkLocationListener);
170182
}
171183

172184
public void stop() {

0 commit comments

Comments
 (0)