Merge "Use int array for included and excluded uids"
This commit is contained in:
@@ -172,8 +172,8 @@ package android.net {
|
||||
|
||||
public final class ProfileNetworkPreference implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public java.util.List<java.lang.Integer> getExcludedUids();
|
||||
method @NonNull public java.util.List<java.lang.Integer> getIncludedUids();
|
||||
method @NonNull public int[] getExcludedUids();
|
||||
method @NonNull public int[] getIncludedUids();
|
||||
method public int getPreference();
|
||||
method public int getPreferenceEnterpriseId();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
@@ -183,8 +183,8 @@ package android.net {
|
||||
public static final class ProfileNetworkPreference.Builder {
|
||||
ctor public ProfileNetworkPreference.Builder();
|
||||
method @NonNull public android.net.ProfileNetworkPreference build();
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setExcludedUids(@Nullable java.util.List<java.lang.Integer>);
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setIncludedUids(@Nullable java.util.List<java.lang.Integer>);
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setExcludedUids(@NonNull int[]);
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setIncludedUids(@NonNull int[]);
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setPreference(int);
|
||||
method @NonNull public android.net.ProfileNetworkPreference.Builder setPreferenceEnterpriseId(int);
|
||||
}
|
||||
|
||||
@@ -147,27 +147,32 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
private String mRequestorPackageName;
|
||||
|
||||
/**
|
||||
* Enterprise capability identifier 1.
|
||||
* Enterprise capability identifier 1. It will be used to uniquely identify specific
|
||||
* enterprise network.
|
||||
*/
|
||||
public static final int NET_ENTERPRISE_ID_1 = 1;
|
||||
|
||||
/**
|
||||
* Enterprise capability identifier 2.
|
||||
* Enterprise capability identifier 2. It will be used to uniquely identify specific
|
||||
* enterprise network.
|
||||
*/
|
||||
public static final int NET_ENTERPRISE_ID_2 = 2;
|
||||
|
||||
/**
|
||||
* Enterprise capability identifier 3.
|
||||
* Enterprise capability identifier 3. It will be used to uniquely identify specific
|
||||
* enterprise network.
|
||||
*/
|
||||
public static final int NET_ENTERPRISE_ID_3 = 3;
|
||||
|
||||
/**
|
||||
* Enterprise capability identifier 4.
|
||||
* Enterprise capability identifier 4. It will be used to uniquely identify specific
|
||||
* enterprise network.
|
||||
*/
|
||||
public static final int NET_ENTERPRISE_ID_4 = 4;
|
||||
|
||||
/**
|
||||
* Enterprise capability identifier 5.
|
||||
* Enterprise capability identifier 5. It will be used to uniquely identify specific
|
||||
* enterprise network.
|
||||
*/
|
||||
public static final int NET_ENTERPRISE_ID_5 = 5;
|
||||
|
||||
|
||||
@@ -22,14 +22,12 @@ import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1;
|
||||
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_5;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.net.ConnectivityManager.ProfileNetworkPreferencePolicy;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -41,31 +39,31 @@ import java.util.Objects;
|
||||
public final class ProfileNetworkPreference implements Parcelable {
|
||||
private final @ProfileNetworkPreferencePolicy int mPreference;
|
||||
private final @NetworkCapabilities.EnterpriseId int mPreferenceEnterpriseId;
|
||||
private final List<Integer> mIncludedUids;
|
||||
private final List<Integer> mExcludedUids;
|
||||
private int[] mIncludedUids = new int[0];
|
||||
private int[] mExcludedUids = new int[0];
|
||||
|
||||
private ProfileNetworkPreference(int preference, List<Integer> includedUids,
|
||||
List<Integer> excludedUids,
|
||||
private ProfileNetworkPreference(int preference, int[] includedUids,
|
||||
int[] excludedUids,
|
||||
@NetworkCapabilities.EnterpriseId int preferenceEnterpriseId) {
|
||||
mPreference = preference;
|
||||
mPreferenceEnterpriseId = preferenceEnterpriseId;
|
||||
if (includedUids != null) {
|
||||
mIncludedUids = new ArrayList<>(includedUids);
|
||||
mIncludedUids = includedUids.clone();
|
||||
} else {
|
||||
mIncludedUids = new ArrayList<>();
|
||||
mIncludedUids = new int[0];
|
||||
}
|
||||
|
||||
if (excludedUids != null) {
|
||||
mExcludedUids = new ArrayList<>(excludedUids);
|
||||
mExcludedUids = excludedUids.clone();
|
||||
} else {
|
||||
mExcludedUids = new ArrayList<>();
|
||||
mExcludedUids = new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
private ProfileNetworkPreference(Parcel in) {
|
||||
mPreference = in.readInt();
|
||||
mIncludedUids = in.readArrayList(Integer.class.getClassLoader());
|
||||
mExcludedUids = in.readArrayList(Integer.class.getClassLoader());
|
||||
in.readIntArray(mIncludedUids);
|
||||
in.readIntArray(mExcludedUids);
|
||||
mPreferenceEnterpriseId = in.readInt();
|
||||
}
|
||||
|
||||
@@ -74,31 +72,31 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of UIDs subject to this preference.
|
||||
* Get the array of UIDs subject to this preference.
|
||||
*
|
||||
* Included UIDs and Excluded UIDs can't both be non-empty.
|
||||
* if both are empty, it means this request applies to all uids in the user profile.
|
||||
* if included is not empty, then only included UIDs are applied.
|
||||
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
|
||||
* @return List of uids included for the profile preference.
|
||||
* @return Array of uids included for the profile preference.
|
||||
* {@see #getExcludedUids()}
|
||||
*/
|
||||
public @NonNull List<Integer> getIncludedUids() {
|
||||
return new ArrayList<>(mIncludedUids);
|
||||
public @NonNull int[] getIncludedUids() {
|
||||
return mIncludedUids.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of UIDS excluded from this preference.
|
||||
* Get the array of UIDS excluded from this preference.
|
||||
*
|
||||
* <ul>Included UIDs and Excluded UIDs can't both be non-empty.</ul>
|
||||
* <ul>If both are empty, it means this request applies to all uids in the user profile.</ul>
|
||||
* <ul>If included is not empty, then only included UIDs are applied.</ul>
|
||||
* <ul>If excluded is not empty, then it is all uids in the user profile except these UIDs.</ul>
|
||||
* @return List of uids not included for the profile preference.
|
||||
* @return Array of uids not included for the profile preference.
|
||||
* {@see #getIncludedUids()}
|
||||
*/
|
||||
public @NonNull List<Integer> getExcludedUids() {
|
||||
return new ArrayList<>(mExcludedUids);
|
||||
public @NonNull int[] getExcludedUids() {
|
||||
return mExcludedUids.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,8 +132,8 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final ProfileNetworkPreference that = (ProfileNetworkPreference) o;
|
||||
return mPreference == that.mPreference
|
||||
&& (Objects.equals(mIncludedUids, that.mIncludedUids))
|
||||
&& (Objects.equals(mExcludedUids, that.mExcludedUids))
|
||||
&& (Arrays.equals(mIncludedUids, that.mIncludedUids))
|
||||
&& (Arrays.equals(mExcludedUids, that.mExcludedUids))
|
||||
&& mPreferenceEnterpriseId == that.mPreferenceEnterpriseId;
|
||||
}
|
||||
|
||||
@@ -143,8 +141,8 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
public int hashCode() {
|
||||
return mPreference
|
||||
+ mPreferenceEnterpriseId * 2
|
||||
+ (Objects.hashCode(mIncludedUids) * 11)
|
||||
+ (Objects.hashCode(mExcludedUids) * 13);
|
||||
+ (Arrays.hashCode(mIncludedUids) * 11)
|
||||
+ (Arrays.hashCode(mExcludedUids) * 13);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,8 +152,8 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
public static final class Builder {
|
||||
private @ProfileNetworkPreferencePolicy int mPreference =
|
||||
PROFILE_NETWORK_PREFERENCE_DEFAULT;
|
||||
private @NonNull List<Integer> mIncludedUids = new ArrayList<>();
|
||||
private @NonNull List<Integer> mExcludedUids = new ArrayList<>();
|
||||
private int[] mIncludedUids = new int[0];
|
||||
private int[] mExcludedUids = new int[0];
|
||||
private int mPreferenceEnterpriseId;
|
||||
|
||||
/**
|
||||
@@ -177,44 +175,38 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a list of uids for which profile perefence is set.
|
||||
* Null would mean that this preference applies to all uids in the profile.
|
||||
* {@see #setExcludedUids(List<Integer>)}
|
||||
* This is a array of uids for which profile perefence is set.
|
||||
* Empty would mean that this preference applies to all uids in the profile.
|
||||
* {@see #setExcludedUids(int[])}
|
||||
* Included UIDs and Excluded UIDs can't both be non-empty.
|
||||
* if both are empty, it means this request applies to all uids in the user profile.
|
||||
* if included is not empty, then only included UIDs are applied.
|
||||
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
|
||||
* @param uids list of uids that are included
|
||||
* @param uids Array of uids that are included
|
||||
* @return The builder to facilitate chaining.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setIncludedUids(@Nullable List<Integer> uids) {
|
||||
if (uids != null) {
|
||||
mIncludedUids = new ArrayList<Integer>(uids);
|
||||
} else {
|
||||
mIncludedUids = new ArrayList<Integer>();
|
||||
}
|
||||
public Builder setIncludedUids(@NonNull int[] uids) {
|
||||
Objects.requireNonNull(uids);
|
||||
mIncludedUids = uids.clone();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a list of uids that are excluded for the profile perefence.
|
||||
* {@see #setIncludedUids(List<Integer>)}
|
||||
* This is a array of uids that are excluded for the profile perefence.
|
||||
* {@see #setIncludedUids(int[])}
|
||||
* Included UIDs and Excluded UIDs can't both be non-empty.
|
||||
* if both are empty, it means this request applies to all uids in the user profile.
|
||||
* if included is not empty, then only included UIDs are applied.
|
||||
* if excluded is not empty, then it is all uids in the user profile except these UIDs.
|
||||
* @param uids list of uids that are not included
|
||||
* @param uids Array of uids that are not included
|
||||
* @return The builder to facilitate chaining.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setExcludedUids(@Nullable List<Integer> uids) {
|
||||
if (uids != null) {
|
||||
mExcludedUids = new ArrayList<Integer>(uids);
|
||||
} else {
|
||||
mExcludedUids = new ArrayList<Integer>();
|
||||
}
|
||||
public Builder setExcludedUids(@NonNull int[] uids) {
|
||||
Objects.requireNonNull(uids);
|
||||
mExcludedUids = uids.clone();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -241,7 +233,7 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
*/
|
||||
@NonNull
|
||||
public ProfileNetworkPreference build() {
|
||||
if (mIncludedUids.size() > 0 && mExcludedUids.size() > 0) {
|
||||
if (mIncludedUids.length > 0 && mExcludedUids.length > 0) {
|
||||
throw new IllegalArgumentException("Both includedUids and excludedUids "
|
||||
+ "cannot be nonempty");
|
||||
}
|
||||
@@ -280,8 +272,8 @@ public final class ProfileNetworkPreference implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
|
||||
dest.writeInt(mPreference);
|
||||
dest.writeList(mIncludedUids);
|
||||
dest.writeList(mExcludedUids);
|
||||
dest.writeIntArray(mIncludedUids);
|
||||
dest.writeIntArray(mExcludedUids);
|
||||
dest.writeInt(mPreferenceEnterpriseId);
|
||||
}
|
||||
|
||||
|
||||
@@ -10625,15 +10625,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
@NonNull final UserHandle profile,
|
||||
@NonNull final ProfileNetworkPreference profileNetworkPreference) {
|
||||
final UidRange profileUids = UidRange.createForUser(profile);
|
||||
Set<UidRange> uidRangeSet = UidRangeUtils.convertListToUidRange(
|
||||
Set<UidRange> uidRangeSet = UidRangeUtils.convertArrayToUidRange(
|
||||
profileNetworkPreference.getIncludedUids());
|
||||
|
||||
if (uidRangeSet.size() > 0) {
|
||||
if (!UidRangeUtils.isRangeSetInUidRange(profileUids, uidRangeSet)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Allow uid range is outside the uid range of profile.");
|
||||
}
|
||||
} else {
|
||||
ArraySet<UidRange> disallowUidRangeSet = UidRangeUtils.convertListToUidRange(
|
||||
ArraySet<UidRange> disallowUidRangeSet = UidRangeUtils.convertArrayToUidRange(
|
||||
profileNetworkPreference.getExcludedUids());
|
||||
if (disallowUidRangeSet.size() > 0) {
|
||||
if (!UidRangeUtils.isRangeSetInUidRange(profileUids, disallowUidRangeSet)) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.net.UidRange;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -125,7 +126,7 @@ public final class UidRangeUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a list of uid to set of UidRanges.
|
||||
* Convert a list of uids to set of UidRanges.
|
||||
* @param uids list of uids
|
||||
* @return set of UidRanges
|
||||
* @hide
|
||||
@@ -153,4 +154,34 @@ public final class UidRangeUtils {
|
||||
uidRangeSet.add(new UidRange(start, stop));
|
||||
return uidRangeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array of uids to set of UidRanges.
|
||||
* @param uids array of uids
|
||||
* @return set of UidRanges
|
||||
* @hide
|
||||
*/
|
||||
public static ArraySet<UidRange> convertArrayToUidRange(@NonNull int[] uids) {
|
||||
Objects.requireNonNull(uids);
|
||||
final ArraySet<UidRange> uidRangeSet = new ArraySet<UidRange>();
|
||||
if (uids.length == 0) {
|
||||
return uidRangeSet;
|
||||
}
|
||||
int[] uidsNew = uids.clone();
|
||||
Arrays.sort(uidsNew);
|
||||
int start = uidsNew[0];
|
||||
int stop = start;
|
||||
|
||||
for (int i : uidsNew) {
|
||||
if (i <= stop + 1) {
|
||||
stop = i;
|
||||
} else {
|
||||
uidRangeSet.add(new UidRange(start, stop));
|
||||
start = i;
|
||||
stop = i;
|
||||
}
|
||||
}
|
||||
uidRangeSet.add(new UidRange(start, stop));
|
||||
return uidRangeSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13870,12 +13870,13 @@ public class ConnectivityServiceTest {
|
||||
ProfileNetworkPreference profileNetworkPreference) {
|
||||
final Set<UidRange> uidRangeSet;
|
||||
UidRange range = UidRange.createForUser(handle);
|
||||
if (profileNetworkPreference.getIncludedUids().size() != 0) {
|
||||
uidRangeSet = UidRangeUtils.convertListToUidRange(
|
||||
if (profileNetworkPreference.getIncludedUids().length != 0) {
|
||||
uidRangeSet = UidRangeUtils.convertArrayToUidRange(
|
||||
profileNetworkPreference.getIncludedUids());
|
||||
} else if (profileNetworkPreference.getExcludedUids().size() != 0) {
|
||||
|
||||
} else if (profileNetworkPreference.getExcludedUids().length != 0) {
|
||||
uidRangeSet = UidRangeUtils.removeRangeSetFromUidRange(
|
||||
range, UidRangeUtils.convertListToUidRange(
|
||||
range, UidRangeUtils.convertArrayToUidRange(
|
||||
profileNetworkPreference.getExcludedUids()));
|
||||
} else {
|
||||
uidRangeSet = new ArraySet<>();
|
||||
@@ -14247,7 +14248,7 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
|
||||
profileNetworkPreferenceBuilder.setIncludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID)});
|
||||
registerDefaultNetworkCallbacks();
|
||||
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||
profileNetworkPreferenceBuilder.build(), false, testHandle,
|
||||
@@ -14266,7 +14267,7 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
|
||||
profileNetworkPreferenceBuilder.setIncludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
registerDefaultNetworkCallbacks();
|
||||
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||
profileNetworkPreferenceBuilder.build(), false,
|
||||
@@ -14285,7 +14286,7 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
|
||||
profileNetworkPreferenceBuilder.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
registerDefaultNetworkCallbacks();
|
||||
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||
profileNetworkPreferenceBuilder.build(), false,
|
||||
@@ -14305,7 +14306,7 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
|
||||
profileNetworkPreferenceBuilder.setExcludedUids(
|
||||
List.of(testHandle.getUid(0) - 1));
|
||||
new int[]{testHandle.getUid(0) - 1});
|
||||
final TestOnCompleteListener listener = new TestOnCompleteListener();
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
|
||||
@@ -14313,7 +14314,7 @@ public class ConnectivityServiceTest {
|
||||
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setIncludedUids(
|
||||
List.of(testHandle.getUid(0) - 1));
|
||||
new int[]{testHandle.getUid(0) - 1});
|
||||
Assert.assertThrows(IllegalArgumentException.class,
|
||||
() -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
|
||||
@@ -14322,9 +14323,9 @@ public class ConnectivityServiceTest {
|
||||
|
||||
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder.setIncludedUids(
|
||||
List.of(testHandle.getUid(0) - 1));
|
||||
new int[]{testHandle.getUid(0) - 1});
|
||||
profileNetworkPreferenceBuilder.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
Assert.assertThrows(IllegalArgumentException.class,
|
||||
() -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build()),
|
||||
@@ -14335,9 +14336,9 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder2.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder2.setPreferenceEnterpriseId(NET_ENTERPRISE_ID_1);
|
||||
profileNetworkPreferenceBuilder2.setIncludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
profileNetworkPreferenceBuilder.setIncludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
Assert.assertThrows(IllegalArgumentException.class,
|
||||
() -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
|
||||
@@ -14346,9 +14347,9 @@ public class ConnectivityServiceTest {
|
||||
|
||||
profileNetworkPreferenceBuilder2.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||
profileNetworkPreferenceBuilder2.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
profileNetworkPreferenceBuilder.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
Assert.assertThrows(IllegalArgumentException.class,
|
||||
() -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
|
||||
@@ -14358,9 +14359,9 @@ public class ConnectivityServiceTest {
|
||||
profileNetworkPreferenceBuilder2.setPreference(
|
||||
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK);
|
||||
profileNetworkPreferenceBuilder2.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
profileNetworkPreferenceBuilder.setExcludedUids(
|
||||
List.of(testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)));
|
||||
new int[]{testHandle.getUid(TEST_WORK_PROFILE_APP_UID_2)});
|
||||
Assert.assertThrows(IllegalArgumentException.class,
|
||||
() -> mCm.setProfileNetworkPreferences(
|
||||
testHandle, List.of(profileNetworkPreferenceBuilder.build(),
|
||||
|
||||
@@ -351,4 +351,55 @@ public class UidRangeUtilsTest {
|
||||
expected.add(uids6);
|
||||
assertEquals(expected, UidRangeUtils.convertListToUidRange(input));
|
||||
}
|
||||
|
||||
@Test @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
public void testConvertArrayToUidRange() {
|
||||
final UidRange uids1_1 = new UidRange(1, 1);
|
||||
final UidRange uids1_2 = new UidRange(1, 2);
|
||||
final UidRange uids100_100 = new UidRange(100, 100);
|
||||
final UidRange uids10_10 = new UidRange(10, 10);
|
||||
|
||||
final UidRange uids10_14 = new UidRange(10, 14);
|
||||
final UidRange uids20_24 = new UidRange(20, 24);
|
||||
|
||||
final Set<UidRange> expected = new ArraySet<>();
|
||||
int[] input = new int[0];
|
||||
|
||||
assertThrows(NullPointerException.class, () -> UidRangeUtils.convertArrayToUidRange(null));
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[] {1};
|
||||
expected.add(uids1_1);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[]{1, 2};
|
||||
expected.clear();
|
||||
expected.add(uids1_2);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[]{1, 100};
|
||||
expected.clear();
|
||||
expected.add(uids1_1);
|
||||
expected.add(uids100_100);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[]{100, 1};
|
||||
expected.clear();
|
||||
expected.add(uids1_1);
|
||||
expected.add(uids100_100);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[]{100, 1, 2, 1, 10};
|
||||
expected.clear();
|
||||
expected.add(uids1_2);
|
||||
expected.add(uids10_10);
|
||||
expected.add(uids100_100);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
|
||||
input = new int[]{10, 11, 12, 13, 14, 20, 21, 22, 23, 24};
|
||||
expected.clear();
|
||||
expected.add(uids10_14);
|
||||
expected.add(uids20_24);
|
||||
assertEquals(expected, UidRangeUtils.convertArrayToUidRange(input));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user