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

Verify client is connected #167

Merged
merged 8 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=Mapzen
POM_DEVELOPER_NAME=Mapzen

org.gradle.jvmargs=-Xmx1536m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void onConnectionSuspended() {
super.onStop();
LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient,
MultipleLocationListenerMultipleClientsActivity.this);
fragment.removeLocationUpdates();
lostApiClient.disconnect();
}

Expand Down Expand Up @@ -145,12 +144,9 @@ public void onConnectionSuspended() {
fragmentClient.connect();
}

public void removeLocationUpdates() {
LocationServices.FusedLocationApi.removeLocationUpdates(fragmentClient, this);
}

@Override public void onStop() {
super.onStop();
LocationServices.FusedLocationApi.removeLocationUpdates(fragmentClient, this);
fragmentClient.disconnect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface FusedLocationProviderApi {
* The best accuracy available while respecting the location permissions will be returned.
* @param client The client to return location for.
* @return The best, most recent location available.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
Location getLastLocation(LostApiClient client);
Expand All @@ -40,6 +41,7 @@ public interface FusedLocationProviderApi {
*
* @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.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
LocationAvailability getLocationAvailability(LostApiClient client);
Expand All @@ -57,6 +59,7 @@ public interface FusedLocationProviderApi {
* @param request Specifies desired location accuracy, update interval, etc.
* @param listener Listener to make calls on when location becomes available.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
Expand All @@ -76,6 +79,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param listener Listener to make calls on when location becomes available.
* @param looper Looper to implement the listener callbacks on.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
Expand All @@ -95,6 +99,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param callback Callback to make calls on when location becomes available.
* @param looper Looper to implement the listener callbacks on.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
Expand All @@ -119,6 +124,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param request Specifies desired location accuracy, update interval, etc.
* @param callbackIntent Intent to be sent for each location update.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
Expand All @@ -127,27 +133,33 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
/**
* Removes location updates for the {@link LocationListener}
*
* @param client Client which registered the listener.
* @param client Client which registered the listener. The client must be connected at the time
* of this call.
* @param listener Listener to remove updates for.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> removeLocationUpdates(LostApiClient client, LocationListener listener);

/**
* Removes location updates for the {@link PendingIntent}
*
* @param client Client which registered the listener.
* @param client Client which registered the pending intent. The client must be connected at the
* time of this call.
* @param callbackIntent Intent to remove updates for.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> removeLocationUpdates(LostApiClient client, PendingIntent callbackIntent);

/**
* Remove location updates for the {@link LocationCallback}
*
* @param client Client which registered the listener.
* @param client Client which registered the location callback. The client must be connected at
* the time of this call.
* @param callback Callback to remove updates for.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> removeLocationUpdates(LostApiClient client, LocationCallback callback);

Expand All @@ -162,6 +174,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param client Connected client.
* @param isMockMode Whether mock mode should be enabled or not.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> setMockMode(LostApiClient client, boolean isMockMode);

Expand All @@ -173,6 +186,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param client Connected client.
* @param mockLocation Location to be set for the location provider.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> setMockLocation(LostApiClient client, Location mockLocation);

Expand All @@ -184,6 +198,7 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @param client Connected client.
* @param file GPX file to be used to report location.
* @return a {@link PendingResult} for the call to check whether call was successful.
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> setMockTrace(LostApiClient client, final File file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ public boolean isConnected() {
}

@Override public Location getLastLocation(LostApiClient client) {
throwIfNotConnected(client);
return service.getLastLocation(client);
}

@Override public LocationAvailability getLocationAvailability(LostApiClient client) {
throwIfNotConnected(client);
return service.getLocationAvailability(client);
}

@Override public PendingResult<Status> requestLocationUpdates(LostApiClient client,
LocationRequest request, LocationListener listener) {
throwIfNotConnected(client);
return service.requestLocationUpdates(client, request, listener);
}

Expand All @@ -116,40 +119,48 @@ public boolean isConnected() {

@Override public PendingResult<Status> requestLocationUpdates(LostApiClient client,
LocationRequest request, LocationCallback callback, Looper looper) {
throwIfNotConnected(client);
return service.requestLocationUpdates(client, request, callback, looper);
}

@Override
public PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
PendingIntent callbackIntent) {
throwIfNotConnected(client);
return service.requestLocationUpdates(client, request, callbackIntent);
}

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationListener listener) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, listener);
}

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
PendingIntent callbackIntent) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, callbackIntent);
}

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationCallback callback) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, callback);
}

@Override public PendingResult<Status> setMockMode(LostApiClient client, boolean isMockMode) {
throwIfNotConnected(client);
return service.setMockMode(client, isMockMode);
}

@Override public PendingResult<Status> setMockLocation(LostApiClient client,
Location mockLocation) {
throwIfNotConnected(client);
return service.setMockLocation(client, mockLocation);
}

@Override public PendingResult<Status> setMockTrace(LostApiClient client, File file) {
throwIfNotConnected(client);
return service.setMockTrace(client, file);
}

Expand All @@ -172,4 +183,10 @@ void removeConnectionCallbacks(LostApiClient.ConnectionCallbacks callbacks) {
FusedLocationServiceConnectionManager getServiceConnectionManager() {
return serviceConnectionManager;
}

private void throwIfNotConnected(LostApiClient client) {
if (!client.isConnected()) {
throw new IllegalStateException("LostApiClient is not connected.");
}
}
}
Loading