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

Commit c3f8f13e authored by Shuo Qian's avatar Shuo Qian Committed by Gerrit Code Review
Browse files

Merge "Cache the emergency number list indication"

parents d32e272d 16f19792
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ import android.os.Registrant;
import android.os.RegistrantList;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;

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

/**
 * {@hide}
@@ -144,6 +148,11 @@ public abstract class BaseCommands implements CommandsInterface {
    protected Registrant mSsRegistrant;
    protected Registrant mRegistrationFailedRegistrant;

    // Lock that mLastEmergencyNumberListIndication uses.
    private Object mLastEmergencyNumberListIndicationLock = new Object();
    // Cache last emergency number list indication from radio
    private final List<EmergencyNumber> mLastEmergencyNumberListIndication = new ArrayList<>();

    // Preferred network type received from PhoneFactory.
    // This is used when establishing a connection to the
    // vendor ril so it starts up in the correct mode.
@@ -803,6 +812,14 @@ public abstract class BaseCommands implements CommandsInterface {
    @Override
    public void registerForEmergencyNumberList(Handler h, int what, Object obj) {
        mEmergencyNumberListRegistrants.addUnique(h, what, obj);
        // Notify the last emergency number list from radio to new registrants because they may
        // miss the latest indication (e.g. constructed in a delay after HAL is registrated).
        List<EmergencyNumber> lastEmergencyNumberListIndication =
                getLastEmergencyNumberListIndication();
        if (lastEmergencyNumberListIndication != null) {
            mEmergencyNumberListRegistrants.notifyRegistrants(new AsyncResult(
                    null, getLastEmergencyNumberListIndication(), null));
        }
    }

    @Override
@@ -860,6 +877,20 @@ public abstract class BaseCommands implements CommandsInterface {
        }
    }

    protected void cacheEmergencyNumberListIndication(
            List<EmergencyNumber> emergencyNumberListIndication) {
        synchronized (mLastEmergencyNumberListIndicationLock) {
            mLastEmergencyNumberListIndication.clear();
            mLastEmergencyNumberListIndication.addAll(emergencyNumberListIndication);
        }
    }

    private List<EmergencyNumber> getLastEmergencyNumberListIndication() {
        synchronized (mLastEmergencyNumberListIndicationLock) {
            return new ArrayList<>(mLastEmergencyNumberListIndication);
        }
    }

    /**
     * {@inheritDoc}
     */
+4 −0
Original line number Diff line number Diff line
@@ -328,6 +328,10 @@ public class RadioIndication extends IRadioIndication.Stub {

        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_EMERGENCY_NUMBER_LIST, response);

        // Cache emergency number list from last indication.
        mRil.cacheEmergencyNumberListIndication(response);

        // Notify emergency number list from radio to registrants
        mRil.mEmergencyNumberListRegistrants.notifyRegistrants(
                new AsyncResult(null, response, null));
    }