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

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

Merge "Supported single PDN arbitration"

parents a236a123 ef96497c
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -214,6 +214,11 @@ public class DataEvaluation {
        PREFERRED_TRANSPORT_CHANGED,
        /** Slice config changed. */
        SLICE_CONFIG_CHANGED,
        /**
         * Single data network arbitration. On certain RATs, only one data network is allowed at the
         * same time.
         */
        SINGLE_DATA_NETWORK_ARBITRATION,
    }

    /** Disallowed reasons. There could be multiple reasons if it is not allowed. */
@@ -266,7 +271,9 @@ public class DataEvaluation {
        /** Data network is not in the right state. */
        ILLEGAL_STATE(true),
        /** VoPS is not supported by the network. */
        VOPS_NOT_SUPPORTED(true);
        VOPS_NOT_SUPPORTED(true),
        /** Only one data network is allowed at one time. */
        ONLY_ALLOWED_SINGLE_NETWORK(true);

        private final boolean mIsHardReason;

+17 −0
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ public class DataNetwork extends StateMachine {
                    TEAR_DOWN_REASON_DATA_PROFILE_NOT_PREFERRED,
                    TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY,
                    TEAR_DOWN_REASON_ILLEGAL_STATE,
                    TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK,
            })
    public @interface TearDownReason {}

