ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

调整Wifi满格信号的阀值

2021-07-17 14:58:25  阅读:340  来源: 互联网

标签:wifi return level int Wifi RSSI android 满格 阀值


要想wifi在信号比较差的时候也显示满格信号,可参考如下方法

http://aospxref.com/android-11.0.0_r21/xref/frameworks/base/wifi/java/android/net/wifi/WifiManager.java

    /** Anything worse than or equal to this will show 0 bars. */
    @UnsupportedAppUsage
    private static final int MIN_RSSI = -100;

    /** Anything better than or equal to this will show the max bars. */
    @UnsupportedAppUsage
    private static final int MAX_RSSI = -55;

    /**
     * Number of RSSI levels used in the framework to initiate {@link #RSSI_CHANGED_ACTION}
     * broadcast, where each level corresponds to a range of RSSI values.
     * The {@link #RSSI_CHANGED_ACTION} broadcast will only fire if the RSSI
     * change is significant enough to change the RSSI signal level.
     * @hide
     */
    @UnsupportedAppUsage
    public static final int RSSI_LEVELS = 5;
    /**
     * Calculates the level of the signal. This should be used any time a signal
     * is being shown.
     *
     * @param rssi The power of the signal measured in RSSI.
     * @param numLevels The number of levels to consider in the calculated level.
     * @return A level of the signal, given in the range of 0 to numLevels-1 (both inclusive).
     * @deprecated Callers should use {@link #calculateSignalLevel(int)} instead to get the
     * signal level using the system default RSSI thresholds, or otherwise compute the RSSI level
     * themselves using their own formula.
     */
    @Deprecated
    public static int calculateSignalLevel(int rssi, int numLevels) {
        if (rssi <= MIN_RSSI) {
            return 0;
        } else if (rssi >= MAX_RSSI) {
            return numLevels - 1;
        } else {
            float inputRange = (MAX_RSSI - MIN_RSSI);
            float outputRange = (numLevels - 1);
            return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
        }
    }

 

对于Android11,接口有变化

http://aospxref.com/android-11.0.0_r21/xref/frameworks/opt/net/wifi/service/java/com/android/server/wifi/util/RssiUtil.java

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.server.wifi.util;

import android.annotation.NonNull;
import android.content.Context;

import com.android.wifi.resources.R;

/** Utilities for computations involving RSSI. */
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) {
        // getIntArray() will never return null, it will throw instead
        return context.getResources().getIntArray(R.array.config_wifiRssiLevelThresholds);
    }
}

http://aospxref.com/android-11.0.0_r21/xref/frameworks/opt/net/wifi/service/res/values/config.xml

    <!--
    Controls the mapping between RSSI and RSSI levels.

    RSSI                                    RSSI Level
    (-infinity, thresholds[0])                       0
    [threshold[0], threshold[1])                     1
    [threshold[1], threshold[2])                     2
    ...                                            ...
    [threshold[len-2], threshold[len-1])         len-1
    [threshold[len-1], +infinity)                  len

    where:
        [a, b) is the range of integers `n` such that a <= n < b
        `threshold[i]` represents the i'th element of the config_wifiRssiLevelThresholds array
        and `len` is the length of the config_wifiRssiLevelThresholds array.
    -->
    <integer-array translatable="false" name="config_wifiRssiLevelThresholds">
                         <!-- RSSI                RSSI Level -->
        <item>-88</item> <!-- (-infinity, -88)             0 -->
        <item>-77</item> <!-- [-88, -77)                   1 -->
        <item>-66</item> <!-- [-77, -66)                   2 -->
        <item>-55</item> <!-- [-66, -55)                   3 -->
                         <!-- [-55, +infinity)             4 -->
    </integer-array>

如何确认修改有效,打开开发者选项,勾选开启wlan详细日记记录,然后到wifi的搜索界面上看下已连接wifi信号的rssi值,然后移动手机,看信号格数有没有符合要求。

标签:wifi,return,level,int,Wifi,RSSI,android,满格,阀值
来源: https://blog.csdn.net/mike8825/article/details/118856424

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有