| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.display; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
|
| 24 |
import java.util.Objects; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public final class WifiDisplay implements Parcelable { |
| 35 |
private final String mDeviceAddress; |
| 36 |
private final String mDeviceName; |
| 37 |
private final String mDeviceAlias; |
| 38 |
private final boolean mIsAvailable; |
| 39 |
private final boolean mCanConnect; |
| 40 |
private final boolean mIsRemembered; |
| 41 |
|
| 42 |
public static final WifiDisplay[] EMPTY_ARRAY = new WifiDisplay[0]; |
| 43 |
|
| 44 |
public static final @android.annotation.NonNull Creator<WifiDisplay> CREATOR = new Creator<WifiDisplay>() { |
| 45 |
public WifiDisplay createFromParcel(Parcel in) { |
| 46 |
String deviceAddress = in.readString(); |
| 47 |
String deviceName = in.readString(); |
| 48 |
String deviceAlias = in.readString(); |
| 49 |
boolean isAvailable = (in.readInt() != 0); |
| 50 |
boolean canConnect = (in.readInt() != 0); |
| 51 |
boolean isRemembered = (in.readInt() != 0); |
| 52 |
return new WifiDisplay(deviceAddress, deviceName, deviceAlias, |
| 53 |
isAvailable, canConnect, isRemembered); |
| 54 |
} |
| 55 |
|
| 56 |
public WifiDisplay[] newArray(int size) { |
| 57 |
return size == 0 ? EMPTY_ARRAY : new WifiDisplay[size]; |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
public WifiDisplay(String deviceAddress, String deviceName, String deviceAlias, |
| 62 |
boolean available, boolean canConnect, boolean remembered) { |
| 63 |
if (deviceAddress == null) { |
| 64 |
throw new IllegalArgumentException("deviceAddress must not be null"); |
| 65 |
} |
| 66 |
if (deviceName == null) { |
| 67 |
throw new IllegalArgumentException("deviceName must not be null"); |
| 68 |
} |
| 69 |
|
| 70 |
mDeviceAddress = deviceAddress; |
| 71 |
mDeviceName = deviceName; |
| 72 |
mDeviceAlias = deviceAlias; |
| 73 |
mIsAvailable = available; |
| 74 |
mCanConnect = canConnect; |
| 75 |
mIsRemembered = remembered; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
@UnsupportedAppUsage |
| 82 |
public String getDeviceAddress() { |
| 83 |
return mDeviceAddress; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
@UnsupportedAppUsage |
| 90 |
public String getDeviceName() { |
| 91 |
return mDeviceName; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
@UnsupportedAppUsage |
| 102 |
public String getDeviceAlias() { |
| 103 |
return mDeviceAlias; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
@UnsupportedAppUsage |
| 110 |
public boolean isAvailable() { |
| 111 |
return mIsAvailable; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
@UnsupportedAppUsage |
| 118 |
public boolean canConnect() { |
| 119 |
return mCanConnect; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
@UnsupportedAppUsage |
| 126 |
public boolean isRemembered() { |
| 127 |
return mIsRemembered; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public String getFriendlyDisplayName() { |
| 135 |
return mDeviceAlias != null ? mDeviceAlias : mDeviceName; |
| 136 |
} |
| 137 |
|
| 138 |
@Override |
| 139 |
public boolean equals(@Nullable Object o) { |
| 140 |
return o instanceof WifiDisplay && equals((WifiDisplay)o); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
@UnsupportedAppUsage |
| 148 |
public boolean equals(WifiDisplay other) { |
| 149 |
return other != null |
| 150 |
&& mDeviceAddress.equals(other.mDeviceAddress) |
| 151 |
&& mDeviceName.equals(other.mDeviceName) |
| 152 |
&& Objects.equals(mDeviceAlias, other.mDeviceAlias); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public boolean hasSameAddress(WifiDisplay other) { |
| 161 |
return other != null && mDeviceAddress.equals(other.mDeviceAddress); |
| 162 |
} |
| 163 |
|
| 164 |
@Override |
| 165 |
public int hashCode() { |
| 166 |
|
| 167 |
return mDeviceAddress.hashCode(); |
| 168 |
} |
| 169 |
|
| 170 |
@Override |
| 171 |
public void writeToParcel(Parcel dest, int flags) { |
| 172 |
dest.writeString(mDeviceAddress); |
| 173 |
dest.writeString(mDeviceName); |
| 174 |
dest.writeString(mDeviceAlias); |
| 175 |
dest.writeInt(mIsAvailable ? 1 : 0); |
| 176 |
dest.writeInt(mCanConnect ? 1 : 0); |
| 177 |
dest.writeInt(mIsRemembered ? 1 : 0); |
| 178 |
} |
| 179 |
|
| 180 |
@Override |
| 181 |
public int describeContents() { |
| 182 |
return 0; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
@Override |
| 187 |
public String toString() { |
| 188 |
String result = mDeviceName + " (" + mDeviceAddress + ")"; |
| 189 |
if (mDeviceAlias != null) { |
| 190 |
result += ", alias " + mDeviceAlias; |
| 191 |
} |
| 192 |
result += ", isAvailable " + mIsAvailable + ", canConnect " + mCanConnect |
| 193 |
+ ", isRemembered " + mIsRemembered; |
| 194 |
return result; |
| 195 |
} |
| 196 |
} |