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

Commit ca207e40 authored by Yu-Han Yang's avatar Yu-Han Yang Committed by Android (Google) Code Review
Browse files

Merge "Add register/unregister methods for SvStatus and NMEA (frameworks/base)"

parents 1f77cfff 59c5b981
Loading
Loading
Loading
Loading
+14 −5
Original line number Original line Diff line number Diff line
@@ -63,16 +63,25 @@ class GnssNmeaProvider extends GnssListenerMultiplexer<Void, IGnssNmeaListener,
    @Override
    @Override
    protected boolean registerWithService(Void ignored,
    protected boolean registerWithService(Void ignored,
            Collection<GnssListenerRegistration> registrations) {
            Collection<GnssListenerRegistration> registrations) {
        if (mGnssNative.startNmeaMessageCollection()) {
            if (D) {
            if (D) {
            Log.d(TAG, "starting gnss nmea messages");
                Log.d(TAG, "starting gnss nmea messages collection");
            }
            }
            return true;
            return true;
        } else {
            Log.e(TAG, "error starting gnss nmea messages collection");
            return false;
        }
    }
    }


    @Override
    @Override
    protected void unregisterWithService() {
    protected void unregisterWithService() {
        if (mGnssNative.stopNmeaMessageCollection()) {
            if (D) {
            if (D) {
            Log.d(TAG, "stopping gnss nmea messages");
                Log.d(TAG, "stopping gnss nmea messages collection");
            }
        } else {
            Log.e(TAG, "error stopping gnss nmea messages collection");
        }
        }
    }
    }


+16 −5
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ public class GnssStatusProvider extends


    private final AppOpsHelper mAppOpsHelper;
    private final AppOpsHelper mAppOpsHelper;
    private final LocationUsageLogger mLogger;
    private final LocationUsageLogger mLogger;
    private final GnssNative mGnssNative;


    private boolean mIsNavigating = false;
    private boolean mIsNavigating = false;


@@ -50,6 +51,7 @@ public class GnssStatusProvider extends
        super(injector);
        super(injector);
        mAppOpsHelper = injector.getAppOpsHelper();
        mAppOpsHelper = injector.getAppOpsHelper();
        mLogger = injector.getLocationUsageLogger();
        mLogger = injector.getLocationUsageLogger();
        mGnssNative = gnssNative;


        gnssNative.addBaseCallbacks(this);
        gnssNative.addBaseCallbacks(this);
        gnssNative.addStatusCallbacks(this);
        gnssNative.addStatusCallbacks(this);
@@ -64,16 +66,25 @@ public class GnssStatusProvider extends
    @Override
    @Override
    protected boolean registerWithService(Void ignored,
    protected boolean registerWithService(Void ignored,
            Collection<GnssListenerRegistration> registrations) {
            Collection<GnssListenerRegistration> registrations) {
        if (mGnssNative.startSvStatusCollection()) {
            if (D) {
            if (D) {
            Log.d(TAG, "starting gnss status");
                Log.d(TAG, "starting gnss sv status");
            }
            }
            return true;
            return true;
        } else {
            Log.e(TAG, "error starting gnss sv status");
            return false;
        }
    }
    }


    @Override
    @Override
    protected void unregisterWithService() {
    protected void unregisterWithService() {
        if (mGnssNative.stopSvStatusCollection()) {
            if (D) {
            if (D) {
            Log.d(TAG, "stopping gnss status");
                Log.d(TAG, "stopping gnss sv status");
            }
        } else {
            Log.e(TAG, "error stopping gnss sv status");
        }
        }
    }
    }


+57 −0
Original line number Original line Diff line number Diff line
@@ -782,6 +782,38 @@ public class GnssNative {
        return mGnssHal.stopMeasurementCollection();
        return mGnssHal.stopMeasurementCollection();
    }
    }


    /**
     * Starts sv status collection.
     */
    public boolean startSvStatusCollection() {
        Preconditions.checkState(mRegistered);
        return mGnssHal.startSvStatusCollection();
    }

    /**
     * Stops sv status collection.
     */
    public boolean stopSvStatusCollection() {
        Preconditions.checkState(mRegistered);
        return mGnssHal.stopSvStatusCollection();
    }

    /**
     * Starts NMEA message collection.
     */
    public boolean startNmeaMessageCollection() {
        Preconditions.checkState(mRegistered);
        return mGnssHal.startNmeaMessageCollection();
    }

    /**
     * Stops NMEA message collection.
     */
    public boolean stopNmeaMessageCollection() {
        Preconditions.checkState(mRegistered);
        return mGnssHal.stopNmeaMessageCollection();
    }

    /**
    /**
     * Returns true if measurement corrections are supported.
     * Returns true if measurement corrections are supported.
     */
     */
