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

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

Snap for 5533229 from f18a7b3a to qt-release

Change-Id: I0f7ee55e3428f1d2c126bb5da9c950a592b6bdfe
parents fb678b19 f18a7b3a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class CellularNetworkValidator {
    /**
     * Check whether this feature is supported or not.
     */
    public static boolean isValidationFeatureSupported() {
    public boolean isValidationFeatureSupported() {
        return PhoneConfigurationManager.getInstance().getCurrentPhoneCapability()
                .validationBeforeSwitchSupported;
    }
+40 −8
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.util.Log;

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

/**
 * This class manages phone's configuration which defines the potential capability (static) of the
@@ -156,7 +157,7 @@ public class PhoneConfigurationManager {
                        int phoneId = msg.arg1;
                        boolean enabled = (boolean) ar.result;
                        //update the cache each time getModemStatus is requested
                        mPhoneStatusMap.put(phoneId, enabled);
                        addToPhoneStatusCache(phoneId, enabled);
                    } else {
                        log(msg.what + " failure. Not updating modem status." + ar.exception);
                    }
@@ -186,11 +187,12 @@ public class PhoneConfigurationManager {
            return;
        }
        phone.mCi.enableModem(enable, result);
        updatePhoneStatus(phone);
    }

    /**
     * Get phone status (enabled/disabled)
     * first query cache, if the status is not in cache,
     * add it to cache and return a default value true (non-blocking).
     *
     * @param phone which phone to operate on
     */
@@ -203,24 +205,54 @@ public class PhoneConfigurationManager {
        int phoneId = phone.getPhoneId();

        //use cache if the status has already been updated/queried
        if (mPhoneStatusMap.containsKey(phoneId)) {
            return mPhoneStatusMap.get(phoneId);
        } else {
        try {
            return getPhoneStatusFromCache(phoneId);
        } catch (NoSuchElementException ex) {
            updatePhoneStatus(phone);
            // Return true if modem status is not in cache. For most of case, modem status
            // 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;
        }
    }

    /**
     * Get phone status (enabled/disabled) directly from modem, and use a result Message object
     * Note: the caller of this method is reponsible to call this in a blocking fashion as well
     * as read the results and handle the error case.
     * (In order to be consistent, in error case, we should return default value of true; refer
     *  to #getPhoneStatus method)
     *
     * @param phone which phone to operate on
     * @param result message that will be updated with result
     */
    public void getPhoneStatusFromModem(Phone phone, Message result) {
        if (phone == null) {
            log("getPhoneStatus failed phone is null");
        }
        phone.mCi.getModemStatus(result);
    }

    /**
     * return modem status from cache, NoSuchElementException if phoneId not in cache
     * @param phoneId
     */
    public boolean getPhoneStatusFromCache(int phoneId) throws NoSuchElementException {
        if (mPhoneStatusMap.containsKey(phoneId)) {
            return mPhoneStatusMap.get(phoneId);
        } else {
            throw new NoSuchElementException("phoneId not found: " + phoneId);
        }
    }

    /**
     * method to call RIL getModemStatus
     */
    private void updatePhoneStatus(Phone phone) {
        Message callback = Message.obtain(
        Message result = Message.obtain(
                mHandler, EVENT_GET_MODEM_STATUS_DONE, phone.getPhoneId(), 0 /**dummy arg*/);
        phone.mCi.getModemStatus(callback);
        phone.mCi.getModemStatus(result);
    }

    /**
+52 −30
Original line number Diff line number Diff line
@@ -104,7 +104,8 @@ public class PhoneSwitcher extends Handler {
    @VisibleForTesting
    public final PhoneStateListener mPhoneStateListener;
    private final CellularNetworkValidator mValidator;
    private final CellularNetworkValidator.ValidationCallback mValidationCallback =
    @VisibleForTesting
    public final CellularNetworkValidator.ValidationCallback mValidationCallback =
            (validated, subId) -> Message.obtain(PhoneSwitcher.this,
                    EVENT_NETWORK_VALIDATION_DONE, subId, validated ? 1 : 0).sendToTarget();
    @UnsupportedAppUsage
@@ -405,11 +406,7 @@ public class PhoneSwitcher extends Handler {
                boolean needValidation = (msg.arg2 == 1);
                ISetOpportunisticDataCallback callback =
                        (ISetOpportunisticDataCallback) msg.obj;
                if (SubscriptionManager.isUsableSubscriptionId(subId)) {
                setOpportunisticDataSubscription(subId, needValidation, callback);
                } else {
                    unsetOpportunisticDataSubscription(callback);
                }
                break;
            }
            case EVENT_RADIO_AVAILABLE: {
@@ -909,18 +906,31 @@ public class PhoneSwitcher extends Handler {
    /**
     * Set opportunistic data subscription. It's an indication to switch Internet data to this
     * subscription. It has to be an active subscription, and PhoneSwitcher will try to validate
     * it first if needed.
     * it first if needed. If subId is DEFAULT_SUBSCRIPTION_ID, it means we are un-setting
     * opportunistic data sub and switch data back to primary sub.
     *
     * @param subId the opportunistic data subscription to switch to. pass DEFAULT_SUBSCRIPTION_ID
     *              if un-setting it.
     * @param needValidation whether Telephony will wait until the network is validated by
     *              connectivity service before switching data to it. More details see
     *              {@link NetworkCapabilities#NET_CAPABILITY_VALIDATED}.
     * @param callback Callback will be triggered once it succeeds or failed.
     *                 Pass null if don't care about the result.
     */
    private void setOpportunisticDataSubscription(int subId, boolean needValidation,
            ISetOpportunisticDataCallback callback) {
        if (!mSubscriptionController.isActiveSubId(subId)) {
        if (!mSubscriptionController.isActiveSubId(subId)
                && subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            log("Can't switch data to inactive subId " + subId);
            sendSetOpptCallbackHelper(callback, SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION);
            return;
        }

        int subIdToValidate = (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)
                ? mPrimaryDataSubId : subId;

        if (mValidator.isValidating()
                && (!needValidation || subId != mValidator.getSubIdInValidation())) {
                && (!needValidation || subIdToValidate != mValidator.getSubIdInValidation())) {
            mValidator.stopValidation();
        }

@@ -931,11 +941,11 @@ public class PhoneSwitcher extends Handler {

        // If validation feature is not supported, set it directly. Otherwise,
        // start validation on the subscription first.
        if (CellularNetworkValidator.isValidationFeatureSupported() && needValidation) {
        if (mValidator.isValidationFeatureSupported() && needValidation) {
            logDataSwitchEvent(subId, TelephonyEvent.EventState.EVENT_STATE_START,
                    DataSwitch.Reason.DATA_SWITCH_REASON_CBRS);
            mSetOpptSubCallback = callback;
            mValidator.validate(subId, DEFAULT_VALIDATION_EXPIRATION_TIME,
            mValidator.validate(subIdToValidate, DEFAULT_VALIDATION_EXPIRATION_TIME,
                    false, mValidationCallback);
        } else {
            setOpportunisticSubscriptionInternal(subId);
@@ -943,21 +953,6 @@ public class PhoneSwitcher extends Handler {
        }
    }

    /**
     * Unset opportunistic data subscription. It's an indication to switch Internet data back
     * from opportunistic subscription to primary subscription.
     */
    private void unsetOpportunisticDataSubscription(ISetOpportunisticDataCallback callback) {
        if (mValidator.isValidating()) {
            mValidator.stopValidation();
        }

        // Set mOpptDataSubId back to DEFAULT_SUBSCRIPTION_ID. This will trigger
        // data switch to mPrimaryDataSubId.
        setOpportunisticSubscriptionInternal(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
        sendSetOpptCallbackHelper(callback, SET_OPPORTUNISTIC_SUB_SUCCESS);
    }

    private void sendSetOpptCallbackHelper(ISetOpportunisticDataCallback callback, int result) {
        if (callback == null) return;
        try {
@@ -983,18 +978,45 @@ public class PhoneSwitcher extends Handler {
    }

    private void onValidationDone(int subId, boolean passed) {
        log("Network validation " + (passed ? "passed" : "failed")
        log("onValidationDone: " + (passed ? "passed" : "failed")
                + " on subId " + subId);
        if (passed) setOpportunisticSubscriptionInternal(subId);
        int resultForCallBack;

        if (!mSubscriptionController.isActiveSubId(subId)) {
            log("onValidationDone: subId " + subId + " is no longer active");
            resultForCallBack = SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION;
        } else if (!passed) {
            resultForCallBack = SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED;
        } else {
            if (mSubscriptionController.isOpportunistic(subId)) {
                setOpportunisticSubscriptionInternal(subId);
            } else {
                // Switching data back to primary subscription.
                setOpportunisticSubscriptionInternal(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
            }
            resultForCallBack = SET_OPPORTUNISTIC_SUB_SUCCESS;
        }

        // Trigger callback if needed
        sendSetOpptCallbackHelper(mSetOpptSubCallback, passed ? SET_OPPORTUNISTIC_SUB_SUCCESS
                : SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED);
        sendSetOpptCallbackHelper(mSetOpptSubCallback, resultForCallBack);
        mSetOpptSubCallback = null;
    }

    /**
     * Notify PhoneSwitcher to try to switch data to an opportunistic subscription.
     *
     * Set opportunistic data subscription. It's an indication to switch Internet data to this
     * subscription. It has to be an active subscription, and PhoneSwitcher will try to validate
     * it first if needed. If subId is DEFAULT_SUBSCRIPTION_ID, it means we are un-setting
     * opportunistic data sub and switch data back to primary sub.
     *
     * @param subId the opportunistic data subscription to switch to. pass DEFAULT_SUBSCRIPTION_ID
     *              if un-setting it.
     * @param needValidation whether Telephony will wait until the network is validated by
     *              connectivity service before switching data to it. More details see
     *              {@link NetworkCapabilities#NET_CAPABILITY_VALIDATED}.
     * @param callback Callback will be triggered once it succeeds or failed.
     *                 Pass null if don't care about the result.
     */
    public void trySetOpportunisticDataSubscription(int subId, boolean needValidation,
            ISetOpportunisticDataCallback callback) {
+18 −4
Original line number Diff line number Diff line
@@ -3315,6 +3315,10 @@ public class ServiceStateTracker extends Handler {
                mSS.getVoiceRegState() == ServiceState.STATE_IN_SERVICE
                        && mNewSS.getVoiceRegState() != ServiceState.STATE_IN_SERVICE;

        boolean hasAirplaneModeOnChanged =
                mSS.getVoiceRegState() != ServiceState.STATE_POWER_OFF
                        && mNewSS.getVoiceRegState() == ServiceState.STATE_POWER_OFF;

        SparseBooleanArray hasDataAttached = new SparseBooleanArray(
                mTransportManager.getAvailableTransports().length);
        SparseBooleanArray hasDataDetached = new SparseBooleanArray(
@@ -3331,7 +3335,12 @@ public class ServiceStateTracker extends Handler {
            NetworkRegistrationInfo newNrs = mNewSS.getNetworkRegistrationInfo(
                    NetworkRegistrationInfo.DOMAIN_PS, transport);

            boolean changed = (oldNrs == null || !oldNrs.isInService())
            // If the previously it was not in service, and now it's in service, trigger the
            // attached event. Also if airplane mode was just turned on, and data is already in
            // service, we need to trigger the attached event again so that DcTracker can setup
            // data on all connectable APNs again (because we've already torn down all data
            // connections just before airplane mode turned on)
            boolean changed = (oldNrs == null || !oldNrs.isInService() || hasAirplaneModeOnChanged)
                    && (newNrs != null && newNrs.isInService());
            hasDataAttached.put(transport, changed);

@@ -3448,7 +3457,8 @@ public class ServiceStateTracker extends Handler {
                    + " hasLostMultiApnSupport = " + hasLostMultiApnSupport
                    + " hasCssIndicatorChanged = " + hasCssIndicatorChanged
                    + " hasNrFrequencyRangeChanged = " + hasNrFrequencyRangeChanged
                    + " hasNrStateChanged = " + hasNrStateChanged);
                    + " hasNrStateChanged = " + hasNrStateChanged
                    + " hasAirplaneModeOnlChanged = " + hasAirplaneModeOnChanged);
        }

        // Add an event log when connection state changes
@@ -3620,13 +3630,17 @@ public class ServiceStateTracker extends Handler {

            if (hasDataAttached.get(transport)) {
                shouldLogAttachedChange = true;
                if (mAttachedRegistrants.get(transport) != null) {
                    mAttachedRegistrants.get(transport).notifyRegistrants();
                }
            }
            if (hasDataDetached.get(transport)) {
                shouldLogAttachedChange = true;
                if (mDetachedRegistrants.get(transport) != null) {
                    mDetachedRegistrants.get(transport).notifyRegistrants();
                }
            }
        }

        if (shouldLogAttachedChange) {
            logAttachChange();
+8 −2
Original line number Diff line number Diff line
@@ -392,8 +392,14 @@ public class TelephonyNetworkFactory extends NetworkFactory {
        int originTransport = (targetTransport == AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                ? AccessNetworkConstants.TRANSPORT_TYPE_WLAN
                : AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
        releaseNetworkInternal(networkRequest, DcTracker.RELEASE_TYPE_HANDOVER,
                originTransport);
        int releaseType = success
                ? DcTracker.RELEASE_TYPE_HANDOVER
                // If handover fails, we need to tear down the existing connection, so the
                // new data connection can be re-established on the new transport. If we leave
                // the existing data connection in current transport, then DCT and qualified
                // network service will be out of sync.
                : DcTracker.RELEASE_TYPE_NORMAL;
        releaseNetworkInternal(networkRequest, releaseType, originTransport);
        mNetworkRequests.put(networkRequest, targetTransport);

        handoverParams.callback.onCompleted(success);
Loading