android 9.x mtk 定位模拟

该代码修改涉及到了`android.location.GpsStatus.java`文件,主要增加了对GPS卫星状态的检查和模拟。代码首先检查是否有GPS卫星存在,然后对特定的卫星ID(209和229)进行初始化和设置,包括信号强度、方位、仰角等参数。这一改动可能用于测试或模拟GPS接收器的行为。
摘要由CSDN通过智能技术生成

引言

懂的都懂。

方案

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;
+            }
+        }
+    }
+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值