android 9.x mtk 定位模拟

android 9.x mtk 定位模拟,第1张

android 9.x mtk 定位模拟 引言

懂的都懂。

方案
diff --git a/frameworks/base/location/java/android/location/GpsStatus.java b/frameworks/base/location/java/android/location/GpsStatus.java
index d4ca5fe854..4502e26559 100644
--- a/frameworks/base/location/java/android/location/GpsStatus.java
+++ b/frameworks/base/location/java/android/location/GpsStatus.java
@@ -193,6 +193,42 @@ public final class GpsStatus {
                         (svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0;
             }
         }

+        boolean isHasGps = false;
+        for (int i = 0; i < 30; i++) {
+            GpsSatellite satellite = mSatellites.get(i);
+            if (satellite != null && satellite.mValid && (satellite.mSnr > 0.0f)) {
+                isHasGps = true;
+                break;
+            }
+        }
+        if(isHasGps){
+            GpsSatellite satellite209 = mSatellites.get(209);
+            if (satellite209 == null) {
+                satellite209 = new GpsSatellite(209);
+                mSatellites.put(209, satellite209);
+            }
+            satellite209.mValid = true;
+            satellite209.mSnr = Float.parseFloat(formateRate(20.0f,10.0f));
+            satellite209.mElevation = 49.0f;
+            satellite209.mAzimuth = 201.0f;
+            satellite209.mHasEphemeris = false;
+            satellite209.mHasAlmanac = false;
+            satellite209.mUsedInFix = false;
+
+            GpsSatellite satellite229 = mSatellites.get(229);
+            if (satellite229 == null) {
+                satellite229 = new GpsSatellite(229);
+                mSatellites.put(229, satellite229);
+            }
+            satellite229.mValid = true;
+            satellite229.mSnr = Float.parseFloat(formateRate(20.0f,10.0f));
+            satellite229.mElevation = 40.0f;
+            satellite229.mAzimuth = 165.0f;
+            satellite229.mHasEphemeris = false;
+            satellite229.mHasAlmanac = false;
+            satellite229.mUsedInFix = false;
+        }
     }
diff --git a/frameworks/base/location/java/android/location/GpsStatus.java b/frameworks/base/location/java/android/location/GpsStatus.java
index b601cde353..d4ca5fe854 100644
--- a/frameworks/base/location/java/android/location/GpsStatus.java
+++ b/frameworks/base/location/java/android/location/GpsStatus.java
@@ -20,6 +20,7 @@ import android.util.SparseArray;

 import java.util.Iterator;
 import java.util.NoSuchElementException;
+import java.util.Random;


 /**
@@ -240,11 +241,54 @@ public final class GpsStatus {
         return NUM_SATELLITES;
     }

+    private static String formateRate(final double min, final double max) {
+        String rateStr = ""+(min + ((max - min) * new Random().nextDouble()));
+        if (rateStr.indexOf(".") != -1) {
+            int num = 0;
+            num = rateStr.indexOf(".");
+            String dianAfter = rateStr.substring(0, num + 1);
+            String afterData = rateStr.replace(dianAfter, "");
+            return rateStr.substring(0, num) + "." + afterData.substring(0, 1);
+        } else {
+            if (rateStr == "1") {
+                return "100";
+            } else {
+                return rateStr;
+            }
+        }
+    }
+

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5597202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存