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

Commit

Permalink
Migrate client management from service to fused location api implemen…
Browse files Browse the repository at this point in the history
…tation (#182)

* Removes client param from service get last location method

* Removes client param from service get location availability method

* Removes unused client param from service mock mode methods

* Migrates client management out of service for location listener requests

* Migrates client management out of service for pending intent requests

* Migrates client management out of service for location callback requests

* Removes more deprecated provider enabled stuff

* Migrates remove location listener logic from service to fused location api implementation

* Checkstyle

* Support repository version

* Eliminates client param from methods to remove pending intents and location callbacks

* Renames FusedLocationProviderServiceImpl -> FusedLocationProviderServiceDelegate

"Impl" is usually reserved for a class that implements an interface. The name "Delegate" better describes the pattern in use here http://best-practice-software-engineering.ifs.tuwien.ac.at/patterns/delegation.html.

* Removes explicit start/stop service
  • Loading branch information
ecgreb authored and sarahsnow1 committed Apr 19, 2017
1 parent 678b8bd commit ae35abe
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 520 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
pre:
- if [ ! -e /usr/local/android-sdk-linux/build-tools/24.0.2 ]; then echo y | android update sdk --all --no-ui --filter "build-tools-24.0.2"; fi;
- if [ ! -e /usr/local/android-sdk-linux/platforms/android-24 ]; then echo y | android update sdk --all --no-ui --filter "android-24"; fi;
- if ! $(grep -q "Revision=43.0.0" /usr/local/android-sdk-linux/extras/android/m2repository/source.properties); then echo y | android update sdk --all --no-ui --filter "extra-android-m2repository"; fi;
- if ! $(grep -q "Revision=47.0.0" /usr/local/android-sdk-linux/extras/android/m2repository/source.properties); then echo y | android update sdk --all --no-ui --filter "extra-android-m2repository"; fi;
cache_directories:
- /usr/local/android-sdk-linux/build-tools/24.0.2
- /usr/local/android-sdk-linux/platforms/android-24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,4 @@ PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationReque
* @throws IllegalStateException if the client is not connected at the time of this call.
*/
PendingResult<Status> setMockTrace(LostApiClient client, final File file);

/**
* @deprecated Use {@link SettingsApi#checkLocationSettings(LostApiClient,
* LocationSettingsRequest)}.
*/
@Deprecated boolean isProviderEnabled(LostApiClient client, String provider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* Used by {@link LostApiClientImpl} to manage connected clients and by
* {@link FusedLocationProviderServiceImpl} to manage client's {@link LocationListener}s,
* {@link FusedLocationProviderServiceDelegate} to manage client's {@link LocationListener}s,
* {@link PendingIntent}s, and {@link LocationCallback}s.
*/
public interface ClientManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class FusedLocationProviderApiImpl
@Override public void onConnect(Context context) {
this.context = context;
final Intent intent = new Intent(context, FusedLocationProviderService.class);
context.startService(intent);
context.bindService(intent, this, Context.BIND_AUTO_CREATE);
}

Expand All @@ -56,8 +55,6 @@ public class FusedLocationProviderApiImpl
isBound = false;
}

Intent intent = new Intent(context, FusedLocationProviderService.class);
context.stopService(intent);
service = null;
}

Expand Down Expand Up @@ -98,18 +95,19 @@ public boolean isConnected() {

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

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

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

@Override public PendingResult<Status> requestLocationUpdates(LostApiClient client,
Expand All @@ -120,56 +118,59 @@ 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);
LostClientManager.shared().addLocationCallback(client, request, callback, looper);
return service.requestLocationUpdates(request);
}

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

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationListener listener) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, listener);
boolean hasResult = LostClientManager.shared().removeListener(client, listener);
service.removeLocationUpdates();
return new SimplePendingResult(hasResult);
}

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
PendingIntent callbackIntent) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, callbackIntent);
boolean hasResult = LostClientManager.shared().removePendingIntent(client, callbackIntent);
service.removeLocationUpdates();
return new SimplePendingResult(hasResult);
}

