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.nl80211;
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 
26 import java.util.Objects;
27 
28 /**
29  * Structure providing information about clients (STAs) associated with a SoftAp.
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class NativeWifiClient implements Parcelable {
35     private final MacAddress mMacAddress;
36 
37     /**
38      * The MAC address of the client (STA) represented by this object. The MAC address may be null
39      * in case of an error.
40      */
getMacAddress()41     @Nullable public MacAddress getMacAddress() {
42         return mMacAddress;
43     }
44 
45     /**
46      * Construct a native Wi-Fi client.
47      */
NativeWifiClient(@ullable MacAddress macAddress)48     public NativeWifiClient(@Nullable MacAddress macAddress) {
49         this.mMacAddress = macAddress;
50     }
51 
52     /** override comparator */
53     @Override
equals(Object rhs)54     public boolean equals(Object rhs) {
55         if (this == rhs) return true;
56         if (!(rhs instanceof NativeWifiClient)) {
57             return false;
58         }
59         NativeWifiClient other = (NativeWifiClient) rhs;
60         return Objects.equals(mMacAddress, other.mMacAddress);
61     }
62 
63     /** override hash code */
64     @Override
hashCode()65     public int hashCode() {
66         return mMacAddress.hashCode();
67     }
68 
69     /** implement Parcelable interface */
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     /**
76      * implement Parcelable interface
77      * |flag| is ignored.
78      */
79     @Override
writeToParcel(@onNull Parcel out, int flags)80     public void writeToParcel(@NonNull Parcel out, int flags) {
81         out.writeByteArray(mMacAddress.toByteArray());
82     }
83 
84     /** implement Parcelable interface */
85     @NonNull public static final Parcelable.Creator<NativeWifiClient> CREATOR =
86             new Parcelable.Creator<NativeWifiClient>() {
87                 @Override
88                 public NativeWifiClient createFromParcel(Parcel in) {
89                     MacAddress macAddress;
90                     try {
91                         macAddress = MacAddress.fromBytes(in.createByteArray());
92                     } catch (IllegalArgumentException e) {
93                         macAddress = null;
94                     }
95                     return new NativeWifiClient(macAddress);
96                 }
97 
98                 @Override
99                 public NativeWifiClient[] newArray(int size) {
100                     return new NativeWifiClient[size];
101                 }
102             };
103 }
104