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

Commit 634b94b4 authored by Ling Ma's avatar Ling Ma
Browse files

Check default APN type before set preferred profile

Without the change, a DUN | DEFAULT data profile will be updated to be the default if it's the only connected internet network at the time even though a preferred data profile exists. This happens when single connection rule is in place. To prevent setting DUN | DEFAULT profiles as the preferred when there exists a clean DEFAULT profile, this change assumes an existing preferred profile, if any, has the right APN types, and thus future preferred profile candidates should resemble.

Fix: 287171389
Test: basic testing +  reviewed log + verified by reporter
Change-Id: I3d69485ee9343d5968dff5a3ec64f4d74bc88d98
parent ead02acc
Loading
Loading
Loading
Loading
+15 −17
Original line number Diff line number Diff line
@@ -410,23 +410,18 @@ public class DataProfileManager extends Handler {
     * @param internetNetworks The connected internet data networks.
     */
    private void onInternetDataNetworkConnected(@NonNull List<DataNetwork> internetNetworks) {
        DataProfile defaultProfile = null;
        if (internetNetworks.size() == 1) {
        // Most of the cases there should be only one.
            defaultProfile = internetNetworks.get(0).getDataProfile();
        } else if (internetNetworks.size() > 1) {
        // but in case there are multiple, find the default internet network, and choose the
        // one which has longest life cycle.
            logv("onInternetDataNetworkConnected: mPreferredDataProfile=" + mPreferredDataProfile
                    + " internetNetworks=" + internetNetworks);
            defaultProfile = internetNetworks.stream()
        DataProfile defaultProfile = internetNetworks.stream()
                .filter(network -> mPreferredDataProfile == null
                        // Find the one most resembles the current preferred profile,
                        // avoiding e.g. DUN default network.
                        || canPreferredDataProfileSatisfy(
                        network.getAttachedNetworkRequestList()))
                .map(DataNetwork::getDataProfile)
                .min(Comparator.comparingLong(DataProfile::getLastSetupTimestamp))
                .orElse(null);
        }

        // Update a working internet data profile as a future candidate for preferred data profile
        // after APNs are reset to default
@@ -436,6 +431,9 @@ public class DataProfileManager extends Handler {
        // brought up a network means it passed sophisticated checks, update the preferred data
        // profile so that this network won't be torn down in future network evaluations.
        if (defaultProfile == null || defaultProfile.equals(mPreferredDataProfile)) return;
        logv("onInternetDataNetworkConnected: defaultProfile=" + defaultProfile
                + " previous preferredDataProfile=" + mPreferredDataProfile
                + " internetNetworks=" + internetNetworks);
        // Save the preferred data profile into database.
        setPreferredDataProfile(defaultProfile);
        updateDataProfiles(false/*force update IA*/);
+20 −11
Original line number Diff line number Diff line
@@ -841,20 +841,27 @@ public class DataProfileManagerTest extends TelephonyTest {

        assertThat(mDataProfileManagerUT.isDataProfilePreferred(legacyRatDataProfile)).isTrue();

        // Test Another supl default internet network temporarily connected. Verify preferred
        // doesn't change.
        TelephonyNetworkRequest suplTnr = new TelephonyNetworkRequest(
        // Test Another dun default internet network temporarily connected. Verify preferred
        // doesn't change. Mock DUN | DEFAULT.
        TelephonyNetworkRequest dunTnr = new TelephonyNetworkRequest(
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_SUPL)
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_DUN)
                        .build(), mPhone);
        DataProfile suplDataProfile = mDataProfileManagerUT.getDataProfileForNetworkRequest(
                suplTnr, TelephonyManager.NETWORK_TYPE_LTE, false);
        DataNetwork suplInternetNetwork = Mockito.mock(DataNetwork.class);
        doReturn(suplDataProfile).when(suplInternetNetwork).getDataProfile();
        doReturn(new DataNetworkController.NetworkRequestList(List.of(suplTnr)))
                .when(suplInternetNetwork).getAttachedNetworkRequestList();
        DataProfile dunDataProfile = mDataProfileManagerUT.getDataProfileForNetworkRequest(
                dunTnr, TelephonyManager.NETWORK_TYPE_LTE, false);
        DataNetwork dunInternetNetwork = Mockito.mock(DataNetwork.class);
        doReturn(dunDataProfile).when(dunInternetNetwork).getDataProfile();
        doReturn(new DataNetworkController.NetworkRequestList(List.of(dunTnr)))
                .when(dunInternetNetwork).getAttachedNetworkRequestList();
        mDataNetworkControllerCallback.onInternetDataNetworkConnected(List.of(
                legacyRatInternetNetwork, suplInternetNetwork));
                legacyRatInternetNetwork, dunInternetNetwork));
        processAllMessages();

        assertThat(mDataProfileManagerUT.isDataProfilePreferred(legacyRatDataProfile)).isTrue();

        // Test a single dun default internet network temporarily connected. Verify preferred
        // doesn't change. Mock DUN | DEFAULT and enforced single connection.
        mDataNetworkControllerCallback.onInternetDataNetworkConnected(List.of(dunInternetNetwork));
        processAllMessages();

        assertThat(mDataProfileManagerUT.isDataProfilePreferred(legacyRatDataProfile)).isTrue();
@@ -1203,6 +1210,8 @@ public class DataProfileManagerTest extends TelephonyTest {
        dataProfile.setLastSetupTimestamp(SystemClock.elapsedRealtime());
        DataNetwork internetNetwork = Mockito.mock(DataNetwork.class);
        doReturn(dataProfile).when(internetNetwork).getDataProfile();
        doReturn(new DataNetworkController.NetworkRequestList(List.of(tnr)))
                .when(internetNetwork).getAttachedNetworkRequestList();
        mDataNetworkControllerCallback.onInternetDataNetworkConnected(List.of(internetNetwork));
        processAllMessages();