码迷,mamicode.com
首页 > 其他好文 > 详细

WIFI 状态栏显示的wifi信号强度与wifisetting列表不一致

时间:2014-07-22 18:05:51      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:android   wifi   通信   源码   

[DESCRIPTION]
状态栏显示的wifi信号强度与wifisetting列表不一致(不同步)

[ANALYSIS]
1、apk都是接收RSSI_CHANGED intent,并调用WifiManager.calculateSignalLevel()方法计算信号个数
2、WifiSettings界面和状态栏的调用点分别是AccessPoints.java和NetworkController(Gemini).java,可以看到两个地方所传给WifiManager.calculateSignalLevel()的level值不同,一个是4一个是5,所以计算下来有可能格数不一致
3、当处于WifiSettings列表界面时,会6s钟刷新一次信号,定义在WifiSettings.WIFI_RESCAN_INTERVAL_MS
4、状态条刷新的时间是3s,定义在wifiStatemachine.java中(POLL_RSSI_INTERVAL_MSECS),若信号变化会丢RSSI_CHANGE出来
 
[SOLUTION]
1、把两边的level都改成5级(注意数组不要越界)
2、在wifiSettings接受RSSI_CHANGED消息,之后调用updateAccesspoint把界面和状态条同步更新
3、需要注意的是,假定两边的rssi值一个是-69、一个是-66,送给WifiManager.calculateSignalLevel()的计算值会有区别:
31 × 4 / 45 = 124 / 45 = 2.xxx
34 × 4 / 45 = 136 / 45 = 3.xxx
这种情况下可以按rssi范围返回level值,减少浮点数转int带来的误差,比如:
if(rssi 在-55和-65之间)返回4
if(rssi 在-65和-75之间)返回xxx


【MODIFY:】
按照MTK给的方案进行了修改,另外还加了一些字符串数组的修改:

--------------- apps/Settings/res/drawable/wifi_signal_lock.xml ---------------
index 2ad6d91..f7953d2 100644
@@ -15,9 +15,12 @@
 -->

 <level-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:maxLevel="0"
android:drawable="@drawable/ic_wifi_lock_signal_1" />
-    <item android:maxLevel="1"
android:drawable="@drawable/ic_wifi_lock_signal_2" />
-    <item android:maxLevel="2"
android:drawable="@drawable/ic_wifi_lock_signal_3" />
-    <item android:maxLevel="3"
android:drawable="@drawable/ic_wifi_lock_signal_4" />
+    <!-- modify by BW_APP_zengdakui for bug(39969) .start-->
+    <item android:maxLevel="0"
android:drawable="@drawable/ic_wifi_lock_signal_0" />
+    <item android:maxLevel="1"
android:drawable="@drawable/ic_wifi_lock_signal_1" />
+    <item android:maxLevel="2"
android:drawable="@drawable/ic_wifi_lock_signal_2" />
+    <item android:maxLevel="3"
android:drawable="@drawable/ic_wifi_lock_signal_3" />
+    <item android:maxLevel="4"
android:drawable="@drawable/ic_wifi_lock_signal_4" />
+    <!-- modify by BW_APP_zengdakui for bug(39969) .end -->
 </level-list>


--------------- apps/Settings/res/drawable/wifi_signal_open.xml ---------------
index b506dd3..44dfb9b 100644
@@ -15,9 +15,12 @@
 -->

 <level-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:maxLevel="0" android:drawable="@drawable/ic_wifi_signal_1"
/>
-    <item android:maxLevel="1" android:drawable="@drawable/ic_wifi_signal_2"
/>
-    <item android:maxLevel="2" android:drawable="@drawable/ic_wifi_signal_3"
/>
-    <item android:maxLevel="3" android:drawable="@drawable/ic_wifi_signal_4"
/>
+    <!-- modify by BW_APP_zengdakui for bug(39969) .start -->
+    <item android:maxLevel="0" android:drawable="@drawable/ic_wifi_signal_0"
/>
+    <item android:maxLevel="1" android:drawable="@drawable/ic_wifi_signal_1"
/>
+    <item android:maxLevel="2" android:drawable="@drawable/ic_wifi_signal_2"
/>
+    <item android:maxLevel="3" android:drawable="@drawable/ic_wifi_signal_3"
/>
+    <item android:maxLevel="4" android:drawable="@drawable/ic_wifi_signal_4"
/>
+    <!-- modify by BW_APP_zengdakui for bug(39969) .end -->
 </level-list>


