diff options
author | David Christie <dnchrist@google.com> | 2015-04-11 23:15:08 -0700 |
---|---|---|
committer | David Christie <dnchrist@google.com> | 2015-04-12 16:22:03 -0700 |
commit | ffca45a2cdd778e6edd5c3959bf53c6192b7e035 (patch) | |
tree | 0cfdbd98208c1472dee47baf0b37bde953165d4e /location | |
parent | 295a93b99f1773638553a0d00898824dc7ba79e5 (diff) | |
download | frameworks_base-ffca45a2cdd778e6edd5c3959bf53c6192b7e035.zip frameworks_base-ffca45a2cdd778e6edd5c3959bf53c6192b7e035.tar.gz frameworks_base-ffca45a2cdd778e6edd5c3959bf53c6192b7e035.tar.bz2 |
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
Diffstat (limited to 'location')
-rw-r--r-- | location/lib/java/com/android/location/provider/FusedLocationHardware.java | 40 | ||||
-rw-r--r-- | location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java | 33 |
2 files changed, 64 insertions, 9 deletions
diff --git a/location/lib/java/com/android/location/provider/FusedLocationHardware.java b/location/lib/java/com/android/location/provider/FusedLocationHardware.java index bc5a8a1..44cb199 100644 --- a/location/lib/java/com/android/location/provider/FusedLocationHardware.java +++ b/location/lib/java/com/android/location/provider/FusedLocationHardware.java @@ -34,7 +34,7 @@ import java.util.Map; * Class that exposes IFusedLocationHardware functionality to unbundled services. */ public final class FusedLocationHardware { - private final String TAG = "FusedLocationHardware"; + private static final String TAG = "FusedLocationHardware"; private IFusedLocationHardware mLocationHardware; @@ -52,6 +52,11 @@ public final class FusedLocationHardware { public void onDiagnosticDataAvailable(String data) { dispatchDiagnosticData(data); } + + @Override + public void onCapabilities(int capabilities) { + dispatchCapabilities(capabilities); + } }; /** @@ -204,6 +209,7 @@ public final class FusedLocationHardware { private class DispatcherHandler extends Handler { public static final int DISPATCH_LOCATION = 1; public static final int DISPATCH_DIAGNOSTIC_DATA = 2; + public static final int DISPATCH_CAPABILITIES = 3; public DispatcherHandler(Looper looper) { super(looper, null /*callback*/ , true /*async*/); @@ -218,6 +224,10 @@ public final class FusedLocationHardware { break; case DISPATCH_DIAGNOSTIC_DATA: command.dispatchDiagnosticData(); + break; + case DISPATCH_CAPABILITIES: + command.dispatchCapabilities(); + break; default: Log.e(TAG, "Invalid dispatch message"); break; @@ -229,14 +239,17 @@ public final class FusedLocationHardware { private final FusedLocationHardwareSink mSink; private final Location[] mLocations; private final String mData; + private final int mCapabilities; public MessageCommand( FusedLocationHardwareSink sink, Location[] locations, - String data) { + String data, + int capabilities) { mSink = sink; mLocations = locations; mData = data; + mCapabilities = capabilities; } public void dispatchLocation() { @@ -246,6 +259,10 @@ public final class FusedLocationHardware { public void dispatchDiagnosticData() { mSink.onDiagnosticDataAvailable(mData); } + + public void dispatchCapabilities() { + mSink.onCapabilities(mCapabilities); + } } private void dispatchLocations(Location[] locations) { @@ -258,7 +275,7 @@ public final class FusedLocationHardware { Message message = Message.obtain( entry.getValue(), DispatcherHandler.DISPATCH_LOCATION, - new MessageCommand(entry.getKey(), locations, null /*data*/)); + new MessageCommand(entry.getKey(), locations, null /*data*/, 0)); message.sendToTarget(); } } @@ -273,7 +290,22 @@ public final class FusedLocationHardware { Message message = Message.obtain( entry.getValue(), DispatcherHandler.DISPATCH_DIAGNOSTIC_DATA, - new MessageCommand(entry.getKey(), null /*locations*/, data)); + new MessageCommand(entry.getKey(), null /*locations*/, data, 0)); + message.sendToTarget(); + } + } + + private void dispatchCapabilities(int capabilities) { + HashMap<FusedLocationHardwareSink, DispatcherHandler> sinks; + synchronized(mSinkList) { + sinks = mSinkList; + } + + for(Map.Entry<FusedLocationHardwareSink, DispatcherHandler> entry : sinks.entrySet()) { + Message message = Message.obtain( + entry.getValue(), + DispatcherHandler.DISPATCH_CAPABILITIES, + new MessageCommand(entry.getKey(), null /*locations*/, null, capabilities)); message.sendToTarget(); } } diff --git a/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java index 2c39fa8..aaef773 100644 --- a/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java +++ b/location/lib/java/com/android/location/provider/FusedLocationHardwareSink.java @@ -20,11 +20,34 @@ import android.location.Location; /** * Base class for sinks to interact with FusedLocationHardware. + * + * <p>Default implementations allow new methods to be added without crashing + * clients compiled against an old library version. */ -public abstract class FusedLocationHardwareSink { - /* - * Methods to provide a facade for IFusedLocationHardware +public class FusedLocationHardwareSink { + /** + * Called when one or more locations are available from the FLP + * HAL. + */ + public void onLocationAvailable(Location[] locations) { + // default do nothing + } + + /** + * Called when diagnostic data is available from the FLP HAL. + */ + public void onDiagnosticDataAvailable(String data) { + // default do nothing + } + + /** + * Called when capabilities are available from the FLP HAL. + * Should be called once right after initialization. + * + * @param capabilities A bitmask of capabilities defined in + * fused_location.h. */ - public abstract void onLocationAvailable(Location[] locations); - public abstract void onDiagnosticDataAvailable(String data); + public void onCapabilities(int capabilities) { + // default do nothing + } }
\ No newline at end of file |