| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net.vcn; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.net.NetworkSpecifier; |
| 21 |
import android.net.TelephonyNetworkSpecifier; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import com.android.internal.annotations.VisibleForTesting; |
| 26 |
import com.android.internal.annotations.VisibleForTesting.Visibility; |
| 27 |
import com.android.internal.util.ArrayUtils; |
| 28 |
|
| 29 |
import java.util.Arrays; |
| 30 |
import java.util.Objects; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public final class VcnUnderlyingNetworkSpecifier extends NetworkSpecifier implements Parcelable { |
| 40 |
@NonNull private final int[] mSubIds; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public VcnUnderlyingNetworkSpecifier(@NonNull int[] subIds) { |
| 48 |
mSubIds = Objects.requireNonNull(subIds, "subIds were null"); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@NonNull |
| 57 |
@VisibleForTesting(visibility = Visibility.PRIVATE) |
| 58 |
public int[] getSubIds() { |
| 59 |
return mSubIds; |
| 60 |
} |
| 61 |
|
| 62 |
public static final @NonNull Creator<VcnUnderlyingNetworkSpecifier> CREATOR = |
| 63 |
new Creator<VcnUnderlyingNetworkSpecifier>() { |
| 64 |
@Override |
| 65 |
public VcnUnderlyingNetworkSpecifier createFromParcel(Parcel in) { |
| 66 |
int[] subIds = in.createIntArray(); |
| 67 |
return new VcnUnderlyingNetworkSpecifier(subIds); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public VcnUnderlyingNetworkSpecifier[] newArray(int size) { |
| 72 |
return new VcnUnderlyingNetworkSpecifier[size]; |
| 73 |
} |
| 74 |
}; |
| 75 |
|
| 76 |
@Override |
| 77 |
public int describeContents() { |
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 83 |
dest.writeIntArray(mSubIds); |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public int hashCode() { |
| 88 |
return Arrays.hashCode(mSubIds); |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public boolean equals(Object obj) { |
| 93 |
if (this == obj) { |
| 94 |
return true; |
| 95 |
} |
| 96 |
if (!(obj instanceof VcnUnderlyingNetworkSpecifier)) { |
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
VcnUnderlyingNetworkSpecifier lhs = (VcnUnderlyingNetworkSpecifier) obj; |
| 101 |
return Arrays.equals(mSubIds, lhs.mSubIds); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
public String toString() { |
| 106 |
return new StringBuilder() |
| 107 |
.append("VcnUnderlyingNetworkSpecifier [") |
| 108 |
.append("mSubIds = ").append(Arrays.toString(mSubIds)) |
| 109 |
.append("]") |
| 110 |
.toString(); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
@Override |
| 115 |
public boolean canBeSatisfiedBy(NetworkSpecifier other) { |
| 116 |
if (other instanceof TelephonyNetworkSpecifier) { |
| 117 |
return ArrayUtils.contains( |
| 118 |
mSubIds, ((TelephonyNetworkSpecifier) other).getSubscriptionId()); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
return equals(other); |
| 124 |
} |
| 125 |
} |