------------------ apps/Settings/res/values-zh-rCN/arrays.xml
------------------
index 4f92ef6..19e6bb8 100644
@@ -122,12 +122,16 @@
     <item msgid="477015974247590543">"1 小时"</item>
     <item msgid="5198271470953124739">"永不超时"</item>
   </string-array>
+  
+    <!-- modify by BW_APP_zengdakui for bug(39969) .start -->
   <string-array name="wifi_signal">
+    <item msgid="2245412278046491293">"极弱"</item>
     <item msgid="2245412278046491293">"弱"</item>
     <item msgid="5615082285463430971">"一般"</item>
     <item msgid="3565079809875324621">"较强"</item>
     <item msgid="5702329417707689835">"强"</item>
   </string-array>
+    <!-- modify by BW_APP_zengdakui for bug(39969) .end -->
   <string-array name="wifi_sleep_policy_entries">
     <item msgid="3269131034472904310">"始终"</item>
     <item msgid="844721238536786870">"仅限充电时"</item>

--------------------- apps/Settings/res/values/arrays.xml ---------------------
index bf83879..c0a5f08 100644
@@ -358,12 +358,15 @@

     <!-- Match this with drawable.wifi_signal. --> <skip />
     <!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
+<!--modify by BW_APP_zengdakui for bug(39969) .start -->
     <string-array name="wifi_signal">
+        <item>Poorest</item>
         <item>Poor</item>
         <item>Fair</item>
         <item>Good</item>
         <item>Excellent</item>
     </string-array>
+<!--modify by BW_APP_zengdakui for bug(39969) .end -->

     <!-- Wi-Fi settings. Presented as a list dialog to the user to choose the
Wi-Fi sleep policy. -->
     <string-array name="wifi_sleep_policy_entries">

--------- apps/Settings/src/com/android/settings/wifi/AccessPoint.java
---------
index d30be9d..5ca64b0 100644
@@ -371,13 +371,16 @@ class AccessPoint extends Preference {
         if (mRssi == Integer.MAX_VALUE) {
             return -1;
         }
+
+        //modify by BW_APP_zengdakui for bug(39969) .start
         /**[Add/Comment] by BW_APP [wangyao] for [39862 wifi signal cts
failed.] --start*/
         if (SystemProperties.getBoolean("ro.bw.show_huawei_wifi", false)) {
-            return WifiManager.calculateSignalLevelCustom(mRssi, 4);
+            return WifiManager.calculateSignalLevelCustom(mRssi, 5);
         } else {
-            return WifiManager.calculateSignalLevel(mRssi, 4);
+            return WifiManager.calculateSignalLevel(mRssi, 5);
         }
         /**[Add/Comment] by BW_APP [wangyao] for [39862 wifi signal cts
failed.] --end*/
+        //modify by BW_APP_zengdakui for bug(39969) .end
     }

     WifiConfiguration getConfig() {

-------- apps/Settings/src/com/android/settings/wifi/WifiSettings.java --------
index c668a1c..2813aed 100644
@@ -1111,6 +1111,9 @@ public class WifiSettings extends
SettingsPreferenceFragment
             }
         } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
             updateConnectionState(null);
+            //modify by BW_APP_zengdakui for bug(39969) .start
+            updateAccessPoints(); 
+            //modify by BW_APP_zengdakui for bug(39969) .end
         } else if (WifiManager.NO_CERTIFICATION_ACTION.equals(action)) { 
             /// M: show error message @{
             String apSSID = "";

------- apps/Settings/src/com/android/settings/wifi/p2p/WifiP2pPeer.java
-------
index d05c9a3..eb169ee 100644
@@ -39,8 +39,9 @@ public class WifiP2pPeer extends Preference {

     private int mRssi;
     private ImageView mSignal;
-
-    private static final int SIGNAL_LEVELS = 4;
+//modify by BW_APP_zengdakui for bug(39969) .start
+    private static final int SIGNAL_LEVELS = 5;
+//modify by BW_APP_zengdakui for bug(39969) .end

     public WifiP2pPeer(Context context, WifiP2pDevice dev) {
         super(context);

WIFI 状态栏显示的wifi信号强度与wifisetting列表不一致

标签:android   wifi   通信   源码   

原文地址:http://blog.csdn.net/eoeandroida/article/details/38040759

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!