Wifi列表中文亂碼

同事拿了塊海思平臺的板子過來,說是Wifi列表中文顯示亂碼,讓我幫忙分析下原因。然後自己查看了下/data/misc/wifi目錄:
這裏寫圖片描述

查看了一下wpa_supplicant.conf文件,如下圖,
這裏寫圖片描述

在那個板子上發現這裏的中文是正常顯示的,
然後跟蹤了一下Setting調用到Framework的WifiSsid.java中,發現在進行字符編碼的時候,Hisi默認處理爲GB2312,修改爲UTF-8即可。

具體修改的位置:
framework/base/wifi/java/android/net/wifi/WifiSsid.java

    public String toString() {
        byte[] ssidBytes = octets.toByteArray();
        // Supplicant returns \x00\x00\x00\x00\x00\x00\x00\x00 hex string
        // for a hidden access point. Make sure we maintain the previous
        // behavior of returning empty string for this case.
        if (octets.size() <= 0 || isArrayAllZeroes(ssidBytes)) 
            return "";
        // TODO: Handle conversion to other charsets upon failure
        Charset charset = Charset.forName("GB2312");
        CharsetDecoder decoder = charset.newDecoder()
                .onMalformedInput(CodingErrorAction.REPLACE)
                .onUnmappableCharacter(CodingErrorAction.REPLACE);
        CharBuffer out = CharBuffer.allocate(32);

        CoderResult result = decoder.decode(ByteBuffer.wrap(ssidBytes), out, true);
        out.flip();
        if (result.isError()) {
            return NONE;
        }
        return out.toString();
    }    

這裏將GB2312修改爲UTF-8即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章