1 /* 2 * Copyright (C) 2020 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.NetworkCapabilities; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Objects; 25 26 /** 27 * VcnUnderlyingNetworkPolicy represents the Network policy for a VCN-managed Network. 28 * 29 * <p>Transports that are bringing up networks capable of acting as a VCN's underlying network 30 * should query for policy state upon major capability changes (e.g. changing of TRUSTED bit), and 31 * when prompted by VcnManagementService via VcnUnderlyingNetworkPolicyListener. 32 * 33 * @hide 34 */ 35 public final class VcnUnderlyingNetworkPolicy implements Parcelable { 36 private final VcnNetworkPolicyResult mVcnNetworkPolicyResult; 37 38 /** 39 * Constructs a VcnUnderlyingNetworkPolicy with the specified parameters. 40 * 41 * @hide 42 */ VcnUnderlyingNetworkPolicy( boolean isTearDownRequested, @NonNull NetworkCapabilities mergedNetworkCapabilities)43 public VcnUnderlyingNetworkPolicy( 44 boolean isTearDownRequested, @NonNull NetworkCapabilities mergedNetworkCapabilities) { 45 Objects.requireNonNull( 46 mergedNetworkCapabilities, "mergedNetworkCapabilities must be nonnull"); 47 48 mVcnNetworkPolicyResult = 49 new VcnNetworkPolicyResult(isTearDownRequested, mergedNetworkCapabilities); 50 } 51 VcnUnderlyingNetworkPolicy(@onNull VcnNetworkPolicyResult vcnNetworkPolicyResult)52 private VcnUnderlyingNetworkPolicy(@NonNull VcnNetworkPolicyResult vcnNetworkPolicyResult) { 53 this.mVcnNetworkPolicyResult = 54 Objects.requireNonNull(vcnNetworkPolicyResult, "vcnNetworkPolicyResult"); 55 } 56 57 /** 58 * Returns whether this Carrier VCN policy policy indicates that the underlying Network should 59 * be torn down. 60 */ isTeardownRequested()61 public boolean isTeardownRequested() { 62 return mVcnNetworkPolicyResult.isTeardownRequested(); 63 } 64 65 /** 66 * Returns the NetworkCapabilities with Carrier VCN policy bits merged into the provided 67 * capabilities. 68 */ 69 @NonNull getMergedNetworkCapabilities()70 public NetworkCapabilities getMergedNetworkCapabilities() { 71 return mVcnNetworkPolicyResult.getNetworkCapabilities(); 72 } 73 74 @Override hashCode()75 public int hashCode() { 76 return Objects.hash(mVcnNetworkPolicyResult); 77 } 78 79 @Override equals(Object o)80 public boolean equals(Object o) { 81 if (this == o) return true; 82 if (!(o instanceof VcnUnderlyingNetworkPolicy)) return false; 83 final VcnUnderlyingNetworkPolicy that = (VcnUnderlyingNetworkPolicy) o; 84 85 return mVcnNetworkPolicyResult.equals(that.mVcnNetworkPolicyResult); 86 } 87 88 @Override toString()89 public String toString() { 90 return mVcnNetworkPolicyResult.toString(); 91 } 92 93 /** {@inheritDoc} */ 94 @Override describeContents()95 public int describeContents() { 96 return 0; 97 } 98 99 /** {@inheritDoc} */ 100 @Override writeToParcel(@onNull Parcel dest, int flags)101 public void writeToParcel(@NonNull Parcel dest, int flags) { 102 dest.writeParcelable(mVcnNetworkPolicyResult, flags); 103 } 104 105 /** Implement the Parcelable interface */ 106 public static final @NonNull Creator<VcnUnderlyingNetworkPolicy> CREATOR = 107 new Creator<VcnUnderlyingNetworkPolicy>() { 108 public VcnUnderlyingNetworkPolicy createFromParcel(Parcel in) { 109 return new VcnUnderlyingNetworkPolicy(in.readParcelable(null)); 110 } 111 112 public VcnUnderlyingNetworkPolicy[] newArray(int size) { 113 return new VcnUnderlyingNetworkPolicy[size]; 114 } 115 }; 116 } 117