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

Commit 165f4986 authored by Jayachandran C's avatar Jayachandran C Committed by Automerger Merge Worker
Browse files

Merge "Revert "Fix loading SIM phonebook redundantly"" am: 7dfa08a1

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1980167

Change-Id: I9516f91f93c43e1921d575aeed1279a7659da274
parents 1fe7c0e5 7dfa08a1
Loading
Loading
Loading
Loading
+0 −12
Original line number Original line Diff line number Diff line
@@ -54,10 +54,6 @@ public class AdnCapacity implements Parcelable {
        mMaxAnrLength = maxAnrLength;
        mMaxAnrLength = maxAnrLength;
    }
    }


    public AdnCapacity() {
        this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }

    public int getMaxAdnCount() {
    public int getMaxAdnCount() {
        return mMaxAdnCount;
        return mMaxAdnCount;
    }
    }
@@ -102,14 +98,6 @@ public class AdnCapacity implements Parcelable {
        return mMaxAdnCount == mUsedAdnCount;
        return mMaxAdnCount == mUsedAdnCount;
    }
    }


    public boolean isSimEmpty() {
        return mUsedAdnCount == 0;
    }

    public boolean isSimValid() {
        return mMaxAdnCount > 0;
    }

    public static final Parcelable.Creator<AdnCapacity> CREATOR
    public static final Parcelable.Creator<AdnCapacity> CREATOR
            = new Parcelable.Creator<AdnCapacity>() {
            = new Parcelable.Creator<AdnCapacity>() {
        @Override
        @Override
+6 −22
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ import java.util.stream.Collectors;
        value = "TelephonyManager.CAPABILITY_SIM_PHONEBOOK_IN_MODEM")
        value = "TelephonyManager.CAPABILITY_SIM_PHONEBOOK_IN_MODEM")
