概述
WIFI 的修改
修改代码路径
packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml
修改逻辑
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
......
<integer-array translatable="false" name="config_wifiRssiLevelThresholds">
<!-- RSSI RSSI Level -->
<item>-88</item> <!-- (-infinity, -88) 0 -->
<item>-85</item> <!-- [-88, -85) 1 -->
<item>-75</item> <!-- [-85, -75) 2 -->
<item>-60</item> <!-- [-75, -60) 3 -->
<!-- [-60, +infinity) 4 -->
</integer-array>
......
</resources>
按照需求修改以上阀值即可
原理简析
- 涉及的代码
packages/modules/Wifi/framework/java/android/net/wifi/WifiManager.java
packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java
packages/modules/Wifi/service/java/com/android/server/wifi/util/RssiUtil.java
WifiManager.java
看代码中注释1-1
/**
* Given a raw RSSI, return the RSSI signal quality rating using the system default RSSI
* quality rating thresholds.
* @param rssi a raw RSSI value, in dBm, usually between -55 and -90
* @return the RSSI signal quality rating, in the range
* [0, {@link #getMaxSignalLevel()}], where 0 is the lowest (worst signal) RSSI
* rating and {@link #getMaxSignalLevel()} is the highest (best signal) RSSI rating.
*/
@IntRange(from = 0)
public int calculateSignalLevel(int rssi) {
try {
// 注释1-1: 注意看这里是Binder实现端服务代理处理
return mService.calculateSignalLevel(rssi);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
WifiServiceImpl.java
以上WifiManager.java的 Binder 的实现,也是calculateSignalLevel方法的具体实现的地方
@Override
public int calculateSignalLevel(int rssi) {
// 注释1-2:这里将实现逻辑丢给了RssiUtil.java来实现
return RssiUtil.calculateSignalLevel(mContext, rssi);
}
RssiUtil.java
看以下代码注释1-3,信号区间的数据从xml文件读取config_wifiRssiLevelThresholds这个数组数据,全局搜索一下,最后调用的文件目录即为
packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml
public class RssiUtil {
private RssiUtil() {}
/** Calculate RSSI level from RSSI using overlaid RSSI level thresholds. */
public static int calculateSignalLevel(Context context, int rssi) {
int[] thresholds = getRssiLevelThresholds(context);
for (int level = 0; level < thresholds.length; level++) {
if (rssi < thresholds[level]) {
return level;
}
}
return thresholds.length;
}
@NonNull
private static int[] getRssiLevelThresholds(Context context) {
// 注释1-3:从xml资源里读取config_wifiRssiLevelThresholds这个数组资源
// getIntArray() will never return null, it will throw instead
return context.getResources().getIntArray(R.array.config_wifiRssiLevelThresholds);
}
}
LTE 的修改
修改代码路径
vendor/mediatek/proprietary/frameworks/opt/telephony-base/java/mediatek/telephony/SignalStrengthExt.java
修改逻辑
注意,是修改mapLteSignalLevel这个方法
public int mapLteSignalLevel(int mLteRsrp, int mLteRssnr, int mLteSignalStrength) {
......
int rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
int rsrpIconLevel = -1;
int snrIconLevel = -1;
if([自己项目内部定制化的开关判断]){
if (mLteRsrp > -44) {
rsrpIconLevel = -1;
} else if (mLteRsrp >= -89) {
rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
} else if (mLteRsrp >= -97) {
rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
} else if (mLteRsrp >= -108) {
rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
} else if (mLteRsrp >= -116) {
rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
} else if (mLteRsrp >= -125) {
rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
}
}else{
... 系统默认的配置 ...
}
......
}
最后
以上就是飘逸电脑为你收集整理的MTK Android12自定义修改WiFi/LTE RSSI信号格阀值的全部内容,希望文章能够帮你解决MTK Android12自定义修改WiFi/LTE RSSI信号格阀值所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复