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

Commit d376b242 authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

DO NOT MERGE ANYWHERE Use Relaxed id match for radio state changes

In case of radio state changes use relaxed id change in which even if the caller's record has invalid phone index, map phone 0 indications to record.

Bug: 336916327
Test: manual system test that image switching is fine
      Re run all CTS tests
      Regression test for voice + data + sms and modem restarts in between

Change-Id: Ie7c7f4c5c9fa621188b84f81565dbb2aae75bb10
parent 1a74c985
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -2691,7 +2691,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                for (Record r : mRecords) {
                    if (r.matchTelephonyCallbackEvent(
                            TelephonyCallback.EVENT_RADIO_POWER_STATE_CHANGED)
                            && idMatch(r, subId, phoneId)) {
                            && idMatchRelaxed(r, subId, phoneId)) {
                        try {
                            r.callback.onRadioPowerStateChanged(state);
                        } catch (RemoteException ex) {
@@ -4089,6 +4089,42 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        }
    }

    /**
     * Match the sub id or phone id of the event to the record with relaxed rules
     *
     * We follow the rules below:
     * 1) If sub id of the event is invalid, phone id should be used.
     * 2) If record's phoneId is also invalid then allow phone 0 notifications
     * 3) The event on default sub should be notified to the records
     * which register the default sub id.
     * 4) Sub id should be exactly matched for all other cases.
     * TODO: b/337878785 for longterm fix
     */
    boolean idMatchRelaxed(Record r, int subId, int phoneId) {

        if (subId < 0) {
            // Invalid case, we need compare phoneId.
            // If the record does not have a valid phone Id send phone 0 notifications.
            // A record's phoneId can get invalid if there is no SIM or modem was restarting
            // when caller registered.
            if (r.phoneId == INVALID_SIM_SLOT_INDEX) {
                return (phoneId == 0);
            } else {
                return (r.phoneId == phoneId);
            }
        }

        if (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            // if the registered record does not have a valid phoneId then use the phone 0
            if (r.phoneId == INVALID_SIM_SLOT_INDEX) {
                return (phoneId == 0);
            }
            return (subId == mDefaultSubId);
        } else {
            return (r.subId == subId);
        }
    }

    private boolean checkFineLocationAccess(Record r) {
        return checkFineLocationAccess(r, Build.VERSION_CODES.BASE);
    }