Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fff30439 authored by David Christie's avatar David Christie
Browse files

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
parent 83201796
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -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;
}
+8 −0
Original line number Diff line number Diff line
@@ -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();
+6 −0
Original line number Diff line number Diff line
@@ -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();
+6 −0
Original line number Diff line number Diff line
@@ -116,4 +116,10 @@ public class FusedLocationHardwareSecure extends IFusedLocationHardware.Stub {
        checkPermissions();
        mLocationHardware.injectDeviceContext(deviceEnabledContext);
    }

    @Override
    public void flushBatchedLocations() throws RemoteException {
        checkPermissions();
        mLocationHardware.flushBatchedLocations();
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -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<void*>(GetBatchedLocation)},
  {"nativeFlushBatchedLocations",
          "()V",
          reinterpret_cast<void*>(FlushBatchedLocations)},
  {"nativeInjectLocation",
        "(Landroid/location/Location;)V",
        reinterpret_cast<void*>(InjectLocation)},