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

Commit 829633b4 authored by Jack Yu's avatar Jack Yu
Browse files

Disable tethering profile when roaming

Some carriers require not using tethering APN when the device
is roaming. By returning false for TelephonyManager.isTetheringApnRequired(),
tethering service will automatically use the default network, which
supports internet, for tethering purposes.

Fix: 233002812
Test: atest DataProfileManagerTest + Basic testing
Merged-In: I175ee6616be0c0528c66f96934a4f2863761729c
Change-Id: I175ee6616be0c0528c66f96934a4f2863761729c
parent df7f98fc
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -582,6 +582,14 @@ public class DataConfigManager extends Handler {
                .collect(Collectors.toUnmodifiableSet());
                .collect(Collectors.toUnmodifiableSet());
    }
    }


    /**
     * @return {@code true} if tethering profile should not be used when the device is roaming.
     */
    public boolean isTetheringProfileDisabledForRoaming() {
        return mCarrierConfig.getBoolean(
                CarrierConfigManager.KEY_DISABLE_DUN_APN_WHILE_ROAMING_WITH_PRESET_APN_BOOL);
    }

    /**
    /**
     * Check if the network capability metered.
     * Check if the network capability metered.
     *
     *
@@ -1254,6 +1262,8 @@ public class DataConfigManager extends Handler {
                com.android.internal.R.string.config_bandwidthEstimateSource));
                com.android.internal.R.string.config_bandwidthEstimateSource));
        pw.println("isDelayTearDownImsEnabled=" + isImsDelayTearDownEnabled());
        pw.println("isDelayTearDownImsEnabled=" + isImsDelayTearDownEnabled());
        pw.println("isEnhancedIwlanHandoverCheckEnabled=" + isEnhancedIwlanHandoverCheckEnabled());
        pw.println("isEnhancedIwlanHandoverCheckEnabled=" + isEnhancedIwlanHandoverCheckEnabled());
        pw.println("isTetheringProfileDisabledForRoaming="
                + isTetheringProfileDisabledForRoaming());
        pw.decreaseIndent();
        pw.decreaseIndent();
    }
    }
}
}
+11 −2
Original line number Original line Diff line number Diff line
@@ -688,14 +688,21 @@ public class DataProfileManager extends Handler {
     * Check if there is tethering data profile for certain network type.
     * Check if there is tethering data profile for certain network type.
     *
     *
     * @param networkType The network type
     * @param networkType The network type
     * @return {@code true} if tethering data profile is found.
     * @return {@code true} if tethering data profile is found. {@code false} if no specific profile
     * should used for tethering. In this case, tethering service will use internet network for
     * tethering.
     */
     */
    public boolean isTetheringDataProfileExisting(@NetworkType int networkType) {
    public boolean isTetheringDataProfileExisting(@NetworkType int networkType) {
        if (mDataConfigManager.isTetheringProfileDisabledForRoaming()
                && mPhone.getServiceState().getDataRoaming()) {
            // Use internet network for tethering.
            return false;
        }
        TelephonyNetworkRequest networkRequest = new TelephonyNetworkRequest(
        TelephonyNetworkRequest networkRequest = new TelephonyNetworkRequest(
                new NetworkRequest.Builder()
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_DUN)
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_DUN)
                        .build(), mPhone);
                        .build(), mPhone);
        return null != getDataProfileForNetworkRequest(networkRequest, networkType);
        return getDataProfileForNetworkRequest(networkRequest, networkType) != null;
    }
    }


     /**
     /**
@@ -934,6 +941,8 @@ public class DataProfileManager extends Handler {
        pw.println("Preferred data profile from config=" + getPreferredDataProfileFromConfig());
        pw.println("Preferred data profile from config=" + getPreferredDataProfileFromConfig());
        pw.println("Preferred data profile set id=" + mPreferredDataProfileSetId);
        pw.println("Preferred data profile set id=" + mPreferredDataProfileSetId);
        pw.println("Initial attach data profile=" + mInitialAttachDataProfile);
        pw.println("Initial attach data profile=" + mInitialAttachDataProfile);
        pw.println("isTetheringDataProfileExisting=" + isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_LTE));


        pw.println("Local logs:");
        pw.println("Local logs:");
        pw.increaseIndent();
        pw.increaseIndent();
+34 −0
Original line number Original line Diff line number Diff line
@@ -36,7 +36,9 @@ import android.net.Uri;
import android.os.Looper;
import android.os.Looper;
import android.os.SystemClock;
import android.os.SystemClock;
import android.provider.Telephony;
import android.provider.Telephony;
import android.telephony.AccessNetworkConstants;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataProfile;
import android.telephony.data.DataProfile;
@@ -860,4 +862,36 @@ public class DataProfileManagerTest extends TelephonyTest {
        assertThat(mDataProfileManagerUT.isAnyPreferredDataProfileExisting()).isFalse();
        assertThat(mDataProfileManagerUT.isAnyPreferredDataProfileExisting()).isFalse();
        assertThat(mDataProfileManagerUT.isDataProfilePreferred(dataProfile)).isFalse();
        assertThat(mDataProfileManagerUT.isDataProfilePreferred(dataProfile)).isFalse();
    }
    }

    @Test
    public void testTetheringApnExisting() {
        assertThat(mDataProfileManagerUT.isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_NR)).isTrue();
        assertThat(mDataProfileManagerUT.isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_LTE)).isFalse();
    }

    @Test
    public void testTetheringApnDisabledForRoaming() {
        doReturn(true).when(mDataConfigManager).isTetheringProfileDisabledForRoaming();

        assertThat(mDataProfileManagerUT.isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_NR)).isTrue();

        ServiceState ss = new ServiceState();

        ss.addNetworkRegistrationInfo(new NetworkRegistrationInfo.Builder()
                .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_NR)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING)
                .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
                .build());

        ss.setDataRoamingFromRegistration(true);
        doReturn(ss).when(mSST).getServiceState();
        doReturn(ss).when(mPhone).getServiceState();

        assertThat(mDataProfileManagerUT.isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_NR)).isFalse();
    }
}
}