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

Commit 51572757 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "Disable tethering profile when roaming" into tm-dev

parents 3497e7d7 ddf661ee
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -536,6 +536,14 @@ public class DataConfigManager extends Handler {
                .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.
     *
@@ -1226,6 +1234,8 @@ public class DataConfigManager extends Handler {
                com.android.internal.R.string.config_bandwidthEstimateSource));
        pw.println("isDelayTearDownImsEnabled=" + isImsDelayTearDownEnabled());
        pw.println("isEnhancedIwlanHandoverCheckEnabled=" + isEnhancedIwlanHandoverCheckEnabled());
        pw.println("isTetheringProfileDisabledForRoaming="
                + isTetheringProfileDisabledForRoaming());
        pw.decreaseIndent();
    }
}
+11 −2
Original line number 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.
     *
     * @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) {
        if (mDataConfigManager.isTetheringProfileDisabledForRoaming()
                && mPhone.getServiceState().getDataRoaming()) {
            // Use internet network for tethering.
            return false;
        }
        TelephonyNetworkRequest networkRequest = new TelephonyNetworkRequest(
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_DUN)
                        .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 set id=" + mPreferredDataProfileSetId);
        pw.println("Initial attach data profile=" + mInitialAttachDataProfile);
        pw.println("isTetheringDataProfileExisting=" + isTetheringDataProfileExisting(
                TelephonyManager.NETWORK_TYPE_LTE));

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