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

Commit ad68e934 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5681502 from 8553410b to qt-c2f2-release

Change-Id: If876144a8bc95a4d3a125d4d747236050af1bbba
parents ef7748ef 8553410b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -208,12 +208,14 @@ public class PhoneConfigurationManager {
        try {
            return getPhoneStatusFromCache(phoneId);
        } catch (NoSuchElementException ex) {
            updatePhoneStatus(phone);
            // Return true if modem status cannot be retrieved. For most cases, modem status
            // is on. And for older version modems, GET_MODEM_STATUS and disable modem are not
            // supported. Modem is always on.
            //TODO: this should be fixed in R to support a third status UNKNOWN b/131631629
            return true;
        } finally {
            //in either case send an asynchronous request to retrieve the phone status
            updatePhoneStatus(phone);
        }
    }

+57 −76
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.internal.telephony;

import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.telephony.PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE;
import static android.telephony.PhoneStateListener.LISTEN_PRECISE_CALL_STATE;
import static android.telephony.SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
import static android.telephony.SubscriptionManager.INVALID_PHONE_INDEX;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@@ -50,7 +48,6 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.PhoneCapability;
import android.telephony.PhoneStateListener;
import android.telephony.PreciseCallState;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -223,15 +220,17 @@ public class PhoneSwitcher extends Handler {
    // mEmergencyOverride, start the countdown to remove the override using the message
    // EVENT_REMOVE_DDS_EMERGENCY_OVERRIDE. The only exception to this is if the device moves to
    // ECBM, which is detected by EVENT_EMERGENCY_TOGGLE.
    private static final int EVENT_PHONE_IN_CALL_CHANGED          = 109;
    @VisibleForTesting
    public static final int EVENT_PRECISE_CALL_STATE_CHANGED      = 109;
    private static final int EVENT_NETWORK_VALIDATION_DONE        = 110;
    private static final int EVENT_REMOVE_DEFAULT_NETWORK_CHANGE_CALLBACK = 111;
    private static final int EVENT_MODEM_COMMAND_DONE             = 112;
    private static final int EVENT_MODEM_COMMAND_RETRY            = 113;
    private static final int EVENT_DATA_ENABLED_CHANGED           = 114;
    @VisibleForTesting
    public static final int EVENT_DATA_ENABLED_CHANGED            = 114;
    // An emergency call is about to be originated and requires the DDS to be overridden.
    // Uses EVENT_PHONE_IN_CALL_CHANGED message to start countdown to finish override defined in
    // mEmergencyOverride. If EVENT_PHONE_IN_CALL_CHANGED does not come in
    // Uses EVENT_PRECISE_CALL_STATE_CHANGED message to start countdown to finish override defined
    // in mEmergencyOverride. If EVENT_PRECISE_CALL_STATE_CHANGED does not come in
    // DEFAULT_DATA_OVERRIDE_TIMEOUT_MS milliseconds, then the override will be removed.
    private static final int EVENT_OVERRIDE_DDS_FOR_EMERGENCY     = 115;
    // If it exists, remove the current mEmergencyOverride DDS override.
@@ -315,6 +314,28 @@ public class PhoneSwitcher extends Handler {
        mValidator = CellularNetworkValidator.getInstance();
    }

    private boolean isPhoneInVoiceCallChanged() {
        int oldPhoneIdInVoiceCall = mPhoneIdInVoiceCall;
        // If there's no active call, the value will become INVALID_PHONE_INDEX
        // and internet data will be switched back to system selected or user selected
        // subscription.
        mPhoneIdInVoiceCall = SubscriptionManager.INVALID_PHONE_INDEX;
        for (Phone phone : mPhones) {
            if (isCallActive(phone) || isCallActive(phone.getImsPhone())) {
                mPhoneIdInVoiceCall = phone.getPhoneId();
                break;
            }
        }

        if (mPhoneIdInVoiceCall != oldPhoneIdInVoiceCall) {
            log("isPhoneInVoiceCallChanged from phoneId " + oldPhoneIdInVoiceCall
                    + " to phoneId " + mPhoneIdInVoiceCall);
            return true;
        } else {
            return false;
        }
    }

    @VisibleForTesting
    public PhoneSwitcher(int maxActivePhones, int numPhones, Context context,
            SubscriptionController subscriptionController, Looper looper, ITelephonyRegistry tr,
@@ -335,58 +356,25 @@ public class PhoneSwitcher extends Handler {
            public void onPhoneCapabilityChanged(PhoneCapability capability) {
                onPhoneCapabilityChangedInternal(capability);
            }

            @Override
            public void onPreciseCallStateChanged(PreciseCallState callState) {
                int oldPhoneIdInVoiceCall = mPhoneIdInVoiceCall;
                // If there's no active call, the value will become INVALID_PHONE_INDEX
                // and internet data will be switched back to system selected or user selected
                // subscription.
                mPhoneIdInVoiceCall = SubscriptionManager.INVALID_PHONE_INDEX;
                for (Phone phone : mPhones) {
                    if (isCallActive(phone) || isCallActive(phone.getImsPhone())) {
                        mPhoneIdInVoiceCall = phone.getPhoneId();
                        break;
                    }
                }

                if (mPhoneIdInVoiceCall != oldPhoneIdInVoiceCall) {
                    log("mPhoneIdInVoiceCall changed from" + oldPhoneIdInVoiceCall
                            + " to " + mPhoneIdInVoiceCall);

                    // Switches and listens to the updated voice phone.
                    Phone dataPhone = findPhoneById(mPhoneIdInVoiceCall);
                    if (dataPhone != null && dataPhone.getDataEnabledSettings() != null) {
                        dataPhone.getDataEnabledSettings()
                                .registerForDataEnabledChanged(getInstance(),
                                        EVENT_DATA_ENABLED_CHANGED, null);
                    }

                    Phone oldDataPhone = findPhoneById(oldPhoneIdInVoiceCall);
                    if (oldDataPhone != null && oldDataPhone.getDataEnabledSettings() != null) {
                        oldDataPhone.getDataEnabledSettings()
                                .unregisterForDataEnabledChanged(getInstance());
                    }

                    Message msg = PhoneSwitcher.this.obtainMessage(EVENT_PHONE_IN_CALL_CHANGED);
                    msg.sendToTarget();
                }
            }
        };

        mValidator = CellularNetworkValidator.getInstance();

        TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(mPhoneStateListener, LISTEN_PHONE_CAPABILITY_CHANGE
                | LISTEN_PRECISE_CALL_STATE);

        mActivePhoneRegistrants = new RegistrantList();
        mPhoneStates = new PhoneState[numPhones];
        for (int i = 0; i < numPhones; i++) {
            mPhoneStates[i] = new PhoneState();
            if (mPhones[i] != null) {
                mPhones[i].registerForEmergencyCallToggle(this, EVENT_EMERGENCY_TOGGLE, null);
                // TODO (b/135566422): combine register for both GsmCdmaPhone and ImsPhone.
                mPhones[i].registerForPreciseCallStateChanged(
                        this, EVENT_PRECISE_CALL_STATE_CHANGED, null);
                if (mPhones[i].getImsPhone() != null) {
                    mPhones[i].getImsPhone().registerForPreciseCallStateChanged(
                            this, EVENT_PRECISE_CALL_STATE_CHANGED, null);
                }
                mPhones[i].getDataEnabledSettings().registerForDataEnabledChanged(
                        this, EVENT_DATA_ENABLED_CHANGED, null);
            }
        }

@@ -510,7 +498,10 @@ public class PhoneSwitcher extends Handler {
                onEvaluate(REQUESTS_UNCHANGED, "EVENT_RADIO_AVAILABLE");
                break;
            }
            case EVENT_PHONE_IN_CALL_CHANGED: {
            case EVENT_PRECISE_CALL_STATE_CHANGED: {
                // If the phoneId in voice call didn't change, do nothing.
                if (!isPhoneInVoiceCallChanged()) break;

                // Only handle this event if we are currently waiting for the emergency call
                // associated with the override request to start or end.
                if (mEmergencyOverride != null && mEmergencyOverride.mPendingOriginatingCall) {
@@ -529,7 +520,7 @@ public class PhoneSwitcher extends Handler {
            }
            // fall through
            case EVENT_DATA_ENABLED_CHANGED:
                if (onEvaluate(REQUESTS_UNCHANGED, "EVENT_PHONE_IN_CALL_CHANGED")) {
                if (onEvaluate(REQUESTS_UNCHANGED, "EVENT_PRECISE_CALL_STATE_CHANGED")) {
                    logDataSwitchEvent(mOpptDataSubId,
                            TelephonyEvent.EventState.EVENT_STATE_START,
                            DataSwitch.Reason.DATA_SWITCH_REASON_IN_CALL);
@@ -601,8 +592,8 @@ public class PhoneSwitcher extends Handler {
                Message msg2 = obtainMessage(EVENT_REMOVE_DDS_EMERGENCY_OVERRIDE);
                // Make sure that if we never get an incall indication that we remove the override.
                sendMessageDelayed(msg2, DEFAULT_DATA_OVERRIDE_TIMEOUT_MS);
                // Wait for call to end and EVENT_PHONE_IN_CALL_CHANGED to be called, then start
                // timer to remove DDS emergency override.
                // Wait for call to end and EVENT_PRECISE_CALL_STATE_CHANGED to be called, then
                // start timer to remove DDS emergency override.
                if (!onEvaluate(REQUESTS_UNCHANGED, "emer_override_dds")) {
                    // Nothing changed as a result of override, so no modem command was sent. Treat
                    // as success.
@@ -621,19 +612,6 @@ public class PhoneSwitcher extends Handler {
        }
    }

    private boolean isEmergency() {
        if (isInEmergencyCallbackMode()) return true;
        for (Phone p : mPhones) {
            if (p == null) continue;
            if (p.isInEmergencyCall()) return true;
            Phone imsPhone = p.getImsPhone();
            if (imsPhone != null && imsPhone.isInEmergencyCall()) {
                return true;
            }
        }
        return false;
    }

    private boolean isInEmergencyCallbackMode() {
        for (Phone p : mPhones) {
            if (p == null) continue;
@@ -749,10 +727,6 @@ public class PhoneSwitcher extends Handler {
     */
    private boolean onEvaluate(boolean requestsChanged, String reason) {
        StringBuilder sb = new StringBuilder(reason);
        if (isEmergency()) {
            log("onEvaluate for reason " + reason + " aborted due to Emergency");
            return false;
        }

        // If we use HAL_COMMAND_PREFERRED_DATA,
        boolean diffDetected = mHalCommandToUse != HAL_COMMAND_PREFERRED_DATA && requestsChanged;
@@ -827,6 +801,12 @@ public class PhoneSwitcher extends Handler {
                        newActivePhones.add(mPhones[i].getPhoneId());
                    }
                } else {
                    // First try to activate phone in voice call.
                    if (mPhoneIdInVoiceCall != SubscriptionManager.INVALID_PHONE_INDEX) {
                        newActivePhones.add(mPhoneIdInVoiceCall);
                    }

                    if (newActivePhones.size() < mMaxActivePhones) {
                        for (DcRequest dcRequest : mPrioritizedDcRequests) {
                            int phoneIdForRequest = phoneIdForRequest(dcRequest.networkRequest);
                            if (phoneIdForRequest == INVALID_PHONE_INDEX) continue;
@@ -834,6 +814,7 @@ public class PhoneSwitcher extends Handler {
                            newActivePhones.add(phoneIdForRequest);
                            if (newActivePhones.size() >= mMaxActivePhones) break;
                        }
                    }

                    if (newActivePhones.size() < mMaxActivePhones
                            && newActivePhones.contains(mPreferredDataPhoneId)
+17 −1
Original line number Diff line number Diff line
@@ -2391,6 +2391,11 @@ public class ServiceStateTracker extends Handler {
             */
            boolean roaming = (mGsmRoaming || mDataRoaming);

            // for IWLAN case, data is home. Only check voice roaming.
            if (mNewSS.getRilDataRadioTechnology() == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) {
                roaming = mGsmRoaming;
            }

            if (mGsmRoaming && !isOperatorConsideredRoaming(mNewSS)
                    && (isSameNamedOperators(mNewSS) || isOperatorConsideredNonRoaming(mNewSS))) {
                log("updateRoamingState: resource override set non roaming.isSameNamedOperators="
@@ -2880,7 +2885,18 @@ public class ServiceStateTracker extends Handler {
            // Checking the Concurrent Service Supported flag first for all phone types.
            return true;
        } else if (mPhone.isPhoneTypeGsm()) {
            return (mSS.getRilDataRadioTechnology() >= ServiceState.RIL_RADIO_TECHNOLOGY_UMTS);
            int radioTechnology = mSS.getRilDataRadioTechnology();
            // There are cases where we we would setup data connection even data is not yet
            // attached. In these cases we check voice rat.
            if (radioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN
                    && mSS.getDataRegState() != ServiceState.STATE_IN_SERVICE) {
                radioTechnology = mSS.getRilVoiceRadioTechnology();
            }
            // Concurrent voice and data is not allowed for 2G technologies. It's allowed in other
            // rats e.g. UMTS, LTE, etc.
            return radioTechnology != ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN
                    && ServiceState.rilRadioTechnologyToAccessNetworkType(radioTechnology)
                        != AccessNetworkType.GERAN;
        } else {
            return false;
        }
+21 −7
Original line number Diff line number Diff line
@@ -1131,14 +1131,28 @@ public class DataConnection extends StateMachine {
     * @return True if this data connection should only be used for unmetered purposes.
     */
    private boolean isUnmeteredUseOnly() {
        // The data connection can only be unmetered used only if all requests' reasons are
        // unmetered.
        // If this data connection is on IWLAN, then it's unmetered and can be used by everyone.
        // Should not be for unmetered used only.
        if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
            return false;
        }

        // If data is enabled, this data connection can't be for unmetered used only because
        // everyone should be able to use it.
        if (mPhone.getDataEnabledSettings().isDataEnabled()) {
            return false;
        }

        // If the device is roaming and data roaming it turned on, then this data connection can't
        // be for unmetered use only.
        if (mDct.getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) {
            return false;
        }

        // The data connection can only be unmetered used only if all attached APN contexts
        // attached to this data connection are unmetered.
        for (ApnContext apnContext : mApnContexts.keySet()) {
            DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
            boolean isDataAllowed = mDct.isDataAllowed(apnContext, DcTracker.REQUEST_TYPE_NORMAL,
                    dataConnectionReasons);
            if (!isDataAllowed || !dataConnectionReasons.contains(
                    DataConnectionReasons.DataAllowedReasonType.UNMETERED_APN)) {
            if (ApnSettingUtils.isMeteredApnType(apnContext.getApnTypeBitmask(), mPhone)) {
                return false;
            }
        }
+15 −11
Original line number Diff line number Diff line
@@ -3881,23 +3881,27 @@ public class DcTracker extends Handler {
        mPhone.updateCurrentCarrierInProvider();
    }

    /**
     * For non DDS phone, mAutoAttachEnabled should be true because it may be detached
     * automatically from network only because it's idle for too long. In this case, we should
     * try setting up data call even if it's not attached for 2G or 3G networks. And doing so will
     * trigger PS attach if possible.
     */
    @VisibleForTesting
    public boolean shouldAutoAttach() {
        if (mAutoAttachEnabled.get()) return true;

        PhoneSwitcher phoneSwitcher = PhoneSwitcher.getInstance();
        ServiceState serviceState = mPhone.getServiceState();
        return phoneSwitcher != null && serviceState != null
                && mPhone.getPhoneId() != phoneSwitcher.getPreferredDataPhoneId()
                && serviceState.getVoiceRegState() == ServiceState.STATE_IN_SERVICE
                && serviceState.getVoiceNetworkType() != NETWORK_TYPE_LTE
                && serviceState.getVoiceNetworkType() != NETWORK_TYPE_NR;

        if (phoneSwitcher == null || serviceState == null) return false;

        // If voice is also not in service, don't auto attach.
        if (serviceState.getVoiceRegState() != ServiceState.STATE_IN_SERVICE) return false;

        // If voice is on LTE or NR, don't auto attach as for LTE / NR data would be attached.
        if (serviceState.getVoiceNetworkType() == NETWORK_TYPE_LTE
                || serviceState.getVoiceNetworkType() == NETWORK_TYPE_NR) return false;

        // If phone is non default phone, modem may have detached from data for optimization.
        // If phone is in voice call, for DSDS case DDS switch may be limited so we do try our
        // best to setup data connection and allow auto-attach.
        return (mPhone.getPhoneId() != phoneSwitcher.getPreferredDataPhoneId()
                || mPhone.getState() != PhoneConstants.State.IDLE);
    }

    private void notifyAllDataDisconnected() {
Loading