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

Commit 57501f63 authored by Mengjun Leng's avatar Mengjun Leng Committed by Sarah Chin
Browse files

Optimize SIM phonebook feature with new batch APIs

Add new request and response for loading and updating SIM
contacts.

Bug: 23044962
Change-Id: Ib59b898eeeba93b5a148738416b42c49037ad28f
Merged-In: Ib59b898eeeba93b5a148738416b42c49037ad28f
parent ba92f404
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.telephony.Annotation.RadioPowerState;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;

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

import java.util.ArrayList;
import java.util.List;

@@ -109,6 +111,8 @@ public abstract class BaseCommands implements CommandsInterface {
    protected RegistrantList mEmergencyNumberListRegistrants = new RegistrantList();
    protected RegistrantList mUiccApplicationsEnablementRegistrants = new RegistrantList();
    protected RegistrantList mBarringInfoChangedRegistrants = new RegistrantList();
    protected RegistrantList mSimPhonebookChangedRegistrants = new RegistrantList();
    protected RegistrantList mSimPhonebookRecordsReceivedRegistrants = new RegistrantList();

    @UnsupportedAppUsage
    protected Registrant mGsmSmsRegistrant;
@@ -1085,4 +1089,36 @@ public abstract class BaseCommands implements CommandsInterface {
    public void unregisterForBarringInfoChanged(Handler h) {
        mBarringInfoChangedRegistrants.remove(h);
    }

    @Override
    public void registerForSimPhonebookChanged(Handler h, int what, Object obj) {
        mSimPhonebookChangedRegistrants.addUnique(h, what, obj);
    }

    @Override
    public void unregisterForSimPhonebookChanged(Handler h) {
        mSimPhonebookChangedRegistrants.remove(h);
    }

    @Override
    public void registerForSimPhonebookRecordsReceived(Handler h, int what, Object obj) {
        mSimPhonebookRecordsReceivedRegistrants.addUnique(h, what, obj);
    }

    @Override
    public void unregisterForSimPhonebookRecordsReceived(Handler h) {
        mSimPhonebookRecordsReceivedRegistrants.remove(h);
    }

    @Override
    public void getSimPhonebookRecords(Message result) {
    }

    @Override
    public void getSimPhonebookCapacity(Message result) {
    }

    @Override
    public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
    }
}
+54 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
import com.android.internal.telephony.uicc.IccCardStatus;
import com.android.internal.telephony.uicc.SimPhonebookRecord;

import java.util.List;

@@ -2650,4 +2651,57 @@ public interface CommandsInterface {
     */
    default void setDataThrottling(Message result, WorkSource workSource,
            int dataThrottlingAction, long completionWindowMillis) {};

   /**
     * Request the SIM phonebook records of all activated UICC applications
     *
     * @param result Callback message containing the count of ADN valid record.
     */
    public void getSimPhonebookRecords(Message result);

   /**
     * Request the SIM phonebook Capacity of all activated UICC applications
     *
     */
    public void getSimPhonebookCapacity(Message result);

    /**
     * Request to insert/delete/update the SIM phonebook record
     *
     * @param phonebookRecordInfo adn record information to be updated
     * @param result Callback message containing the SIM phonebook record index.
     */
    public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecordInfo, Message result);

    /**
     * Registers the handler when the SIM phonebook is changed.
     *
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object .
     */
    public void registerForSimPhonebookChanged(Handler h, int what, Object obj);

    /**
     * Unregister for notifications when SIM phonebook has already init done.
     *
     * @param h Handler to be removed from the registrant list.
     */
    public void unregisterForSimPhonebookChanged(Handler h);

    /**
     * Registers the handler when a group of SIM phonebook records received.
     *
     * @param h Handler for notification message.
     * @param what User-defined message code.
     * @param obj User object.
     */
    public void registerForSimPhonebookRecordsReceived(Handler h, int what, Object obj);

    /**
     * Unregister for notifications when a group of SIM phonebook records received.
     *
     * @param h Handler to be removed from the registrant list.
     */
     public void unregisterForSimPhonebookRecordsReceived(Handler h);
}
+87 −17
Original line number Diff line number Diff line
@@ -33,13 +33,16 @@ import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
import com.android.internal.telephony.uicc.IccConstants;
import com.android.internal.telephony.uicc.IccFileHandler;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.SimPhonebookRecordCache;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccProfile;
import com.android.telephony.Rlog;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.List;

/**
 * SimPhoneBookInterfaceManager to provide an inter-process communication to
 * IccPhoneBookInterfaceManager to provide an inter-process communication to
 * access ADN-like SIM records.
 */
