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

Commit 919902a0 authored by destradaa's avatar destradaa Committed by Android (Google) Code Review
Browse files

Merge "Re-work the initialization of FLP HAL to make isSupported() static. b/14839888"

parents 39f5300e 5ce66d8d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -427,8 +427,9 @@ public class LocationManagerService extends ILocationManager.Stub {
        }

        // bind to fused provider if supported
        if (FlpHardwareProvider.getInstance(mContext).isSupported()) {
          FlpHardwareProvider flpHardwareProvider = FlpHardwareProvider.getInstance(mContext);
        if (FlpHardwareProvider.isSupported()) {
          FlpHardwareProvider flpHardwareProvider =
              FlpHardwareProvider.getInstance(mContext);
          FusedProxy fusedProxy = FusedProxy.createAndBind(
                  mContext,
                  mLocationHandler,
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class FlpHardwareProvider {
                Looper.myLooper());
    }

    public boolean isSupported() {
    public static boolean isSupported() {
        return nativeIsSupported();
    }

+38 −39
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ static int SetThreadEvent(ThreadEvent event) {
 * the HW module and obtaining the proper interfaces.
 */
static void ClassInit(JNIEnv* env, jclass clazz) {
  sFlpInterface = NULL;

  // get references to the Java provider methods
  sOnLocationReport = env->GetMethodID(
      clazz,
@@ -163,6 +165,38 @@ static void ClassInit(JNIEnv* env, jclass clazz) {
  sOnGeofenceRemove = env->GetMethodID(clazz, "onGeofenceRemove", "(II)V");
  sOnGeofencePause = env->GetMethodID(clazz, "onGeofencePause", "(II)V");
  sOnGeofenceResume = env->GetMethodID(clazz, "onGeofenceResume", "(II)V");

  // open the hardware module
  const hw_module_t* module = NULL;
  int err = hw_get_module(FUSED_LOCATION_HARDWARE_MODULE_ID, &module);
  if (err != 0) {
    ALOGE("Error hw_get_module '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
    return;
  }

  err = module->methods->open(
      module,
      FUSED_LOCATION_HARDWARE_MODULE_ID,
      &sHardwareDevice);
  if (err != 0) {
    ALOGE("Error opening device '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
    return;
  }

  // acquire the interfaces pointers
  flp_device_t* flp_device = reinterpret_cast<flp_device_t*>(sHardwareDevice);
  sFlpInterface = flp_device->get_flp_interface(flp_device);

  if (sFlpInterface != NULL) {
    sFlpDiagnosticInterface = reinterpret_cast<const FlpDiagnosticInterface*>(
        sFlpInterface->get_extension(FLP_DIAGNOSTIC_INTERFACE));

    sFlpGeofencingInterface = reinterpret_cast<const FlpGeofencingInterface*>(
        sFlpInterface->get_extension(FLP_GEOFENCING_INTERFACE));

    sFlpDeviceContextInterface = reinterpret_cast<const FlpDeviceContextInterface*>(
        sFlpInterface->get_extension(FLP_DEVICE_CONTEXT_INTERFACE));
  }
}

/*
@@ -637,44 +671,6 @@ FlpGeofenceCallbacks sFlpGeofenceCallbacks = {
 * the Flp interfaces are initialized properly.
 */
static void Init(JNIEnv* env, jobject obj) {
  if(sHardwareDevice != NULL) {
    ALOGD("Hardware Device already opened.");
    return;
  }

  const hw_module_t* module = NULL;
  int err = hw_get_module(FUSED_LOCATION_HARDWARE_MODULE_ID, &module);
  if(err != 0) {
    ALOGE("Error hw_get_module '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
    return;
  }

  err = module->methods->open(
        module,
        FUSED_LOCATION_HARDWARE_MODULE_ID, &sHardwareDevice);
  if(err != 0) {
    ALOGE("Error opening device '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
    return;
  }

  sFlpInterface = NULL;
  flp_device_t* flp_device = reinterpret_cast<flp_device_t*>(sHardwareDevice);
  sFlpInterface = flp_device->get_flp_interface(flp_device);

  if(sFlpInterface != NULL) {
    sFlpDiagnosticInterface = reinterpret_cast<const FlpDiagnosticInterface*>(
        sFlpInterface->get_extension(FLP_DIAGNOSTIC_INTERFACE)
        );

    sFlpGeofencingInterface = reinterpret_cast<const FlpGeofencingInterface*>(
        sFlpInterface->get_extension(FLP_GEOFENCING_INTERFACE)
        );

    sFlpDeviceContextInterface = reinterpret_cast<const FlpDeviceContextInterface*>(
        sFlpInterface->get_extension(FLP_DEVICE_CONTEXT_INTERFACE)
        );
  }

  if(sCallbacksObj == NULL) {
    sCallbacksObj = env->NewGlobalRef(obj);
  }
@@ -696,7 +692,10 @@ static void Init(JNIEnv* env, jobject obj) {
}

static jboolean IsSupported(JNIEnv* env, jclass clazz) {
  return sFlpInterface != NULL;
  if (sFlpInterface == NULL) {
    return JNI_FALSE;
  }
  return JNI_TRUE;
}

static jint GetBatchSize(JNIEnv* env, jobject object) {