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

Commit

Permalink
Log Exceptions (#230)
Browse files Browse the repository at this point in the history
* log exceptions

* update location availability documentation

* better log.e
  • Loading branch information
sarahsnow1 authored Jun 30, 2017
1 parent e5eb545 commit 3ed32b3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface FusedLocationProviderApi {
* Network location is enabled and the {@link android.location.LocationManager} has a last known
* Network location
*
* This method can return null if there is a problem getting the availability.
*
* @param client The client to return availability for.
* @return The availability of location data.
* @throws IllegalStateException if the client is not connected at the time of this call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;

import java.util.List;
import java.util.Map;
Expand All @@ -31,6 +32,7 @@
public class FusedLocationProviderApiImpl extends ApiImpl
implements FusedLocationProviderApi, EventCallbacks, ServiceConnection {

private static final String TAG = FusedLocationProviderApiImpl.class.getSimpleName();
private Context context;
private FusedLocationServiceConnectionManager serviceConnectionManager;
private FusedLocationServiceCallbackManager serviceCallbackManager;
Expand Down Expand Up @@ -123,19 +125,25 @@ public boolean isConnected() {

@Override public Location getLastLocation(LostApiClient client) {
throwIfNotConnected(client);
Location location = null;
try {
return service.getLastLocation();
location = service.getLastLocation();
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get last Location", e);
} finally {
return location;
}
}

@Override public LocationAvailability getLocationAvailability(LostApiClient client) {
throwIfNotConnected(client);
LocationAvailability availability = null;
try {
return service.getLocationAvailability();
availability = service.getLocationAvailability();
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get LocationAvailability", e);
} finally {
return availability;
}
}

Expand Down Expand Up @@ -179,7 +187,7 @@ private void requestLocationUpdatesInternal(LocationRequest request) {
try {
service.requestLocationUpdates(request);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to request location updates", e);
}
}

Expand All @@ -190,7 +198,7 @@ private void removeLocationUpdatesInternal(List<LocationRequest> requests) {
try {
service.removeLocationUpdates(requests);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to remove location updates", e);
}
}

Expand Down Expand Up @@ -244,7 +252,8 @@ private void checkAllListenersPendingIntentsAndCallbacks() {
try {
service.setMockMode(isMockMode);
} catch (RemoteException e) {
throw new RuntimeException(e);
String mode = isMockMode ? "enabled" : "disabled";
Log.e(TAG, "Error occurred trying to set mock mode " + mode, e);
}
return new SimplePendingResult(true);
}
Expand All @@ -255,7 +264,7 @@ private void checkAllListenersPendingIntentsAndCallbacks() {
try {
service.setMockLocation(mockLocation);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to set mock location", e);
}
return new SimplePendingResult(true);
}
Expand All @@ -266,7 +275,7 @@ private void checkAllListenersPendingIntentsAndCallbacks() {
try {
service.setMockTrace(path, filename);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to set mock trace", e);
}
return new SimplePendingResult(true);
}
Expand All @@ -288,7 +297,7 @@ void registerRemoteCallback() {
try {
service.init(remoteCallback);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to register remote callback", e);
}
}
}
Expand All @@ -298,7 +307,7 @@ void unregisterRemoteCallback() {
try {
service.init(null);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to unregister remote callback", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Looper;
import android.os.RemoteException;
import android.support.annotation.RequiresPermission;
import android.util.Log;

import java.io.File;
import java.util.List;
Expand All @@ -19,6 +20,7 @@

public class FusedLocationProviderServiceDelegate implements LocationEngine.Callback {

private static final String TAG = FusedLocationProviderServiceDelegate.class.getSimpleName();
private Context context;

private boolean mockMode;
Expand Down Expand Up @@ -76,7 +78,7 @@ public void reportLocation(Location location) {
try {
callback.onLocationChanged(location);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to report a new Location", e);
}
}
}
Expand Down Expand Up @@ -130,7 +132,7 @@ private void notifyLocationAvailabilityChanged() {
try {
callback.onLocationAvailabilityChanged(availability);
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to report a new LocationAvailability", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import android.content.Context;
import android.location.Location;
import android.os.RemoteException;
import android.util.Log;

import java.util.ArrayList;

import static android.content.ContentValues.TAG;

/**
* Handles callbacks received in {@link FusedLocationProviderApiImpl} from
* {@link FusedLocationProviderService}.
Expand All @@ -29,11 +32,11 @@ void onLocationChanged(Context context, Location location, LostClientManager cli

ReportedChanges changes = clientManager.reportLocationChanged(location);

LocationAvailability availability;
LocationAvailability availability = null;
try {
availability = service.getLocationAvailability();
} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get LocationAvailability", e);
}

ArrayList<Location> locations = new ArrayList<>();
Expand Down

0 comments on commit 3ed32b3

Please sign in to comment.