From ffca45a2cdd778e6edd5c3959bf53c6192b7e035 Mon Sep 17 00:00:00 2001 From: David Christie Date: Sat, 11 Apr 2015 23:15:08 -0700 Subject: Add capability callback for FLP HAL. Let HAL implementation tell if geofencing/batching is supported and which technologies (GNNS, wifi, etc) can be used. Still todo: Add ability for GmsCore geofencing to tell which technologies are supported (instead of just using it to update monitoring). This requires SystemApi change + approval so will do in separate CL. Note that the classes in the lib are not copied directly into GmsCore. The instance will always be whatever is in the platform. This is why the callback is backwards compatible as long as their is a default implementation (but not if it's abstract). Change-Id: I7d6adeb049b89935bc4443785df5d7ef4c730e5d --- .../hardware/location/GeofenceHardwareImpl.java | 27 +++++++++++++++++++++- .../hardware/location/GeofenceHardwareService.java | 11 +++++++++ .../location/IFusedLocationHardwareSink.aidl | 10 ++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'core/java') diff --git a/core/java/android/hardware/location/GeofenceHardwareImpl.java b/core/java/android/hardware/location/GeofenceHardwareImpl.java index 4696b2a..5d40e94 100644 --- a/core/java/android/hardware/location/GeofenceHardwareImpl.java +++ b/core/java/android/hardware/location/GeofenceHardwareImpl.java @@ -53,6 +53,7 @@ public final class GeofenceHardwareImpl { private IFusedGeofenceHardware mFusedService; private IGpsGeofenceHardware mGpsService; + private int mCapabilities; private int[] mSupportedMonitorTypes = new int[GeofenceHardware.NUM_MONITORS]; @@ -89,6 +90,9 @@ public final class GeofenceHardwareImpl { private static final int RESOLUTION_LEVEL_COARSE = 2; private static final int RESOLUTION_LEVEL_FINE = 3; + // Capability constant corresponding to fused_location.h entry when geofencing supports GNNS. + private static final int CAPABILITY_GNSS = 1; + public synchronized static GeofenceHardwareImpl getInstance(Context context) { if (sInstance == null) { sInstance = new GeofenceHardwareImpl(context); @@ -141,7 +145,9 @@ public final class GeofenceHardwareImpl { private void updateFusedHardwareAvailability() { boolean fusedSupported; try { - fusedSupported = (mFusedService != null ? mFusedService.isSupported() : false); + fusedSupported = (mFusedService != null + ? mFusedService.isSupported() && (mCapabilities & CAPABILITY_GNSS) != 0 + : false); } catch (RemoteException e) { Log.e(TAG, "RemoteException calling LocationManagerService"); fusedSupported = false; @@ -166,6 +172,11 @@ public final class GeofenceHardwareImpl { } } + public void onCapabilities(int capabilities) { + mCapabilities = capabilities; + updateFusedHardwareAvailability(); + } + public void setFusedGeofenceHardware(IFusedGeofenceHardware service) { if(mFusedService == null) { mFusedService = service; @@ -212,6 +223,20 @@ public final class GeofenceHardwareImpl { } } + public int getCapabilitiesForMonitoringType(int monitoringType) { + switch (mSupportedMonitorTypes[monitoringType]) { + case GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE: + switch (monitoringType) { + case GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE: + return CAPABILITY_GNSS; + case GeofenceHardware.MONITORING_TYPE_FUSED_HARDWARE: + return mCapabilities; + } + break; + } + return 0; + } + public boolean addCircularFence( int monitoringType, GeofenceHardwareRequestParcelable request, diff --git a/core/java/android/hardware/location/GeofenceHardwareService.java b/core/java/android/hardware/location/GeofenceHardwareService.java index 4816c5f..c0bcb27 100644 --- a/core/java/android/hardware/location/GeofenceHardwareService.java +++ b/core/java/android/hardware/location/GeofenceHardwareService.java @@ -65,14 +65,17 @@ public class GeofenceHardwareService extends Service { } private IBinder mBinder = new IGeofenceHardware.Stub() { + @Override public void setGpsGeofenceHardware(IGpsGeofenceHardware service) { mGeofenceHardwareImpl.setGpsHardwareGeofence(service); } + @Override public void setFusedGeofenceHardware(IFusedGeofenceHardware service) { mGeofenceHardwareImpl.setFusedGeofenceHardware(service); } + @Override public int[] getMonitoringTypes() { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, "Location Hardware permission not granted to access hardware geofence"); @@ -80,12 +83,15 @@ public class GeofenceHardwareService extends Service { return mGeofenceHardwareImpl.getMonitoringTypes(); } + @Override public int getStatusOfMonitoringType(int monitoringType) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, "Location Hardware permission not granted to access hardware geofence"); return mGeofenceHardwareImpl.getStatusOfMonitoringType(monitoringType); } + + @Override public boolean addCircularFence( int monitoringType, GeofenceHardwareRequestParcelable request, @@ -96,6 +102,7 @@ public class GeofenceHardwareService extends Service { return mGeofenceHardwareImpl.addCircularFence(monitoringType, request, callback); } + @Override public boolean removeGeofence(int id, int monitoringType) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, "Location Hardware permission not granted to access hardware geofence"); @@ -104,6 +111,7 @@ public class GeofenceHardwareService extends Service { return mGeofenceHardwareImpl.removeGeofence(id, monitoringType); } + @Override public boolean pauseGeofence(int id, int monitoringType) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, "Location Hardware permission not granted to access hardware geofence"); @@ -112,6 +120,7 @@ public class GeofenceHardwareService extends Service { return mGeofenceHardwareImpl.pauseGeofence(id, monitoringType); } + @Override public boolean resumeGeofence(int id, int monitoringType, int monitorTransitions) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, "Location Hardware permission not granted to access hardware geofence"); @@ -120,6 +129,7 @@ public class GeofenceHardwareService extends Service { return mGeofenceHardwareImpl.resumeGeofence(id, monitoringType, monitorTransitions); } + @Override public boolean registerForMonitorStateChangeCallback(int monitoringType, IGeofenceHardwareMonitorCallback callback) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, @@ -130,6 +140,7 @@ public class GeofenceHardwareService extends Service { callback); } + @Override public boolean unregisterForMonitorStateChangeCallback(int monitoringType, IGeofenceHardwareMonitorCallback callback) { mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, diff --git a/core/java/android/hardware/location/IFusedLocationHardwareSink.aidl b/core/java/android/hardware/location/IFusedLocationHardwareSink.aidl index a11d8ab..2107ae8 100644 --- a/core/java/android/hardware/location/IFusedLocationHardwareSink.aidl +++ b/core/java/android/hardware/location/IFusedLocationHardwareSink.aidl @@ -30,12 +30,18 @@ interface IFusedLocationHardwareSink { * * @param locations The batch of location information available. */ - void onLocationAvailable(in Location[] locations); + void onLocationAvailable(in Location[] locations) = 0; /** * Event generated from FLP HAL to provide diagnostic data to the platform. * * @param data The diagnostic data provided by FLP HAL. */ - void onDiagnosticDataAvailable(in String data); + void onDiagnosticDataAvailable(in String data) = 1; + + /** + * Event generated from FLP HAL to provide a mask of supported + * capabilities. Should be called immediatly after init. + */ + void onCapabilities(int capabilities) = 2; } \ No newline at end of file -- cgit v1.1