• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.text.TextUtils;
24 
25 import java.util.Objects;
26 
27 /**
28  * A {@link NetworkSpecifier} used to identify ethernet interfaces.
29  *
30  * @see EthernetManager
31  */
32 public final class EthernetNetworkSpecifier extends NetworkSpecifier implements Parcelable {
33 
34     /**
35      * Name of the network interface.
36      */
37     @NonNull
38     private final String mInterfaceName;
39 
40     /**
41      * Create a new EthernetNetworkSpecifier.
42      * @param interfaceName Name of the ethernet interface the specifier refers to.
43      */
EthernetNetworkSpecifier(@onNull String interfaceName)44     public EthernetNetworkSpecifier(@NonNull String interfaceName) {
45         if (TextUtils.isEmpty(interfaceName)) {
46             throw new IllegalArgumentException();
47         }
48         mInterfaceName = interfaceName;
49     }
50 
51     /**
52      * Get the name of the ethernet interface the specifier refers to.
53      */
54     @Nullable
getInterfaceName()55     public String getInterfaceName() {
56         // This may be null in the future to support specifiers based on data other than the
57         // interface name.
58         return mInterfaceName;
59     }
60 
61     /** @hide */
62     @Override
canBeSatisfiedBy(@ullable NetworkSpecifier other)63     public boolean canBeSatisfiedBy(@Nullable NetworkSpecifier other) {
64         return equals(other);
65     }
66 
67     @Override
equals(@ullable Object o)68     public boolean equals(@Nullable Object o) {
69         if (!(o instanceof EthernetNetworkSpecifier)) return false;
70         return TextUtils.equals(mInterfaceName, ((EthernetNetworkSpecifier) o).mInterfaceName);
71     }
72 
73     @Override
hashCode()74     public int hashCode() {
75         return Objects.hashCode(mInterfaceName);
76     }
77 
78     @Override
toString()79     public String toString() {
80         return "EthernetNetworkSpecifier (" + mInterfaceName + ")";
81     }
82 
83     @Override
describeContents()84     public int describeContents() {
85         return 0;
86     }
87 
88     @Override
writeToParcel(@onNull Parcel dest, int flags)89     public void writeToParcel(@NonNull Parcel dest, int flags) {
90         dest.writeString(mInterfaceName);
91     }
92 
93     public static final @NonNull Parcelable.Creator<EthernetNetworkSpecifier> CREATOR =
94             new Parcelable.Creator<EthernetNetworkSpecifier>() {
95         public EthernetNetworkSpecifier createFromParcel(Parcel in) {
96             return new EthernetNetworkSpecifier(in.readString());
97         }
98         public EthernetNetworkSpecifier[] newArray(int size) {
99             return new EthernetNetworkSpecifier[size];
100         }
101     };
102 }
103