From fff30439cafb737eb54de807caab4fb61432f2cc Mon Sep 17 00:00:00 2001 From: David Christie Date: Sun, 12 Apr 2015 21:26:02 -0700 Subject: [PATCH] Add ability to flush FLP HAL batched locations buffer. Currently GmsCore has to guess how many locations to retrieve based on requested frequency and then demux the output looking for timestamps (that aren't monotonically increasing). This capability gives GmsCore a more graceful solution. Change-Id: Ie1d71615f699bc0d3c63f8b80aa7b40b9971cf96 --- .../location/IFusedLocationHardware.aidl | 29 ++++++++++++------- .../provider/FusedLocationHardware.java | 8 +++++ .../server/location/FlpHardwareProvider.java | 6 ++++ .../location/FusedLocationHardwareSecure.java | 6 ++++ ...id_server_location_FlpHardwareProvider.cpp | 11 +++++++ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/core/java/android/hardware/location/IFusedLocationHardware.aidl b/core/java/android/hardware/location/IFusedLocationHardware.aidl index 382c12c85be17..3de766add3ba4 100644 --- a/core/java/android/hardware/location/IFusedLocationHardware.aidl +++ b/core/java/android/hardware/location/IFusedLocationHardware.aidl @@ -32,21 +32,21 @@ interface IFusedLocationHardware { * * @param eventSink The sink to register. */ - void registerSink(in IFusedLocationHardwareSink eventSink); + void registerSink(in IFusedLocationHardwareSink eventSink) = 0; /** * Unregisters a sink with the Location Hardware object. * * @param eventSink The sink to unregister. */ - void unregisterSink(in IFusedLocationHardwareSink eventSink); + void unregisterSink(in IFusedLocationHardwareSink eventSink) = 1; /** * Provides access to the batch size available in Hardware. * * @return The batch size the hardware supports. */ - int getSupportedBatchSize(); + int getSupportedBatchSize() = 2; /** * Requests the Hardware to start batching locations. @@ -56,7 +56,7 @@ interface IFusedLocationHardware { * * @throws RuntimeException if the request Id exists. */ - void startBatching(in int id, in FusedBatchOptions batchOptions); + void startBatching(in int id, in FusedBatchOptions batchOptions) = 3; /** * Requests the Hardware to stop batching for the given Id. @@ -64,7 +64,7 @@ interface IFusedLocationHardware { * @param id The request that needs to be stopped. * @throws RuntimeException if the request Id is unknown. */ - void stopBatching(in int id); + void stopBatching(in int id) = 4; /** * Updates a batching operation in progress. @@ -74,7 +74,7 @@ interface IFusedLocationHardware { * * @throws RuntimeException if the Id of the request is unknown. */ - void updateBatchingOptions(in int id, in FusedBatchOptions batchOptions); + void updateBatchingOptions(in int id, in FusedBatchOptions batchOptions) = 5; /** * Requests the most recent locations available in Hardware. @@ -83,14 +83,14 @@ interface IFusedLocationHardware { * * @param batchSizeRequested The number of locations requested. */ - void requestBatchOfLocations(in int batchSizeRequested); + void requestBatchOfLocations(in int batchSizeRequested) = 6; /** * Flags if the Hardware supports injection of diagnostic data. * * @return True if data injection is supported, false otherwise. */ - boolean supportsDiagnosticDataInjection(); + boolean supportsDiagnosticDataInjection() = 7; /** * Injects diagnostic data into the Hardware subsystem. @@ -98,14 +98,14 @@ interface IFusedLocationHardware { * @param data The data to inject. * @throws RuntimeException if injection is not supported. */ - void injectDiagnosticData(in String data); + void injectDiagnosticData(in String data) = 8; /** * Flags if the Hardware supports injection of device context information. * * @return True if device context injection is supported, false otherwise. */ - boolean supportsDeviceContextInjection(); + boolean supportsDeviceContextInjection() = 9; /** * Injects device context information into the Hardware subsystem. @@ -113,5 +113,12 @@ interface IFusedLocationHardware { * @param deviceEnabledContext The context to inject. * @throws RuntimeException if injection is not supported. */ - void injectDeviceContext(in int deviceEnabledContext); + void injectDeviceContext(in int deviceEnabledContext) = 10; + + /** + * Requests all batched locations currently available in Hardware + * and clears the buffer. Any subsequent calls will not return any + * of the locations returned in this call. + */ + void flushBatchedLocations() = 11; } diff --git a/location/lib/java/com/android/location/provider/FusedLocationHardware.java b/location/lib/java/com/android/location/provider/FusedLocationHardware.java index cbe404b7aafa7..480a18ccb32d2 100644 --- a/location/lib/java/com/android/location/provider/FusedLocationHardware.java +++ b/location/lib/java/com/android/location/provider/FusedLocationHardware.java @@ -174,6 +174,14 @@ public final class FusedLocationHardware { } } + public void flushBatchedLocations() { + try { + mLocationHardware.flushBatchedLocations(); + } catch(RemoteException e) { + Log.e(TAG, "RemoteException at flushBatchedLocations"); + } + } + public boolean supportsDiagnosticDataInjection() { try { return mLocationHardware.supportsDiagnosticDataInjection(); diff --git a/services/core/java/com/android/server/location/FlpHardwareProvider.java b/services/core/java/com/android/server/location/FlpHardwareProvider.java index f41d930805935..834dff2caecf1 100644 --- a/services/core/java/com/android/server/location/FlpHardwareProvider.java +++ b/services/core/java/com/android/server/location/FlpHardwareProvider.java @@ -273,6 +273,7 @@ public class FlpHardwareProvider { private native void nativeUpdateBatchingOptions(int requestId, FusedBatchOptions optionsObject); private native void nativeStopBatching(int id); private native void nativeRequestBatchedLocation(int lastNLocations); + private native void nativeFlushBatchedLocations(); private native void nativeInjectLocation(Location location); // TODO [Fix] sort out the lifetime of the instance private native void nativeCleanup(); @@ -363,6 +364,11 @@ public class FlpHardwareProvider { nativeRequestBatchedLocation(batchSizeRequested); } + @Override + public void flushBatchedLocations() { + nativeFlushBatchedLocations(); + } + @Override public boolean supportsDiagnosticDataInjection() { return nativeIsDiagnosticSupported(); diff --git a/services/core/java/com/android/server/location/FusedLocationHardwareSecure.java b/services/core/java/com/android/server/location/FusedLocationHardwareSecure.java index 389bd2477c84f..e49c411b16802 100644 --- a/services/core/java/com/android/server/location/FusedLocationHardwareSecure.java +++ b/services/core/java/com/android/server/location/FusedLocationHardwareSecure.java @@ -116,4 +116,10 @@ public class FusedLocationHardwareSecure extends IFusedLocationHardware.Stub { checkPermissions(); mLocationHardware.injectDeviceContext(deviceEnabledContext); } + + @Override + public void flushBatchedLocations() throws RemoteException { + checkPermissions(); + mLocationHardware.flushBatchedLocations(); + } } diff --git a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp index 81cdcb0aad540..852b5e9e19d73 100644 --- a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp +++ b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp @@ -847,6 +847,14 @@ static void GetBatchedLocation(JNIEnv* env, jobject /* object */, jint lastNLoca sFlpInterface->get_batched_location(lastNLocations); } +static void FlushBatchedLocations(JNIEnv* env, jobject /* object */) { + if(sFlpInterface == NULL) { + ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__); + } + + sFlpInterface->flush_batched_locations(); +} + static void InjectLocation(JNIEnv* env, jobject /* object */, jobject locationObject) { if(locationObject == NULL) { ALOGE("Invalid location for injection: %p", locationObject); @@ -1029,6 +1037,9 @@ static JNINativeMethod sMethods[] = { {"nativeRequestBatchedLocation", "(I)V", reinterpret_cast(GetBatchedLocation)}, + {"nativeFlushBatchedLocations", + "()V", + reinterpret_cast(FlushBatchedLocations)}, {"nativeInjectLocation", "(Landroid/location/Location;)V", reinterpret_cast(InjectLocation)},