ScanResult.java revision 137ff532ebb062ea513d6ea0dd894b91f373d1a3
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 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; 31 32 /** Ascii encoded SSID. This will replace SSID when we deprecate it. @hide */ 33 public WifiSsid wifiSsid; 34 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. 44 */ 45 public int level; 46 /** 47 * The frequency in MHz of the channel over which the client is communicating 48 * with the access point. 49 */ 50 public int frequency; 51 52 /** 53 * Time Synchronization Function (tsf) timestamp in microseconds when 54 * this result was last seen. 55 */ 56 public long timestamp; 57 58 /** 59 * The approximate distance to the AP in centimeter, if available. Else 60 * {@link UNSPECIFIED}. 61 * {@hide} 62 */ 63 public int distanceCm; 64 65 /** 66 * The standard deviation of the distance to the AP, if available. 67 * Else {@link UNSPECIFIED}. 68 * {@hide} 69 */ 70 public int distanceSdCm; 71 72 /** 73 * {@hide} 74 */ 75 public final static int UNSPECIFIED = -1; 76 77 /** {@hide} */ 78 public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency, 79 long tsf) { 80 this.wifiSsid = wifiSsid; 81 this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; 82 this.BSSID = BSSID; 83 this.capabilities = caps; 84 this.level = level; 85 this.frequency = frequency; 86 this.timestamp = tsf; 87 this.distanceCm = UNSPECIFIED; 88 this.distanceSdCm = UNSPECIFIED; 89 } 90 91 /** {@hide} */ 92 public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency, 93 long tsf, int distCm, int distSdCm) { 94 this.wifiSsid = wifiSsid; 95 this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; 96 this.BSSID = BSSID; 97 this.capabilities = caps; 98 this.level = level; 99 this.frequency = frequency; 100 this.timestamp = tsf; 101 this.distanceCm = distCm; 102 this.distanceSdCm = distSdCm; 103 } 104 105 /** copy constructor {@hide} */ 106 public ScanResult(ScanResult source) { 107 if (source != null) { 108 wifiSsid = source.wifiSsid; 109 SSID = source.SSID; 110 BSSID = source.BSSID; 111 capabilities = source.capabilities; 112 level = source.level; 113 frequency = source.frequency; 114 timestamp = source.timestamp; 115 distanceCm = source.distanceCm; 116 distanceSdCm = source.distanceSdCm; 117 } 118 } 119 120 @Override 121 public String toString() { 122 StringBuffer sb = new StringBuffer(); 123 String none = "<none>"; 124 125 sb.append("SSID: "). 126 append(wifiSsid == null ? WifiSsid.NONE : wifiSsid). 127 append(", BSSID: "). 128 append(BSSID == null ? none : BSSID). 129 append(", capabilities: "). 130 append(capabilities == null ? none : capabilities). 131 append(", level: "). 132 append(level). 133 append(", frequency: "). 134 append(frequency). 135 append(", timestamp: "). 136 append(timestamp); 137 138 sb.append(", distance: ").append((distanceCm != UNSPECIFIED ? distanceCm : "?")). 139 append("(cm)"); 140 sb.append(", distanceSd: ").append((distanceSdCm != UNSPECIFIED ? distanceSdCm : "?")). 141 append("(cm)"); 142 143 return sb.toString(); 144 } 145 146 /** Implement the Parcelable interface {@hide} */ 147 public int describeContents() { 148 return 0; 149 } 150 151 /** Implement the Parcelable interface {@hide} */ 152 public void writeToParcel(Parcel dest, int flags) { 153 if (wifiSsid != null) { 154 dest.writeInt(1); 155 wifiSsid.writeToParcel(dest, flags); 156 } else { 157 dest.writeInt(0); 158 } 159 dest.writeString(BSSID); 160 dest.writeString(capabilities); 161 dest.writeInt(level); 162 dest.writeInt(frequency); 163 dest.writeLong(timestamp); 164 dest.writeInt(distanceCm); 165 dest.writeInt(distanceSdCm); 166 } 167 168 /** Implement the Parcelable interface {@hide} */ 169 public static final Creator<ScanResult> CREATOR = 170 new Creator<ScanResult>() { 171 public ScanResult createFromParcel(Parcel in) { 172 WifiSsid wifiSsid = null; 173 if (in.readInt() == 1) { 174 wifiSsid = WifiSsid.CREATOR.createFromParcel(in); 175 } 176 return new ScanResult( 177 wifiSsid, 178 in.readString(), 179 in.readString(), 180 in.readInt(), 181 in.readInt(), 182 in.readLong(), 183 in.readInt(), 184 in.readInt() 185 ); 186 } 187 188 public ScanResult[] newArray(int size) { 189 return new ScanResult[size]; 190 } 191 }; 192 193} 194