Loading src/java/com/android/internal/telephony/data/DataNetwork.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -3131,7 +3131,7 @@ public class DataNetwork extends StateMachine { && !mAttachedNetworkRequestList.isEmpty()) { && !mAttachedNetworkRequestList.isEmpty()) { TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); DataProfile dataProfile = mDataNetworkController.getDataProfileManager() DataProfile dataProfile = mDataNetworkController.getDataProfileManager() .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, true); .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, false); // Some carriers have different profiles between cellular and IWLAN. We need to // Some carriers have different profiles between cellular and IWLAN. We need to // dynamically switch profile, but only when those profiles have same APN name. // dynamically switch profile, but only when those profiles have same APN name. if (dataProfile != null && dataProfile.getApnSetting() != null if (dataProfile != null && dataProfile.getApnSetting() != null Loading src/java/com/android/internal/telephony/data/DataProfileManager.java +18 −6 Original line number Original line Diff line number Diff line Loading @@ -704,15 +704,28 @@ public class DataProfileManager extends Handler { return null; 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. // Filter out the data profile that can't satisfy the request. // Preferred data profile should be returned in the top of the list. // Preferred data profile should be returned in the top of the list. List<DataProfile> dataProfiles = mAllDataProfiles.stream() List<DataProfile> dataProfiles = mAllDataProfiles.stream() .filter(networkRequest::canBeSatisfiedBy) .filter(networkRequest::canBeSatisfiedBy) // Put the preferred data profile at the top of the list, then the longest time // The longest time hasn't used data profile will be in the front so all the data // hasn't used data profile will be in the front so all the data profiles can be // profiles can be tried. // tried. .sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp)) .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile)) .thenComparingLong(DataProfile::getLastSetupTimestamp)) .collect(Collectors.toList()); .collect(Collectors.toList()); for (DataProfile dataProfile : dataProfiles) { for (DataProfile dataProfile : dataProfiles) { logv("Satisfied profile: " + dataProfile + ", last setup=" logv("Satisfied profile: " + dataProfile + ", last setup=" Loading Loading @@ -740,7 +753,6 @@ public class DataProfileManager extends Handler { && (dp.getApnSetting().getApnSetId() && (dp.getApnSetting().getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID == Telephony.Carriers.MATCH_ALL_APN_SET_ID || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed()) .collect(Collectors.toList()); .collect(Collectors.toList()); if (dataProfiles.size() == 0) { if (dataProfiles.size() == 0) { log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" Loading tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java +43 −0 Original line number Original line Diff line number Diff line Loading @@ -1401,4 +1401,47 @@ public class DataProfileManagerTest extends TelephonyTest { assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile3)).isTrue(); assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile3)).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 Original line Diff line number Diff line Loading @@ -3131,7 +3131,7 @@ public class DataNetwork extends StateMachine { && !mAttachedNetworkRequestList.isEmpty()) { && !mAttachedNetworkRequestList.isEmpty()) { TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); TelephonyNetworkRequest networkRequest = mAttachedNetworkRequestList.get(0); DataProfile dataProfile = mDataNetworkController.getDataProfileManager() DataProfile dataProfile = mDataNetworkController.getDataProfileManager() .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, true); .getDataProfileForNetworkRequest(networkRequest, targetNetworkType, false); // Some carriers have different profiles between cellular and IWLAN. We need to // Some carriers have different profiles between cellular and IWLAN. We need to // dynamically switch profile, but only when those profiles have same APN name. // dynamically switch profile, but only when those profiles have same APN name. if (dataProfile != null && dataProfile.getApnSetting() != null if (dataProfile != null && dataProfile.getApnSetting() != null Loading
src/java/com/android/internal/telephony/data/DataProfileManager.java +18 −6 Original line number Original line Diff line number Diff line Loading @@ -704,15 +704,28 @@ public class DataProfileManager extends Handler { return null; 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. // Filter out the data profile that can't satisfy the request. // Preferred data profile should be returned in the top of the list. // Preferred data profile should be returned in the top of the list. List<DataProfile> dataProfiles = mAllDataProfiles.stream() List<DataProfile> dataProfiles = mAllDataProfiles.stream() .filter(networkRequest::canBeSatisfiedBy) .filter(networkRequest::canBeSatisfiedBy) // Put the preferred data profile at the top of the list, then the longest time // The longest time hasn't used data profile will be in the front so all the data // hasn't used data profile will be in the front so all the data profiles can be // profiles can be tried. // tried. .sorted(Comparator.comparing(DataProfile::getLastSetupTimestamp)) .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile)) .thenComparingLong(DataProfile::getLastSetupTimestamp)) .collect(Collectors.toList()); .collect(Collectors.toList()); for (DataProfile dataProfile : dataProfiles) { for (DataProfile dataProfile : dataProfiles) { logv("Satisfied profile: " + dataProfile + ", last setup=" logv("Satisfied profile: " + dataProfile + ", last setup=" Loading Loading @@ -740,7 +753,6 @@ public class DataProfileManager extends Handler { && (dp.getApnSetting().getApnSetId() && (dp.getApnSetting().getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID == Telephony.Carriers.MATCH_ALL_APN_SET_ID || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId)) .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed()) .collect(Collectors.toList()); .collect(Collectors.toList()); if (dataProfiles.size() == 0) { if (dataProfiles.size() == 0) { log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId=" Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataProfileManagerTest.java +43 −0 Original line number Original line Diff line number Diff line Loading @@ -1401,4 +1401,47 @@ public class DataProfileManagerTest extends TelephonyTest { assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile3)).isTrue(); assertThat(mDataProfileManagerUT.isDataProfileCompatible(dataProfile3)).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(); } } }