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

Commit 17af5e95 authored by blong's avatar blong
Browse files

Telephony: add the support for Anr and Email for SIM Card

- Add ANR/EMAIL support for AdnRecord
- add the related interface for ADN,ANR,EMAIL
- Support loading part of records in IccFileHandler.
- Cleanup some unused codes.

Change-Id: I282650251b98317a4a2bf59d61adad66a30cc9c9
parent ee995d50
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import android.content.ContentValues;

import com.android.internal.telephony.uicc.AdnRecord;


@@ -68,6 +70,21 @@ interface IIccPhoneBook {
            String newTag, String newPhoneNumber,
            String pin2);

    /**
     * Replace oldAdn with newAdn in ADN-like record in EF
     *
     * getAdnRecordsInEf must be called at least once before this function,
     * otherwise an error will be returned
     *
     * @param efid must be one among EF_ADN, EF_FDN, and EF_SDN
     * @param values to be updated
     * @param pin2 required to update EF_FDN, otherwise must be null
     * @return true for success
     */
    boolean updateAdnRecordsWithContentValuesInEfBySearch(int efid,
            in ContentValues values,
            String pin2);

    /**
     * Update an ADN-like EF record by record index
     *
@@ -98,4 +115,56 @@ interface IIccPhoneBook {
     */
    int[] getAdnRecordsSize(int efid);

    /**
     * Update an ADN-like EF record by record index
     *
     * @param efid must be one among EF_ADN, EF_FDN, and EF_SDN
     * @param newTag adn tag to be stored
     * @param newPhoneNumber adn number to be stored
     *        Set both newTag and newPhoneNubmer to "" means to replace the old
     *        record with empty one, aka, delete old record
     * @param anrNumbers adn additional number to be stored
     * @param emails adn email to be stored
     * @param index is 1-based adn record index to be updated
     * @param pin2 required to update EF_FDN, otherwise must be null
     * @return true for success
     */
    boolean updateUsimAdnRecordsInEfByIndex(int efid, String newTag,
            String newPhoneNumber, in String[] anrNumbers, in String[] emails, int index,
            String pin2);

    /**
     * Get the adn count of sim card
     *
     * @return the adn count of sim card
     */
    int getAdnCount();

    /**
     * Get the anr count of sim card
     *
     * @return the anr count of sim card
     */
    int getAnrCount();

    /**
     * Get the email count of sim card
     *
     * @return the email count of sim card
     */
    int getEmailCount();

    /**
     * Get the spare anr count of sim card
     *
     * @return the spare anr count of sim card
     */
    int getSpareAnrCount();

    /**
     * Get the spare email count of sim card
     *
     * @return the spare email count of sim card
     */
    int getSpareEmailCount();
}
+142 −0
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.internal.telephony;

import android.content.ContentValues;
import android.content.pm.PackageManager;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.ServiceManager;
import android.telephony.Rlog;
import android.text.TextUtils;

