Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed47f558 authored by Nalla Kartheek's avatar Nalla Kartheek Committed by Ethan Chen
Browse files

P2P : Fix for P2P group name

When device is in Chinese language, P2P group SSID names will be encoded
into UTF-8 hex format. When displaying group SSID in UI Settings, this
UTF-8 should be converted back to UTF-8 binary format.
Implemented method to convert UTF-8 hex to UTF-8 binary format. When
group is created, it checks the hex format by looking '\x' sequence,
then converts to binary format.

Change-Id: I381b9e6c89ea4c82d41d2d4b69effe0d5e71d2e8
CRs-Fixed: 661989
parent d847a71f
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ import com.android.settings.SettingsPreferenceFragment;
import java.util.Arrays;
import java.util.List;
import java.util.Collection;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

/*
 * Displays Wi-fi p2p settings UI
@@ -523,11 +525,44 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
        }
        if (DBG) Log.d(TAG, " mConnectedDevices " + mConnectedDevices);
    }

    private String utfToString(String utf) {
        int value;
        byte[] utfBytes = utf.getBytes();
        ByteBuffer decodedBytes = ByteBuffer.allocate(utf.length());
        int size = 0;
        for (int i = 0; i < utfBytes.length; i++) {
            if ((utfBytes[i] == '\\') && (utfBytes[i + 1] == 'x')) {
               value = Integer.parseInt(utf.substring(i + 2, i + 4), 16);
               decodedBytes.put((byte) value);
               i = i + 3;
            } else {
               decodedBytes.put(utfBytes[i]);
            }
            size++;
        }
        try {
            ByteBuffer sink = ByteBuffer.allocate(size);
            for (int j = 0; j < size; j++) {
                sink.put(decodedBytes.get(j));
            }
            return new String(sink.array(), "UTF-8");
        } catch (UnsupportedEncodingException uee) {
            uee.printStackTrace();
        }
        return null;
    }
    public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) {
        CharSequence cs = "\\x";
        mPersistentGroup.removeAll();

        for (WifiP2pGroup group: groups.getGroupList()) {
            String networkName = group.getNetworkName();
            if (networkName.contains(cs)){
                String string = utfToString(networkName);
                if (string != null){
                    group.setNetworkName(string);
                }
            }
            if (DBG) Log.d(TAG, " group " + group);
            WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getActivity(), group);
            mPersistentGroup.addPreference(wppg);