public class SimPhonebookRecordCache extends Handler {
public class SimPhonebookRecordCache extends Handler {
    // Instance Variables
    // Instance Variables
    private String LOG_TAG = "SimPhonebookRecordCache";
    private static final String LOG_TAG = "SimPhonebookRecordCache";
    private static final boolean DBG = true;
    private static final boolean DBG = true;
    // Event Constants
    // Event Constants
    private static final int EVENT_PHONEBOOK_CHANGED = 1;
    private static final int EVENT_PHONEBOOK_CHANGED = 1;
@@ -100,7 +100,6 @@ public class SimPhonebookRecordCache extends Handler {
        mCi = ci;
        mCi = ci;
        mPhoneId = phoneId;
        mPhoneId = phoneId;
        mContext = context;
        mContext = context;
        LOG_TAG += "[" + phoneId + "]";
        mCi.registerForSimPhonebookChanged(this, EVENT_PHONEBOOK_CHANGED, null);
        mCi.registerForSimPhonebookChanged(this, EVENT_PHONEBOOK_CHANGED, null);
        mCi.registerForIccRefresh(this, EVENT_SIM_REFRESH, null);
        mCi.registerForIccRefresh(this, EVENT_SIM_REFRESH, null);
        mCi.registerForSimPhonebookRecordsReceived(this, EVENT_PHONEBOOK_RECORDS_RECEIVED, null);
        mCi.registerForSimPhonebookRecordsReceived(this, EVENT_PHONEBOOK_RECORDS_RECEIVED, null);
@@ -206,7 +205,7 @@ public class SimPhonebookRecordCache extends Handler {
        synchronized (mReadLock) {
        synchronized (mReadLock) {
            mAdnLoadingWaiters.add(response);
            mAdnLoadingWaiters.add(response);
            final int pendingSize = mAdnLoadingWaiters.size();
            final int pendingSize = mAdnLoadingWaiters.size();
            final boolean isCapacityInvalid = isAdnCapacityInvalid();
            boolean isCapacityInvalid = getAdnCapacity() == null;
            if (isCapacityInvalid) {
            if (isCapacityInvalid) {
                getSimPhonebookCapacity();
                getSimPhonebookCapacity();
            }
            }
@@ -228,10 +227,6 @@ public class SimPhonebookRecordCache extends Handler {
        fillCache();
        fillCache();
    }
    }


    private boolean isAdnCapacityInvalid() {
        return getAdnCapacity() == null || !getAdnCapacity().isSimValid();
    }

    @VisibleForTesting
    @VisibleForTesting
    public boolean isLoading() {
    public boolean isLoading() {
        return mIsRecordLoading.get();
        return mIsRecordLoading.get();
@@ -317,7 +312,7 @@ public class SimPhonebookRecordCache extends Handler {
                .build();
                .build();
        UpdateRequest updateRequest = new UpdateRequest(index, newAdn, updateAdn, response);
        UpdateRequest updateRequest = new UpdateRequest(index, newAdn, updateAdn, response);
        mUpdateRequests.add(updateRequest);
        mUpdateRequests.add(updateRequest);
        final boolean isCapacityInvalid = isAdnCapacityInvalid();
        boolean isCapacityInvalid = getAdnCapacity() == null;
        if (isCapacityInvalid) {
        if (isCapacityInvalid) {
            getSimPhonebookCapacity();
            getSimPhonebookCapacity();
        }
        }
@@ -363,11 +358,6 @@ public class SimPhonebookRecordCache extends Handler {
                if (ar != null && ar.exception == null) {
                if (ar != null && ar.exception == null) {
                    AdnCapacity capacity = (AdnCapacity)ar.result;
                    AdnCapacity capacity = (AdnCapacity)ar.result;
                    handlePhonebookCapacityChanged(capacity);
                    handlePhonebookCapacityChanged(capacity);
                } else {
                    if (!isAdnCapacityInvalid()) {
                        mAdnCapacity.set(new AdnCapacity());
                    }
                    invalidateSimPbCache();
                }
                }
                break;
                break;
            case EVENT_PHONEBOOK_RECORDS_RECEIVED:
            case EVENT_PHONEBOOK_RECORDS_RECEIVED:
@@ -435,13 +425,10 @@ public class SimPhonebookRecordCache extends Handler {


    private void handlePhonebookCapacityChanged(AdnCapacity newCapacity) {
    private void handlePhonebookCapacityChanged(AdnCapacity newCapacity) {
        AdnCapacity oldCapacity = mAdnCapacity.get();
        AdnCapacity oldCapacity = mAdnCapacity.get();
        if (newCapacity == null) {
            newCapacity = new AdnCapacity();
        }
        mAdnCapacity.set(newCapacity);
        mAdnCapacity.set(newCapacity);
        if (oldCapacity == null && newCapacity != null) {
        if (oldCapacity == null && newCapacity != null) {
            if (!newCapacity.isSimEmpty()){
            if (newCapacity.getMaxAdnCount() > 0){
                invalidateSimPbCache();
                mSimPbRecords.clear();
                fillCacheWithoutWaiting();
                fillCacheWithoutWaiting();
            } else {
            } else {
                notifyAdnLoadingWaiters();
                notifyAdnLoadingWaiters();
@@ -449,9 +436,7 @@ public class SimPhonebookRecordCache extends Handler {
            mIsInitialized.set(true); // Let's say the whole process is ready
            mIsInitialized.set(true); // Let's say the whole process is ready
        } else {
        } else {
            // There is nothing from PB, so notify waiters directly if any
            // There is nothing from PB, so notify waiters directly if any
            if (newCapacity.isSimEmpty()
            if (newCapacity != null && newCapacity.getMaxAdnCount() == 0) {
                    || !newCapacity.isSimValid()) {
                mIsCacheInvalidated.set(false);
                notifyAdnLoadingWaiters();
                notifyAdnLoadingWaiters();
            } else if (!mIsUpdateDone) {
            } else if (!mIsUpdateDone) {
                invalidateSimPbCache();
                invalidateSimPbCache();
@@ -471,7 +456,6 @@ public class SimPhonebookRecordCache extends Handler {
                populateAdnRecords(records.getPhonebookRecords());
                populateAdnRecords(records.getPhonebookRecords());
                mIsRecordLoading.set(false);
                mIsRecordLoading.set(false);
                mIsInRetry.set(false);
                mIsInRetry.set(false);
                mIsCacheInvalidated.set(false);
                notifyAdnLoadingWaiters();
                notifyAdnLoadingWaiters();
                tryFireUpdatePendingList();
                tryFireUpdatePendingList();
            } else if (records.isRetryNeeded() && !mIsInRetry.get()) {
            } else if (records.isRetryNeeded() && !mIsInRetry.get()) {