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