Merge "Fallback should be evaluated for each preference"

This commit is contained in:
Sooraj Sasindran
2022-05-11 21:05:18 +00:00
committed by Gerrit Code Review
3 changed files with 273 additions and 11 deletions

View File

@@ -10659,7 +10659,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
Objects.requireNonNull(profile);
if (preferences.size() == 0) {
preferences.add((new ProfileNetworkPreference.Builder()).build());
final ProfileNetworkPreference pref = new ProfileNetworkPreference.Builder()
.setPreference(ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT)
.build();
preferences.add(pref);
}
PermissionUtils.enforceNetworkStackPermission(mContext);
@@ -10677,12 +10680,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
final List<ProfileNetworkPreferenceList.Preference> preferenceList =
new ArrayList<ProfileNetworkPreferenceList.Preference>();
boolean allowFallback = true;
boolean hasDefaultPreference = false;
for (final ProfileNetworkPreference preference : preferences) {
final NetworkCapabilities nc;
boolean allowFallback = true;
switch (preference.getPreference()) {
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT:
nc = null;
hasDefaultPreference = true;
if (preference.getPreferenceEnterpriseId() != 0) {
throw new IllegalArgumentException(
"Invalid enterprise identifier in setProfileNetworkPreferences");
@@ -10692,6 +10697,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
allowFallback = false;
// continue to process the enterprise preference.
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE:
// This code is needed even though there is a check later on,
// because isRangeAlreadyInPreferenceList assumes that every preference
// has a UID list.
if (hasDefaultPreference) {
throw new IllegalArgumentException(
"Default profile preference should not be set along with other "
+ "preference");
}
if (!isEnterpriseIdentifierValid(preference.getPreferenceEnterpriseId())) {
throw new IllegalArgumentException(
"Invalid enterprise identifier in setProfileNetworkPreferences");
@@ -10715,6 +10728,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
preferenceList.add(new ProfileNetworkPreferenceList.Preference(
profile, nc, allowFallback));
if (hasDefaultPreference && preferenceList.size() > 1) {
throw new IllegalArgumentException(
"Default profile preference should not be set along with other preference");
}
}
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_PROFILE_NETWORK_PREFERENCE,
new Pair<>(preferenceList, listener)));
@@ -10759,12 +10776,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
return false;
}
private void validateNetworkCapabilitiesOfProfileNetworkPreference(
@Nullable final NetworkCapabilities nc) {
if (null == nc) return; // Null caps are always allowed. It means to remove the setting.
ensureRequestableCapabilities(nc);
}
private ArraySet<NetworkRequestInfo> createNrisFromProfileNetworkPreferences(
@NonNull final ProfileNetworkPreferenceList prefs) {
final ArraySet<NetworkRequestInfo> result = new ArraySet<>();
@@ -10822,10 +10833,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
* Clear all the existing preferences for the user before applying new preferences.
*
*/
mProfileNetworkPreferences = mProfileNetworkPreferences.clearUser(
mProfileNetworkPreferences = mProfileNetworkPreferences.withoutUser(
preferenceList.get(0).user);
for (final ProfileNetworkPreferenceList.Preference preference : preferenceList) {
validateNetworkCapabilitiesOfProfileNetworkPreference(preference.capabilities);
mProfileNetworkPreferences = mProfileNetworkPreferences.plus(preference);
}