@Override public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationCallback callback) {
throwIfNotConnected(client);
return service.removeLocationUpdates(client, callback);
boolean hasResult = LostClientManager.shared().removeLocationCallback(client, callback);
service.removeLocationUpdates();
return new SimplePendingResult(hasResult);
}

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

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

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

@Override public boolean isProviderEnabled(LostApiClient client, String provider) {
return service.isProviderEnabled(client, provider);
return service.setMockTrace(file);
}

public Map<LostApiClient, Set<LocationListener>> getLocationListeners() {
return service.getLocationListeners();
return LostClientManager.shared().getLocationListeners();
}

public FusedLocationProviderService getService() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package com.mapzen.android.lost.internal;

import com.mapzen.android.lost.api.LocationAvailability;
import com.mapzen.android.lost.api.LocationCallback;
import com.mapzen.android.lost.api.LocationListener;
import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LostApiClient;
import com.mapzen.android.lost.api.PendingResult;
import com.mapzen.android.lost.api.Status;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.os.Binder;
import android.os.IBinder;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;

import java.io.File;
import java.util.Map;
import java.util.Set;

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
Expand All @@ -30,7 +23,7 @@
*/
public class FusedLocationProviderService extends Service {

private FusedLocationProviderServiceImpl serviceImpl;
private FusedLocationProviderServiceDelegate serviceImpl;

private final IBinder binder = new FusedLocationProviderBinder();

Expand All @@ -47,65 +40,35 @@ public FusedLocationProviderService getService() {

@Override public void onCreate() {
super.onCreate();
serviceImpl = new FusedLocationProviderServiceImpl(this, LostClientManager.shared());
serviceImpl = new FusedLocationProviderServiceDelegate(this, LostClientManager.shared());
}

public Location getLastLocation(LostApiClient client) {
return serviceImpl.getLastLocation(client);
public Location getLastLocation() {
return serviceImpl.getLastLocation();
}

@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public LocationAvailability getLocationAvailability(LostApiClient client) {
return serviceImpl.getLocationAvailability(client);
public LocationAvailability getLocationAvailability() {
return serviceImpl.getLocationAvailability();
}

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

public PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
PendingIntent callbackIntent) {
return serviceImpl.requestLocationUpdates(client, request, callbackIntent);
public void removeLocationUpdates() {
serviceImpl.removeLocationUpdates();
}

public PendingResult<Status> requestLocationUpdates(LostApiClient client, LocationRequest request,
LocationCallback callback, Looper looper) {
return serviceImpl.requestLocationUpdates(client, request, callback, looper);
public PendingResult<Status> setMockMode(boolean isMockMode) {
return serviceImpl.setMockMode(isMockMode);
}

public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationListener listener) {
return serviceImpl.removeLocationUpdates(client, listener);
public PendingResult<Status> setMockLocation(Location mockLocation) {
return serviceImpl.setMockLocation(mockLocation);
}

public PendingResult<Status> removeLocationUpdates(LostApiClient client,
PendingIntent callbackIntent) {
return serviceImpl.removeLocationUpdates(client, callbackIntent);
}

public PendingResult<Status> removeLocationUpdates(LostApiClient client,
LocationCallback callback) {
return serviceImpl.removeLocationUpdates(client, callback);
}

public PendingResult<Status> setMockMode(LostApiClient client, boolean isMockMode) {
return serviceImpl.setMockMode(client, isMockMode);
}

public PendingResult<Status> setMockLocation(LostApiClient client, Location mockLocation) {
return serviceImpl.setMockLocation(client, mockLocation);
}

public PendingResult<Status> setMockTrace(LostApiClient client, File file) {
return serviceImpl.setMockTrace(client, file);
}

public boolean isProviderEnabled(LostApiClient client, String provider) {
return serviceImpl.isProviderEnabled(client, provider);
}

public Map<LostApiClient, Set<LocationListener>> getLocationListeners() {
return serviceImpl.getLocationListeners();
public PendingResult<Status> setMockTrace(File file) {
return serviceImpl.setMockTrace(file);
}
}
Loading

0 comments on commit ae35abe

Please sign in to comment.