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

Commit 3b45cbf9 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "Use Relaxed id match for radio state changes" into main

parents 0ed39e87 bec5dce3
Loading
Loading
Loading
Loading
+40 −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,45 @@ 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 (!Flags.useRelaxedIdMatch()) {
            return idMatch(r, subId, 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);
    }