@@ -328,6 +329,9 @@ public class DataNetwork extends StateMachine {
    /** Data network tear down due to illegal state. */
    public static final int TEAR_DOWN_REASON_ILLEGAL_STATE = 28;

    /** Data network tear down due to only allowed single network. */
    public static final int TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK = 29;

    @IntDef(prefix = {"BANDWIDTH_SOURCE_"},
            value = {
                    BANDWIDTH_SOURCE_UNKNOWN,
@@ -2273,6 +2277,17 @@ public class DataNetwork extends StateMachine {
        return highestPriorityCapability;
    }

    /**
     * @return The priority of the network. The priority is derived from the highest priority
     * capability of the network.
     */
    public int getPriority() {
        return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                .map(mDataConfigManager::getNetworkCapabilityPriority)
                .max(Integer::compare)
                .orElse(-1);
    }

    /**
     * @return The attached network request list.
     */
@@ -2619,6 +2634,8 @@ public class DataNetwork extends StateMachine {
                return "TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY";
            case TEAR_DOWN_REASON_ILLEGAL_STATE:
                return "TEAR_DOWN_REASON_ILLEGAL_STATE";
            case TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK:
                return "TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK";
            default:
                return "UNKNOWN(" + reason + ")";
        }
+43 −8
Original line number Diff line number Diff line
@@ -135,9 +135,6 @@ public class DataNetworkController extends Handler {
    /** Event for removing a network request. */
    private static final int EVENT_REMOVE_NETWORK_REQUEST = 3;

    /** Event for satisfying a single network request. */
    private static final int EVENT_SATISFY_NETWORK_REQUEST = 4;

    /** Re-evaluate all unsatisfied network requests. */
    private static final int EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS = 5;

@@ -891,9 +888,6 @@ public class DataNetworkController extends Handler {
            case EVENT_ADD_NETWORK_REQUEST:
                onAddNetworkRequest((TelephonyNetworkRequest) msg.obj);
                break;
            case EVENT_SATISFY_NETWORK_REQUEST:
                onSatisfyNetworkRequest((TelephonyNetworkRequest) msg.obj);
                break;
            case EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS:
                DataEvaluationReason reason = (DataEvaluationReason) msg.obj;
                onReevaluateUnsatisfiedNetworkRequests(reason);
@@ -1036,7 +1030,7 @@ public class DataNetworkController extends Handler {
            return;
        }
        logv("onAddNetworkRequest: added " + networkRequest);
        sendMessage(obtainMessage(EVENT_SATISFY_NETWORK_REQUEST, networkRequest));
        onSatisfyNetworkRequest(networkRequest);
    }

    /**
@@ -1070,6 +1064,12 @@ public class DataNetworkController extends Handler {
                setupDataNetwork(dataProfile, null,
                        evaluation.getDataAllowedReason());
            }
        } else if (evaluation.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)) {
            // Re-evaluate the existing data networks. If this request's priority is higher than
            // the existing data network, the data network will be torn down so this request will
            // get a chance to be satisfied.
            sendMessage(obtainMessage(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS,
                    DataEvaluationReason.SINGLE_DATA_NETWORK_ARBITRATION));
        }
    }

@@ -1136,7 +1136,6 @@ public class DataNetworkController extends Handler {
     */
    private boolean shouldCheckRegistrationState() {
        // Always don't check registration state on non-DDS sub.
        log("shouldCheckRegistrationState: phoneSwitcher=" + PhoneSwitcher.getInstance());
        if (mPhone.getPhoneId() != PhoneSwitcher.getInstance().getPreferredDataPhoneId()) {
            return false;
        }
@@ -1148,6 +1147,16 @@ public class DataNetworkController extends Handler {
        return true;
    }

    /**
     * @return {@code true} if the network only allows single data network at one time.
     */
    private boolean isOnlySingleDataNetworkAllowed(@TransportType int transport) {
        if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) return false;

        return mDataConfigManager.getNetworkTypesOnlySupportSingleDataNetwork()
                .contains(getDataNetworkType(transport));
    }

    /**
     * Evaluate a network request. The goal is to find a suitable {@link DataProfile} that can be
     * used to setup the data network.
@@ -1255,6 +1264,12 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
        }

        // Check if only one data network is allowed.
        if (isOnlySingleDataNetworkAllowed(transport) && !mDataNetworkList.isEmpty()) {
            evaluation.addDataDisallowedReason(
                    DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
        }

        if (!mDataSettingsManager.isDataEnabled(DataUtils.networkCapabilityToApnType(
                networkRequest.getApnTypeNetworkCapability()))) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
@@ -1432,6 +1447,24 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
        }

        // Check if there are other network that has higher priority, and only single data network
        // is allowed.
        if (isOnlySingleDataNetworkAllowed(dataNetwork.getTransport())) {
            // If there is network request that has higher priority than this data network, then
            // tear down the network, regardless that network request is satisfied or not.
            if (mAllNetworkRequestList.stream()
                    .filter(request -> dataNetwork.getTransport()
                            == mAccessNetworksManager.getPreferredTransportByNetworkCapability(
                                    request.getApnTypeNetworkCapability()))
                    .anyMatch(request -> request.getPriority() > dataNetwork.getPriority())) {
                evaluation.addDataDisallowedReason(
                        DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
            } else {
                log("evaluateDataNetwork: " + dataNetwork + " has the highest priority. "
                        + "No need to tear down");
            }
        }

        // Check if data is disabled
        boolean dataDisabled = false;
        if (!mDataSettingsManager.isDataEnabled()) {
@@ -1655,6 +1688,8 @@ public class DataNetworkController extends Handler {
                    return DataNetwork.TEAR_DOWN_REASON_ILLEGAL_STATE;
                case VOPS_NOT_SUPPORTED:
                    return DataNetwork.TEAR_DOWN_REASON_VOPS_NOT_SUPPORTED;
                case ONLY_ALLOWED_SINGLE_NETWORK:
                    return DataNetwork.TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK;
            }
        }
        return 0;
+107 −5
Original line number Diff line number Diff line
@@ -141,8 +141,11 @@ public class DataNetworkControllerTest extends TelephonyTest {
                    .setProtocol(ApnSetting.PROTOCOL_IPV6)
                    .setRoamingProtocol(ApnSetting.PROTOCOL_IP)
                    .setCarrierEnabled(true)
                    .setNetworkTypeBitmask((int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE)
                    .setNetworkTypeBitmask((int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN
                            | TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT))
                    .setLingeringNetworkTypeBitmask((int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT
                            | TelephonyManager.NETWORK_TYPE_BITMASK_UMTS
                            | TelephonyManager.NETWORK_TYPE_BITMASK_NR))
                    .setProfileId(1234)
@@ -165,8 +168,10 @@ public class DataNetworkControllerTest extends TelephonyTest {
                    .setProtocol(ApnSetting.PROTOCOL_IPV6)
                    .setRoamingProtocol(ApnSetting.PROTOCOL_IP)
                    .setCarrierEnabled(true)
                    .setNetworkTypeBitmask((int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE)
                    .setNetworkTypeBitmask((int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN))
                    .setLingeringNetworkTypeBitmask((int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN
                            | TelephonyManager.NETWORK_TYPE_BITMASK_UMTS
                            | TelephonyManager.NETWORK_TYPE_BITMASK_NR))
                    .setProfileId(1235)
@@ -180,6 +185,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    private final DataProfile mEmergencyDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
                    .setEntryName("DEFAULT EIMS")
                    .setId(2165)
                    .setProtocol(ApnSetting.PROTOCOL_IPV4V6)
                    .setRoamingProtocol(ApnSetting.PROTOCOL_IPV4V6)
                    .setApnName("sos")
@@ -189,6 +195,51 @@ public class DataNetworkControllerTest extends TelephonyTest {
                    .build())
            .build();

    private final DataProfile mFotaDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
                    .setId(2166)
                    .setOperatorNumeric("12345")
                    .setEntryName("fota_apn")
                    .setApnName("fota_apn")
                    .setUser("user")
                    .setPassword("passwd")
                    .setApnTypeBitmask(ApnSetting.TYPE_FOTA)
                    .setProtocol(ApnSetting.PROTOCOL_IPV6)
                    .setRoamingProtocol(ApnSetting.PROTOCOL_IP)
                    .setCarrierEnabled(true)
                    .setNetworkTypeBitmask((int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | (int) TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT)
                    .setProfileId(1236)
                    .setMaxConns(321)
                    .setWaitTime(456)
                    .setMaxConnsTime(789)
                    .build())
            .setPreferred(false)
            .build();

    private final DataProfile mTetheringDataProfile = new DataProfile.Builder()
            .setApnSetting(new ApnSetting.Builder()
                    .setId(2167)
                    .setOperatorNumeric("12345")
                    .setEntryName("dun_apn")
                    .setApnName("dun_apn")
                    .setUser("user")
                    .setPassword("passwd")
                    .setApnTypeBitmask(ApnSetting.TYPE_DUN)
                    .setProtocol(ApnSetting.PROTOCOL_IPV6)
                    .setRoamingProtocol(ApnSetting.PROTOCOL_IP)
                    .setCarrierEnabled(true)
                    .setNetworkTypeBitmask((int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE
                            | (int) TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT)
                    .setProfileId(1236)
                    .setMaxConns(321)
                    .setWaitTime(456)
                    .setMaxConnsTime(789)
                    .build())
            .setPreferred(false)
            .build();


    /** Data call response map. The first key is the transport type, the second key is the cid. */
    private final Map<Integer, Map<Integer, DataCallResponse>> mDataCallResponses = new HashMap<>();

@@ -366,6 +417,11 @@ public class DataNetworkControllerTest extends TelephonyTest {
        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_NETWORK_TEMP_NOT_METERED_SUPPORTED_BOOL,
                true);

        mCarrierConfig.putIntArray(CarrierConfigManager.KEY_ONLY_SINGLE_DC_ALLOWED_INT_ARRAY,
                new int[] {TelephonyManager.NETWORK_TYPE_CDMA, TelephonyManager.NETWORK_TYPE_1xRTT,
                        TelephonyManager.NETWORK_TYPE_EVDO_0, TelephonyManager.NETWORK_TYPE_EVDO_A,
                        TelephonyManager.NETWORK_TYPE_EVDO_B});

        mContextFixture.putResource(com.android.internal.R.string.config_bandwidthEstimateSource,
                "bandwidth_estimator");
    }
@@ -444,14 +500,19 @@ public class DataNetworkControllerTest extends TelephonyTest {
        doAnswer(invocation -> {
            TelephonyNetworkRequest networkRequest =
                    (TelephonyNetworkRequest) invocation.getArguments()[0];
            int networkType = (int) invocation.getArguments()[1];
            List<DataProfile> profiles = List.of(mGeneralPurposeDataProfile, mImsDataProfile,
                    mEmergencyDataProfile);
                    mEmergencyDataProfile, mFotaDataProfile, mTetheringDataProfile);
            for (DataProfile dataProfile : profiles) {
                if (dataProfile.canSatisfy(networkRequest.getCapabilities())) {
                if (dataProfile.canSatisfy(networkRequest.getCapabilities())
                        && (dataProfile.getApnSetting().getNetworkTypeBitmask() == 0
                        || (dataProfile.getApnSetting().getNetworkTypeBitmask()
                        & ServiceState.getBitmaskForTech(networkType)) != 0)) {
                    return dataProfile;
                }
            }
            logd("Cannot find data profile to satisfy " + networkRequest);
            logd("Cannot find data profile to satisfy " + networkRequest + ", network type="
                    + TelephonyManager.getNetworkTypeName(networkType));
            return null;
        }).when(mDataProfileManager).getDataProfileForNetworkRequest(
                any(TelephonyNetworkRequest.class), anyInt());
@@ -1720,4 +1781,45 @@ public class DataNetworkControllerTest extends TelephonyTest {
                // network should still be not-restricted.
                NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
    }

    @Test
    public void testSinglePdnArbitration() throws Exception {
        // On old 1x network, only one data network is allowed.
        serviceStateChanged(TelephonyManager.NETWORK_TYPE_1xRTT,
                NetworkRegistrationInfo.REGISTRATION_STATE_HOME);

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_DUN));
        processAllMessages();
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN);

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET));
        processAllFutureMessages();
        // Lower priority network should not trump the higher priority network.
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN);
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);

        // Now send a higher priority network request
        TelephonyNetworkRequest fotaRequest = createNetworkRequest(
                NetworkCapabilities.NET_CAPABILITY_FOTA);
        mDataNetworkControllerUT.addNetworkRequest(fotaRequest);
        processAllFutureMessages();
        // The existing internet data network should be torn down.
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_DUN);
        // The higher priority emergency data network should be established.
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_FOTA);

        // Now remove the fota request and tear down fota network.
        mDataNetworkControllerUT.removeNetworkRequest(fotaRequest);
        processAllMessages();
        List<DataNetwork> dataNetworks = getDataNetworks();
        dataNetworks.get(0).tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
        processAllMessages();

        // The tethering data network should come back since now it has the highest priority after
        // fota is gone.
        verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN);
        verifyNoConnectedNetworkHasCapability(NetworkCapabilities.NET_CAPABILITY_FOTA);
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -487,6 +487,18 @@ public class DataProfileManagerTest extends TelephonyTest {
        assertThat(dp.getApnSetting().getApnName()).isEqualTo(TETHERING_APN);
    }

    @Test
    public void testGetDataProfileForNetworkRequestNoCompatibleRat() {
        NetworkRequest request = new NetworkRequest.Builder()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build();
        TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone);
        DataProfile dp = mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr,
                TelephonyManager.NETWORK_TYPE_GSM);
        // Should not find data profile due to RAT incompatible.
        assertThat(dp).isNull();
    }

    @Test
    public void testGetDataProfileForNetworkRequestRotation() {
        TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(