Debian Codegraph @

core/java/android/net/vcn/VcnUnderlyingNetworkSpecifier.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * NetworkSpecifier object for VCN underlying network requests.
34 *
35 * <p>This matches any underlying network with the appropriate subIds.
36 *
37 * @hide
38 */
39 public final class VcnUnderlyingNetworkSpecifier extends NetworkSpecifier implements Parcelable {
40 @NonNull private final int[] mSubIds;
41
42 /**
43 * Builds a new VcnUnderlyingNetworkSpecifier with the given list of subIds
44 *
45 * @hide
46 */
47 public VcnUnderlyingNetworkSpecifier(@NonNull int[] subIds) {
48 mSubIds = Objects.requireNonNull(subIds, "subIds were null");
49 }
50
51 /**
52 * Retrieves the list of subIds supported by this VcnUnderlyingNetworkSpecifier
53 *
54 * @hide
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 /** @hide */
114 @Override
115 public boolean canBeSatisfiedBy(NetworkSpecifier other) {
116 if (other instanceof TelephonyNetworkSpecifier) {
117 return ArrayUtils.contains(
118 mSubIds, ((TelephonyNetworkSpecifier) other).getSubscriptionId());
119 }
120 // TODO(b/180140053): Allow matching against WifiNetworkAgentSpecifier
121
122 // MatchAllNetworkSpecifier matched in NetworkCapabilities.
123 return equals(other);
124 }
125 }