Loading src/java/com/android/internal/telephony/dataconnection/DataConnectionReasons.java +14 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.internal.telephony.dataconnection; import com.android.internal.annotations.VisibleForTesting; import java.util.HashSet; /** Loading Loading @@ -70,7 +72,14 @@ public class DataConnectionReasons { return mDataDisallowedReasonSet.size() == 0; } boolean contains(DataDisallowedReasonType reason) { /** * Check if it contains a certain disallowed reason. * * @param reason The disallowed reason to check. * @return {@code true} if the provided reason matches one of the disallowed reasons. */ @VisibleForTesting public boolean contains(DataDisallowedReasonType reason) { return mDataDisallowedReasonSet.contains(reason); } Loading Loading @@ -137,7 +146,10 @@ public class DataConnectionReasons { DATA_SERVICE_NOT_READY(true), // Qualified networks service does not allow certain types of APN brought up on either // cellular or IWLAN. DISABLED_BY_QNS(true); DISABLED_BY_QNS(true), // Data is throttled. The network explicitly requested device not to establish data // connection for a certain period. DATA_THROTTLED(true); private boolean mIsHardReason; Loading src/java/com/android/internal/telephony/dataconnection/DcTracker.java +6 −0 Original line number Diff line number Diff line Loading @@ -1448,6 +1448,12 @@ public class DcTracker extends Handler { apnContext.getApnTypeBitmask()) && requestType != REQUEST_TYPE_HANDOVER) { reasons.add(DataDisallowedReasonType.ON_OTHER_TRANSPORT); } // Check if the device is under data throttling. long retryTime = mDataThrottler.getRetryTime(apnContext.getApnTypeBitmask()); if (retryTime > SystemClock.elapsedRealtime()) { reasons.add(DataDisallowedReasonType.DATA_THROTTLED); } } boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +32 −21 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.Message; import android.os.PersistableBundle; import android.os.SystemClock; import android.provider.Settings; import android.provider.Telephony; import android.telephony.AccessNetworkConstants; Loading Loading @@ -96,6 +97,7 @@ import com.android.internal.telephony.ISub; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RetryManager; import com.android.internal.telephony.TelephonyTest; import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType; import org.junit.After; import org.junit.Before; Loading Loading @@ -799,18 +801,6 @@ public class DcTrackerTest extends TelephonyTest { assertEquals(FAKE_GATEWAY, linkProperties.getRoutes().get(0).getGateway().getHostAddress()); } private boolean isDataAllowed(DataConnectionReasons dataConnectionReasons) { try { Method method = DcTracker.class.getDeclaredMethod("isDataAllowed", DataConnectionReasons.class); method.setAccessible(true); return (boolean) method.invoke(mDct, dataConnectionReasons); } catch (Exception e) { fail(e.toString()); return false; } } private boolean isHandoverPending(int apnType) { try { Method method = DcTracker.class.getDeclaredMethod("isHandoverPending", Loading Loading @@ -880,7 +870,7 @@ public class DcTrackerTest extends TelephonyTest { @MediumTest public void testDataSetup() throws Exception { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -891,7 +881,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -922,7 +912,7 @@ public class DcTrackerTest extends TelephonyTest { mSimulatedCommands.setDataCallResult(true, result); DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -933,7 +923,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -2666,7 +2656,7 @@ public class DcTrackerTest extends TelephonyTest { @Test public void testRatChanged() throws Exception { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -2676,7 +2666,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -2802,15 +2792,15 @@ public class DcTrackerTest extends TelephonyTest { @Test public void testDataUnthrottled() throws Exception { DataThrottler mockedDataThrottler = Mockito.mock(DataThrottler.class); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mockedDataThrottler); initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING}); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler); mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null); sendInitializationEvents(); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_APN_UNTHROTTLED, new AsyncResult(null, FAKE_APN3, null))); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); verify(mockedDataThrottler).setRetryTime( verify(mDataThrottler).setRetryTime( eq(ApnSetting.TYPE_IMS), eq(RetryManager.NO_SUGGESTED_RETRY_DELAY), eq(DcTracker.REQUEST_TYPE_NORMAL)); Loading Loading @@ -2840,4 +2830,25 @@ public class DcTrackerTest extends TelephonyTest { // Make sure the messages was queued properly instead of fired right away. assertTrue(msgs.get(ApnSetting.TYPE_IMS).contains(msg)); } @Test public void testDataThrottledNotAllowData() throws Exception { initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING}); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler); doReturn(SystemClock.elapsedRealtime() + 100000).when(mDataThrottler) .getRetryTime(ApnSetting.TYPE_IMS); mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null); sendInitializationEvents(); DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = mDct.isDataAllowed(mApnContext, DcTracker.REQUEST_TYPE_NORMAL, dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); assertTrue(dataConnectionReasons.contains(DataDisallowedReasonType.DATA_THROTTLED)); // Makre sure no data setup request verify(mSimulatedCommandsVerifier, never()).setupDataCall( anyInt(), any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(), anyInt(), any(), any(), anyBoolean(), any(Message.class)); } } Loading
src/java/com/android/internal/telephony/dataconnection/DataConnectionReasons.java +14 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.internal.telephony.dataconnection; import com.android.internal.annotations.VisibleForTesting; import java.util.HashSet; /** Loading Loading @@ -70,7 +72,14 @@ public class DataConnectionReasons { return mDataDisallowedReasonSet.size() == 0; } boolean contains(DataDisallowedReasonType reason) { /** * Check if it contains a certain disallowed reason. * * @param reason The disallowed reason to check. * @return {@code true} if the provided reason matches one of the disallowed reasons. */ @VisibleForTesting public boolean contains(DataDisallowedReasonType reason) { return mDataDisallowedReasonSet.contains(reason); } Loading Loading @@ -137,7 +146,10 @@ public class DataConnectionReasons { DATA_SERVICE_NOT_READY(true), // Qualified networks service does not allow certain types of APN brought up on either // cellular or IWLAN. DISABLED_BY_QNS(true); DISABLED_BY_QNS(true), // Data is throttled. The network explicitly requested device not to establish data // connection for a certain period. DATA_THROTTLED(true); private boolean mIsHardReason; Loading
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +6 −0 Original line number Diff line number Diff line Loading @@ -1448,6 +1448,12 @@ public class DcTracker extends Handler { apnContext.getApnTypeBitmask()) && requestType != REQUEST_TYPE_HANDOVER) { reasons.add(DataDisallowedReasonType.ON_OTHER_TRANSPORT); } // Check if the device is under data throttling. long retryTime = mDataThrottler.getRetryTime(apnContext.getApnTypeBitmask()); if (retryTime > SystemClock.elapsedRealtime()) { reasons.add(DataDisallowedReasonType.DATA_THROTTLED); } } boolean isDataEnabled = apnContext == null ? mDataEnabledSettings.isDataEnabled() Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java +32 −21 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.Message; import android.os.PersistableBundle; import android.os.SystemClock; import android.provider.Settings; import android.provider.Telephony; import android.telephony.AccessNetworkConstants; Loading Loading @@ -96,6 +97,7 @@ import com.android.internal.telephony.ISub; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RetryManager; import com.android.internal.telephony.TelephonyTest; import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType; import org.junit.After; import org.junit.Before; Loading Loading @@ -799,18 +801,6 @@ public class DcTrackerTest extends TelephonyTest { assertEquals(FAKE_GATEWAY, linkProperties.getRoutes().get(0).getGateway().getHostAddress()); } private boolean isDataAllowed(DataConnectionReasons dataConnectionReasons) { try { Method method = DcTracker.class.getDeclaredMethod("isDataAllowed", DataConnectionReasons.class); method.setAccessible(true); return (boolean) method.invoke(mDct, dataConnectionReasons); } catch (Exception e) { fail(e.toString()); return false; } } private boolean isHandoverPending(int apnType) { try { Method method = DcTracker.class.getDeclaredMethod("isHandoverPending", Loading Loading @@ -880,7 +870,7 @@ public class DcTrackerTest extends TelephonyTest { @MediumTest public void testDataSetup() throws Exception { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -891,7 +881,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -922,7 +912,7 @@ public class DcTrackerTest extends TelephonyTest { mSimulatedCommands.setDataCallResult(true, result); DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -933,7 +923,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -2666,7 +2656,7 @@ public class DcTrackerTest extends TelephonyTest { @Test public void testRatChanged() throws Exception { DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = isDataAllowed(dataConnectionReasons); boolean allowed = mDct.isDataAllowed(dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); logd("Sending EVENT_ENABLE_APN"); Loading @@ -2676,7 +2666,7 @@ public class DcTrackerTest extends TelephonyTest { sendInitializationEvents(); dataConnectionReasons = new DataConnectionReasons(); allowed = isDataAllowed(dataConnectionReasons); allowed = mDct.isDataAllowed(dataConnectionReasons); assertTrue(dataConnectionReasons.toString(), allowed); ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class); Loading Loading @@ -2802,15 +2792,15 @@ public class DcTrackerTest extends TelephonyTest { @Test public void testDataUnthrottled() throws Exception { DataThrottler mockedDataThrottler = Mockito.mock(DataThrottler.class); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mockedDataThrottler); initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING}); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler); mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null); sendInitializationEvents(); mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_APN_UNTHROTTLED, new AsyncResult(null, FAKE_APN3, null))); waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler()); verify(mockedDataThrottler).setRetryTime( verify(mDataThrottler).setRetryTime( eq(ApnSetting.TYPE_IMS), eq(RetryManager.NO_SUGGESTED_RETRY_DELAY), eq(DcTracker.REQUEST_TYPE_NORMAL)); Loading Loading @@ -2840,4 +2830,25 @@ public class DcTrackerTest extends TelephonyTest { // Make sure the messages was queued properly instead of fired right away. assertTrue(msgs.get(ApnSetting.TYPE_IMS).contains(msg)); } @Test public void testDataThrottledNotAllowData() throws Exception { initApns(ApnSetting.TYPE_IMS_STRING, new String[]{ApnSetting.TYPE_IMS_STRING}); replaceInstance(DcTracker.class, "mDataThrottler", mDct, mDataThrottler); doReturn(SystemClock.elapsedRealtime() + 100000).when(mDataThrottler) .getRetryTime(ApnSetting.TYPE_IMS); mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null); sendInitializationEvents(); DataConnectionReasons dataConnectionReasons = new DataConnectionReasons(); boolean allowed = mDct.isDataAllowed(mApnContext, DcTracker.REQUEST_TYPE_NORMAL, dataConnectionReasons); assertFalse(dataConnectionReasons.toString(), allowed); assertTrue(dataConnectionReasons.contains(DataDisallowedReasonType.DATA_THROTTLED)); // Makre sure no data setup request verify(mSimulatedCommandsVerifier, never()).setupDataCall( anyInt(), any(DataProfile.class), anyBoolean(), anyBoolean(), anyInt(), any(), anyInt(), any(), any(), anyBoolean(), any(Message.class)); } }