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

Commit a888fb8c authored by Shuo Qian's avatar Shuo Qian
Browse files

Cache the emergency number list indication

Telephony PhoneFactory registrates RIL via HAL before constructing various components. This can cause a delay for those components to registrate the radio indication they are interested, and thus fail to receive the indication.

To fix that, we need to have a cache and send it out when the corresponding component is registrating it.

Test: manual
Bug: 152818455
Change-Id: Ide3713f0d9314e07af7202c22d2360e7f3b346f7
parent e8c33aa6
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));
    }