@@ -1369,6 +1401,22 @@ public class GnssNative {
            return native_inject_measurement_corrections(corrections);
            return native_inject_measurement_corrections(corrections);
        }
        }


        protected boolean startSvStatusCollection() {
            return native_start_sv_status_collection();
        }

        protected boolean stopSvStatusCollection() {
            return native_stop_sv_status_collection();
        }

        protected boolean startNmeaMessageCollection() {
            return native_start_nmea_message_collection();
        }

        protected boolean stopNmeaMessageCollection() {
            return native_stop_nmea_message_collection();
        }

        protected int getBatchSize() {
        protected int getBatchSize() {
            return native_get_batch_size();
            return native_get_batch_size();
        }
        }
@@ -1478,6 +1526,10 @@ public class GnssNative {


    private static native int native_read_nmea(byte[] buffer, int bufferSize);
    private static native int native_read_nmea(byte[] buffer, int bufferSize);


    private static native boolean native_start_nmea_message_collection();

    private static native boolean native_stop_nmea_message_collection();

    // location injection APIs
    // location injection APIs


    private static native void native_inject_location(
    private static native void native_inject_location(
@@ -1501,6 +1553,11 @@ public class GnssNative {


    private static native void native_inject_time(long time, long timeReference, int uncertainty);
    private static native void native_inject_time(long time, long timeReference, int uncertainty);


    // sv status APIs
    private static native boolean native_start_sv_status_collection();

    private static native boolean native_stop_sv_status_collection();

    // navigation message APIs
    // navigation message APIs


    private static native boolean native_is_navigation_message_supported();
    private static native boolean native_is_navigation_message_supported();
+84 −2
Original line number Original line Diff line number Diff line
@@ -244,6 +244,9 @@ bool hasLatLong(const GnssLocation_V2_0& location) {
    return hasLatLong(location.v1_0);
    return hasLatLong(location.v1_0);
}
}


bool isSvStatusRegistered = false;
bool isNmeaRegistered = false;

}  // namespace
}  // namespace


static inline jboolean boolToJbool(bool value) {
static inline jboolean boolToJbool(bool value) {
@@ -505,6 +508,13 @@ uint32_t GnssCallback::getConstellationType(


template <class T_list, class T_sv_info>
template <class T_list, class T_sv_info>
Return<void> GnssCallback::gnssSvStatusCbImpl(const T_list& svStatus) {
Return<void> GnssCallback::gnssSvStatusCbImpl(const T_list& svStatus) {
    // In HIDL or AIDL v1, if no listener is registered, do not report svInfoList to the framework.
    if (gnssHalAidl == nullptr || gnssHalAidl->getInterfaceVersion() == 1) {
        if (!isSvStatusRegistered) {
            return Void();
        }
    }

    JNIEnv* env = getJniEnv();
    JNIEnv* env = getJniEnv();


    uint32_t listSize = getGnssSvInfoListSize(svStatus);
    uint32_t listSize = getGnssSvInfoListSize(svStatus);
@@ -566,8 +576,12 @@ Return<void> GnssCallback::gnssSvStatusCbImpl(const T_list& svStatus) {
    return Void();
    return Void();
}
}


Return<void> GnssCallback::gnssNmeaCb(
Return<void> GnssCallback::gnssNmeaCb(int64_t timestamp,
    int64_t timestamp, const ::android::hardware::hidl_string& nmea) {
                                      const ::android::hardware::hidl_string& nmea) {
    // In HIDL, if no listener is registered, do not report nmea to the framework.
    if (!isNmeaRegistered) {
        return Void();
    }
    JNIEnv* env = getJniEnv();
    JNIEnv* env = getJniEnv();
    /*
    /*
     * The Java code will call back to read these values.
     * The Java code will call back to read these values.
@@ -680,6 +694,12 @@ Status GnssCallbackAidl::gnssLocationCb(const GnssLocationAidl& location) {
}
}


Status GnssCallbackAidl::gnssNmeaCb(const int64_t timestamp, const std::string& nmea) {
Status GnssCallbackAidl::gnssNmeaCb(const int64_t timestamp, const std::string& nmea) {
    // In AIDL v1, if no listener is registered, do not report nmea to the framework.
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() == 1) {
        if (!isNmeaRegistered) {
            return Status::ok();
        }
    }
    JNIEnv* env = getJniEnv();
    JNIEnv* env = getJniEnv();
    /*
    /*
     * The Java code will call back to read these values.
     * The Java code will call back to read these values.
@@ -1562,6 +1582,58 @@ static jboolean android_location_gnss_hal_GnssNative_stop(JNIEnv* /* env */, jcl
    return checkHidlReturn(result, "IGnss stop() failed.");
    return checkHidlReturn(result, "IGnss stop() failed.");
}
}


static jboolean android_location_gnss_hal_GnssNative_start_sv_status_collection(JNIEnv* /* env */,
                                                                                jclass) {
    isSvStatusRegistered = true;
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
        auto status = gnssHalAidl->startSvStatus();
        return checkAidlStatus(status, "IGnssAidl startSvStatus() failed.");
    }
    if (gnssHal == nullptr) {
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

static jboolean android_location_gnss_hal_GnssNative_stop_sv_status_collection(JNIEnv* /* env */,
                                                                               jclass) {
    isSvStatusRegistered = false;
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
        auto status = gnssHalAidl->stopSvStatus();
        return checkAidlStatus(status, "IGnssAidl stopSvStatus() failed.");
    }
    if (gnssHal == nullptr) {
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

static jboolean android_location_gnss_hal_GnssNative_start_nmea_message_collection(
        JNIEnv* /* env */, jclass) {
    isNmeaRegistered = true;
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
        auto status = gnssHalAidl->startNmea();
        return checkAidlStatus(status, "IGnssAidl startNmea() failed.");
    }
    if (gnssHal == nullptr) {
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

static jboolean android_location_gnss_hal_GnssNative_stop_nmea_message_collection(JNIEnv* /* env */,
                                                                                  jclass) {
    isNmeaRegistered = false;
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
        auto status = gnssHalAidl->stopNmea();
        return checkAidlStatus(status, "IGnssAidl stopNmea() failed.");
    }
    if (gnssHal == nullptr) {
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

static void android_location_gnss_hal_GnssNative_delete_aiding_data(JNIEnv* /* env */, jclass,
static void android_location_gnss_hal_GnssNative_delete_aiding_data(JNIEnv* /* env */, jclass,
                                                                    jint flags) {
                                                                    jint flags) {
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
    if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
@@ -2365,6 +2437,16 @@ static const JNINativeMethod sLocationProviderMethods[] = {
        {"native_is_gnss_visibility_control_supported", "()Z",
        {"native_is_gnss_visibility_control_supported", "()Z",
         reinterpret_cast<void*>(
         reinterpret_cast<void*>(
                 android_location_gnss_hal_GnssNative_is_gnss_visibility_control_supported)},
                 android_location_gnss_hal_GnssNative_is_gnss_visibility_control_supported)},
        {"native_start_sv_status_collection", "()Z",
         reinterpret_cast<void*>(android_location_gnss_hal_GnssNative_start_sv_status_collection)},
        {"native_stop_sv_status_collection", "()Z",
         reinterpret_cast<void*>(android_location_gnss_hal_GnssNative_stop_sv_status_collection)},
        {"native_start_nmea_message_collection", "()Z",
         reinterpret_cast<void*>(
                 android_location_gnss_hal_GnssNative_start_nmea_message_collection)},
        {"native_stop_nmea_message_collection", "()Z",
         reinterpret_cast<void*>(
                 android_location_gnss_hal_GnssNative_stop_nmea_message_collection)},
};
};


static const JNINativeMethod sBatchingMethods[] = {
static const JNINativeMethod sBatchingMethods[] = {