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

Commit b407596c authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Use proper coded for when a contact is written into EF_ADN of USIM"

parents 20070fdd 29c644c8
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.telephony.Rlog;

import com.android.internal.telephony.GsmAlphabet;

import java.util.Arrays;


@@ -244,7 +242,7 @@ public class AdnRecord implements Parcelable {
                    = (byte) 0xFF; // Extension Record Id

            if (!TextUtils.isEmpty(mAlphaTag)) {
                byteTag = GsmAlphabet.stringToGsm8BitPacked(mAlphaTag);
                byteTag = IccUtils.stringToAdnStringField(mAlphaTag);
                System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
            }

+29 −0
Original line number Diff line number Diff line
@@ -22,8 +22,11 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.telephony.Rlog;


import com.android.internal.telephony.EncodeException;
import com.android.internal.telephony.GsmAlphabet;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
 * Various methods, useful for dealing with SIM data.
@@ -525,4 +528,30 @@ public class IccUtils {
        } while (valueIndex < endIndex);
        return result;
    }

    static byte[]
    stringToAdnStringField(String alphaTag) {
        boolean isUcs2 = false;
        try {
           for(int i = 0; i < alphaTag.length(); i++) {
               GsmAlphabet.countGsmSeptets(alphaTag.charAt(i), true);
           }
        } catch (EncodeException e) {
            isUcs2 = true;
        }
        return stringToAdnStringField(alphaTag, isUcs2);
    }

    static byte[]
    stringToAdnStringField(String alphaTag, boolean isUcs2) {
        if (!isUcs2) {
            return GsmAlphabet.stringToGsm8BitPacked(alphaTag);
        }
        byte[] alphaTagBytes = alphaTag.getBytes(Charset.forName("UTF-16BE"));
        byte[] ret = new byte[1 + alphaTagBytes.length];
        ret[0] = (byte)0x80;
        System.arraycopy(alphaTagBytes, 0, ret, 1, alphaTagBytes.length);

        return ret;
    }
}