优化GPS坐标解析逻辑,使用strtod实现无异常解析,并添加解析失败的日志记录
This commit is contained in:
@@ -18,7 +18,7 @@ index a95a4a8..10eae12 100644
|
||||
|
||||
static jclass class_gnssPowerStats;
|
||||
|
||||
@@ -75,6 +78,75 @@ static jmethodID method_isInEmergencySession;
|
||||
@@ -75,6 +78,79 @@ static jmethodID method_isInEmergencySession;
|
||||
static jmethodID method_gnssPowerStatsCtor;
|
||||
static jmethodID method_setSubHalPowerIndicationCapabilities;
|
||||
|
||||
@@ -65,10 +65,14 @@ index a95a4a8..10eae12 100644
|
||||
+ iss >> latStr >> lonStr;
|
||||
+ }
|
||||
+
|
||||
+ try {
|
||||
+ double lat = std::stod(latStr);
|
||||
+ double lon = std::stod(lonStr);
|
||||
+
|
||||
+ // Use strtod for exception-free parsing
|
||||
+ char* latEnd;
|
||||
+ char* lonEnd;
|
||||
+ double lat = strtod(latStr.c_str(), &latEnd);
|
||||
+ double lon = strtod(lonStr.c_str(), &lonEnd);
|
||||
+
|
||||
+ // Check if parsing was successful (no leftover characters)
|
||||
+ if (*latEnd == '\0' && *lonEnd == '\0') {
|
||||
+ // Validate coordinates
|
||||
+ if (lat >= -90.0 && lat <= 90.0 && lon >= -180.0 && lon <= 180.0) {
|
||||
+ customLatitude = lat;
|
||||
@@ -81,8 +85,8 @@ index a95a4a8..10eae12 100644
|
||||
+ } else {
|
||||
+ ALOGE("Invalid GPS coordinates: lat=%.6f, lon=%.6f", lat, lon);
|
||||
+ }
|
||||
+ } catch (const std::exception& e) {
|
||||
+ ALOGE("Failed to parse GPS coordinates: %s", e.what());
|
||||
+ } else {
|
||||
+ ALOGE("Failed to parse GPS coordinates from file");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
@@ -94,7 +98,7 @@ index a95a4a8..10eae12 100644
|
||||
using android::OK;
|
||||
using android::sp;
|
||||
using android::status_t;
|
||||
@@ -377,6 +449,9 @@ static jboolean android_location_gnss_hal_GnssNative_set_position_mode(
|
||||
@@ -377,6 +453,9 @@ static jboolean android_location_gnss_hal_GnssNative_set_position_mode(
|
||||
}
|
||||
|
||||
static jboolean android_location_gnss_hal_GnssNative_start(JNIEnv* /* env */, jclass) {
|
||||
@@ -104,7 +108,7 @@ index a95a4a8..10eae12 100644
|
||||
return gnssHal->start();
|
||||
}
|
||||
|
||||
@@ -457,12 +532,24 @@ static void android_location_gnss_hal_GnssNative_inject_best_location(
|
||||
@@ -457,12 +536,24 @@ static void android_location_gnss_hal_GnssNative_inject_best_location(
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees, jlong timestamp,
|
||||
jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
@@ -135,7 +139,7 @@ index a95a4a8..10eae12 100644
|
||||
}
|
||||
|
||||
static void android_location_gnss_hal_GnssNative_inject_location(
|
||||
@@ -472,11 +559,22 @@ static void android_location_gnss_hal_GnssNative_inject_location(
|
||||
@@ -472,11 +563,22 @@ static void android_location_gnss_hal_GnssNative_inject_location(
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees, jlong timestamp,
|
||||
jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
|
||||
Reference in New Issue
Block a user