Merge changes from topic "cp"
* changes:
Fixed network tearing down due to data profile check failed
Fixed two IMS data profiles sent to modem
Seperate recovered reason
Improve log for networkTypeBitmask
QNS anomaly report only track frequent HO
Persist user data roaming settings
diff --git a/src/java/com/android/internal/telephony/data/AccessNetworksManager.java b/src/java/com/android/internal/telephony/data/AccessNetworksManager.java
index e209a32..e7734d5 100644
--- a/src/java/com/android/internal/telephony/data/AccessNetworksManager.java
+++ b/src/java/com/android/internal/telephony/data/AccessNetworksManager.java
@@ -364,13 +364,18 @@
}
List<QualifiedNetworks> qualifiedNetworksList = new ArrayList<>();
+ // For anomaly report, only track frequent HO between cellular and IWLAN
+ boolean isRequestedNetworkOnIwlan = Arrays.stream(qualifiedNetworkTypes)
+ .anyMatch(network -> network == AccessNetworkType.IWLAN);
int satisfiedApnTypes = 0;
for (int apnType : SUPPORTED_APN_TYPES) {
if ((apnTypes & apnType) == apnType) {
// skip the APN anomaly detection if not using the T data stack
if (mDataConfigManager != null) {
satisfiedApnTypes |= apnType;
- trackFrequentApnTypeChange(apnType);
+ if (isRequestedNetworkOnIwlan) {
+ trackFrequentApnTypeChange(apnType);
+ }
}
if (mAvailableNetworks.get(apnType) != null) {
diff --git a/src/java/com/android/internal/telephony/data/DataNetworkController.java b/src/java/com/android/internal/telephony/data/DataNetworkController.java
index 5e1388b..9fc9ef5 100644
--- a/src/java/com/android/internal/telephony/data/DataNetworkController.java
+++ b/src/java/com/android/internal/telephony/data/DataNetworkController.java
@@ -1713,9 +1713,11 @@
&& !dataProfile.getApnSetting().canSupportLingeringNetworkType(networkType)) {
log("networkType=" + TelephonyManager.getNetworkTypeName(networkType)
+ ", networkTypeBitmask="
- + dataProfile.getApnSetting().getNetworkTypeBitmask()
+ + TelephonyManager.convertNetworkTypeBitmaskToString(
+ dataProfile.getApnSetting().getNetworkTypeBitmask())
+ ", lingeringNetworkTypeBitmask="
- + dataProfile.getApnSetting().getLingeringNetworkTypeBitmask());
+ + TelephonyManager.convertNetworkTypeBitmaskToString(
+ dataProfile.getApnSetting().getLingeringNetworkTypeBitmask()));
evaluation.addDataDisallowedReason(
DataDisallowedReason.DATA_NETWORK_TYPE_NOT_ALLOWED);
}
@@ -1725,13 +1727,10 @@
evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
}
- // Check if the data profile is still valid, sometimes the users can remove it from the APN
- // editor. We use very loose check here because APN id can change after APN reset to
- // default
- if (mDataProfileManager.getDataProfile(
- dataProfile.getApnSetting() != null
- ? dataProfile.getApnSetting().getApnName() : null,
- dataProfile.getTrafficDescriptor()) == null) {
+ // Check if the data profile is still compatible, sometimes the users can remove it from the
+ // APN editor. If some of the important fields are changed in APN settings, we need to
+ // tear down the network. Note traffic descriptor from the data profile will not be checked.
+ if (!mDataProfileManager.isDataProfileCompatible(dataProfile)) {
evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_PROFILE_INVALID);
}
diff --git a/src/java/com/android/internal/telephony/data/DataProfileManager.java b/src/java/com/android/internal/telephony/data/DataProfileManager.java
index 78427cf..c01c327 100644
--- a/src/java/com/android/internal/telephony/data/DataProfileManager.java
+++ b/src/java/com/android/internal/telephony/data/DataProfileManager.java
@@ -86,7 +86,11 @@
/** Cellular data service. */
private final @NonNull DataServiceManager mWwanDataServiceManager;
- /** All data profiles for the current carrier. */
+ /**
+ * All data profiles for the current carrier. Note only data profiles loaded from the APN
+ * database will be stored here. The on-demand data profiles (generated dynamically, for
+ * example, enterprise data profiles with differentiator) are not stored here.
+ */
private final @NonNull List<DataProfile> mAllDataProfiles = new ArrayList<>();
/** The data profile used for initial attach. */
@@ -911,39 +915,29 @@
}
/**
- * Get data profile by APN name and/or traffic descriptor.
+ * Check if the provided data profile is still compatible with the current environment. Note
+ * this method ignores APN id check and traffic descriptor check. A data profile with traffic
+ * descriptor only can always be used in any condition.
*
- * @param apnName APN name.
- * @param trafficDescriptor Traffic descriptor.
- *
- * @return Data profile by APN name and/or traffic descriptor. Either one of APN name or
- * traffic descriptor should be provided. {@code null} if data profile is not found.
+ * @param dataProfile The data profile to check.
+ * @return {@code true} if the provided data profile can be still used in current environment.
*/
- public @Nullable DataProfile getDataProfile(@Nullable String apnName,
- @Nullable TrafficDescriptor trafficDescriptor) {
- if (apnName == null && trafficDescriptor == null) return null;
-
- List<DataProfile> dataProfiles = mAllDataProfiles;
-
- // Check if any existing data profile has the same traffic descriptor.
- if (trafficDescriptor != null) {
- dataProfiles = mAllDataProfiles.stream()
- .filter(dp -> trafficDescriptor.equals(dp.getTrafficDescriptor()))
- .collect(Collectors.toList());
+ public boolean isDataProfileCompatible(@NonNull DataProfile dataProfile) {
+ if (dataProfile == null) {
+ return false;
}
- // Check if any existing data profile has the same APN name.
- if (apnName != null) {
- dataProfiles = dataProfiles.stream()
- .filter(dp -> dp.getApnSetting() != null
- && (dp.getApnSetting().getApnSetId()
- == Telephony.Carriers.MATCH_ALL_APN_SET_ID
- || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId))
- .filter(dp -> apnName.equals(dp.getApnSetting().getApnName()))
- .collect(Collectors.toList());
+ if (dataProfile.getApnSetting() == null && dataProfile.getTrafficDescriptor() != null) {
+ // A traffic descriptor only data profile can be always used. Traffic descriptors are
+ // always generated on the fly instead loaded from the database.
+ return true;
}
- return dataProfiles.isEmpty() ? null : dataProfiles.get(0);
+ // Only check the APN from the profile is compatible or not.
+ return mAllDataProfiles.stream()
+ .filter(dp -> dp.getApnSetting() != null)
+ .anyMatch(dp -> dp.getApnSetting().equals(dataProfile.getApnSetting(),
+ mPhone.getServiceState().getDataRoamingFromRegistration()));
}
/**
diff --git a/src/java/com/android/internal/telephony/data/DataRetryManager.java b/src/java/com/android/internal/telephony/data/DataRetryManager.java
index cd18883..ec5ba1b 100644
--- a/src/java/com/android/internal/telephony/data/DataRetryManager.java
+++ b/src/java/com/android/internal/telephony/data/DataRetryManager.java
@@ -65,6 +65,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* DataRetryManager manages data network setup retry and its configurations.
@@ -1397,18 +1398,19 @@
// equal to the data profiles kept in data profile manager (due to some fields missing
// in DataProfileInfo.aidl), so we need to get the equivalent data profile from data
// profile manager.
- final DataProfile dp = mDataProfileManager.getDataProfile(
- dataProfile.getApnSetting() != null
- ? dataProfile.getApnSetting().getApnName() : null,
- dataProfile.getTrafficDescriptor());
- log("onDataProfileUnthrottled: getDataProfile=" + dp);
- if (dp != null) {
- dataUnthrottlingEntries = mDataThrottlingEntries.stream()
- .filter(entry -> entry.expirationTimeMillis > now
- && entry.dataProfile.equals(dp)
- && entry.transport == transport)
- .collect(Collectors.toList());
+ log("onDataProfileUnthrottled: dataProfile=" + dataProfile);
+ Stream<DataThrottlingEntry> stream = mDataThrottlingEntries.stream();
+ stream = stream.filter(entry -> entry.expirationTimeMillis > now);
+ if (dataProfile.getApnSetting() != null) {
+ stream = stream
+ .filter(entry -> entry.dataProfile.getApnSetting() != null)
+ .filter(entry -> entry.dataProfile.getApnSetting().getApnName()
+ .equals(dataProfile.getApnSetting().getApnName()));
}
+ stream = stream.filter(entry -> Objects.equals(entry.dataProfile.getTrafficDescriptor(),
+ dataProfile.getTrafficDescriptor()));
+
+ dataUnthrottlingEntries = stream.collect(Collectors.toList());
} else if (apn != null) {
// For HIDL 1.6 or below
dataUnthrottlingEntries = mDataThrottlingEntries.stream()
diff --git a/src/java/com/android/internal/telephony/data/DataSettingsManager.java b/src/java/com/android/internal/telephony/data/DataSettingsManager.java
index f4f7381..c593f88 100644
--- a/src/java/com/android/internal/telephony/data/DataSettingsManager.java
+++ b/src/java/com/android/internal/telephony/data/DataSettingsManager.java
@@ -221,14 +221,8 @@
}
case EVENT_SET_DATA_ROAMING_ENABLED: {
boolean enabled = (boolean) msg.obj;
- // Will trigger handleDataOnRoamingChange() through observer
- boolean changed = GlobalSettingsHelper.setBoolean(mPhone.getContext(),
- Settings.Global.DATA_ROAMING, mSubId, enabled);
- if (changed) {
- logl("DataRoamingEnabled changed to " + enabled);
- mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
- () -> callback.onDataRoamingEnabledChanged(enabled)));
- }
+ setDataRoamingEnabledInternal(enabled);
+ setDataRoamingFromUserAction();
break;
}
case EVENT_SET_ALWAYS_ALLOW_MMS_DATA: {
@@ -501,7 +495,7 @@
}
/**
- * Enable or disable data roaming.
+ * Enable or disable data roaming from user settings.
* @param enabled {@code true} to enable data roaming and {@code false} to disable.
*/
public void setDataRoamingEnabled(boolean enabled) {
@@ -509,6 +503,21 @@
}
/**
+ * Enable or disable data roaming.
+ * @param enabled {@code true} to enable data roaming and {@code false} to disable.
+ */
+ private void setDataRoamingEnabledInternal(boolean enabled) {
+ // Will trigger handleDataOnRoamingChange() through observer
+ boolean changed = GlobalSettingsHelper.setBoolean(mPhone.getContext(),
+ Settings.Global.DATA_ROAMING, mSubId, enabled);
+ if (changed) {
+ logl("DataRoamingEnabled changed to " + enabled);
+ mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
+ () -> callback.onDataRoamingEnabledChanged(enabled)));
+ }
+ }
+
+ /**
* Check whether data roaming is enabled for the device based on the current
* {@link Settings.Global#DATA_ROAMING} value.
* @return {@code true} if data roaming is enabled and {@code false} otherwise.
@@ -537,7 +546,7 @@
public void setDefaultDataRoamingEnabled() {
// For SSSS, this is a per-phone property from DATA_ROAMING_IS_USER_SETTING_KEY.
// For DSDS, this is a per-sub property from Settings.Global.DATA_ROAMING + subId.
- // If the user has not manually set the value, use the default from carrier configurations.
+ // If the user has not manually set the value, use the default value.
boolean useCarrierSpecificDefault = false;
if (mPhone.getContext().getSystemService(TelephonyManager.class).getSimCount() != 1) {
String setting = Settings.Global.DATA_ROAMING + mPhone.getSubId();
@@ -554,7 +563,7 @@
log("setDefaultDataRoamingEnabled: useCarrierSpecificDefault=" + useCarrierSpecificDefault);
if (useCarrierSpecificDefault) {
boolean defaultVal = isDefaultDataRoamingEnabled();
- setDataRoamingEnabled(defaultVal);
+ setDataRoamingEnabledInternal(defaultVal);
}
}
@@ -573,6 +582,17 @@
return sp.getBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, true);
}
+ /**
+ * Indicate that the user has manually enabled or disabled the data roaming value from settings.
+ * If the user has not manually set the data roaming value, the default value from
+ * {@link #isDefaultDataRoamingEnabled()} will continue to be used.
+ */
+ private void setDataRoamingFromUserAction() {
+ final SharedPreferences.Editor sp = PreferenceManager
+ .getDefaultSharedPreferences(mPhone.getContext()).edit();
+ sp.putBoolean(Phone.DATA_ROAMING_IS_USER_SETTING_KEY, true).commit();
+ }
+
private @NonNull DataEnabledOverride getDataEnabledOverride() {
return new DataEnabledOverride(SubscriptionController.getInstance()
.getDataEnabledOverrideRules(mSubId));
@@ -724,6 +744,9 @@
pw.println("isDataEnabled(internet)=" + isDataEnabled(ApnSetting.TYPE_DEFAULT));
pw.println("isDataEnabled(mms)=" + isDataEnabled(ApnSetting.TYPE_MMS));
pw.println("isUserDataEnabled=" + isUserDataEnabled());
+ pw.println("isDataRoamingEnabled=" + isDataRoamingEnabled());
+ pw.println("isDefaultDataRoamingEnabled=" + isDefaultDataRoamingEnabled());
+ pw.println("isDataRoamingFromUserAction=" + isDataRoamingFromUserAction());
pw.println("device_provisioned=" + Settings.Global.getInt(
mResolver, Settings.Global.DEVICE_PROVISIONED, 0));
pw.println("isProvisioningDataEnabled=" + isProvisioningDataEnabled());
diff --git a/src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java b/src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java
index 247459e..e467815 100644
--- a/src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java
+++ b/src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java
@@ -26,6 +26,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
+import android.provider.Settings;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.ValidationStatus;
import android.telephony.CellSignalStrength;
@@ -164,6 +165,8 @@
private boolean mNetworkCheckTimerStarted = false;
/** Whether radio state changed during data stall. */
private boolean mRadioStateChangedDuringDataStall;
+ /** Whether airplane mode enabled during data stall. */
+ private boolean mIsAirPlaneModeEnableDuringDataStall;
/** Whether mobile data change to Enabled during data stall. */
private boolean mMobileDataChangedToEnabledDuringDataStall;
/** Whether attempted all recovery steps. */
@@ -285,6 +288,12 @@
if (mDataStalled) {
// Store the radio state changed flag only when data stall occurred.
mRadioStateChangedDuringDataStall = true;
+ if (Settings.Global.getInt(
+ mPhone.getContext().getContentResolver(),
+ Settings.Global.AIRPLANE_MODE_ON,
+ 0) != 0) {
+ mIsAirPlaneModeEnableDuringDataStall = true;
+ }
}
break;
default:
@@ -345,6 +354,7 @@
mIsValidNetwork = true;
mIsAttemptedAllSteps = false;
mRadioStateChangedDuringDataStall = false;
+ mIsAirPlaneModeEnableDuringDataStall = false;
mMobileDataChangedToEnabledDuringDataStall = false;
cancelNetworkCheckTimer();
mTimeLastRecoveryStartMs = 0;
@@ -380,6 +390,7 @@
mTimeLastRecoveryStartMs = 0;
mMobileDataChangedToEnabledDuringDataStall = false;
mRadioStateChangedDuringDataStall = false;
+ mIsAirPlaneModeEnableDuringDataStall = false;
setRecoveryAction(RECOVERY_ACTION_GET_DATA_CALL_LIST);
}
@@ -628,6 +639,9 @@
if (mLastAction > RECOVERY_ACTION_CLEANUP) {
ret = RECOVERED_REASON_DSRM;
}
+ if (mIsAirPlaneModeEnableDuringDataStall) {
+ ret = RECOVERED_REASON_USER;
+ }
} else if (mMobileDataChangedToEnabledDuringDataStall) {
ret = RECOVERED_REASON_USER;
}
@@ -799,6 +813,7 @@
pw.println("mIsValidNetwork=" + mIsValidNetwork);
pw.println("mIsInternetNetworkConnected=" + mIsInternetNetworkConnected);
+ pw.println("mIsAirPlaneModeEnableDuringDataStall=" + mIsAirPlaneModeEnableDuringDataStall);
pw.println("mDataStalled=" + mDataStalled);
pw.println("mLastAction=" + recoveryActionToString(mLastAction));
pw.println("mIsAttemptedAllSteps=" + mIsAttemptedAllSteps);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java
index 1f0b704..c27d075 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java
@@ -129,7 +129,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
-import java.util.stream.Collectors;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -711,6 +710,20 @@
mTetheringDataProfile);
doAnswer(invocation -> {
+ DataProfile dp = (DataProfile) invocation.getArguments()[0];
+
+ if (dp.getApnSetting() == null) return true;
+
+ for (DataProfile dataProfile : profiles) {
+ if (dataProfile.getApnSetting() != null
+ && dataProfile.getApnSetting().equals(dp.getApnSetting(), false)) {
+ return true;
+ }
+ }
+ return null;
+ }).when(mDataProfileManager).isDataProfileCompatible(any(DataProfile.class));
+
+ doAnswer(invocation -> {
TelephonyNetworkRequest networkRequest =
(TelephonyNetworkRequest) invocation.getArguments()[0];
int networkType = (int) invocation.getArguments()[1];
@@ -732,27 +745,6 @@
doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WWAN).when(mAccessNetworksManager)
.getPreferredTransportByNetworkCapability(anyInt());
doReturn(true).when(mDataProfileManager).isDataProfilePreferred(any(DataProfile.class));
- doAnswer(invocation -> {
- String apnName = (String) invocation.getArguments()[0];
- TrafficDescriptor td = (TrafficDescriptor) invocation.getArguments()[1];
-
- List<DataProfile> dps = profiles;
-
- if (td != null) {
- dps = dps.stream()
- .filter(dp -> td.equals(dp.getTrafficDescriptor()))
- .collect(Collectors.toList());
- }
-
- if (apnName != null) {
- dps = dps.stream()
- .filter(dp -> dp.getApnSetting() != null)
- .filter(dp -> apnName.equals(dp.getApnSetting().getApnName()))
- .collect(Collectors.toList());
- }
-
- return dps.isEmpty() ? null : dps.get(0);
- }).when(mDataProfileManager).getDataProfile(anyString(), any());
doAnswer(invocation -> {
((Runnable) invocation.getArguments()[0]).run();
diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java
index d55be8d..157f62b 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java
@@ -42,6 +42,7 @@
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataProfile;
+import android.telephony.data.TrafficDescriptor;
import android.telephony.data.TrafficDescriptor.OsAppId;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
@@ -60,11 +61,13 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -413,6 +416,12 @@
method.invoke(mDataProfileManagerUT, dataProfiles);
}
+ private @NonNull List<DataProfile> getAllDataProfiles() throws Exception {
+ Field field = DataProfileManager.class.getDeclaredField("mAllDataProfiles");
+ field.setAccessible(true);
+ return (List<DataProfile>) field.get(mDataProfileManagerUT);
+ }
+
@Before
public void setUp() throws Exception {
logd("DataProfileManagerTest +Setup!");
@@ -936,4 +945,54 @@
assertThat(mDataProfileManagerUT.isTetheringDataProfileExisting(
TelephonyManager.NETWORK_TYPE_NR)).isFalse();
}
+
+ @Test
+ public void testNoDefaultIms() throws Exception {
+ List<DataProfile> dataProfiles = getAllDataProfiles();
+
+ // Since the database already had IMS, there should not be default IMS created in the
+ // database.
+ assertThat(dataProfiles.stream()
+ .filter(dp -> dp.canSatisfy(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .collect(Collectors.toList())).hasSize(1);
+ }
+
+ @Test
+ public void testDataProfileCompatibility() throws Exception {
+ DataProfile enterpriseDataProfile = new DataProfile.Builder()
+ .setTrafficDescriptor(new TrafficDescriptor(null,
+ new TrafficDescriptor.OsAppId(TrafficDescriptor.OsAppId.ANDROID_OS_ID,
+ "ENTERPRISE", 1).getBytes()))
+ .build();
+
+ // Make sure the TD only profile is always compatible.
+ assertThat(mDataProfileManagerUT.isDataProfileCompatible(enterpriseDataProfile)).isTrue();
+
+ // Make sure the profile which is slightly modified is also compatible.
+ DataProfile dataProfile1 = new DataProfile.Builder()
+ .setApnSetting(new ApnSetting.Builder()
+ .setEntryName(GENERAL_PURPOSE_APN)
+ .setId(1)
+ .setApnName(GENERAL_PURPOSE_APN)
+ .setProxyAddress("")
+ .setMmsProxyAddress("")
+ .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS
+ | ApnSetting.TYPE_SUPL | ApnSetting.TYPE_IA | ApnSetting.TYPE_FOTA)
+ .setUser("")
+ .setPassword("")
+ .setAuthType(ApnSetting.AUTH_TYPE_NONE)
+ .setProtocol(ApnSetting.PROTOCOL_IPV4V6)
+ .setRoamingProtocol(ApnSetting.PROTOCOL_IPV4V6)
+ .setCarrierEnabled(true)
+ .setPersistent(true)
+ .setMtuV4(1280)
+ .setMtuV6(1280)
+ .setNetworkTypeBitmask((int) (TelephonyManager.NETWORK_TYPE_BITMASK_LTE
+ | TelephonyManager.NETWORK_TYPE_BITMASK_NR))
+ .setMvnoMatchData("")
+ .build())
+ .build();
+
+ assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile1)).isTrue();
+ }
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/data/DataRetryManagerTest.java b/tests/telephonytests/src/com/android/internal/telephony/data/DataRetryManagerTest.java
index a53408a..4fbc31c 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/data/DataRetryManagerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/data/DataRetryManagerTest.java
@@ -22,7 +22,6 @@
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
@@ -57,7 +56,6 @@
import java.util.Collections;
import java.util.List;
-import java.util.stream.Collectors;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -153,28 +151,6 @@
mDataRetryManagerUT = new DataRetryManager(mPhone, mDataNetworkController,
mockedDataServiceManagers, Looper.myLooper(), mDataRetryManagerCallbackMock);
- doAnswer(invocation -> {
- String apnName = (String) invocation.getArguments()[0];
- TrafficDescriptor td = (TrafficDescriptor) invocation.getArguments()[1];
-
- if (apnName == null && td == null) return null;
-
- List<DataProfile> dataProfiles = mAllDataProfileList;
- if (apnName != null) {
- dataProfiles = dataProfiles.stream()
- .filter(dp -> dp.getApnSetting() != null
- && apnName.equals(dp.getApnSetting().getApnName()))
- .collect(Collectors.toList());
- }
- if (td != null) {
- dataProfiles = dataProfiles.stream()
- .filter(dp -> dp.getTrafficDescriptor() != null
- && td.equals(dp.getTrafficDescriptor()))
- .collect(Collectors.toList());
- }
- return dataProfiles.isEmpty() ? null : dataProfiles.get(0);
- }).when(mDataProfileManager).getDataProfile(anyString(), any());
-
ArgumentCaptor<DataConfigManagerCallback> dataConfigManagerCallbackCaptor =
ArgumentCaptor.forClass(DataConfigManagerCallback.class);
verify(mDataConfigManager).registerCallback(dataConfigManagerCallbackCaptor.capture());
@@ -380,6 +356,41 @@
}
@Test
+ public void testEnterpriseUnthrottling() throws Exception {
+ NetworkRequest request = new NetworkRequest.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_ENTERPRISE)
+ .build();
+ TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone);
+ DataNetworkController.NetworkRequestList
+ networkRequestList = new DataNetworkController.NetworkRequestList(tnr);
+
+ DataProfile enterpriseDataProfile = new DataProfile.Builder()
+ .setTrafficDescriptor(new TrafficDescriptor(null,
+ new TrafficDescriptor.OsAppId(TrafficDescriptor.OsAppId.ANDROID_OS_ID,
+ "ENTERPRISE", 1).getBytes()))
+ .build();
+
+ mDataRetryManagerUT.evaluateDataSetupRetry(enterpriseDataProfile,
+ AccessNetworkConstants.TRANSPORT_TYPE_WWAN, networkRequestList, 123,
+ Long.MAX_VALUE);
+ processAllFutureMessages();
+
+ mDataRetryManagerUT.obtainMessage(6/*EVENT_DATA_PROFILE_UNTHROTTLED*/,
+ new AsyncResult(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, enterpriseDataProfile,
+ null)).sendToTarget();
+ processAllMessages();
+
+ ArgumentCaptor<DataSetupRetryEntry> dataSetupRetryEntryCaptor =
+ ArgumentCaptor.forClass(DataSetupRetryEntry.class);
+ verify(mDataRetryManagerCallbackMock)
+ .onDataNetworkSetupRetry(dataSetupRetryEntryCaptor.capture());
+ DataSetupRetryEntry entry = dataSetupRetryEntryCaptor.getValue();
+ assertThat(entry.dataProfile).isEqualTo(enterpriseDataProfile);
+ assertThat(entry.retryDelayMillis).isEqualTo(0);
+ assertThat(entry.transport).isEqualTo(AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
+ }
+
+ @Test
public void testDataSetupRetryPermanentFailure() {
DataSetupRetryRule retryRule = new DataSetupRetryRule(
"fail_causes=8|27|28|29|30|32|33|35|50|51|111|-5|-6|65537|65538|-3|2253|"