import com.android.internal.telephony.uicc.AdnRecord;
import com.android.internal.telephony.uicc.AdnRecordCache;
@@ -258,6 +261,49 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        return mSuccess;
    }

    @Override
    public boolean updateAdnRecordsWithContentValuesInEfBySearch(int efid, ContentValues values,
            String pin2) {

        if (mPhone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires android.permission.WRITE_CONTACTS permission");
        }

        String oldTag = values.getAsString(IccProvider.STR_TAG);
        String newTag = values.getAsString(IccProvider.STR_NEW_TAG);
        String oldPhoneNumber = values.getAsString(IccProvider.STR_NUMBER);
        String newPhoneNumber = values.getAsString(IccProvider.STR_NEW_NUMBER);
        String oldEmail = values.getAsString(IccProvider.STR_EMAILS);
        String newEmail = values.getAsString(IccProvider.STR_NEW_EMAILS);
        String oldAnr = values.getAsString(IccProvider.STR_ANRS);
        String newAnr = values.getAsString(IccProvider.STR_NEW_ANRS);
        String[] oldEmailArray = TextUtils.isEmpty(oldEmail) ? null : getStringArray(oldEmail);
        String[] newEmailArray = TextUtils.isEmpty(newEmail) ? null : getStringArray(newEmail);
        String[] oldAnrArray = TextUtils.isEmpty(oldAnr) ? null : getStringArray(oldAnr);
        String[] newAnrArray = TextUtils.isEmpty(newAnr) ? null : getStringArray(newAnr);
        efid = updateEfForIccType(efid);

        if (DBG)
            logd("updateAdnRecordsInEfBySearch: efid=" + efid + ", values = " + values + ", pin2="
                    + pin2);
        synchronized (mLock) {
            checkThread();
            mSuccess = false;
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
            AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber, oldEmailArray, oldAnrArray);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber, newEmailArray, newAnrArray);
            if (mAdnCache != null) {
                mAdnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
                waitForResult(status);
            } else {
                loge("Failure while trying to update by search due to uninitialised adncache");
            }
        }
        return mSuccess;
    }

    /**
     * Update an ADN-like EF record by record index
     *
@@ -365,6 +411,13 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        }
    }

    private String[] getStringArray(String str) {
        if (str != null) {
            return str.split(",");
        }
        return null;
    }

    protected void waitForResult(AtomicBoolean status) {
        while (!status.get()) {
            try {
@@ -384,5 +437,94 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        }
        return efid;
    }

    @Override
    public boolean updateUsimAdnRecordsInEfByIndex(int efid, String newTag, String newPhoneNumber,
            String[] anrNumbers, String[] emails, int index, String pin2) {

        if (mPhone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires android.permission.WRITE_CONTACTS permission");
        }

        if (DBG)
            logd("updateAdnRecordsInEfByIndex: efid=" + efid + " Index=" + index + " ==> " + "("
                    + newTag + "," + newPhoneNumber + ")" + " pin2=" + pin2);
        synchronized (mLock) {
            checkThread();
            mSuccess = false;
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber, emails, anrNumbers);
            efid = updateEfForIccType(efid);
            if (mAdnCache != null) {
                mAdnCache.updateUsimAdnByIndex(efid, newAdn, index, pin2, response);
                waitForResult(status);
            } else {
                if (DBG)
                    logd("Failure while trying to update by index due to uninitialised adncache");
            }
        }
        return mSuccess;
    }

    @Override
    public int getAdnCount() {
        int adnCount = 0;
        if (mAdnCache != null) {
            if (mPhone.getCurrentUiccAppType() == AppType.APPTYPE_USIM) {
                adnCount = mAdnCache.getUsimAdnCount();
            } else {
                adnCount = mAdnCache.getAdnCount();
            }
        } else {
            loge("mAdnCache is NULL when getAdnCount.");
        }
        return adnCount;
    }

    @Override
    public int getAnrCount() {
        int anrCount = 0;
        if (mAdnCache != null) {
            anrCount = mAdnCache.getAnrCount();
        } else {
            loge("mAdnCache is NULL when getAnrCount.");
        }
        return anrCount;
    }

    @Override
    public int getEmailCount() {
        int emailCount = 0;
        if (mAdnCache != null) {
            emailCount = mAdnCache.getEmailCount();
        } else {
            loge("mAdnCache is NULL when getEmailCount.");
        }
        return emailCount;
    }

    @Override
    public int getSpareAnrCount() {
        int spareAnrCount = 0;
        if (mAdnCache != null) {
            spareAnrCount = mAdnCache.getSpareAnrCount();
        } else {
            loge("mAdnCache is NULL when getSpareAnrCount.");
        }
        return spareAnrCount;
    }

    @Override
    public int getSpareEmailCount() {
        int spareEmailCount = 0;
        if (mAdnCache != null) {
            spareEmailCount = mAdnCache.getSpareEmailCount();
        } else {
            loge("mAdnCache is NULL when getSpareEmailCount.");
        }
        return spareEmailCount;
    }
}
+41 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import android.content.ContentValues;
import android.os.RemoteException;
import android.os.ServiceManager;
import com.android.internal.telephony.uicc.AdnRecord;

@@ -53,6 +55,12 @@ public class IccPhoneBookInterfaceManagerProxy extends IIccPhoneBook.Stub {
                efid, oldTag, oldPhoneNumber, newTag, newPhoneNumber, pin2);
    }

    @Override
    public boolean updateAdnRecordsWithContentValuesInEfBySearch(int efid, ContentValues values,
            String pin2) throws android.os.RemoteException {
        return mIccPhoneBookInterfaceManager.updateAdnRecordsWithContentValuesInEfBySearch(efid,
                values, pin2);
    }
    @Override
    public boolean
    updateAdnRecordsInEfByIndex(int efid, String newTag,
@@ -70,4 +78,37 @@ public class IccPhoneBookInterfaceManagerProxy extends IIccPhoneBook.Stub {
    public List<AdnRecord> getAdnRecordsInEf(int efid) {
        return mIccPhoneBookInterfaceManager.getAdnRecordsInEf(efid);
    }

    @Override
    public boolean updateUsimAdnRecordsInEfByIndex(int efid, String newTag, String newPhoneNumber,
            String[] anrNumbers, String[] emails, int index, String pin2)
            throws android.os.RemoteException {
        return mIccPhoneBookInterfaceManager.updateUsimAdnRecordsInEfByIndex(efid, newTag,
                newPhoneNumber, anrNumbers, emails, index, pin2);
    }

    @Override
    public int getAdnCount() {
        return mIccPhoneBookInterfaceManager.getAdnCount();
    }

    @Override
    public int getAnrCount() {
        return mIccPhoneBookInterfaceManager.getAnrCount();
    }

    @Override
    public int getEmailCount() {
        return mIccPhoneBookInterfaceManager.getEmailCount();
    }

    @Override
    public int getSpareAnrCount() {
        return mIccPhoneBookInterfaceManager.getSpareAnrCount();
    }

    @Override
    public int getSpareEmailCount() {
        return mIccPhoneBookInterfaceManager.getSpareEmailCount();
    }
}
+63 −73
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class IccProvider extends ContentProvider {
        "name",
        "number",
        "emails",
        "anrs",
        "_id"
    };

@@ -53,10 +54,15 @@ public class IccProvider extends ContentProvider {
    private static final int FDN = 2;
    private static final int SDN = 3;

    protected static final String STR_TAG = "tag";
    protected static final String STR_NUMBER = "number";
    protected static final String STR_EMAILS = "emails";
    protected static final String STR_PIN2 = "pin2";
    public static final String STR_TAG = "tag";
    public static final String STR_NUMBER = "number";
    public static final String STR_EMAILS = "emails";
    public static final String STR_ANRS = "anrs";
    public static final String STR_NEW_TAG = "newTag";
    public static final String STR_NEW_NUMBER = "newNumber";
    public static final String STR_NEW_EMAILS = "newEmails";
    public static final String STR_NEW_ANRS = "newAnrs";
    public static final String STR_PIN2 = "pin2";

    private static final UriMatcher URL_MATCHER =
                            new UriMatcher(UriMatcher.NO_MATCH);
@@ -130,9 +136,20 @@ public class IccProvider extends ContentProvider {

        String tag = initialValues.getAsString("tag");
        String number = initialValues.getAsString("number");
        String emails = initialValues.getAsString("emails");
        String anrs = initialValues.getAsString("anrs");

        // TODO(): Read email instead of sending null.
        boolean success = addIccRecordToEf(efType, tag, number, null, pin2);
        ContentValues mValues = new ContentValues();
        mValues.put(STR_TAG,"");
        mValues.put(STR_NUMBER,"");
        mValues.put(STR_EMAILS,"");
        mValues.put(STR_ANRS,"");
        mValues.put(STR_NEW_TAG,tag);
        mValues.put(STR_NEW_NUMBER,number);
        mValues.put(STR_NEW_EMAILS,emails);
        mValues.put(STR_NEW_ANRS,anrs);
        boolean success = updateIccRecordInEf(efType, mValues, pin2);

        if (!success) {
            return null;
@@ -204,7 +221,8 @@ public class IccProvider extends ContentProvider {
        // parse where clause
        String tag = null;
        String number = null;
        String[] emails = null;
        String emails = null;
        String anrs = null;
        String pin2 = null;

        String[] tokens = where.split("AND");
@@ -216,6 +234,11 @@ public class IccProvider extends ContentProvider {

            String[] pair = param.split("=", 2);

            if (pair.length != 2) {
                Rlog.e(TAG, "resolve: bad whereClause parameter: " + param);
                continue;
            }

            String key = pair[0].trim();
            String val = pair[1].trim();

@@ -224,18 +247,29 @@ public class IccProvider extends ContentProvider {
            } else if (STR_NUMBER.equals(key)) {
                number = normalizeValue(val);
            } else if (STR_EMAILS.equals(key)) {
                //TODO(): Email is null.
                emails = null;
                emails = normalizeValue(val);
            } else if (STR_ANRS.equals(key)) {
                anrs = normalizeValue(val);
            } else if (STR_PIN2.equals(key)) {
                pin2 = normalizeValue(val);
            }
        }

        if (efType == IccConstants.EF_FDN && TextUtils.isEmpty(pin2)) {
        ContentValues mValues = new ContentValues();
        mValues.put(STR_TAG,tag);
        mValues.put(STR_NUMBER,number);
        mValues.put(STR_EMAILS,emails);
        mValues.put(STR_ANRS,anrs);
        mValues.put(STR_NEW_TAG,"");
        mValues.put(STR_NEW_NUMBER,"");
        mValues.put(STR_NEW_EMAILS,"");
        mValues.put(STR_NEW_ANRS,"");
        if ((efType == FDN) && TextUtils.isEmpty(pin2)) {
            return 0;
        }

        boolean success = deleteIccRecordFromEf(efType, tag, number, emails, pin2);
        if (DBG) log("delete mvalues= " + mValues);
        boolean success = updateIccRecordInEf(efType, mValues, pin2);
        if (!success) {
            return 0;
        }
@@ -274,8 +308,7 @@ public class IccProvider extends ContentProvider {
        String newNumber = values.getAsString("newNumber");
        String[] newEmails = null;
        // TODO(): Update for email.
        boolean success = updateIccRecordInEf(efType, tag, number,
                newTag, newNumber, pin2);
        boolean success = updateIccRecordInEf(efType, values, pin2);

        if (!success) {
            return 0;
@@ -318,47 +351,16 @@ public class IccProvider extends ContentProvider {
    }

    private boolean
    addIccRecordToEf(int efType, String name, String number, String[] emails, String pin2) {
        if (DBG) log("addIccRecordToEf: efType=" + efType + ", name=" + name +
                ", number=" + number + ", emails=" + emails);

        boolean success = false;

        // TODO: do we need to call getAdnRecordsInEf() before calling
        // updateAdnRecordsInEfBySearch()? In any case, we will leave
        // the UI level logic to fill that prereq if necessary. But
        // hopefully, we can remove this requirement.

        try {
            IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
                    ServiceManager.getService("simphonebook"));
            if (iccIpb != null) {
                success = iccIpb.updateAdnRecordsInEfBySearch(efType, "", "",
                        name, number, pin2);
            }
        } catch (RemoteException ex) {
            // ignore it
        } catch (SecurityException ex) {
            if (DBG) log(ex.toString());
        }
        if (DBG) log("addIccRecordToEf: " + success);
        return success;
    }

    private boolean
    updateIccRecordInEf(int efType, String oldName, String oldNumber,
            String newName, String newNumber, String pin2) {
        if (DBG) log("updateIccRecordInEf: efType=" + efType +
                ", oldname=" + oldName + ", oldnumber=" + oldNumber +
                ", newname=" + newName + ", newnumber=" + newNumber);
    updateIccRecordInEf(int efType, ContentValues values, String pin2) {
        if (DBG) log("updateIccRecordInEf: efType=" + efType + ", values: "+ values);
        boolean success = false;

        try {
            IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
                    ServiceManager.getService("simphonebook"));
            if (iccIpb != null) {
                success = iccIpb.updateAdnRecordsInEfBySearch(efType,
                        oldName, oldNumber, newName, newNumber, pin2);
                success = iccIpb
                        .updateAdnRecordsWithContentValuesInEfBySearch(efType, values, pin2);
            }
        } catch (RemoteException ex) {
            // ignore it
@@ -370,29 +372,6 @@ public class IccProvider extends ContentProvider {
    }


    private boolean deleteIccRecordFromEf(int efType, String name, String number, String[] emails,
            String pin2) {
        if (DBG) log("deleteIccRecordFromEf: efType=" + efType +
                ", name=" + name + ", number=" + number + ", emails=" + emails + ", pin2=" + pin2);

        boolean success = false;

        try {
            IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
                    ServiceManager.getService("simphonebook"));
            if (iccIpb != null) {
                success = iccIpb.updateAdnRecordsInEfBySearch(efType,
                        name, number, "", "", pin2);
            }
        } catch (RemoteException ex) {
            // ignore it
        } catch (SecurityException ex) {
            if (DBG) log(ex.toString());
        }
        if (DBG) log("deleteIccRecordFromEf: " + success);
        return success;
    }

    /**
     * Loads an AdnRecord into a MatrixCursor. Must be called with mLock held.
     *
@@ -401,10 +380,10 @@ public class IccProvider extends ContentProvider {
     */
    protected void loadRecord(AdnRecord record, MatrixCursor cursor, int id) {
        if (!record.isEmpty()) {
            Object[] contact = new Object[4];
            Object[] contact = new Object[5];
            String alphaTag = record.getAlphaTag();
            String number = record.getNumber();

            String[] anrs =record.getAdditionalNumbers();
            if (DBG) log("loadRecord: " + alphaTag + ", " + number + ",");
            contact[0] = alphaTag;
            contact[1] = number;
@@ -419,7 +398,18 @@ public class IccProvider extends ContentProvider {
                }
                contact[2] = emailString.toString();
            }
            contact[3] = id;

            if (anrs != null) {
                StringBuilder anrString = new StringBuilder();
                for (String anr : anrs) {
                    if (DBG) log("Adding anr:" + anr);
                    anrString.append(anr);
                    anrString.append(",");
                }
                contact[3] = anrString.toString();
            }

            contact[4] = id;
            cursor.addRow(contact);
        }
    }
Loading