The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.os.Parcelable; |
| 20 | import android.os.Parcel; |
| 21 | |
| 22 | /** |
| 23 | * Describes information about a detected access point. In addition |
| 24 | * to the attributes described here, the supplicant keeps track of |
| 25 | * {@code quality}, {@code noise}, and {@code maxbitrate} attributes, |
| 26 | * but does not currently report them to external clients. |
| 27 | */ |
| 28 | public class ScanResult implements Parcelable { |
| 29 | /** The network name. */ |
| 30 | public String SSID; |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 31 | |
| 32 | /** Ascii encoded SSID. This will replace SSID when we deprecate it. @hide */ |
| 33 | public WifiSsid wifiSsid; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | /** The address of the access point. */ |
| 36 | public String BSSID; |
| 37 | /** |
| 38 | * Describes the authentication, key management, and encryption schemes |
| 39 | * supported by the access point. |
| 40 | */ |
| 41 | public String capabilities; |
| 42 | /** |
| 43 | * The detected signal level in dBm. At least those are the units used by |
| 44 | * the TI driver. |
| 45 | */ |
| 46 | public int level; |
| 47 | /** |
| 48 | * The frequency in MHz of the channel over which the client is communicating |
| 49 | * with the access point. |
| 50 | */ |
| 51 | public int frequency; |
| 52 | |
| 53 | /** |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 54 | * Time Synchronization Function (tsf) timestamp in microseconds when |
| 55 | * this result was last seen. |
| 56 | */ |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 57 | public long timestamp; |
| 58 | |
| 59 | /** |
| 60 | * The approximate distance to the AP in centimeter, if available. Else |
| 61 | * {@link UNSPECIFIED}. |
| 62 | * {@hide} |
| 63 | */ |
| 64 | public int distanceCm; |
| 65 | |
| 66 | /** |
| 67 | * The standard deviation of the distance to the AP, if available. |
| 68 | * Else {@link UNSPECIFIED}. |
| 69 | * {@hide} |
| 70 | */ |
| 71 | public int distanceSdCm; |
| 72 | |
| 73 | /** |
| 74 | * {@hide} |
| 75 | */ |
| 76 | public final static int UNSPECIFIED = -1; |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 77 | |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 78 | /** {@hide} */ |
| 79 | public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency, |
| 80 | long tsf) { |
| 81 | this.wifiSsid = wifiSsid; |
| 82 | this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | this.BSSID = BSSID; |
| 84 | this.capabilities = caps; |
| 85 | this.level = level; |
| 86 | this.frequency = frequency; |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 87 | this.timestamp = tsf; |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 88 | this.distanceCm = UNSPECIFIED; |
| 89 | this.distanceSdCm = UNSPECIFIED; |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 92 | /** {@hide} */ |
| 93 | public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency, |
| 94 | long tsf, int distCm, int distSdCm) { |
| 95 | this.wifiSsid = wifiSsid; |
| 96 | this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; |
| 97 | this.BSSID = BSSID; |
| 98 | this.capabilities = caps; |
| 99 | this.level = level; |
| 100 | this.frequency = frequency; |
| 101 | this.timestamp = tsf; |
| 102 | this.distanceCm = distCm; |
| 103 | this.distanceSdCm = distSdCm; |
| 104 | } |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 105 | |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 106 | /** copy constructor {@hide} */ |
| 107 | public ScanResult(ScanResult source) { |
| 108 | if (source != null) { |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 109 | wifiSsid = source.wifiSsid; |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 110 | SSID = source.SSID; |
| 111 | BSSID = source.BSSID; |
| 112 | capabilities = source.capabilities; |
| 113 | level = source.level; |
| 114 | frequency = source.frequency; |
| 115 | timestamp = source.timestamp; |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 116 | distanceCm = source.distanceCm; |
| 117 | distanceSdCm = source.distanceSdCm; |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public String toString() { |
| 123 | StringBuffer sb = new StringBuffer(); |
| 124 | String none = "<none>"; |
| 125 | |
| 126 | sb.append("SSID: "). |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 127 | append(wifiSsid == null ? WifiSsid.NONE : wifiSsid). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | append(", BSSID: "). |
| 129 | append(BSSID == null ? none : BSSID). |
| 130 | append(", capabilities: "). |
| 131 | append(capabilities == null ? none : capabilities). |
| 132 | append(", level: "). |
| 133 | append(level). |
| 134 | append(", frequency: "). |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 135 | append(frequency). |
| 136 | append(", timestamp: "). |
| 137 | append(timestamp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 139 | sb.append(", distance: ").append((distanceCm != UNSPECIFIED ? distanceCm : "?")). |
| 140 | append("(cm)"); |
| 141 | sb.append(", distanceSd: ").append((distanceSdCm != UNSPECIFIED ? distanceSdCm : "?")). |
| 142 | append("(cm)"); |
| 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | return sb.toString(); |
| 145 | } |
| 146 | |
| 147 | /** Implement the Parcelable interface {@hide} */ |
| 148 | public int describeContents() { |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /** Implement the Parcelable interface {@hide} */ |
| 153 | public void writeToParcel(Parcel dest, int flags) { |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 154 | if (wifiSsid != null) { |
| 155 | dest.writeInt(1); |
| 156 | wifiSsid.writeToParcel(dest, flags); |
| 157 | } else { |
| 158 | dest.writeInt(0); |
| 159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | dest.writeString(BSSID); |
| 161 | dest.writeString(capabilities); |
| 162 | dest.writeInt(level); |
| 163 | dest.writeInt(frequency); |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 164 | dest.writeLong(timestamp); |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 165 | dest.writeInt(distanceCm); |
| 166 | dest.writeInt(distanceSdCm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** Implement the Parcelable interface {@hide} */ |
| 170 | public static final Creator<ScanResult> CREATOR = |
| 171 | new Creator<ScanResult>() { |
| 172 | public ScanResult createFromParcel(Parcel in) { |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 173 | WifiSsid wifiSsid = null; |
| 174 | if (in.readInt() == 1) { |
| 175 | wifiSsid = WifiSsid.CREATOR.createFromParcel(in); |
| 176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | return new ScanResult( |
Irfan Sheriff | b6deeed | 2012-09-05 10:46:24 -0700 | [diff] [blame] | 178 | wifiSsid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | in.readString(), |
| 180 | in.readString(), |
| 181 | in.readInt(), |
Iliyan Malchev | 06c43d5 | 2012-08-20 12:52:35 -0700 | [diff] [blame] | 182 | in.readInt(), |
Robert Greenwalt | 0451d59 | 2013-08-01 18:24:13 -0700 | [diff] [blame] | 183 | in.readLong(), |
| 184 | in.readInt(), |
| 185 | in.readInt() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | ); |
| 187 | } |
| 188 | |
| 189 | public ScanResult[] newArray(int size) { |
| 190 | return new ScanResult[size]; |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | } |