diff options
4 files changed, 171 insertions, 12 deletions
diff --git a/services/core/java/com/android/server/location/gnss/GnssNmeaProvider.java b/services/core/java/com/android/server/location/gnss/GnssNmeaProvider.java index 5036a6e7edf5..bfef97856838 100644 --- a/services/core/java/com/android/server/location/gnss/GnssNmeaProvider.java +++ b/services/core/java/com/android/server/location/gnss/GnssNmeaProvider.java @@ -63,16 +63,25 @@ class GnssNmeaProvider extends GnssListenerMultiplexer<Void, IGnssNmeaListener, @Override protected boolean registerWithService(Void ignored, Collection<GnssListenerRegistration> registrations) { - if (D) { - Log.d(TAG, "starting gnss nmea messages"); + if (mGnssNative.startNmeaMessageCollection()) { + if (D) { + Log.d(TAG, "starting gnss nmea messages collection"); + } + return true; + } else { + Log.e(TAG, "error starting gnss nmea messages collection"); + return false; } - return true; } @Override protected void unregisterWithService() { - if (D) { - Log.d(TAG, "stopping gnss nmea messages"); + if (mGnssNative.stopNmeaMessageCollection()) { + if (D) { + Log.d(TAG, "stopping gnss nmea messages collection"); + } + } else { + Log.e(TAG, "error stopping gnss nmea messages collection"); } } diff --git a/services/core/java/com/android/server/location/gnss/GnssStatusProvider.java b/services/core/java/com/android/server/location/gnss/GnssStatusProvider.java index 936283deda8e..0ce36d6a8276 100644 --- a/services/core/java/com/android/server/location/gnss/GnssStatusProvider.java +++ b/services/core/java/com/android/server/location/gnss/GnssStatusProvider.java @@ -43,6 +43,7 @@ public class GnssStatusProvider extends private final AppOpsHelper mAppOpsHelper; private final LocationUsageLogger mLogger; + private final GnssNative mGnssNative; private boolean mIsNavigating = false; @@ -50,6 +51,7 @@ public class GnssStatusProvider extends super(injector); mAppOpsHelper = injector.getAppOpsHelper(); mLogger = injector.getLocationUsageLogger(); + mGnssNative = gnssNative; gnssNative.addBaseCallbacks(this); gnssNative.addStatusCallbacks(this); @@ -64,16 +66,25 @@ public class GnssStatusProvider extends @Override protected boolean registerWithService(Void ignored, Collection<GnssListenerRegistration> registrations) { - if (D) { - Log.d(TAG, "starting gnss status"); + if (mGnssNative.startSvStatusCollection()) { + if (D) { + Log.d(TAG, "starting gnss sv status"); + } + return true; + } else { + Log.e(TAG, "error starting gnss sv status"); + return false; } - return true; } @Override protected void unregisterWithService() { - if (D) { - Log.d(TAG, "stopping gnss status"); + if (mGnssNative.stopSvStatusCollection()) { + if (D) { + Log.d(TAG, "stopping gnss sv status"); + } + } else { + Log.e(TAG, "error stopping gnss sv status"); } } diff --git a/services/core/java/com/android/server/location/gnss/hal/GnssNative.java b/services/core/java/com/android/server/location/gnss/hal/GnssNative.java index e072bf7dc1f7..af87677ecb66 100644 --- a/services/core/java/com/android/server/location/gnss/hal/GnssNative.java +++ b/services/core/java/com/android/server/location/gnss/hal/GnssNative.java @@ -783,6 +783,38 @@ public class GnssNative { } /** + * 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. */ public boolean isMeasurementCorrectionsSupported() { @@ -1369,6 +1401,22 @@ public class GnssNative { 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() { 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 boolean native_start_nmea_message_collection(); + + private static native boolean native_stop_nmea_message_collection(); + // location injection APIs 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); + // sv status APIs + private static native boolean native_start_sv_status_collection(); + + private static native boolean native_stop_sv_status_collection(); + // navigation message APIs private static native boolean native_is_navigation_message_supported(); diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp index 161d7ce350fc..555f188aa266 100644 --- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp +++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp @@ -244,6 +244,9 @@ bool hasLatLong(const GnssLocation_V2_0& location) { return hasLatLong(location.v1_0); } +bool isSvStatusRegistered = false; +bool isNmeaRegistered = false; + } // namespace static inline jboolean boolToJbool(bool value) { @@ -505,6 +508,13 @@ uint32_t GnssCallback::getConstellationType( template <class T_list, class T_sv_info> 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(); uint32_t listSize = getGnssSvInfoListSize(svStatus); @@ -566,8 +576,12 @@ Return<void> GnssCallback::gnssSvStatusCbImpl(const T_list& svStatus) { return Void(); } -Return<void> GnssCallback::gnssNmeaCb( - int64_t timestamp, const ::android::hardware::hidl_string& nmea) { +Return<void> GnssCallback::gnssNmeaCb(int64_t timestamp, + 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(); /* * 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) { + // 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(); /* * 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."); } +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, jint flags) { if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) { @@ -2365,6 +2437,16 @@ static const JNINativeMethod sLocationProviderMethods[] = { {"native_is_gnss_visibility_control_supported", "()Z", reinterpret_cast<void*>( 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[] = { |