Loading src/java/com/android/internal/telephony/data/DataNetwork.java +11 −0 Original line number Diff line number Diff line Loading @@ -3207,6 +3207,17 @@ public class DataNetwork extends StateMachine { return mVcnManager.applyVcnNetworkPolicy(networkCapabilities, getLinkProperties()); } /** * Check if any of the attached request has the specified network capability. * * @param netCapability The network capability to check. * @return {@code true} if at least one network request has specified network capability. */ public boolean hasNetworkCapabilityInNetworkRequests(@NetCapability int netCapability) { return mAttachedNetworkRequestList.stream().anyMatch( request -> request.hasCapability(netCapability)); } /** * Convert the data tear down reason to string. * Loading src/java/com/android/internal/telephony/data/DataNetworkController.java +9 −4 Original line number Diff line number Diff line Loading @@ -1511,8 +1511,10 @@ public class DataNetworkController extends Handler { // Check if it's SUPL during emergency call. evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL); } else if (!networkRequest.hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) { // Check if request is restricted. NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !networkRequest .hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) { // Check if request is restricted and not for tethering, which always comes with // a restricted network request. evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST); } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { // Check if request is unmetered (WiFi or unmetered APN). Loading Loading @@ -1753,8 +1755,11 @@ public class DataNetworkController extends Handler { // Check if it's SUPL during emergency call. evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL); } else if (!dataNetwork.getNetworkCapabilities().hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) { // Check if request is restricted NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !dataNetwork.hasNetworkCapabilityInNetworkRequests( NetworkCapabilities.NET_CAPABILITY_DUN)) { // Check if request is restricted and there are no DUN network requests attached to // the network. evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST); } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { // Check if request is unmetered (WiFi or unmetered APN) Loading tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +58 −0 Original line number Diff line number Diff line Loading @@ -2351,6 +2351,64 @@ public class DataNetworkControllerTest extends TelephonyTest { assertThat(dataNetworkList.get(0).isConnected()).isTrue(); } @Test public void testDataDisableTearingDownTetheringNetwork() throws Exception { // User data enabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, true, mContext.getOpPackageName()); processAllMessages(); // Request the restricted tethering network. NetworkCapabilities netCaps = new NetworkCapabilities(); netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN); netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); NetworkRequest nativeNetworkRequest = new NetworkRequest(netCaps, ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId, NetworkRequest.Type.REQUEST); mDataNetworkControllerUT.addNetworkRequest( new TelephonyNetworkRequest(nativeNetworkRequest, mPhone)); processAllMessages(); verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN); // User data disabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName()); processAllMessages(); // Everything should be disconnected. verifyAllDataDisconnected(); } @Test public void testDataDisableNotAllowingBringingUpTetheringNetwork() throws Exception { // User data disabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName()); processAllMessages(); // Request the restricted tethering network. NetworkCapabilities netCaps = new NetworkCapabilities(); netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN); netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); NetworkRequest nativeNetworkRequest = new NetworkRequest(netCaps, ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId, NetworkRequest.Type.REQUEST); mDataNetworkControllerUT.addNetworkRequest( new TelephonyNetworkRequest(nativeNetworkRequest, mPhone)); processAllMessages(); // Everything should be disconnected. verifyAllDataDisconnected(); // Telephony should not try to setup a data call for DUN. verify(mMockedWwanDataServiceManager, never()).setupDataCall(anyInt(), any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(), anyInt(), any(), any(), anyBoolean(), any(Message.class)); } @Test public void testNonVoPSNoIMSSetup() throws Exception { DataSpecificRegistrationInfo dsri = new DataSpecificRegistrationInfo(8, false, true, true, Loading Loading
src/java/com/android/internal/telephony/data/DataNetwork.java +11 −0 Original line number Diff line number Diff line Loading @@ -3207,6 +3207,17 @@ public class DataNetwork extends StateMachine { return mVcnManager.applyVcnNetworkPolicy(networkCapabilities, getLinkProperties()); } /** * Check if any of the attached request has the specified network capability. * * @param netCapability The network capability to check. * @return {@code true} if at least one network request has specified network capability. */ public boolean hasNetworkCapabilityInNetworkRequests(@NetCapability int netCapability) { return mAttachedNetworkRequestList.stream().anyMatch( request -> request.hasCapability(netCapability)); } /** * Convert the data tear down reason to string. * Loading
src/java/com/android/internal/telephony/data/DataNetworkController.java +9 −4 Original line number Diff line number Diff line Loading @@ -1511,8 +1511,10 @@ public class DataNetworkController extends Handler { // Check if it's SUPL during emergency call. evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL); } else if (!networkRequest.hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) { // Check if request is restricted. NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !networkRequest .hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) { // Check if request is restricted and not for tethering, which always comes with // a restricted network request. evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST); } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { // Check if request is unmetered (WiFi or unmetered APN). Loading Loading @@ -1753,8 +1755,11 @@ public class DataNetworkController extends Handler { // Check if it's SUPL during emergency call. evaluation.addDataAllowedReason(DataAllowedReason.EMERGENCY_SUPL); } else if (!dataNetwork.getNetworkCapabilities().hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) { // Check if request is restricted NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) && !dataNetwork.hasNetworkCapabilityInNetworkRequests( NetworkCapabilities.NET_CAPABILITY_DUN)) { // Check if request is restricted and there are no DUN network requests attached to // the network. evaluation.addDataAllowedReason(DataAllowedReason.RESTRICTED_REQUEST); } else if (dataNetwork.getTransport() == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { // Check if request is unmetered (WiFi or unmetered APN) Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +58 −0 Original line number Diff line number Diff line Loading @@ -2351,6 +2351,64 @@ public class DataNetworkControllerTest extends TelephonyTest { assertThat(dataNetworkList.get(0).isConnected()).isTrue(); } @Test public void testDataDisableTearingDownTetheringNetwork() throws Exception { // User data enabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, true, mContext.getOpPackageName()); processAllMessages(); // Request the restricted tethering network. NetworkCapabilities netCaps = new NetworkCapabilities(); netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN); netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); NetworkRequest nativeNetworkRequest = new NetworkRequest(netCaps, ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId, NetworkRequest.Type.REQUEST); mDataNetworkControllerUT.addNetworkRequest( new TelephonyNetworkRequest(nativeNetworkRequest, mPhone)); processAllMessages(); verifyConnectedNetworkHasCapabilities(NetworkCapabilities.NET_CAPABILITY_DUN); // User data disabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName()); processAllMessages(); // Everything should be disconnected. verifyAllDataDisconnected(); } @Test public void testDataDisableNotAllowingBringingUpTetheringNetwork() throws Exception { // User data disabled mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName()); processAllMessages(); // Request the restricted tethering network. NetworkCapabilities netCaps = new NetworkCapabilities(); netCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN); netCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED); NetworkRequest nativeNetworkRequest = new NetworkRequest(netCaps, ConnectivityManager.TYPE_MOBILE, ++mNetworkRequestId, NetworkRequest.Type.REQUEST); mDataNetworkControllerUT.addNetworkRequest( new TelephonyNetworkRequest(nativeNetworkRequest, mPhone)); processAllMessages(); // Everything should be disconnected. verifyAllDataDisconnected(); // Telephony should not try to setup a data call for DUN. verify(mMockedWwanDataServiceManager, never()).setupDataCall(anyInt(), any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(), anyInt(), any(), any(), anyBoolean(), any(Message.class)); } @Test public void testNonVoPSNoIMSSetup() throws Exception { DataSpecificRegistrationInfo dsri = new DataSpecificRegistrationInfo(8, false, true, true, Loading