Loading src/java/com/android/internal/telephony/dataconnection/DataConnection.java +21 −7 Original line number Diff line number Diff line Loading @@ -1131,14 +1131,28 @@ public class DataConnection extends StateMachine { * @return True if this data connection should only be used for unmetered purposes. */ private boolean isUnmeteredUseOnly() { // The data connection can only be unmetered used only if all requests' reasons are // unmetered. // If this data connection is on IWLAN, then it's unmetered and can be used by everyone. // Should not be for unmetered used only. if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { return false; } // If data is enabled, this data connection can't be for unmetered used only because // everyone should be able to use it. if (mPhone.getDataEnabledSettings().isDataEnabled()) { return false; } // If the device is roaming and data roaming it turned on, then this data connection can't // be for unmetered use only. if (mDct.getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) { return false; } // The data connection can only be unmetered used only if all attached APN contexts // attached to this data connection are unmetered. for (ApnContext apnContext : mApnContexts.keySet()) { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean isDataAllowed = mDct.isDataAllowed(apnContext, DcTracker.REQUEST_TYPE_NORMAL, dataConnectionReasons); if (!isDataAllowed || !dataConnectionReasons.contains( DataConnectionReasons.DataAllowedReasonType.UNMETERED_APN)) { if (ApnSettingUtils.isMeteredApnType(apnContext.getApnTypeBitmask(), mPhone)) { return false; } } Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -343,6 +343,12 @@ public class DataConnectionTest extends TelephonyTest { return (long) method.invoke(mDc, response); } private boolean isUnmeteredUseOnly() throws Exception { Method method = DataConnection.class.getDeclaredMethod("isUnmeteredUseOnly"); method.setAccessible(true); return (boolean) method.invoke(mDc); } private SetupResult setLinkProperties(DataCallResponse response, LinkProperties linkProperties) throws Exception { Loading Loading @@ -902,4 +908,28 @@ public class DataConnectionTest extends TelephonyTest { public void testStartNattKeepaliveFailCondensed() throws Exception { checkStartNattKeepaliveFail(true); } @Test @SmallTest public void testIsUnmeteredUseOnly() throws Exception { Field field = DataConnection.class.getDeclaredField("mTransportType"); field.setAccessible(true); field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WLAN); assertFalse(isUnmeteredUseOnly()); field = DataConnection.class.getDeclaredField("mTransportType"); field.setAccessible(true); field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); doReturn(false).when(mDataEnabledSettings).isDataEnabled(); doReturn(false).when(mServiceState).getDataRoaming(); doReturn(ApnSetting.TYPE_MMS).when(mApnContext).getApnTypeBitmask(); mContextFixture.getCarrierConfigBundle().putStringArray( CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[] { "default" }); assertTrue(isUnmeteredUseOnly()); } } Loading
src/java/com/android/internal/telephony/dataconnection/DataConnection.java +21 −7 Original line number Diff line number Diff line Loading @@ -1131,14 +1131,28 @@ public class DataConnection extends StateMachine { * @return True if this data connection should only be used for unmetered purposes. */ private boolean isUnmeteredUseOnly() { // The data connection can only be unmetered used only if all requests' reasons are // unmetered. // If this data connection is on IWLAN, then it's unmetered and can be used by everyone. // Should not be for unmetered used only. if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) { return false; } // If data is enabled, this data connection can't be for unmetered used only because // everyone should be able to use it. if (mPhone.getDataEnabledSettings().isDataEnabled()) { return false; } // If the device is roaming and data roaming it turned on, then this data connection can't // be for unmetered use only. if (mDct.getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) { return false; } // The data connection can only be unmetered used only if all attached APN contexts // attached to this data connection are unmetered. for (ApnContext apnContext : mApnContexts.keySet()) { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean isDataAllowed = mDct.isDataAllowed(apnContext, DcTracker.REQUEST_TYPE_NORMAL, dataConnectionReasons); if (!isDataAllowed || !dataConnectionReasons.contains( DataConnectionReasons.DataAllowedReasonType.UNMETERED_APN)) { if (ApnSettingUtils.isMeteredApnType(apnContext.getApnTypeBitmask(), mPhone)) { return false; } } Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DataConnectionTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -343,6 +343,12 @@ public class DataConnectionTest extends TelephonyTest { return (long) method.invoke(mDc, response); } private boolean isUnmeteredUseOnly() throws Exception { Method method = DataConnection.class.getDeclaredMethod("isUnmeteredUseOnly"); method.setAccessible(true); return (boolean) method.invoke(mDc); } private SetupResult setLinkProperties(DataCallResponse response, LinkProperties linkProperties) throws Exception { Loading Loading @@ -902,4 +908,28 @@ public class DataConnectionTest extends TelephonyTest { public void testStartNattKeepaliveFailCondensed() throws Exception { checkStartNattKeepaliveFail(true); } @Test @SmallTest public void testIsUnmeteredUseOnly() throws Exception { Field field = DataConnection.class.getDeclaredField("mTransportType"); field.setAccessible(true); field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WLAN); assertFalse(isUnmeteredUseOnly()); field = DataConnection.class.getDeclaredField("mTransportType"); field.setAccessible(true); field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); doReturn(false).when(mDataEnabledSettings).isDataEnabled(); doReturn(false).when(mServiceState).getDataRoaming(); doReturn(ApnSetting.TYPE_MMS).when(mApnContext).getApnTypeBitmask(); mContextFixture.getCarrierConfigBundle().putStringArray( CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[] { "default" }); assertTrue(isUnmeteredUseOnly()); } }