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

Commit c854d620 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I2bb5c346,I85e7fd9d,Id7b20d4a,I2bf3dc81,Ie2e41c1c, ...

* changes:
  Use DataSettingsManagerCallback for new data stack
  DataServiceManager update binder died behavior
  Adjusted APN type capability and priority
  Fixed network request was removed before retry
  Allowing the wrong PDN deactivation behavior on old HAL
  Switch data profile when handover
parents e644644d ebf85d87
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_T
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE;
import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID;

import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.PendingIntent;
@@ -52,6 +53,7 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.data.DataSettingsManager.DataSettingsManagerCallback;
import com.android.internal.telephony.util.ArrayUtils;

import java.lang.annotation.Retention;
@@ -59,6 +61,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
@@ -150,6 +153,9 @@ public class MultiSimSettingController extends Handler {
    // device.
    private final boolean mIsAskEverytimeSupportedForSms;

    // The number of existing DataSettingsControllerCallback
    private int mCallbacksCount;

    private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub";

    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@@ -165,6 +171,37 @@ public class MultiSimSettingController extends Handler {
        }
    };

    private static class DataSettingsControllerCallback extends DataSettingsManagerCallback {
        private final Phone mPhone;

        DataSettingsControllerCallback(@NonNull Phone phone,
                @NonNull @CallbackExecutor Executor executor) {
            super(executor);
            mPhone = phone;
        }

        @Override
        public void onDataEnabledChanged(boolean enabled,
                @TelephonyManager.DataEnabledChangedReason int reason, String callingPackage) {
            int subId = mPhone.getSubId();
            // notifyUserDataEnabled if the change is called from external and reason is
            // DATA_ENABLED_REASON_USER
            if (SubscriptionManager.isValidSubscriptionId(subId)
                    && reason == TelephonyManager.DATA_ENABLED_REASON_USER
                    && !getInstance().mContext.getOpPackageName().equals(callingPackage)) {
                getInstance().notifyUserDataEnabled(mPhone.getSubId(), enabled);
            }
        }

        @Override
        public void onDataRoamingEnabledChanged(boolean enabled) {
            int subId = mPhone.getSubId();
            if (SubscriptionManager.isValidSubscriptionId(subId)) {
                getInstance().notifyRoamingDataEnabled(mPhone.getSubId(), enabled);
            }
        }
    }

    /**
     * Return the singleton or create one if not existed.
     */
