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. 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 /** 54 * Time Synchronization Function (tsf) timestamp in microseconds when 55 * this result was last seen. 56 */ 57 public long timestamp; 58 59 /** {@hide} */ 60 public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency, 61 long tsf) { 62 this.wifiSsid = wifiSsid; 63 this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE; 64 this.BSSID = BSSID; 65 this.capabilities = caps; 66 this.level = level; 67 this.frequency = frequency; 68 this.timestamp = tsf; 69 } 70 71 72 /** copy constructor {@hide} */ 73 public ScanResult(ScanResult source) { 74 if (source != null) { 75 wifiSsid = source.wifiSsid; 76 SSID = source.SSID; 77 BSSID = source.BSSID; 78 capabilities = source.capabilities; 79 level = source.level; 80 frequency = source.frequency; 81 timestamp = source.timestamp; 82 } 83 } 84 85 @Override 86 public String toString() { 87 StringBuffer sb = new StringBuffer(); 88 String none = "<none>"; 89 90 sb.append("SSID: "). 91 append(wifiSsid == null ? WifiSsid.NONE : wifiSsid). 92 append(", BSSID: "). 93 append(BSSID == null ? none : BSSID). 94 append(", capabilities: "). 95 append(capabilities == null ? none : capabilities). 96 append(", level: "). 97 append(level). 98 append(", frequency: "). 99 append(frequency). 100 append(", timestamp: "). 101 append(timestamp); 102 103 return sb.toString(); 104 } 105 106 /** Implement the Parcelable interface {@hide} */ 107 public int describeContents() { 108 return 0; 109 } 110 111 /** Implement the Parcelable interface {@hide} */ 112 public void writeToParcel(Parcel dest, int flags) { 113 if (wifiSsid != null) { 114 dest.writeInt(1); 115 wifiSsid.writeToParcel(dest, flags); 116 } else { 117 dest.writeInt(0); 118 } 119 dest.writeString(BSSID); 120 dest.writeString(capabilities); 121 dest.writeInt(level); 122 dest.writeInt(frequency); 123 dest.writeLong(timestamp); 124 } 125 126 /** Implement the Parcelable interface {@hide} */ 127 public static final Creator<ScanResult> CREATOR = 128 new Creator<ScanResult>() { 129 public ScanResult createFromParcel(Parcel in) { 130 WifiSsid wifiSsid = null; 131 if (in.readInt() == 1) { 132 wifiSsid = WifiSsid.CREATOR.createFromParcel(in); 133 } 134 return new ScanResult( 135 wifiSsid, 136 in.readString(), 137 in.readString(), 138 in.readInt(), 139 in.readInt(), 140 in.readLong() 141 ); 142 } 143 144 public ScanResult[] newArray(int size) { 145 return new ScanResult[size]; 146 } 147 }; 148 149} 150