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

Commit edff6dbe authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge "Switch from hardware_legacy to new HAL GPS interface." into kraken

parents 86d663fa b7ff4574
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@

#include "JNIHelp.h"
#include "jni.h"
#include "hardware_legacy/gps.h"
#include "hardware_legacy/gps_ni.h"
#include "hardware/hardware.h"
#include "hardware/gps.h"
#include "utils/Log.h"
#include "utils/misc.h"

@@ -204,16 +204,34 @@ static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env,
    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
}

static const GpsInterface* get_gps_interface() {
    int err;
    hw_module_t* module;
    const GpsInterface* interface = NULL;

    err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
    if (err == 0) {
        hw_device_t* device;
        err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
        if (err == 0) {
            gps_device_t* gps_device = (gps_device_t *)device;
            interface = gps_device->get_gps_interface(gps_device);
        }
    }

    return interface;
}

static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
    if (!sGpsInterface)
        sGpsInterface = gps_get_interface();
        sGpsInterface = get_gps_interface();
    return (sGpsInterface != NULL);
}

static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj)
{
    if (!sGpsInterface)
        sGpsInterface = gps_get_interface();
        sGpsInterface = get_gps_interface();
    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
        return false;