public class IccPhoneBookInterfaceManager {
@@ -51,6 +54,7 @@ public class IccPhoneBookInterfaceManager {
    protected Phone mPhone;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    protected AdnRecordCache mAdnCache;
    protected SimPhonebookRecordCache mSimPbRecordCache;

    protected static final int EVENT_GET_SIZE_DONE = 1;
    protected static final int EVENT_LOAD_DONE = 2;
@@ -121,9 +125,13 @@ public class IccPhoneBookInterfaceManager {
        if (r != null) {
            mAdnCache = r.getAdnCache();
        }

        mSimPbRecordCache = new SimPhonebookRecordCache(
                phone.getContext(), phone.getPhoneId(), phone.mCi);
    }

    public void dispose() {
        mSimPbRecordCache.dispose();
    }

    public void updateIccRecords(IccRecords iccRecords) {
@@ -203,10 +211,14 @@ public class IccPhoneBookInterfaceManager {
        checkThread();
        Request updateRequest = new Request();
        synchronized (updateRequest) {
            checkThread();
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, updateRequest);
            AdnRecord oldAdn = generateAdnRecordWithOldTagByContentValues(values);
            AdnRecord newAdn = generateAdnRecordWithNewTagByContentValues(values);
            if (usesPbCache(efid)) {
                mSimPbRecordCache.updateSimPbAdnBySearch(oldAdn, newAdn, response);
                waitForResult(updateRequest);
                return (boolean) updateRequest.mResult;
            } else {
                if (mAdnCache != null) {
                    mAdnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
                    waitForResult(updateRequest);
@@ -217,6 +229,7 @@ public class IccPhoneBookInterfaceManager {
                }
            }
        }
    }

    /**
     * Update an ADN-like EF record by record index
@@ -244,7 +257,7 @@ public class IccPhoneBookInterfaceManager {
            throw new SecurityException(
                    "Requires android.permission.WRITE_CONTACTS permission");
        }

        efid = updateEfForIccType(efid);
        if (DBG) {
            logd("updateAdnRecordsInEfByIndex: efid=" + efid + ", values = " +
                values + " index=" + index + ", pin2=" + pin2);
@@ -255,6 +268,11 @@ public class IccPhoneBookInterfaceManager {
        synchronized (updateRequest) {
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, updateRequest);
            AdnRecord newAdn = generateAdnRecordWithNewTagByContentValues(values);
            if (usesPbCache(efid)) {
                mSimPbRecordCache.updateSimPbAdnByRecordId(index, newAdn, response);
                waitForResult(updateRequest);
                return (boolean) updateRequest.mResult;
            } else {
                if (mAdnCache != null) {
                    mAdnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
                    waitForResult(updateRequest);
@@ -265,6 +283,7 @@ public class IccPhoneBookInterfaceManager {
                }
            }
        }
    }

    /**
     * Get the capacity of records in efid
@@ -318,8 +337,14 @@ public class IccPhoneBookInterfaceManager {
        Request loadRequest = new Request();
        synchronized (loadRequest) {
            Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE, loadRequest);
            if (usesPbCache(efid)) {
                mSimPbRecordCache.requestLoadAllPbRecords(response);
                waitForResult(loadRequest);
                return (List<AdnRecord>) loadRequest.mResult;
            } else {
                if (mAdnCache != null) {
                mAdnCache.requestLoadAllAdnLike(efid, mAdnCache.extensionEfForEf(efid), response);
                    mAdnCache.requestLoadAllAdnLike(efid,
                            mAdnCache.extensionEfForEf(efid), response);
                    waitForResult(loadRequest);
                    return (List<AdnRecord>) loadRequest.mResult;
                } else {
@@ -328,6 +353,7 @@ public class IccPhoneBookInterfaceManager {
                }
            }
        }
    }

    @UnsupportedAppUsage
    protected void checkThread() {
@@ -377,7 +403,51 @@ public class IccPhoneBookInterfaceManager {
     */
    public AdnCapacity getAdnRecordsCapacity() {
        if (DBG) logd("getAdnRecordsCapacity" );
        if (mPhone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException(
                    "Requires android.permission.READ_CONTACTS permission");
        }
        int phoneId = mPhone.getPhoneId();

        UiccProfile profile = UiccController.getInstance().getUiccProfileForPhone(phoneId);

        if (profile != null) {
            IccCardConstants.State cardstate = profile.getState();
            if (cardstate == IccCardConstants.State.READY
                    || cardstate == IccCardConstants.State.LOADED) {
                checkThread();
                AdnCapacity capacity = mSimPbRecordCache.isEnabled()
                        ? mSimPbRecordCache.getAdnCapacity() : null;
                if (capacity == null) {
                    loge("Adn capacity is null");
                    return null;
                }

                if (DBG) logd("getAdnRecordsCapacity on slot " + phoneId
                        + ": max adn=" + capacity.getMaxAdnCount()
                        + ", used adn=" + capacity.getUsedAdnCount()
                        + ", max email=" + capacity.getMaxEmailCount()
                        + ", used email=" + capacity.getUsedEmailCount()
                        + ", max anr=" + capacity.getMaxAnrCount()
                        + ", used anr=" + capacity.getUsedAnrCount()
                        + ", max name length="+ capacity.getMaxNameLength()
                        + ", max number length =" + capacity.getMaxNumberLength()
                        + ", max email length =" + capacity.getMaxEmailLength()
                        + ", max anr length =" + capacity.getMaxAnrLength());
                return capacity;
            } else {
                logd("No UICC when getAdnRecordsCapacity.");
            }
        } else {
            logd("sim state is not ready when getAdnRecordsCapacity.");
        }
        return null;
    }

    private boolean usesPbCache(int efid) {
        return mSimPbRecordCache.isEnabled() &&
                    (efid == IccConstants.EF_PBR || efid == IccConstants.EF_ADN);
    }
}
+105 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.SimPhonebookRecord;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

@@ -5978,6 +5979,100 @@ public class RIL extends BaseCommands implements CommandsInterface {
        }
    }

