1 /*
2  * Copyright (C) 2019 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.wifi;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.net.MacAddress;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.util.Log;
26 
27 import java.util.Objects;
28 
29 /** @hide */
30 @SystemApi
31 public final class WifiClient implements Parcelable {
32 
33     private static final String TAG = "WifiClient";
34 
35     private final MacAddress mMacAddress;
36 
37     /** The identifier of the AP instance which the client connected. */
38     private final String mApInstanceIdentifier;
39 
40     /**
41      * The mac address of this client.
42      */
43     @NonNull
getMacAddress()44     public MacAddress getMacAddress() {
45         return mMacAddress;
46     }
47 
48     /**
49      * Get AP instance identifier.
50      *
51      * The AP instance identifier is a unique identity which can be used to
52      * associate the {@link SoftApInfo} to a specific {@link WifiClient}
53      * - see {@link SoftApInfo#getApInstanceIdentifier()}
54      * @hide
55      */
56     @NonNull
getApInstanceIdentifier()57     public String getApInstanceIdentifier() {
58         return mApInstanceIdentifier;
59     }
60 
WifiClient(Parcel in)61     private WifiClient(Parcel in) {
62         mMacAddress = in.readParcelable(null);
63         mApInstanceIdentifier = in.readString();
64     }
65 
66     /** @hide */
WifiClient(@onNull MacAddress macAddress, @NonNull String apInstanceIdentifier)67     public WifiClient(@NonNull MacAddress macAddress, @NonNull String apInstanceIdentifier) {
68         if (macAddress == null) {
69             Log.wtf(TAG, "Null MacAddress provided");
70             this.mMacAddress = WifiManager.ALL_ZEROS_MAC_ADDRESS;
71         } else {
72             this.mMacAddress = macAddress;
73         }
74         this.mApInstanceIdentifier = apInstanceIdentifier;
75     }
76 
77     @Override
describeContents()78     public int describeContents() {
79         return 0;
80     }
81 
82     @Override
writeToParcel(@onNull Parcel dest, int flags)83     public void writeToParcel(@NonNull Parcel dest, int flags) {
84         dest.writeParcelable(mMacAddress, flags);
85         dest.writeString(mApInstanceIdentifier);
86     }
87 
88     @NonNull
89     public static final Creator<WifiClient> CREATOR = new Creator<WifiClient>() {
90         public WifiClient createFromParcel(Parcel in) {
91             return new WifiClient(in);
92         }
93 
94         public WifiClient[] newArray(int size) {
95             return new WifiClient[size];
96         }
97     };
98 
99     @NonNull
100     @Override
toString()101     public String toString() {
102         return "WifiClient{"
103                 + "mMacAddress=" + mMacAddress
104                 + "mApInstanceIdentifier=" + mApInstanceIdentifier
105                 + '}';
106     }
107 
108     @Override
equals(@ullable Object o)109     public boolean equals(@Nullable Object o) {
110         if (this == o) return true;
111         if (!(o instanceof WifiClient)) return false;
112         WifiClient client = (WifiClient) o;
113         return Objects.equals(mMacAddress, client.mMacAddress)
114                 && mApInstanceIdentifier.equals(client.mApInstanceIdentifier);
115     }
116 
117     @Override
hashCode()118     public int hashCode() {
119         return Objects.hash(mMacAddress, mApInstanceIdentifier);
120     }
121 }
122