1 /* 2 * Copyright (C) 2023 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; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 25 /** 26 * Information about a local network. 27 * 28 * This is sent to ConnectivityManager.NetworkCallback. 29 * @hide 30 */ 31 // TODO : make public 32 public final class LocalNetworkInfo implements Parcelable { 33 @Nullable private final Network mUpstreamNetwork; 34 LocalNetworkInfo(@ullable final Network upstreamNetwork)35 public LocalNetworkInfo(@Nullable final Network upstreamNetwork) { 36 this.mUpstreamNetwork = upstreamNetwork; 37 } 38 39 /** 40 * Return the upstream network, or null if none. 41 */ 42 @Nullable getUpstreamNetwork()43 public Network getUpstreamNetwork() { 44 return mUpstreamNetwork; 45 } 46 47 @Override describeContents()48 public int describeContents() { 49 return 0; 50 } 51 52 @Override writeToParcel(@onNull final Parcel dest, final int flags)53 public void writeToParcel(@NonNull final Parcel dest, final int flags) { 54 dest.writeParcelable(mUpstreamNetwork, flags); 55 } 56 57 @Override toString()58 public String toString() { 59 return "LocalNetworkInfo { upstream=" + mUpstreamNetwork + " }"; 60 } 61 62 public static final @NonNull Creator<LocalNetworkInfo> CREATOR = new Creator<>() { 63 public LocalNetworkInfo createFromParcel(Parcel in) { 64 final Network upstreamNetwork = in.readParcelable(null); 65 return new LocalNetworkInfo(upstreamNetwork); 66 } 67 68 @Override 69 public LocalNetworkInfo[] newArray(final int size) { 70 return new LocalNetworkInfo[size]; 71 } 72 }; 73 74 /** 75 * Builder for LocalNetworkInfo 76 */ 77 public static final class Builder { 78 @Nullable private Network mUpstreamNetwork; 79 80 /** 81 * Set the upstream network, or null if none. 82 * @return the builder 83 */ setUpstreamNetwork(@ullable final Network network)84 @NonNull public Builder setUpstreamNetwork(@Nullable final Network network) { 85 mUpstreamNetwork = network; 86 return this; 87 } 88 89 /** 90 * Build the LocalNetworkInfo 91 */ build()92 @NonNull public LocalNetworkInfo build() { 93 return new LocalNetworkInfo(mUpstreamNetwork); 94 } 95 } 96 } 97