Loading src/java/com/android/internal/telephony/dataconnection/DcTracker.java +12 −7 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.telephony.TelephonyManager.NETWORK_TYPE_LTE; import static android.telephony.TelephonyManager.NETWORK_TYPE_NR; import static android.telephony.TelephonyManager.NETWORK_TYPE_NR; import static android.telephony.data.ApnSetting.PROTOCOL_IPV4V6; import static android.telephony.data.ApnSetting.PROTOCOL_IPV4V6; import static android.telephony.data.ApnSetting.TYPE_DEFAULT; import static android.telephony.data.ApnSetting.TYPE_DEFAULT; import static android.telephony.data.ApnSetting.TYPE_IA; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_DEFAULT; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_DEFAULT; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_INVALID; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_INVALID; Loading Loading @@ -1250,6 +1251,11 @@ public class DcTracker extends Handler { DataConnectionReasons reasons = new DataConnectionReasons(); DataConnectionReasons reasons = new DataConnectionReasons(); int requestApnType = 0; if (apnContext != null) { requestApnType = apnContext.getApnTypeBitmask(); } // Step 1: Get all environment conditions. // Step 1: Get all environment conditions. final boolean internalDataEnabled = mDataEnabledSettings.isInternalDataEnabled(); final boolean internalDataEnabled = mDataEnabledSettings.isInternalDataEnabled(); boolean attachedState = mAttached.get(); boolean attachedState = mAttached.get(); Loading @@ -1266,8 +1272,7 @@ public class DcTracker extends Handler { SubscriptionManager.getDefaultDataSubscriptionId()); SubscriptionManager.getDefaultDataSubscriptionId()); boolean isMeteredApnType = apnContext == null boolean isMeteredApnType = apnContext == null || ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypesBitmaskFromString( || ApnSettingUtils.isMeteredApnType(requestApnType, mPhone); apnContext.getApnType()) , mPhone); PhoneConstants.State phoneState = PhoneConstants.State.IDLE; PhoneConstants.State phoneState = PhoneConstants.State.IDLE; // Note this is explicitly not using mPhone.getState. See b/19090488. // Note this is explicitly not using mPhone.getState. See b/19090488. Loading @@ -1283,7 +1288,7 @@ public class DcTracker extends Handler { // Step 2: Special handling for emergency APN. // Step 2: Special handling for emergency APN. if (apnContext != null if (apnContext != null && apnContext.getApnType().equals(PhoneConstants.APN_TYPE_EMERGENCY) && requestApnType == ApnSetting.TYPE_EMERGENCY && apnContext.isConnectable()) { && apnContext.isConnectable()) { // If this is an emergency APN, as long as the APN is connectable, we // If this is an emergency APN, as long as the APN is connectable, we // should allow it. // should allow it. Loading @@ -1301,8 +1306,8 @@ public class DcTracker extends Handler { // In legacy mode, if RAT is IWLAN then don't allow default/IA PDP at all. // In legacy mode, if RAT is IWLAN then don't allow default/IA PDP at all. // Rest of APN types can be evaluated for remaining conditions. // Rest of APN types can be evaluated for remaining conditions. if ((apnContext != null && (apnContext.getApnType().equals(PhoneConstants.APN_TYPE_DEFAULT) if ((apnContext != null && requestApnType == TYPE_DEFAULT || apnContext.getApnType().equals(PhoneConstants.APN_TYPE_IA))) || requestApnType == TYPE_IA) && mPhone.getTransportManager().isInLegacyMode() && mPhone.getTransportManager().isInLegacyMode() && dataRat == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { && dataRat == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { reasons.add(DataDisallowedReasonType.ON_IWLAN); reasons.add(DataDisallowedReasonType.ON_IWLAN); Loading Loading @@ -1353,7 +1358,7 @@ public class DcTracker extends Handler { } } boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() : mDataEnabledSettings.isDataEnabled(apnContext.getApnTypeBitmask()); : mDataEnabledSettings.isDataEnabled(requestApnType); if (!isDataEnabled) { if (!isDataEnabled) { reasons.add(DataDisallowedReasonType.DATA_DISABLED); reasons.add(DataDisallowedReasonType.DATA_DISABLED); Loading @@ -1378,7 +1383,7 @@ public class DcTracker extends Handler { // Or if the data is on cellular, and the APN type is determined unmetered by the // Or if the data is on cellular, and the APN type is determined unmetered by the // configuration. // configuration. } else if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WWAN } else if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WWAN && !isMeteredApnType) { && !isMeteredApnType && requestApnType != TYPE_DEFAULT) { reasons.add(DataAllowedReasonType.UNMETERED_APN); reasons.add(DataAllowedReasonType.UNMETERED_APN); } } Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +39 −2 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; Loading Loading @@ -1040,6 +1041,8 @@ public class DcTrackerTest extends TelephonyTest { private void initApns(String targetApn, String[] canHandleTypes) { private void initApns(String targetApn, String[] canHandleTypes) { doReturn(targetApn).when(mApnContext).getApnType(); doReturn(targetApn).when(mApnContext).getApnType(); doReturn(ApnSetting.getApnTypesBitmaskFromString(mApnContext.getApnType())) .when(mApnContext).getApnTypeBitmask(); doReturn(true).when(mApnContext).isConnectable(); doReturn(true).when(mApnContext).isConnectable(); ApnSetting apnSetting = createApnSetting(ApnSetting.getApnTypesBitmaskFromString( ApnSetting apnSetting = createApnSetting(ApnSetting.getApnTypesBitmaskFromString( TextUtils.join(",", canHandleTypes))); TextUtils.join(",", canHandleTypes))); Loading @@ -1056,7 +1059,8 @@ public class DcTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testTrySetupDataEmergencyApn() throws Exception { public void testTrySetupDataEmergencyApn() throws Exception { initApns(PhoneConstants.APN_TYPE_EMERGENCY, new String[]{PhoneConstants.APN_TYPE_ALL}); initApns(PhoneConstants.APN_TYPE_EMERGENCY, new String[]{PhoneConstants.APN_TYPE_EMERGENCY}); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); Loading @@ -1071,7 +1075,7 @@ public class DcTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testTrySetupDataXcapApn() throws Exception { public void testTrySetupDataXcapApn() throws Exception { initApns(PhoneConstants.APN_TYPE_XCAP, new String[]{PhoneConstants.APN_TYPE_ALL}); initApns(PhoneConstants.APN_TYPE_XCAP, new String[]{PhoneConstants.APN_TYPE_XCAP}); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); Loading Loading @@ -1145,6 +1149,39 @@ public class DcTrackerTest extends TelephonyTest { any(Message.class)); any(Message.class)); } } // Test the unmetered default APN setup when data is disabled. Default APN should always honor // the users's setting. @Test @SmallTest public void testTrySetupDataUnmeteredDefaultDataDisabled() throws Exception { initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL}); //mDct.setUserDataEnabled(false); doReturn(false).when(mDataEnabledSettings).isDataEnabled(); doReturn(false).when(mDataEnabledSettings).isDataEnabled(anyInt()); mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_MMS}); logd("Sending EVENT_CARRIER_CONFIG_CHANGED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_CARRIER_CONFIG_CHANGED, 1, 0)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); waitForMs(200); verify(mSimulatedCommandsVerifier, never()).setupDataCall( eq(AccessNetworkType.EUTRAN), any(DataProfile.class), eq(false), eq(false), eq(DataService.REQUEST_REASON_NORMAL), any(), any(Message.class)); } // Test the metered APN setup when data is disabled. // Test the metered APN setup when data is disabled. @Test @Test @SmallTest @SmallTest Loading Loading
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +12 −7 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.telephony.TelephonyManager.NETWORK_TYPE_LTE; import static android.telephony.TelephonyManager.NETWORK_TYPE_NR; import static android.telephony.TelephonyManager.NETWORK_TYPE_NR; import static android.telephony.data.ApnSetting.PROTOCOL_IPV4V6; import static android.telephony.data.ApnSetting.PROTOCOL_IPV4V6; import static android.telephony.data.ApnSetting.TYPE_DEFAULT; import static android.telephony.data.ApnSetting.TYPE_DEFAULT; import static android.telephony.data.ApnSetting.TYPE_IA; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_DEFAULT; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_DEFAULT; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_INVALID; import static com.android.internal.telephony.RILConstants.DATA_PROFILE_INVALID; Loading Loading @@ -1250,6 +1251,11 @@ public class DcTracker extends Handler { DataConnectionReasons reasons = new DataConnectionReasons(); DataConnectionReasons reasons = new DataConnectionReasons(); int requestApnType = 0; if (apnContext != null) { requestApnType = apnContext.getApnTypeBitmask(); } // Step 1: Get all environment conditions. // Step 1: Get all environment conditions. final boolean internalDataEnabled = mDataEnabledSettings.isInternalDataEnabled(); final boolean internalDataEnabled = mDataEnabledSettings.isInternalDataEnabled(); boolean attachedState = mAttached.get(); boolean attachedState = mAttached.get(); Loading @@ -1266,8 +1272,7 @@ public class DcTracker extends Handler { SubscriptionManager.getDefaultDataSubscriptionId()); SubscriptionManager.getDefaultDataSubscriptionId()); boolean isMeteredApnType = apnContext == null boolean isMeteredApnType = apnContext == null || ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypesBitmaskFromString( || ApnSettingUtils.isMeteredApnType(requestApnType, mPhone); apnContext.getApnType()) , mPhone); PhoneConstants.State phoneState = PhoneConstants.State.IDLE; PhoneConstants.State phoneState = PhoneConstants.State.IDLE; // Note this is explicitly not using mPhone.getState. See b/19090488. // Note this is explicitly not using mPhone.getState. See b/19090488. Loading @@ -1283,7 +1288,7 @@ public class DcTracker extends Handler { // Step 2: Special handling for emergency APN. // Step 2: Special handling for emergency APN. if (apnContext != null if (apnContext != null && apnContext.getApnType().equals(PhoneConstants.APN_TYPE_EMERGENCY) && requestApnType == ApnSetting.TYPE_EMERGENCY && apnContext.isConnectable()) { && apnContext.isConnectable()) { // If this is an emergency APN, as long as the APN is connectable, we // If this is an emergency APN, as long as the APN is connectable, we // should allow it. // should allow it. Loading @@ -1301,8 +1306,8 @@ public class DcTracker extends Handler { // In legacy mode, if RAT is IWLAN then don't allow default/IA PDP at all. // In legacy mode, if RAT is IWLAN then don't allow default/IA PDP at all. // Rest of APN types can be evaluated for remaining conditions. // Rest of APN types can be evaluated for remaining conditions. if ((apnContext != null && (apnContext.getApnType().equals(PhoneConstants.APN_TYPE_DEFAULT) if ((apnContext != null && requestApnType == TYPE_DEFAULT || apnContext.getApnType().equals(PhoneConstants.APN_TYPE_IA))) || requestApnType == TYPE_IA) && mPhone.getTransportManager().isInLegacyMode() && mPhone.getTransportManager().isInLegacyMode() && dataRat == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { && dataRat == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { reasons.add(DataDisallowedReasonType.ON_IWLAN); reasons.add(DataDisallowedReasonType.ON_IWLAN); Loading Loading @@ -1353,7 +1358,7 @@ public class DcTracker extends Handler { } } boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() : mDataEnabledSettings.isDataEnabled(apnContext.getApnTypeBitmask()); : mDataEnabledSettings.isDataEnabled(requestApnType); if (!isDataEnabled) { if (!isDataEnabled) { reasons.add(DataDisallowedReasonType.DATA_DISABLED); reasons.add(DataDisallowedReasonType.DATA_DISABLED); Loading @@ -1378,7 +1383,7 @@ public class DcTracker extends Handler { // Or if the data is on cellular, and the APN type is determined unmetered by the // Or if the data is on cellular, and the APN type is determined unmetered by the // configuration. // configuration. } else if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WWAN } else if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WWAN && !isMeteredApnType) { && !isMeteredApnType && requestApnType != TYPE_DEFAULT) { reasons.add(DataAllowedReasonType.UNMETERED_APN); reasons.add(DataAllowedReasonType.UNMETERED_APN); } } Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +39 −2 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; Loading Loading @@ -1040,6 +1041,8 @@ public class DcTrackerTest extends TelephonyTest { private void initApns(String targetApn, String[] canHandleTypes) { private void initApns(String targetApn, String[] canHandleTypes) { doReturn(targetApn).when(mApnContext).getApnType(); doReturn(targetApn).when(mApnContext).getApnType(); doReturn(ApnSetting.getApnTypesBitmaskFromString(mApnContext.getApnType())) .when(mApnContext).getApnTypeBitmask(); doReturn(true).when(mApnContext).isConnectable(); doReturn(true).when(mApnContext).isConnectable(); ApnSetting apnSetting = createApnSetting(ApnSetting.getApnTypesBitmaskFromString( ApnSetting apnSetting = createApnSetting(ApnSetting.getApnTypesBitmaskFromString( TextUtils.join(",", canHandleTypes))); TextUtils.join(",", canHandleTypes))); Loading @@ -1056,7 +1059,8 @@ public class DcTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testTrySetupDataEmergencyApn() throws Exception { public void testTrySetupDataEmergencyApn() throws Exception { initApns(PhoneConstants.APN_TYPE_EMERGENCY, new String[]{PhoneConstants.APN_TYPE_ALL}); initApns(PhoneConstants.APN_TYPE_EMERGENCY, new String[]{PhoneConstants.APN_TYPE_EMERGENCY}); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); Loading @@ -1071,7 +1075,7 @@ public class DcTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testTrySetupDataXcapApn() throws Exception { public void testTrySetupDataXcapApn() throws Exception { initApns(PhoneConstants.APN_TYPE_XCAP, new String[]{PhoneConstants.APN_TYPE_ALL}); initApns(PhoneConstants.APN_TYPE_XCAP, new String[]{PhoneConstants.APN_TYPE_XCAP}); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); Loading Loading @@ -1145,6 +1149,39 @@ public class DcTrackerTest extends TelephonyTest { any(Message.class)); any(Message.class)); } } // Test the unmetered default APN setup when data is disabled. Default APN should always honor // the users's setting. @Test @SmallTest public void testTrySetupDataUnmeteredDefaultDataDisabled() throws Exception { initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL}); //mDct.setUserDataEnabled(false); doReturn(false).when(mDataEnabledSettings).isDataEnabled(); doReturn(false).when(mDataEnabledSettings).isDataEnabled(anyInt()); mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_MMS}); logd("Sending EVENT_CARRIER_CONFIG_CHANGED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_CARRIER_CONFIG_CHANGED, 1, 0)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); logd("Sending EVENT_DATA_CONNECTION_ATTACHED"); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext)); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); waitForMs(200); verify(mSimulatedCommandsVerifier, never()).setupDataCall( eq(AccessNetworkType.EUTRAN), any(DataProfile.class), eq(false), eq(false), eq(DataService.REQUEST_REASON_NORMAL), any(), any(Message.class)); } // Test the metered APN setup when data is disabled. // Test the metered APN setup when data is disabled. @Test @Test @SmallTest @SmallTest Loading