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

Commit 6426e5d6 authored by Jack Yu's avatar Jack Yu
Browse files

Stick with preferred data profile

If preferred data profile is already available, we should always
use it even though it's permanently failed. Selecting other data
profile should only happen when no preferred data profile has
been set yet, or when preferred data profile cannot satisfy the
network request with current network type.

Test: Verified on Docomo + Basic device testing
      + atest DataProfileManagerTest
Bug: 259280093

Change-Id: I9b8ae99c3fa6846a4d5648f4383f22402dc5118b
parent 5138c5ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3131,7 +3131,7 @@ public class DataNetwork extends StateMachine {
                && !mAttachedNetworkRequestList.isEmpty()) {
            TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0);
            DataProfile dataProfile = mDataNetworkController.getDataProfileManager()
                    .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, true);
                    .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, false);
            // 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
+18 −6
Original line number Diff line number Diff line
@@ -704,15 +704,28 @@ public class DataProfileManager extends Handler {
            return null;
        }

        // If the preferred data profile can be used, always use it if it can satisfy the network
        // request with current network type (even though it's been marked as permanent failed.)
        if (mPreferredDataProfile != null
                && networkRequest.canBeSatisfiedBy(mPreferredDataProfile)
                && mPreferredDataProfile.getApnSetting() != null
                && mPreferredDataProfile.getApnSetting().canSupportNetworkType(networkType)) {
            if (ignorePermanentFailure || !mPreferredDataProfile.getApnSetting()
                    .getPermanentFailed()) {
                return mPreferredDataProfile.getApnSetting();
            }
            log("The preferred data profile is permanently failed. Only condition based retry "
                    + "can happen.");
            return null;
        }

        // Filter out the data profile that can't satisfy the request.
        // Preferred data profile should be returned in the top of the list.
        List<DataProfile> dataProfiles = mAllDataProfiles.stream()
                .filter(networkRequest::canBeSatisfiedBy)
                // Put the preferred data profile at the top of the list, then the longest time
                // hasn't used data profile will be in the front so all the data profiles can be
                // tried.
                .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile))
                        .thenComparingLong(DataProfile::getLastSetupTimestamp))
                // The longest time hasn't used data profile will be in the front so all the data
                // profiles can be tried.
                .sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp))
                .collect(Collectors.toList());
        for (DataProfile dataProfile : dataProfiles) {
            logv("Satisfied profile: " + dataProfile + ", last setup="
@@ -740,7 +753,6 @@ public class DataProfileManager extends Handler {
                        && (dp.getApnSetting().getApnSetId()
                        == Telephony.Carriers.MATCH_ALL_APN_SET_ID
                        || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId))
                .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed())
                .collect(Collectors.toList());
        if (dataProfiles.size() == 0) {
            log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId="
+43 −0
Original line number Diff line number Diff line
@@ -1401,4 +1401,47 @@ public class DataProfileManagerTest extends TelephonyTest {

        assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile3)).isTrue();
    }

    @Test
    public void testPermanentFailureWithNoPreferredDataProfile() {
        // No preferred APN is set

        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_LTE, false);

        // Mark the APN as permanent failed.
        dp.getApnSetting().setPermanentFailed(true);

        // Data profile manager should return a different data profile for setup as the previous
        // data profile has been marked as permanent failed.
        assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr,
                TelephonyManager.NETWORK_TYPE_LTE, false)).isNotEqualTo(dp);
    }

    @Test
    public void testPermanentFailureWithPreferredDataProfile() {
        // Set the preferred APN
        mApnSettingContentProvider.setPreferredApn(GENERAL_PURPOSE_APN);
        mDataProfileManagerUT.obtainMessage(2 /* EVENT_APN_DATABASE_CHANGED */).sendToTarget();
        processAllMessages();

        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_LTE, false);

        // Mark the APN as permanent failed.
        dp.getApnSetting().setPermanentFailed(true);

        // Since preferred APN is already set, and that data profile was marked as permanent failed,
        // so this should result in getting nothing.
        assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr,
                TelephonyManager.NETWORK_TYPE_LTE, false)).isNull();
    }
}