    @Override
    public void getSimPhonebookRecords(Message result) {
        IRadio radioProxy = getRadioProxy(result);
        if (radioProxy != null) {
            RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS, result,
                    mRILDefaultWorkSource);

            if (RILJ_LOGD) {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
            }

            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
                android.hardware.radio.V1_6.IRadio radioProxy16 =
                            android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);
                try {
                    radioProxy16.getSimPhonebookRecords(rr.mSerial);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "getPhonebookRecords", e);
                }
            } else {
                riljLog("Unsupported API in lower than version 1.6 radio HAL" );
                if (result != null) {
                    AsyncResult.forMessage(result, null,
                    CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                }
            }
        }
    }

    @Override
    public void getSimPhonebookCapacity(Message result) {
        IRadio radioProxy = getRadioProxy(result);
        if (radioProxy != null) {
            RILRequest rr = obtainRequest(RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY, result,
                    mRILDefaultWorkSource);

            if (RILJ_LOGD) {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
            }

            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
                android.hardware.radio.V1_6.IRadio radioProxy16 =
                            android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);
                try {
                    radioProxy16.getSimPhonebookCapacity(rr.mSerial);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "getPhonebookRecords", e);
                }
            } else {
                riljLog("Unsupported API in lower than version 1.6 radio HAL" );
                if (result != null) {
                    AsyncResult.forMessage(result, null,
                    CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                }
            }
        }
    }

    @Override
    public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
        IRadio radioProxy = getRadioProxy(result);
        if (radioProxy != null) {
            RILRequest rr = obtainRequest(RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD, result,
                    mRILDefaultWorkSource);

            if (RILJ_LOGD) {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
                        + " with " + phonebookRecord.toString());
            }

            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_6)) {
                android.hardware.radio.V1_6.IRadio radioProxy16 =
                        android.hardware.radio.V1_6.IRadio.castFrom(radioProxy);

                android.hardware.radio.V1_6.PhonebookRecordInfo pbRecordInfo =
                        phonebookRecord.toPhonebookRecordInfo();
                try {
                     radioProxy16.updateSimPhonebookRecords(rr.mSerial, pbRecordInfo);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "updatePhonebookRecord", e);
                }
            } else {
                riljLog("Unsupported API in lower than version 1.6 radio HAL" );
                if (result != null) {
                    AsyncResult.forMessage(result, null,
                    CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                }
            }
        }
    }

    //***** Private Methods
    /** Helper that gets V1.6 of the radio interface OR sends back REQUEST_NOT_SUPPORTED */
    @Nullable private android.hardware.radio.V1_6.IRadio getRadioV16(Message msg) {
@@ -6955,6 +7050,12 @@ public class RIL extends BaseCommands implements CommandsInterface {
                return "RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP";
            case RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP:
                return "RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP";
            case RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS:
                return "RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS";
            case RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD:
                return "RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORD";
            case RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY:
                return "RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY";
            default: return "<unknown request>";
        }
    }
@@ -7074,6 +7175,10 @@ public class RIL extends BaseCommands implements CommandsInterface {
                return "RIL_UNSOL_REGISTRATION_FAILED";
            case RIL_UNSOL_BARRING_INFO_CHANGED:
                return "RIL_UNSOL_BARRING_INFO_CHANGED";
            case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED:
                return "RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_CHANGED";
            case RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED:
                return "RIL_UNSOL_RESPONSE_SIM_PHONEBOOK_RECORDS_RECEIVED";
            default:
                return "<unknown response>";
        }
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.telephony.TelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPE
import static android.telephony.TelephonyManager
        .CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE;
import static android.telephony.TelephonyManager.CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE;
import static android.telephony.TelephonyManager.CAPABILITY_SIM_PHONEBOOK_IN_MODEM;
import static android.telephony.TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING;
import static android.telephony.TelephonyManager.RadioInterfaceCapability;

@@ -308,6 +309,8 @@ public class RadioConfigResponse extends IRadioConfigResponse.Stub {
                Rlog.d(TAG, "CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE");
                caps.add(CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
                Rlog.d(TAG, "CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING");
                caps.add(CAPABILITY_SIM_PHONEBOOK_IN_MODEM);
                Rlog.d(TAG, "CAPABILITY_SIM_PHONEBOOK_IN_MODEM");
            }
        }
        return caps;
Loading