From e8158cb8d280e75268d8c169512dacd198c83f43 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 17 Mar 2016 14:50:43 +0100 Subject: [PATCH 1/4] Report a new location only after receiving a non-null update Signed-off-by: mvglasow --- .../org/microg/nlp/location/BackendFuser.java | 7 +++++-- .../microg/nlp/location/BackendHelper.java | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java index 63a2b09..d1e67dd 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java @@ -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() { diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java index 53f98a2..eab1dbf 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java @@ -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) { @@ -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(); } From 3b995b89020268fba38c0e08d9121abb7b0423b2 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 18 Mar 2016 09:09:49 +0100 Subject: [PATCH 2/4] Prevent backends from reporting the same location twice Signed-off-by: mvglasow --- .../src/main/java/org/microg/nlp/location/BackendHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java index eab1dbf..c7fccd4 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendHelper.java @@ -69,7 +69,7 @@ public Location update() { updateWaiting = false; try { result = backend.update(); - if (result != null) { + if ((result != null) && (result.getTime() > lastLocation.getTime())) { setLastLocation(result); backendFuser.reportLocation(); } @@ -150,7 +150,7 @@ public void onServiceDisconnected(ComponentName name) { private class Callback extends LocationCallback.Stub { @Override public void report(Location location) throws RemoteException { - if (location == null) + if ((location == null) || (location.getTime() <= lastLocation.getTime())) return; setLastLocation(location); backendFuser.reportLocation(); From eead0bd32ac5d60d1e29c1f4a48aea6f3fcdd2d3 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 18 Mar 2016 10:08:09 +0100 Subject: [PATCH 3/4] Trigger a location update when a new location is forced Signed-off-by: mvglasow --- .../src/main/java/org/microg/nlp/location/BackendFuser.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java index d1e67dd..29f0f35 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java @@ -135,11 +135,14 @@ public void reportLocation() { } public void forceLocation(Location location) { + if ((forcedLocation != null) && (location != null) && (forcedLocation.getTime() >= location.getTime())) + return; forcedLocation = location; if (forcedLocation != null) { Bundle extras = new Bundle(); extras.putString(LOCATION_EXTRA_BACKEND_PROVIDER, "forced"); location.setExtras(extras); + reportLocation(); } } From 1093f404ab087b18fc8a4f045122eaae3b7a4253 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 18 Mar 2016 15:04:49 +0100 Subject: [PATCH 4/4] Refactor: use Boolean primitive instead of class Signed-off-by: mvglasow --- .../src/main/java/org/microg/nlp/location/BackendFuser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java index 29f0f35..08b2fe1 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/location/BackendFuser.java @@ -78,7 +78,7 @@ public void bind() { } public void update() { - Boolean hasUpdates = false; + boolean hasUpdates = false; fusing = true; for (BackendHelper handler : backendHelpers) { if (handler.update() != null)