android gps杂乱分析

在上层调用locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))时返回了false,追了一下代码看看,以下是

在LocationManagerService.java中

private void _loadProvidersLocked() {
        // Attempt to load "real" providers first
        if(GpsLocationProvider.isSupported()){      //调试返回空,也就是说isSupported为false
            // Create a gps location provider
            GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this);
            mGpsStatusProvider = gpsProvider.getGpsStatusProvider();
            mNetInitiatedListener = gpsProvider.getNetInitiatedListener();
            addProvider(gpsProvider);
            mGpsLocationProvider = gpsProvider;
        }
GpsLocationProvider.isSupported()决定是否支持GPS,而这个方法实现在GpsLocationProvider.java中
 public static boolean isSupported() {
        return native_is_supported();
    }
向下就是调用JNI层的接口了,
{"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported},

static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
    return (sGpsInterface != NULL || get_gps_interface() != NULL);
}
sGpsInterface是gps的接口,get_gps_interface()也是在这个文件中定义的,gps_get_interface函数属于HAL层的调用


 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);
        }
    }

get_gps_interface(devices)


未完

你可能感兴趣的:(android,Module,jni,null,interface)