Loading src/java/com/android/internal/telephony/data/DataNetwork.java +1 −1 Original line number Diff line number Diff line Loading @@ -3152,7 +3152,7 @@ public class DataNetwork extends StateMachine { && !mAttachedNetworkRequestList.isEmpty()) { TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); DataProfile dataProfile = mDataNetworkController.getDataProfileManager() .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, true); .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, false); // Some carriers have different profiles between cellular and IWLAN. We need to // dynamically switch profile, but only when those profiles have same APN name. if (dataProfile != null && dataProfile.getApnSetting() != null Loading src/java/com/android/internal/telephony/data/DataProfileManager.java +18 −6 Original line number Diff line number Diff line Loading @@ -684,15 +684,28 @@ public class DataProfileManager extends Handler { return null; } // If the preferred data profile can be used, always use it if it can satisfy the network // request with current network type (even though it's been marked as permanent failed.) if (mPreferredDataProfile != null && networkRequest.canBeSatisfiedBy(mPreferredDataProfile) && mPreferredDataProfile.getApnSetting() != null && mPreferredDataProfile.getApnSetting().canSupportNetworkType(networkType)) { if (ignorePermanentFailure || !mPreferredDataProfile.getApnSetting() .getPermanentFailed()) { return mPreferredDataProfile.getApnSetting(); } log("The preferred data profile is permanently failed. Only condition based retry " + "can happen."); return null; } // Filter out the data profile that can't satisfy the request. // Preferred data profile should be returned in the top of the list. List<DataProfile> dataProfiles = mAllDataProfiles.stream() .filter(networkRequest::canBeSatisfiedBy) // Put the preferred data profile at the top of the list, then the longest time // hasn't used data profile will be in the front so all the data profiles can be // tried. .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile)) .thenComparingLong(DataProfile::getLastSetupTimestamp)) // The longest time hasn't used data profile will be in the front so all the data // profiles can be tried. .sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp)) .collect(Collectors.toList()); for (DataProfile dataProfile : dataProfiles) { logv("Satisfied profile: " + dataProfile + ", last setup=" Loading Loading @@ -720,7 +733,6 @@ public class DataProfileManager extends Handler { && (dp.getApnSetting().getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed()) .collect(Collectors.toList()); if (dataProfiles.size() == 0) { log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" Loading tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java +55 −0 Original line number Diff line number Diff line Loading @@ -404,6 +404,18 @@ public class DataProfileManagerTest extends TelephonyTest { public void restoreApnSettings() { mDeletedApns.clear(); } public void setPreferredApn(String apnName) { for (Object apnSetting : mAllApnSettings) { if (apnName == ((Object[]) apnSetting)[3]) { mPreferredApnId = (int) ((Object[]) apnSetting)[0]; mPreferredApnSet = (int) ((Object[]) apnSetting)[28]; logd("mPreferredApnId=" + mPreferredApnId + " ,mPreferredApnSet=" + mPreferredApnSet); break; } } } } /** Loading Loading @@ -1069,4 +1081,47 @@ public class DataProfileManagerTest extends TelephonyTest { assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile1)).isTrue(); } @Test public void testPermanentFailureWithNoPreferredDataProfile() { // No preferred APN is set NetworkRequest request = new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(); TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone); DataProfile dp = mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false); // Mark the APN as permanent failed. dp.getApnSetting().setPermanentFailed(true); // Data profile manager should return a different data profile for setup as the previous // data profile has been marked as permanent failed. assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false)).isNotEqualTo(dp); } @Test public void testPermanentFailureWithPreferredDataProfile() { // Set the preferred APN mApnSettingContentProvider.setPreferredApn(GENERAL_PURPOSE_APN); mDataProfileManagerUT.obtainMessage(2 /* EVENT_APN_DATABASE_CHANGED */).sendToTarget(); processAllMessages(); NetworkRequest request = new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(); TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone); DataProfile dp = mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false); // Mark the APN as permanent failed. dp.getApnSetting().setPermanentFailed(true); // Since preferred APN is already set, and that data profile was marked as permanent failed, // so this should result in getting nothing. assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false)).isNull(); } } Loading
src/java/com/android/internal/telephony/data/DataNetwork.java +1 −1 Original line number Diff line number Diff line Loading @@ -3152,7 +3152,7 @@ public class DataNetwork extends StateMachine { && !mAttachedNetworkRequestList.isEmpty()) { TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); DataProfile dataProfile = mDataNetworkController.getDataProfileManager() .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, true); .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, false); // Some carriers have different profiles between cellular and IWLAN. We need to // dynamically switch profile, but only when those profiles have same APN name. if (dataProfile != null && dataProfile.getApnSetting() != null Loading
src/java/com/android/internal/telephony/data/DataProfileManager.java +18 −6 Original line number Diff line number Diff line Loading @@ -684,15 +684,28 @@ public class DataProfileManager extends Handler { return null; } // If the preferred data profile can be used, always use it if it can satisfy the network // request with current network type (even though it's been marked as permanent failed.) if (mPreferredDataProfile != null && networkRequest.canBeSatisfiedBy(mPreferredDataProfile) && mPreferredDataProfile.getApnSetting() != null && mPreferredDataProfile.getApnSetting().canSupportNetworkType(networkType)) { if (ignorePermanentFailure || !mPreferredDataProfile.getApnSetting() .getPermanentFailed()) { return mPreferredDataProfile.getApnSetting(); } log("The preferred data profile is permanently failed. Only condition based retry " + "can happen."); return null; } // Filter out the data profile that can't satisfy the request. // Preferred data profile should be returned in the top of the list. List<DataProfile> dataProfiles = mAllDataProfiles.stream() .filter(networkRequest::canBeSatisfiedBy) // Put the preferred data profile at the top of the list, then the longest time // hasn't used data profile will be in the front so all the data profiles can be // tried. .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile)) .thenComparingLong(DataProfile::getLastSetupTimestamp)) // The longest time hasn't used data profile will be in the front so all the data // profiles can be tried. .sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp)) .collect(Collectors.toList()); for (DataProfile dataProfile : dataProfiles) { logv("Satisfied profile: " + dataProfile + ", last setup=" Loading Loading @@ -720,7 +733,6 @@ public class DataProfileManager extends Handler { && (dp.getApnSetting().getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed()) .collect(Collectors.toList()); if (dataProfiles.size() == 0) { log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java +55 −0 Original line number Diff line number Diff line Loading @@ -404,6 +404,18 @@ public class DataProfileManagerTest extends TelephonyTest { public void restoreApnSettings() { mDeletedApns.clear(); } public void setPreferredApn(String apnName) { for (Object apnSetting : mAllApnSettings) { if (apnName == ((Object[]) apnSetting)[3]) { mPreferredApnId = (int) ((Object[]) apnSetting)[0]; mPreferredApnSet = (int) ((Object[]) apnSetting)[28]; logd("mPreferredApnId=" + mPreferredApnId + " ,mPreferredApnSet=" + mPreferredApnSet); break; } } } } /** Loading Loading @@ -1069,4 +1081,47 @@ public class DataProfileManagerTest extends TelephonyTest { assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile1)).isTrue(); } @Test public void testPermanentFailureWithNoPreferredDataProfile() { // No preferred APN is set NetworkRequest request = new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(); TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone); DataProfile dp = mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false); // Mark the APN as permanent failed. dp.getApnSetting().setPermanentFailed(true); // Data profile manager should return a different data profile for setup as the previous // data profile has been marked as permanent failed. assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false)).isNotEqualTo(dp); } @Test public void testPermanentFailureWithPreferredDataProfile() { // Set the preferred APN mApnSettingContentProvider.setPreferredApn(GENERAL_PURPOSE_APN); mDataProfileManagerUT.obtainMessage(2 /* EVENT_APN_DATABASE_CHANGED */).sendToTarget(); processAllMessages(); NetworkRequest request = new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(); TelephonyNetworkRequest tnr = new TelephonyNetworkRequest(request, mPhone); DataProfile dp = mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false); // Mark the APN as permanent failed. dp.getApnSetting().setPermanentFailed(true); // Since preferred APN is already set, and that data profile was marked as permanent failed, // so this should result in getting nothing. assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr, TelephonyManager.NETWORK_TYPE_LTE, false)).isNull(); } }