@@ -353,6 +390,7 @@ public class MultiSimSettingController extends Handler {
            }
            reEvaluateAll();
        }
        registerDataSettingsControllerCallbackAsNeeded();
    }

    /**
@@ -416,7 +454,11 @@ public class MultiSimSettingController extends Handler {
        reEvaluateAll();
    }

    private boolean isCarrierConfigLoadedForAllSub() {
    /**
     * Check whether carrier config loaded for all subs
     */
    @VisibleForTesting
    public boolean isCarrierConfigLoadedForAllSub() {
        int[] activeSubIds = mSubController.getActiveSubIdList(false);
        for (int activeSubId : activeSubIds) {
            boolean isLoaded = false;
@@ -444,6 +486,7 @@ public class MultiSimSettingController extends Handler {
        for (Phone phone : PhoneFactory.getPhones()) {
            phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        }
        registerDataSettingsControllerCallbackAsNeeded();
    }

    /**
@@ -1009,6 +1052,19 @@ public class MultiSimSettingController extends Handler {
        return true;
    }

    private void registerDataSettingsControllerCallbackAsNeeded() {
        // Only register callbacks for new phone instance as PhoneFactory does not remove
        // existing phone instance.
        Phone[] phones = PhoneFactory.getPhones();
        for (int i = mCallbacksCount; i < phones.length; i++) {
            if (phones[i].isUsingNewDataStack()) {
                phones[i].getDataSettingsManager().registerCallback(
                        new DataSettingsControllerCallback(phones[i], this::post));
            }
        }
        mCallbacksCount = phones.length;
    }

    private void log(String msg) {
        Log.d(LOG_TAG, msg);
    }
+1 −1
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ public class DataEvaluation {
        RETRY_AFTER_DISCONNECTED,
        /** Data setup retry. */
        DATA_RETRY,
        /** Handover between IWLAN and cellular. */
        /** For handover evaluation, or for network tearing down after handover succeeds/fails. */
        DATA_HANDOVER,
        /** Preferred transport changed. */
        PREFERRED_TRANSPORT_CHANGED,
+79 −17
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.RIL;
import com.android.internal.telephony.data.DataEvaluation.DataAllowedReason;
import com.android.internal.telephony.data.DataNetworkController.NetworkRequestList;
import com.android.internal.telephony.data.DataRetryManager.DataHandoverRetryEntry;
@@ -542,7 +543,13 @@ public class DataNetwork extends StateMachine {
    private @Nullable KeepaliveTracker mKeepaliveTracker;

    /** The data profile used to establish this data network. */
    private final @NonNull DataProfile mDataProfile;
    private @NonNull DataProfile mDataProfile;

    /**
     * The data profile used for data handover. Some carriers might use different data profile
     * between IWLAN and cellular. Only set before handover started.
     */
    private @Nullable DataProfile mHandoverDataProfile;

    /** The network capabilities of this data network. */
    private @NonNull NetworkCapabilities mNetworkCapabilities;
@@ -1117,6 +1124,7 @@ public class DataNetwork extends StateMachine {

            notifyPreciseDataConnectionState();
            if (mTransport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                // Defer setupData until we get the PDU session ID response
                allocatePduSessionId();
                return;
            }
@@ -1154,6 +1162,7 @@ public class DataNetwork extends StateMachine {
                case EVENT_PCO_DATA_RECEIVED:
                case EVENT_WAITING_FOR_TEARING_DOWN_CONDITION_MET:
                    // Defer the request until connected or disconnected.
                    log("Defer message " + eventToString(msg.what));
                    deferMessage(msg);
                    break;
                case EVENT_STUCK_IN_TRANSIENT_STATE:
@@ -1322,6 +1331,7 @@ public class DataNetwork extends StateMachine {
                    // signal. So we only defer the related data call list changed event, and drop
                    // the unrelated.
                    if (shouldDeferDataStateChangedEvent(msg)) {
                        log("Defer message " + eventToString(msg.what));
                        deferMessage(msg);
                    }
                    break;
@@ -1332,6 +1342,7 @@ public class DataNetwork extends StateMachine {
                case EVENT_VOICE_CALL_ENDED:
                case EVENT_VOICE_CALL_STARTED:
                    // Defer the request until handover succeeds or fails.
                    log("Defer message " + eventToString(msg.what));
                    deferMessage(msg);
                    break;
                case EVENT_HANDOVER_RESPONSE:
@@ -1588,7 +1599,7 @@ public class DataNetwork extends StateMachine {
        for (TelephonyNetworkRequest networkRequest : requestList) {
            if (!mDataNetworkController.isNetworkRequestExisting(networkRequest)) {
                failedList.add(networkRequest);
                log("Attached failed. Network request was already removed.");
                log("Attached failed. Network request was already removed. " + networkRequest);
            } else if (!networkRequest.canBeSatisfiedBy(getNetworkCapabilities())) {
                failedList.add(networkRequest);
                log("Attached failed. Cannot satisfy the network request "
@@ -2291,6 +2302,11 @@ public class DataNetwork extends StateMachine {
            log("Remove network since deactivate request returned an error.");
            mFailCause = DataFailCause.RADIO_NOT_AVAILABLE;
            transitionTo(mDisconnectedState);
        } else if (mPhone.getHalVersion().less(RIL.RADIO_HAL_VERSION_2_0)) {
            log("Remove network on deactivate data response on old HAL "
                    + mPhone.getHalVersion());
            mFailCause = DataFailCause.LOST_CONNECTION;
            transitionTo(mDisconnectedState);
        }
    }

@@ -2686,26 +2702,51 @@ public class DataNetwork extends StateMachine {

    /**
     * Get the APN type network capability. If there are more than one capabilities that are
     * APN-types, then return the highest priority one.
     * APN types, then return the highest priority one which also has associated network request.
     * For example, if the network supports both MMS and internet, but only internet request
     * attached at this time, then the capability would be internet. Later on if MMS network request
     * attached to this network, then the APN type capability would be MMS.
     *
     * @return The APN type network capability from this network.
     *
     * @see #getPriority()
     */
    public @NetCapability int getApnTypeNetworkCapability() {
        if (!mAttachedNetworkRequestList.isEmpty()) {
            // The highest priority network request is always at the top of list.
            return mAttachedNetworkRequestList.get(0).getApnTypeNetworkCapability();
        } else {
            return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                .filter(cap -> DataUtils.networkCapabilityToApnType(cap) != ApnSetting.TYPE_NONE)
                    .filter(cap -> DataUtils.networkCapabilityToApnType(cap)
                            != ApnSetting.TYPE_NONE)
                    .max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
                    .orElse(-1);
        }
    }

    /**
     * @return The priority of the network. The priority is derived from the highest priority
     * capability of the network.
     * Get the priority of the network. The priority is derived from the highest priority capability
     * which also has such associated network request. For example, if the network supports both
     * MMS and internet, but only has internet request attached, then this network has internet's
     * priority. Later on when the MMS request attached to this network, the network's priority will
     * be updated to MMS's priority.
     *
     * @return The priority of the network.
     *
     * @see #getApnTypeNetworkCapability()
     */
    public int getPriority() {
        if (!mAttachedNetworkRequestList.isEmpty()) {
            // The highest priority network request is always at the top of list.
            return mAttachedNetworkRequestList.get(0).getPriority();
        } else {
            // If all network requests are already detached, then just pick the highest priority
            // capability's priority.
            return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                    .map(mDataConfigManager::getNetworkCapabilityPriority)
                    .max(Integer::compare)
                .orElse(-1);
                    .orElse(0);
        }
    }

    /**
@@ -2872,17 +2913,35 @@ public class DataNetwork extends StateMachine {
        // state in framework, we should set this flag to true as well so the modem will not reject
        // the data call setup (because the modem actually thinks the device is roaming).
        boolean allowRoaming = mPhone.getDataRoamingEnabled()
                || (isModemRoaming && (!mPhone.getServiceState().getDataRoaming()
                /*|| isUnmeteredUseOnly()*/));
                || (isModemRoaming && (!mPhone.getServiceState().getDataRoaming()));

        mHandoverDataProfile = mDataProfile;
        int targetNetworkType = getDataNetworkType(targetTransport);
        if (targetNetworkType != TelephonyManager.NETWORK_TYPE_UNKNOWN
                && !mAttachedNetworkRequestList.isEmpty()) {
            TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0);
            DataProfile dataProfile = mDataNetworkController.getDataProfileManager()
                    .getDataProfileForNetworkRequest(networkRequest, targetNetworkType);
            // Some carriers have different profiles between cellular and IWLAN. We need to
            // dynamically switch profile, but only when those profiles have same APN name.
            if (dataProfile != null && dataProfile.getApnSetting() != null
                    && mDataProfile.getApnSetting() != null
                    && TextUtils.equals(dataProfile.getApnSetting().getApnName(),
                    mDataProfile.getApnSetting().getApnName())
                    && !dataProfile.equals(mDataProfile)) {
                mHandoverDataProfile = dataProfile;
                log("Used different data profile for handover. " + mDataProfile);
            }
        }

        logl("Start handover from " + AccessNetworkConstants.transportTypeToString(mTransport)
                + " to " + AccessNetworkConstants.transportTypeToString(targetTransport));
        // Send the handover request to the target transport data service.
        mDataServiceManagers.get(targetTransport).setupDataCall(
                DataUtils.networkTypeToAccessNetworkType(getDataNetworkType(targetTransport)),
                mDataProfile, isModemRoaming, allowRoaming,
                mHandoverDataProfile, isModemRoaming, allowRoaming,
                DataService.REQUEST_REASON_HANDOVER, mLinkProperties, mPduSessionId,
                mNetworkSliceInfo, mDataProfile.getTrafficDescriptor(), true,
                mNetworkSliceInfo, mHandoverDataProfile.getTrafficDescriptor(), true,
                obtainMessage(EVENT_HANDOVER_RESPONSE, retryEntry));
        transitionTo(mHandoverState);
    }
@@ -2911,6 +2970,9 @@ public class DataNetwork extends StateMachine {
            // Update the logging tag
            mLogTag = "DN-" + mInitialNetworkAgentId + "-"
                    + ((mTransport == AccessNetworkConstants.TRANSPORT_TYPE_WWAN) ? "C" : "I");
            // Switch the data profile. This is no-op in most of the case since almost all carriers
            // use same data profile between IWLAN and cellular.
            mDataProfile = mHandoverDataProfile;
            updateDataNetwork(response);
            if (mTransport != AccessNetworkConstants.TRANSPORT_TYPE_WWAN) {
                // Handover from WWAN to WLAN
+22 −22
Original line number Diff line number Diff line
@@ -801,7 +801,8 @@ public class DataNetworkController extends Handler {
                        new DataSettingsManagerCallback(this::post) {
                            @Override
                            public void onDataEnabledChanged(boolean enabled,
                                    @TelephonyManager.DataEnabledChangedReason int reason) {
                                    @TelephonyManager.DataEnabledChangedReason int reason,
                                    @NonNull String callingPackage) {
                                // If mobile data is enabled by the user, evaluate the unsatisfied
                                // network requests and then attempt to setup data networks to
                                // satisfy them. If mobile data is disabled, evaluate the existing
@@ -2440,7 +2441,7 @@ public class DataNetworkController extends Handler {

    /**
     * Track the frequency of setup data failure on each
     * {@link AccessNetworkConstants#TransportType} data service.
     * {@link AccessNetworkConstants.TransportType} data service.
     *
     * @param transport The transport of the data service.
     */
@@ -2506,16 +2507,17 @@ public class DataNetworkController extends Handler {
     */
    private void onDataNetworkSetupRetry(@NonNull DataSetupRetryEntry dataSetupRetryEntry) {
        // The request might be already removed before retry happens. Remove them from the list
        // if that's the case.
        dataSetupRetryEntry.networkRequestList.removeIf(
                request -> !mAllNetworkRequestList.contains(request));
        if (dataSetupRetryEntry.networkRequestList.isEmpty()) {
        // if that's the case. Copy the list first. We don't want to remove the requests from
        // the retry entry. They can be later used to determine what kind of retry it is.
        NetworkRequestList requestList = new NetworkRequestList(
                dataSetupRetryEntry.networkRequestList);
        requestList.removeIf(request -> !mAllNetworkRequestList.contains(request));
        if (requestList.isEmpty()) {
            loge("onDataNetworkSetupRetry: Request list is empty. Abort retry.");
            dataSetupRetryEntry.setState(DataRetryEntry.RETRY_STATE_CANCELLED);
            return;
        }
        TelephonyNetworkRequest telephonyNetworkRequest =
                dataSetupRetryEntry.networkRequestList.get(0);
        TelephonyNetworkRequest telephonyNetworkRequest = requestList.get(0);

        int networkCapability = telephonyNetworkRequest.getApnTypeNetworkCapability();
        int preferredTransport = mAccessNetworksManager.getPreferredTransportByNetworkCapability(
@@ -2614,7 +2616,7 @@ public class DataNetworkController extends Handler {
        }

        if (!mDataSettingsManager.isRecoveryOnBadNetworkEnabled()) {
            log("Ignore data network validation status changed becaused"
            log("Ignore data network validation status changed because "
                    + "data stall recovery is disabled.");
            return;
        }
@@ -2700,6 +2702,11 @@ public class DataNetworkController extends Handler {
        // manager.
        sendMessage(obtainMessage(EVENT_EVALUATE_PREFERRED_TRANSPORT,
                dataNetwork.getApnTypeNetworkCapability(), 0));

        // There might be network we didn't tear down in the last evaluation due to handover in
        // progress. We should evaluate again.
        sendMessage(obtainMessage(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS,
                DataEvaluationReason.DATA_HANDOVER));
    }

    /**
@@ -2720,6 +2727,11 @@ public class DataNetworkController extends Handler {
        logl("Handover failed. " + dataNetwork + ", cause=" + DataFailCause.toString(cause)
                + ", retryDelayMillis=" + retryDelayMillis + "ms, handoverFailureMode="
                + DataCallResponse.failureModeToString(handoverFailureMode));
        // There might be network we didn't tear down in the last evaluation due to handover in
        // progress. We should evaluate again.
        sendMessage(obtainMessage(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS,
                DataEvaluationReason.DATA_HANDOVER));

        if (dataNetwork.getAttachedNetworkRequestList().isEmpty()) {
            log("onDataNetworkHandoverFailed: No network requests attached to " + dataNetwork
                    + ". No need to retry since the network will be torn down soon.");
@@ -2786,19 +2798,7 @@ public class DataNetworkController extends Handler {
        log("onDataServiceBindingChanged: " + AccessNetworkConstants
                .transportTypeToString(transport) + " data service is "
                + (bound ? "bound." : "unbound."));
        if (!bound) {
            if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                if (!mDataConfigManager.shouldPersistIwlanDataNetworksWhenDataServiceRestarted()) {
                    for (DataNetwork dataNetwork : mDataNetworkList) {
                        if (dataNetwork.getTransport()
                                == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
                            dataNetwork.tearDown(
                                    DataNetwork.TEAR_DOWN_REASON_DATA_SERVICE_NOT_READY);
                        }
                    }
                }
            }
        } else {
        if (bound) {
            mDataNetworkControllerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                    () -> callback.onDataServiceBound(transport)));
        }
+1 −1
Original line number Diff line number Diff line
@@ -1485,7 +1485,7 @@ public class DataRetryManager extends Handler {
                        logl(msg);
                        loge("mDataRetryEntries=" + mDataRetryEntries);
                        AnomalyReporter.reportAnomaly(
                                UUID.fromString("afeab78c-c0b0-49fc-a51f-f766814d7aa5"),
                                UUID.fromString("781af571-f55d-476d-b510-7a5381f633dc"),
                                msg,
                                mPhone.getCarrierId());
                        continue;
Loading