Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Only register engine once per request
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Lensing committed Jun 20, 2016
1 parent 7299c63 commit fa4873a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public Location getLastLocation() {

@Override
public void requestLocationUpdates(LocationRequest request, LocationListener listener) {
LocationEngine existing = locationEngines.get(request);
LocationEngine engine = locationEngineForRequest(request);
addListenerForEngine(engine, listener);
engine.setRequest(request);
if (existing == null) {
engine.setRequest(request);
}
}

@Override
Expand Down Expand Up @@ -227,7 +230,7 @@ private void shutdownAllEngines() {
}

@VisibleForTesting
public List<LocationListener> getListeners() {
List<LocationListener> getListeners() {
List<LocationListener> listeners = new ArrayList<>();
for (LocationEngine engine : engineListeners.keySet()) {
listeners.addAll(engineListeners.get(engine));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void setMockMode_shouldNotRegisterDuplicateListeners() throws Exception {
api.requestLocationUpdates(request, listener);
api.setMockMode(false);
api.requestLocationUpdates(request, listener);
assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).hasSize(4);
assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).hasSize(2);
}

@Test
Expand Down

0 comments on commit fa4873a

Please sign in to comment.