blob: 12729d2acf47e22f17d8a7cc07b6c14392d9717f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.net.wifi;
18
19import android.os.Parcelable;
20import 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 */
28public class ScanResult implements Parcelable {
29 /** The network name. */
30 public String SSID;
Irfan Sheriffb6deeed2012-09-05 10:46:24 -070031
32 /** Ascii encoded SSID. This will replace SSID when we deprecate it. @hide */
33 public WifiSsid wifiSsid;
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 /** 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 Malchev06c43d52012-08-20 12:52:35 -070054 * Time Synchronization Function (tsf) timestamp in microseconds when
55 * this result was last seen.
56 */
Robert Greenwalt0451d592013-08-01 18:24:13 -070057 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 Malchev06c43d52012-08-20 12:52:35 -070077
Irfan Sheriffb6deeed2012-09-05 10:46:24 -070078 /** {@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 Project9066cfe2009-03-03 19:31:44 -080083 this.BSSID = BSSID;
84 this.capabilities = caps;
85 this.level = level;
86 this.frequency = frequency;
Iliyan Malchev06c43d52012-08-20 12:52:35 -070087 this.timestamp = tsf;
Robert Greenwalt0451d592013-08-01 18:24:13 -070088 this.distanceCm = UNSPECIFIED;
89 this.distanceSdCm = UNSPECIFIED;
Iliyan Malchev06c43d52012-08-20 12:52:35 -070090 }
91
Robert Greenwalt0451d592013-08-01 18:24:13 -070092 /** {@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 Sheriffb6deeed2012-09-05 10:46:24 -0700105
Iliyan Malchev06c43d52012-08-20 12:52:35 -0700106 /** copy constructor {@hide} */
107 public ScanResult(ScanResult source) {
108 if (source != null) {
Irfan Sheriffb6deeed2012-09-05 10:46:24 -0700109 wifiSsid = source.wifiSsid;
Iliyan Malchev06c43d52012-08-20 12:52:35 -0700110 SSID = source.SSID;
111 BSSID = source.BSSID;
112 capabilities = source.capabilities;
113 level = source.level;
114 frequency = source.frequency;
115 timestamp = source.timestamp;
Robert Greenwalt0451d592013-08-01 18:24:13 -0700116 distanceCm = source.distanceCm;
117 distanceSdCm = source.distanceSdCm;
Iliyan Malchev06c43d52012-08-20 12:52:35 -0700118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 }
120
121 @Override
122 public String toString() {
123 StringBuffer sb = new StringBuffer();
124 String none = "<none>";
125
126 sb.append("SSID: ").
Irfan Sheriffb6deeed2012-09-05 10:46:24 -0700127 append(wifiSsid == null ? WifiSsid.NONE : wifiSsid).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 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 Malchev06c43d52012-08-20 12:52:35 -0700135 append(frequency).
136 append(", timestamp: ").
137 append(timestamp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
Robert Greenwalt0451d592013-08-01 18:24:13 -0700139 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 Project9066cfe2009-03-03 19:31:44 -0800144 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 Sheriffb6deeed2012-09-05 10:46:24 -0700154 if (wifiSsid != null) {
155 dest.writeInt(1);
156 wifiSsid.writeToParcel(dest, flags);
157 } else {
158 dest.writeInt(0);
159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 dest.writeString(BSSID);
161 dest.writeString(capabilities);
162 dest.writeInt(level);
163 dest.writeInt(frequency);
Iliyan Malchev06c43d52012-08-20 12:52:35 -0700164 dest.writeLong(timestamp);
Robert Greenwalt0451d592013-08-01 18:24:13 -0700165 dest.writeInt(distanceCm);
166 dest.writeInt(distanceSdCm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 }
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 Sheriffb6deeed2012-09-05 10:46:24 -0700173 WifiSsid wifiSsid = null;
174 if (in.readInt() == 1) {
175 wifiSsid = WifiSsid.CREATOR.createFromParcel(in);
176 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 return new ScanResult(
Irfan Sheriffb6deeed2012-09-05 10:46:24 -0700178 wifiSsid,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 in.readString(),
180 in.readString(),
181 in.readInt(),
Iliyan Malchev06c43d52012-08-20 12:52:35 -0700182 in.readInt(),
Robert Greenwalt0451d592013-08-01 18:24:13 -0700183 in.readLong(),
184 in.readInt(),
185 in.readInt()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 );
187 }
188
189 public ScanResult[] newArray(int size) {
190 return new ScanResult[size];
191 }
192 };
193
194}