Skip to content

Commit

Permalink
Report a new location only after receiving a non-null update
Browse files Browse the repository at this point in the history
Signed-off-by: mvglasow <michael -at- vonglasow.com>
  • Loading branch information
mvglasow committed Mar 17, 2016
1 parent bcf1cff commit e8158cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ public void bind() {
}

public void update() {
Boolean hasUpdates = false;
fusing = true;
for (BackendHelper handler : backendHelpers) {
handler.update();
if (handler.update() != null)
hasUpdates = true;
}
fusing = false;
updateLocation();
if (hasUpdates)
updateLocation();
}

void updateLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,31 @@ public Location getLastLocation() {
return lastLocation;
}

public void update() {
/**
* @brief Requests a location update from the backend.
*
* @return The location reported by the backend. This may be null if a backend cannot determine its
* location, or if it is going to return a location asynchronously.
*/
public Location update() {
Location result = null;
if (backend == null) {
Log.d(TAG, "Not (yet) bound.");
updateWaiting = true;
} else {
updateWaiting = false;
try {
setLastLocation(backend.update());
backendFuser.reportLocation();
result = backend.update();
if (result != null) {
setLastLocation(result);
backendFuser.reportLocation();
}
} catch (Exception e) {
Log.w(TAG, e);
unbind();
}
}
return result;
}

private void setLastLocation(Location location) {
Expand Down Expand Up @@ -139,6 +150,8 @@ public void onServiceDisconnected(ComponentName name) {
private class Callback extends LocationCallback.Stub {
@Override
public void report(Location location) throws RemoteException {
if (location == null)
return;
setLastLocation(location);
backendFuser.reportLocation();
}
Expand Down

0 comments on commit e8158cb

Please sign in to comment.