Debian Codegraph @

core/java/android/net/vcn/VcnNetworkPolicyResult.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.annotation.SystemApi;
21 import android.net.NetworkCapabilities;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24
25 import java.util.Objects;
26
27 /**
28 * VcnNetworkPolicyResult represents the Network policy result for a Network transport applying its
29 * VCN policy via {@link VcnManager#applyVcnNetworkPolicy(NetworkCapabilities, LinkProperties)}.
30 *
31 * <p>Bearers that are bringing up networks capable of acting as a VCN's underlying network should
32 * query for Network policy results upon any capability changes (e.g. changing of TRUSTED bit), and
33 * when prompted by VcnManagementService via {@link VcnManager.VcnNetworkPolicyListener}.
34 *
35 * @hide
36 */
37 @SystemApi
38 public final class VcnNetworkPolicyResult implements Parcelable {
39 private final boolean mIsTearDownRequested;
40 private final NetworkCapabilities mNetworkCapabilities;
41
42 /**
43 * Constructs a VcnNetworkPolicyResult with the specified parameters.
44 *
45 * @hide
46 */
47 public VcnNetworkPolicyResult(
48 boolean isTearDownRequested, @NonNull NetworkCapabilities networkCapabilities) {
49 Objects.requireNonNull(networkCapabilities, "networkCapabilities must be non-null");
50
51 mIsTearDownRequested = isTearDownRequested;
52 mNetworkCapabilities = networkCapabilities;
53 }
54
55 /**
56 * Returns whether this VCN policy result requires that the underlying Network should be torn
57 * down.
58 *
59 * <p>Upon querying for the current Network policy result, the bearer must check this method,
60 * and MUST tear down the corresponding Network if it returns true.
61 */
62 public boolean isTeardownRequested() {
63 return mIsTearDownRequested;
64 }
65
66 /**
67 * Returns the NetworkCapabilities that the bearer should be using for the corresponding
68 * Network.
69 */
70 @NonNull
71 public NetworkCapabilities getNetworkCapabilities() {
72 return mNetworkCapabilities;
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hash(mIsTearDownRequested, mNetworkCapabilities);
78 }
79
80 @Override
81 public boolean equals(Object o) {
82 if (this == o) return true;
83 if (!(o instanceof VcnNetworkPolicyResult)) return false;
84 final VcnNetworkPolicyResult that = (VcnNetworkPolicyResult) o;
85
86 return mIsTearDownRequested == that.mIsTearDownRequested
87 && mNetworkCapabilities.equals(that.mNetworkCapabilities);
88 }
89
90 @Override
91 public String toString() {
92 return "VcnNetworkPolicyResult { "
93 + "mIsTeardownRequested = "
94 + mIsTearDownRequested
95 + ", mNetworkCapabilities"
96 + mNetworkCapabilities
97 + " }";
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public int describeContents() {
103 return 0;
104 }
105
106 /** {@inheritDoc} */
107 @Override
108 public void writeToParcel(@NonNull Parcel dest, int flags) {
109 dest.writeBoolean(mIsTearDownRequested);
110 dest.writeParcelable(mNetworkCapabilities, flags);
111 }
112
113 /** Implement the Parcelable interface */
114 public static final @NonNull Creator<VcnNetworkPolicyResult> CREATOR =
115 new Creator<VcnNetworkPolicyResult>() {
116 public VcnNetworkPolicyResult createFromParcel(Parcel in) {
117 return new VcnNetworkPolicyResult(in.readBoolean(), in.readParcelable(null, android.net.NetworkCapabilities.class));
118 }
119
120 public VcnNetworkPolicyResult[] newArray(int size) {
121 return new VcnNetworkPolicyResult[size];
122 }
123 };
124 }