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

Commit

Permalink
fix #224 (#227)
Browse files Browse the repository at this point in the history
* fix #224

* implement review comments
  • Loading branch information
westnordost authored and sarahsnow1 committed Jun 28, 2017
1 parent eec8cd1 commit 539c066
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public class FusedLocationProviderApiImpl extends ApiImpl
private IFusedLocationProviderCallback.Stub remoteCallback
= new IFusedLocationProviderCallback.Stub() {
public void onLocationChanged(final Location location) throws RemoteException {

new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override public void run() {
final LostClientManager clientManager = LostClientManager.shared();
serviceCallbackManager.onLocationChanged(context, location, clientManager, service);
// #224: this call is async, service may have been legally set to null in the meantime
if (service != null)
{
final LostClientManager clientManager = LostClientManager.shared();
serviceCallbackManager.onLocationChanged(context, location, clientManager, service);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ public class FusedLocationServiceCallbackManager {
/**
* Called when a new location has been received. This method handles dispatching changes to all
* {@link com.mapzen.android.lost.api.LocationListener}s, {@link android.app.PendingIntent}s, and
* {@link com.mapzen.android.lost.api.LocationCallback}s which are registered. If the
* {@link IFusedLocationProviderService} is null, an {@link IllegalStateException} will be thrown.
* {@link com.mapzen.android.lost.api.LocationCallback}s which are registered.
* @param context
* @param location
* @param clientManager
* @param service
*/
void onLocationChanged(Context context, Location location, LostClientManager clientManager,
IFusedLocationProviderService service) {
if (service == null) {
throw new IllegalStateException("Location update received after client was "
+ "disconnected. Did you forget to unregister location updates before "
+ "disconnecting?");
}

ReportedChanges changes = clientManager.reportLocationChanged(location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.Intent;
import android.location.Location;
import android.os.Looper;
import android.os.RemoteException;
import android.support.annotation.NonNull;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public class FusedLocationServiceCallbackManagerTest {
FusedLocationServiceCallbackManager callbackManager =
new FusedLocationServiceCallbackManager();

@Test(expected = IllegalStateException.class)
public void onLocationChanged_shouldThrowIfServiceDisconnected() {
callbackManager.onLocationChanged(mock(Context.class), mock(Location.class),
mock(LostClientManager.class), null);
}

@Test public void onLocationChanged_shouldReportLocationChanged() {
LostClientManager clientManager = mock(LostClientManager.class);
Location location = mock(Location.class);
Expand Down

0 comments on commit 539c066

Please sign in to comment.