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

Commit c7289855 authored by gwenlin's avatar gwenlin Committed by Gwen Lin
Browse files

Notify allowed IMS services to RILJ

ImsPhoneCallTracker will notify allowed services to Phone for VoLTE and
VoWiFi based on the enabled capabilities from ImsManager; GsmCdmaPhone
and Phone will notify allowed service for VoNR.

Bug: 389157806
Test: atest ImsPhoneCallTrackerTest
Test: atest GsmCdmaPhoneTest
Test: on device test in b/389157806#comment#4
Flag: com.android.internal.telephony.flags.allowed_services
Change-Id: I52a3d4ae394555eb88fe8dfd133621e16f604640
parent 2991e653
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -180,3 +180,14 @@ flag {
        purpose: PURPOSE_FEATURE
    }
}

# OWNER=gwenlin TARGET=26Q2
flag {
    name: "allowed_services"
    namespace: "telephony"
    description: "Update allowed services to the modem"
    bug:"389157806"
    metadata {
        purpose: PURPOSE_FEATURE
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import android.telephony.TelephonyManager;
import android.telephony.UiccAccessRule;
import android.telephony.UssdResponse;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
@@ -453,7 +454,8 @@ public class GsmCdmaPhone extends Phone {
                int newPreferredTtyMode = intent.getIntExtra(
                        TelecomManager.EXTRA_TTY_PREFERRED_MODE, TelecomManager.TTY_MODE_OFF);
                updateUiTtyMode(newPreferredTtyMode);
            } else if (TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED.equals(action)) {
            } else if (TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED.equals(action)
                           || TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED.equals(action)) {
                if (mPhoneId == intent.getIntExtra(
                        SubscriptionManager.EXTRA_SLOT_INDEX,
                        SubscriptionManager.INVALID_SIM_SLOT_INDEX)) {
@@ -462,6 +464,11 @@ public class GsmCdmaPhone extends Phone {
                    if (mSimState == TelephonyManager.SIM_STATE_LOADED
                            && currentSlotSubIdChanged()) {
                        setNetworkSelectionModeAutomatic(null);
                    } else if (mSimState == TelephonyManager.SIM_STATE_ABSENT
                            || mSimState == TelephonyManager.SIM_STATE_UNKNOWN) {
                        // Clear allowed services while SIM is absent or unknown e.g. modem crash.
                        // Telephony will update allowed services after SIM is loaded.
                        clearAllowedImsServices();
                    }
                }
            }
@@ -529,6 +536,9 @@ public class GsmCdmaPhone extends Phone {
        filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
        filter.addAction(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
        filter.addAction(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED);
        if (mFeatureFlags.allowedServices()) {
            filter.addAction(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED);
        }
        mContext.registerReceiver(mBroadcastReceiver, filter,
                android.Manifest.permission.MODIFY_PHONE_STATE, null, Context.RECEIVER_EXPORTED);

@@ -5329,6 +5339,7 @@ public class GsmCdmaPhone extends Phone {
        boolean enbleVonr = mIsVonrEnabledByCarrier
                && (setting == 1 || (setting == -1 && mDefaultVonr));
        mCi.setVoNrEnabled(enbleVonr, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
        super.setAllowedImsServicesForAny(ImsRegistrationImplBase.REGISTRATION_TECH_NR, enbleVonr);
    }

    private void updateCdmaRoamingSettingsAfterCarrierConfigChanged(
+60 −0
Original line number Diff line number Diff line
@@ -392,6 +392,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    private int mUsageSettingFromModem = SubscriptionManager.USAGE_SETTING_UNKNOWN;
    private boolean mIsUsageSettingSupported = true;
    private boolean mIsNetworkScanStarted = false;
    private Set<Integer> mAllowedImsServicesAny = new HashSet<>();
    private Set<Integer> mAllowedImsServicesHomeOnly = new HashSet<>();

    //IMS
    /**
@@ -4761,6 +4763,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
     **/
    public void setVoNrEnabled(boolean enabled, Message result, WorkSource workSource) {
        mCi.setVoNrEnabled(enabled, result, workSource);
        setAllowedImsServicesForAny(ImsRegistrationImplBase.REGISTRATION_TECH_NR, enabled);
    }

    /**
@@ -5491,6 +5494,63 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.isSatelliteEnabledForCarrier(simSlot, result);
    }

    /**
     * Update allowed IMS services for home network only.
     *
     * @param regTech Which technology is associated with this capability.
     * @param enabled Whether this capability is enabled.
     */
    public void setAllowedImsServicesForHomeOnly(
            @ImsRegistrationImplBase.ImsRegistrationTech int regTech,
            boolean enabled) {
        if (!mFeatureFlags.allowedServices()) return;
        Set<Integer> oldAllowedImsServicesAny = new HashSet<>(mAllowedImsServicesAny);
        Set<Integer> oldAllowedImsServicesHomeOnly = new HashSet<>(mAllowedImsServicesHomeOnly);
        if (enabled) {
            mAllowedImsServicesHomeOnly.add(regTech);
        } else {
            mAllowedImsServicesHomeOnly.remove(regTech);
        }
        mAllowedImsServicesAny.remove(regTech);
        if (!oldAllowedImsServicesAny.equals(mAllowedImsServicesAny)
                || !oldAllowedImsServicesHomeOnly.equals(mAllowedImsServicesHomeOnly)) {
            mCi.updateAllowedImsServices(mAllowedImsServicesAny, mAllowedImsServicesHomeOnly, null);
        }
    }

    /**
     * Update allowed IMS services for home and roaming networks.
     *
     * @param regTech Which technology is associated with this capability.
     * @param enabled Whether this capability is enabled.
     */
    public void setAllowedImsServicesForAny(
            @ImsRegistrationImplBase.ImsRegistrationTech int regTech,
            boolean enabled) {
        if (!mFeatureFlags.allowedServices()) return;
        Set<Integer> oldAllowedImsServicesAny = new HashSet<>(mAllowedImsServicesAny);
        Set<Integer> oldAllowedImsServicesHomeOnly = new HashSet<>(mAllowedImsServicesHomeOnly);
        if (enabled) {
            mAllowedImsServicesAny.add(regTech);
        } else {
            mAllowedImsServicesAny.remove(regTech);
        }
        mAllowedImsServicesHomeOnly.remove(regTech);
        if (!oldAllowedImsServicesAny.equals(mAllowedImsServicesAny)
                || !oldAllowedImsServicesHomeOnly.equals(mAllowedImsServicesHomeOnly)) {
            mCi.updateAllowedImsServices(mAllowedImsServicesAny, mAllowedImsServicesHomeOnly, null);
        }
    }

    /**
     * Clear allowed IMS services.
     */
    public void clearAllowedImsServices() {
        Rlog.d(mLogTag, "clearAllowedImsServices");
        mAllowedImsServicesAny.clear();
        mAllowedImsServicesHomeOnly.clear();
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+17 −0
Original line number Diff line number Diff line
@@ -2919,6 +2919,23 @@ public class ImsPhone extends ImsPhoneBase {
                == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
    }

    /**
     * Update allowed IMS services.
     *
     * @param regTech Which technology is associated with this capability.
     * @param enabled Whether this capability is enabled.
     * @param isHomeOnly Whether this capability change is for home network only.
     */
    public void setAllowedImsServices(
            @ImsRegistrationImplBase.ImsRegistrationTech int regTech,
            boolean enabled, boolean isHomeOnly) {
        if (isHomeOnly) {
            mDefaultPhone.setAllowedImsServicesForHomeOnly(regTech, enabled);
        } else {
            mDefaultPhone.setAllowedImsServicesForAny(regTech, enabled);
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
        IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, "  ");
+79 −9
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ import android.util.ArraySet;
import android.util.LocalLog;
import android.util.Log;
import android.util.Pair;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;

import com.android.ims.FeatureConnector;
@@ -803,6 +804,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    private boolean mSupportCepOnPeer = true;
    private boolean mSupportD2DUsingRtp = false;
    private boolean mSupportSdpForRtpHeaderExtensions = false;
    private boolean mVolteRoamingSupported = false;
    private int mThresholdRtpPacketLoss;
    private int mThresholdRtpJitter;
    private long mThresholdRtpInactivityTime;
@@ -812,6 +814,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    // in progress. Values listed above.
    private HoldSwapState mHoldSwitchingState = HoldSwapState.INACTIVE;
    private MediaThreshold mMediaThreshold;
    private SparseBooleanArray mImsCapability = new SparseBooleanArray();

    private String mLastDialString = null;
    private ImsDialArgs mLastDialArgs = null;
@@ -1482,6 +1485,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        }
        mCurrentlyConnectedSubId = Optional.empty();
        mMediaThreshold = null;
        clearAllowedServices();
        resetImsCapabilities();
        hangupAllOrphanedConnections(DisconnectCause.LOST_SIGNAL);
        // For compatibility with apps that still use deprecated intent
@@ -1919,6 +1923,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        updateImsServiceConfig();
        updateMediaThreshold(
                mThresholdRtpPacketLoss, mThresholdRtpJitter, mThresholdRtpInactivityTime);
        updateAllowedServices(ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
        updateAllowedServices(ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
    }

    /**
@@ -1967,6 +1973,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        mSupportSdpForRtpHeaderExtensions = carrierConfig.getBoolean(
                CarrierConfigManager
                        .KEY_SUPPORTS_SDP_NEGOTIATION_OF_D2D_RTP_HEADER_EXTENSIONS_BOOL);
        mVolteRoamingSupported =
                carrierConfig.getBoolean(
                        CarrierConfigManager.ImsVoice.KEY_CARRIER_VOLTE_ROAMING_AVAILABLE_BOOL);
        mThresholdRtpPacketLoss = carrierConfig.getInt(
                CarrierConfigManager.ImsVoice.KEY_VOICE_RTP_PACKET_LOSS_RATE_THRESHOLD_INT);
        mThresholdRtpInactivityTime = carrierConfig.getLong(
@@ -2057,6 +2066,45 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        }
    }

    /**
     * Update allowed services to the modem.
     *
     * @param regTech Which technology is associated with this capability.
     */
    private void updateAllowedServices(@ImsRegistrationImplBase.ImsRegistrationTech int regTech) {
        if (!mFeatureFlags.allowedServices()) return;
        if (mImsCapability.indexOfKey(regTech) < 0) {
            // Update allowed services until this capability is initialized.
            return;
        }
        boolean enabled = mImsCapability.get(regTech);
        boolean enabledForRoaming;
        switch(regTech) {
            case ImsRegistrationImplBase.REGISTRATION_TECH_LTE:
                enabledForRoaming = enabled && mVolteRoamingSupported;
                break;
            case ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN:
                boolean wfcRoamingEnabledByUser = mImsManager.isWfcRoamingEnabledByUser();
                enabledForRoaming = enabled && wfcRoamingEnabledByUser;
                break;
            default:
                logw("Unhandled registration technology = " + regTech);
                return;
        }
        log("updateAllowedServices for RAT = " + regTech + ", enabled = " + enabled
                + ", enabledForRoaming = " + enabledForRoaming);
        mPhone.setAllowedImsServices(regTech, enabled, !enabledForRoaming);
    }

    /**
     * Clear cached allowed services.
     */
    private void clearAllowedServices() {
        log("clearAllowedServices");
        mImsCapability.clear();
        mVolteRoamingSupported = false;
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private void handleEcmTimer(int action) {
        mPhone.handleTimerInEmergencyCallbackMode(action);
@@ -4638,15 +4686,32 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                }
            };


    private final ImsManager.ImsStatsCallback mImsStatsCallback =
            new ImsManager.ImsStatsCallback() {
                @Override
        public void onEnabledMmTelCapabilitiesChanged(int capability, int regTech,
                boolean isEnabled) {
            int enabledVal = isEnabled ? ProvisioningManager.PROVISIONING_VALUE_ENABLED
                public void onEnabledMmTelCapabilitiesChanged(
                        int capability, int regTech, boolean isEnabled) {
                    int enabledVal =
                            isEnabled
                                    ? ProvisioningManager.PROVISIONING_VALUE_ENABLED
                                    : ProvisioningManager.PROVISIONING_VALUE_DISABLED;
            mMetrics.writeImsSetFeatureValue(mPhone.getPhoneId(), capability, regTech, enabledVal);
                    mMetrics.writeImsSetFeatureValue(
                            mPhone.getPhoneId(), capability, regTech, enabledVal);
                    mPhone.getImsStats().onSetFeatureResponse(capability, regTech, enabledVal);
                    if (mFeatureFlags.allowedServices()
                            && capability == MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE) {
                        switch (regTech) {
                            case (ImsRegistrationImplBase.REGISTRATION_TECH_LTE):
                            case (ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN):
                                if (mImsCapability.indexOfKey(regTech) < 0
                                        || mImsCapability.get(regTech) != isEnabled) {
                                    mImsCapability.put(regTech, isEnabled);
                                    updateAllowedServices(regTech);
                                }
                                break;
                        }
                    }
                }
            };

@@ -5172,6 +5237,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        return NetworkStats.IFACE_VT + mPhone.getSubId();
    }

    @VisibleForTesting(visibility = PRIVATE)
    public ImsManager.ImsStatsCallback getImsStatsCallback() {
        return mImsStatsCallback;
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @Override
    protected void log(String msg) {
Loading