diff options
Diffstat (limited to 'wifi/java/android/net')
| -rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/RttManager.java | 329 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/ScanResult.java | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiConfiguration.java | 242 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiEnterpriseConfig.java | 2 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 182 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiScanner.java | 2 |
7 files changed, 460 insertions, 309 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 5342494..0e888e8 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -47,6 +47,8 @@ interface IWifiManager List<WifiConfiguration> getPrivilegedConfiguredNetworks(); + WifiConfiguration getMatchingWifiConfig(in ScanResult scanResult); + int addOrUpdateNetwork(in WifiConfiguration config); boolean removeNetwork(int netId); @@ -113,6 +115,8 @@ interface IWifiManager WifiConfiguration getWifiApConfiguration(); + WifiConfiguration buildWifiConfig(String uriString, String mimeType, in byte[] data); + void setWifiApConfiguration(in WifiConfiguration wifiConfig); void startWifi(); @@ -162,5 +166,7 @@ interface IWifiManager WifiConnectionStatistics getConnectionStatistics(); void disableEphemeralNetwork(String SSID); + + void factoryReset(); } diff --git a/wifi/java/android/net/wifi/RttManager.java b/wifi/java/android/net/wifi/RttManager.java index 65ecf5d..b156d0c 100644 --- a/wifi/java/android/net/wifi/RttManager.java +++ b/wifi/java/android/net/wifi/RttManager.java @@ -26,51 +26,109 @@ public class RttManager { private static final boolean DBG = true; private static final String TAG = "RttManager"; - /** @deprecated Type must be specified*/ + /** @deprecated It is Not supported anymore. */ @Deprecated public static final int RTT_TYPE_UNSPECIFIED = 0; + public static final int RTT_TYPE_ONE_SIDED = 1; + public static final int RTT_TYPE_TWO_SIDED = 2; - /** @deprecated It is not supported*/ + /** @deprecated It is not supported anymore. */ @Deprecated public static final int RTT_TYPE_11_V = 2; - public static final int RTT_TYPE_TWO_SIDED = 4; - /** @deprecated It is not supported*/ + /** @deprecated It is not supported anymore. */ @Deprecated public static final int RTT_TYPE_11_MC = 4; + /** @deprecated It is not supported anymore. */ + @Deprecated public static final int RTT_PEER_TYPE_UNSPECIFIED = 0; + public static final int RTT_PEER_TYPE_AP = 1; public static final int RTT_PEER_TYPE_STA = 2; /* requires NAN */ + public static final int RTT_PEER_P2P_GO = 3; + public static final int RTT_PEER_P2P_CLIENT = 4; + public static final int RTT_PEER_NAN = 5; + /** + * @deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_20_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_20 = 0; + + /** + * @deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_40_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_40 = 1; + + /** + * @deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_80_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_80 = 2; + + /**@deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_160_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_160 = 3; + + /**@deprecated not supported anymore*/ + @Deprecated public static final int RTT_CHANNEL_WIDTH_80P80 = 4; + + /**@deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_5_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_5 = 5; + + /**@deprecated It is not supported anymore. + * Use {@link android.net.wifi.RttManager#RTT_BW_10_SUPPORT} API. + */ + @Deprecated public static final int RTT_CHANNEL_WIDTH_10 = 6; - /** @deprecated channel info must be specified*/ + /** @deprecated channel info must be specified. */ @Deprecated public static final int RTT_CHANNEL_WIDTH_UNSPECIFIED = -1; public static final int RTT_STATUS_SUCCESS = 0; + /** General failure*/ public static final int RTT_STATUS_FAILURE = 1; + /** Destination does not respond to RTT request*/ public static final int RTT_STATUS_FAIL_NO_RSP = 2; + /** RTT request is rejected by the destination. Double side RTT only*/ public static final int RTT_STATUS_FAIL_REJECTED = 3; + /** */ public static final int RTT_STATUS_FAIL_NOT_SCHEDULED_YET = 4; + /** Timing measurement timeout*/ public static final int RTT_STATUS_FAIL_TM_TIMEOUT = 5; + /** Destination is on a different channel from the RTT Request*/ public static final int RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL = 6; + /** This type of Ranging is not support by Hardware*/ public static final int RTT_STATUS_FAIL_NO_CAPABILITY = 7; + /** Request abort fro uncertain reason*/ public static final int RTT_STATUS_ABORTED = 8; - //if the T1-T4 or TOD/TOA Timestamp is illegal + /** The T1-T4 or TOD/TOA Timestamp is illegal*/ public static final int RTT_STATUS_FAIL_INVALID_TS = 9; - //11mc protocol failed, eg, unrecognized FTMR/FTM + /** 11mc protocol level failed, eg, unrecognized FTMR/FTM frame*/ public static final int RTT_STATUS_FAIL_PROTOCOL = 10; + /** Request can not be scheduled by hardware*/ public static final int RTT_STATUS_FAIL_SCHEDULE = 11; + /** destination is busy now, you can try after a specified time from destination*/ public static final int RTT_STATUS_FAIL_BUSY_TRY_LATER = 12; + /** Bad Request argument*/ + public static final int RTT_STATUS_INVALID_REQ = 13; + /** Wifi is not enabled*/ + public static final int RTT_STATUS_NO_WIFI = 14; + /** Responder overrides param info, cannot range with new params 2-side RTT only*/ + public static final int RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE = 15; public static final int REASON_UNSPECIFIED = -1; public static final int REASON_NOT_AVAILABLE = -2; @@ -80,30 +138,30 @@ public class RttManager { public static final String DESCRIPTION_KEY = "android.net.wifi.RttManager.Description"; /** - * RTT BW supported bit mask + * RTT BW supported bit mask, used as RTT param bandWidth too */ - public static final int RTT_BW_5_SUPPORT = 0x1; - public static final int RTT_BW_10_SUPPORT = 0x2; - public static final int RTT_BW_20_SUPPORT = 0x4; - public static final int RTT_BW_40_SUPPORT = 0x8; + public static final int RTT_BW_5_SUPPORT = 0x01; + public static final int RTT_BW_10_SUPPORT = 0x02; + public static final int RTT_BW_20_SUPPORT = 0x04; + public static final int RTT_BW_40_SUPPORT = 0x08; public static final int RTT_BW_80_SUPPORT = 0x10; public static final int RTT_BW_160_SUPPORT = 0x20; /** * RTT Preamble Support bit mask */ - public static final int PREAMBLE_LEGACY = 0x1; - public static final int PREAMBLE_HT = 0x2; - public static final int PREAMBLE_VHT = 0x4; + public static final int PREAMBLE_LEGACY = 0x01; + public static final int PREAMBLE_HT = 0x02; + public static final int PREAMBLE_VHT = 0x04; - /** @deprecated It has been replaced by RttCapabilities*/ + /** @deprecated Use the new {@link android.net.wifi.RttManager.RttCapabilities} API */ @Deprecated public class Capabilities { public int supportedType; public int supportedPeerType; } - /** @deprecated It has been replaced by getRttCapabilities*/ + /** @deprecated Use the new {@link android.net.wifi.RttManager#getRttCapabilities()} API.*/ @Deprecated public Capabilities getCapabilities() { return new Capabilities(); @@ -241,28 +299,35 @@ public class RttManager { /** specifies parameters for RTT request */ public static class RttParams { /** - * type of destination device being ranged; one of RTT_PEER_TYPE_AP or RTT_PEER_TYPE_STA + * type of destination device being ranged + * currently only support RTT_PEER_TYPE_AP + * Range:RTT_PEER_TYPE_xxxx Default value:RTT_PEER_TYPE_AP */ public int deviceType; /** - * type of RTT measurement method; one of RTT_TYPE_ONE_SIDED or RTT_TYPE_TWO_SIDED. + * type of RTT measurement method. Need check scan result and RttCapabilities first + * Range: RTT_TYPE_ONE_SIDED or RTT_TYPE_TWO_SIDED + * Default value: RTT_TYPE_ONE_SIDED */ public int requestType; - /** mac address of the device being ranged */ + /** + * mac address of the device being ranged + * Default value: null + */ public String bssid; /** - * The primary 20 MHz frequency (in MHz) of the channel over which the client is - * communicating with the access point.Similar as ScanResult.frequency + * The primary control channel over which the client is + * communicating with the AP.Same as ScanResult.frequency + * Default value: 0 */ public int frequency; /** - * channel width used for RTT measurement. User need verify the highest BW the destination - * support (from scan result etc) before set this value. Wider channels result usually give - * better accuracy. However, the frame loss can increase. Similar as ScanResult.channelWidth + * channel width of the destination AP. Same as ScanResult.channelWidth + * Default value: 0 */ public int channelWidth; @@ -270,77 +335,113 @@ public class RttManager { * Not used if the AP bandwidth is 20 MHz * If the AP use 40, 80 or 160 MHz, this is the center frequency * if the AP use 80 + 80 MHz, this is the center frequency of the first segment - * similar as ScanResult.centerFreq0 + * same as ScanResult.centerFreq0 + * Default value: 0 */ public int centerFreq0; /** * Only used if the AP bandwidth is 80 + 80 MHz * if the AP use 80 + 80 MHz, this is the center frequency of the second segment - * similar as ScanResult.centerFreq1 + * same as ScanResult.centerFreq1 + * Default value: 0 */ public int centerFreq1; + /** * number of samples to be taken - * @deprecated It has been replaced by numSamplesPerBurst + * @deprecated Use the new {@link android.net.wifi.RttManager.RttParams#numSamplesPerBurst} */ @Deprecated public int num_samples; /** * number of retries if a sample fails - * @deprecated It has been replaced by numRetriesPerMeasurementFrame + * @deprecated + * Use {@link android.net.wifi.RttManager.RttParams#numRetriesPerMeasurementFrame} API. */ @Deprecated public int num_retries; - /** Number of burst. fixed to 1 for single side RTT*/ + /** Number of burst in exp , 2^x. 0 means single shot measurement, range 0-15 + * Currently only single shot is supported + * Default value: 0 + */ public int numberBurst; - /** valid only if numberBurst > 1, interval between burst(ms). Not used by singe side RTT */ + /** + * valid only if numberBurst > 1, interval between burst(100ms). + * Range : 0-31, 0--means no specific + * Default value: 0 + */ public int interval; - /** number of samples to be taken in one burst*/ + /** + * number of samples to be taken in one burst + * Range: 1-31 + * Default value: 8 + */ public int numSamplesPerBurst; /** number of retries for each measurement frame if a sample fails - * Only used by single side RTT + * Only used by single side RTT, + * Range 0 - 3 Default value: 0 */ public int numRetriesPerMeasurementFrame; - /** number of retries for FTMR frame if fails Only used by 80211MC double side RTT */ + /** + * number of retries for FTMR frame (control frame) if it fails. + * Only used by 80211MC double side RTT + * Range: 0-3 Default Value : 0 + */ public int numRetriesPerFTMR; - /** Request LCI information */ + /** + * Request LCI information, only available when choose double side RTT measurement + * need check RttCapabilties first. + * Default value: false + * */ public boolean LCIRequest; - /** Request LCR information */ + /** + * Request LCR information, only available when choose double side RTT measurement + * need check RttCapabilties first. + * Default value: false + * */ public boolean LCRRequest; - /** Timeout for each burst, unit of 250 us*/ + /** + * Timeout for each burst, (250 * 2^x) us, + * Range 1-11 and 15. 15 means no control Default value: 15 + * */ public int burstTimeout; /** preamble used for RTT measurement - * should be one of PREAMBLE_LEGACY, PREAMBLE_HT, PREAMBLE_VHT + * Range: PREAMBLE_LEGACY, PREAMBLE_HT, PREAMBLE_VHT + * Default value: PREAMBLE_HT */ public int preamble; /** bandWidth used for RTT measurement.User need verify the highest BW the destination * support (from scan result etc) before set this value. Wider channels result usually give * better accuracy. However, the frame loss can increase too. - * should be one of RTT_CHANNEL_WIDTH_20 to RTT_CHANNEL_WIDTH_80 + * should be one of RTT_BW_5_SUPPORT to RTT_BW_160_SUPPORT. However, need check + * RttCapabilities firstto verify HW support this bandwidth. + * Default value:RTT_BW_20_SUPPORT */ public int bandwidth; public RttParams() { //provide initial value for RttParams deviceType = RTT_PEER_TYPE_AP; - numberBurst = 1; + requestType = RTT_TYPE_ONE_SIDED; + numberBurst = 0; numSamplesPerBurst = 8; numRetriesPerMeasurementFrame = 0; - burstTimeout = 40 + numSamplesPerBurst *4; - preamble = PREAMBLE_LEGACY; - bandwidth = RTT_CHANNEL_WIDTH_20; + numRetriesPerFTMR = 0; + burstTimeout = 15; + preamble = PREAMBLE_HT; + bandwidth = RTT_BW_20_SUPPORT; } } @@ -430,26 +531,29 @@ public class RttManager { }; } - public class wifiInformationElement { - /** Information Element ID*/ - public int id; - public String data; + public static class WifiInformationElement { + /** Information Element ID 0xFF means element is invalid. */ + public byte id; + public byte[] data; } /** specifies RTT results */ public static class RttResult { - /** mac address of the device being ranged */ + /** mac address of the device being ranged. */ public String bssid; - /** # of burst for this measurement*/ + /** # of burst for this measurement. */ public int burstNumber; - /** total number of measurement frames in this measurement*/ + /** total number of measurement frames attempted in this measurement. */ public int measurementFrameNumber; - /** total successful number of measurement frames in this measurement*/ + /** total successful number of measurement frames in this measurement. */ public int successMeasurementFrameNumber; - /** Maximum number of frames per burst supported by peer */ + /** + * Maximum number of frames per burst supported by peer. Two side RTT only + * Valid only if less than request + */ public int frameNumberPerBurstPeer; /** status of the request */ @@ -457,120 +561,128 @@ public class RttManager { /** * type of the request used - * @deprecated It has been replaced by measurementType + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#measurementType} */ @Deprecated public int requestType; - /** RTT measurement method type used, shoudl be one of RTT_TYPE_ONE_SIDED or + /** RTT measurement method type used, should be one of RTT_TYPE_ONE_SIDED or * RTT_TYPE_TWO_SIDED. */ public int measurementType; - /** please retry RTT measurement after this S since peer indicate busy at ths moment*/ + /** + * only valid when status == RTT_STATUS_FAIL_BUSY_TRY_LATER + * please retry RTT measurement after this duration since peer indicate busy at ths moment + * Unit S Range:1-31 + */ public int retryAfterDuration; - /** timestamp of completion, in microsecond since boot */ + /** timestamp of completion, in microsecond since boot. */ public long ts; - /** average RSSI observed, unit of 0.5 dB */ + /** average RSSI observed, unit of 0.5 dB. */ public int rssi; /** * RSSI spread (i.e. max - min) - * @deprecated It has been replaced by rssi_spread + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#rssiSpread} API. */ @Deprecated public int rssi_spread; - /**RSSI spread (i.e. max - min), unit of 0.5 dB */ + /**RSSI spread (i.e. max - min), unit of 0.5 dB. */ public int rssiSpread; /** * average transmit rate - * @deprecated It has been replaced by txRate + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#txRate} API. */ @Deprecated public int tx_rate; - /** average transmit rate */ + /** average transmit rate. Unit (100kbps). */ public int txRate; - /** average receiving rate */ + /** average receiving rate Unit (100kbps). */ public int rxRate; /** * average round trip time in nano second - * @deprecated It has been replaced by rtt + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#rtt} API. */ @Deprecated public long rtt_ns; - /** average round trip time in 0.1 nano second */ + /** average round trip time in 0.1 nano second. */ public long rtt; /** * standard deviation observed in round trip time - * @deprecated It has been replaced by rttStandardDeviation + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#rttStandardDeviation} API. */ @Deprecated public long rtt_sd_ns; - /** standard deviation of RTT in 0.1 ns */ + /** standard deviation of RTT in 0.1 ns. */ public long rttStandardDeviation; /** * spread (i.e. max - min) round trip time - * @deprecated It has been replaced by rttSpread + * @deprecated Use {@link android.net.wifi.RttManager.RttResult#rttSpread} API. */ @Deprecated public long rtt_spread_ns; - /** spread (i.e. max - min) RTT in 0.1 ns */ + /** spread (i.e. max - min) RTT in 0.1 ns. */ public long rttSpread; /** * average distance in centimeter, computed based on rtt_ns - * @deprecated It has been replaced by distance + * @deprecated use {@link android.net.wifi.RttManager.RttResult#distance} API. */ @Deprecated public int distance_cm; - /** average distance in cm, computed based on rtt */ + /** average distance in cm, computed based on rtt. */ public int distance; /** * standard deviation observed in distance - * @deprecated It has been replaced with distanceStandardDeviation + * @deprecated + * Use {@link .android.net.wifi.RttManager.RttResult#distanceStandardDeviation} API. */ @Deprecated public int distance_sd_cm; - /** standard deviation observed in distance in cm*/ + /** standard deviation observed in distance in cm. */ public int distanceStandardDeviation; /** * spread (i.e. max - min) distance - * @deprecated It has been replaced by distanceSpread + * @deprecate Use {@link android.net.wifi.RttManager.RttResult#distanceSpread} API. */ @Deprecated public int distance_spread_cm; - /** spread (i.e. max - min) distance in cm */ + /** spread (i.e. max - min) distance in cm. */ public int distanceSpread; - /** the duration of this measurement burst*/ + /** the duration of this measurement burst, unit ms. */ public int burstDuration; - /** LCI information Element*/ - wifiInformationElement LCI; + /** Burst number supported by peer after negotiation, 2side RTT only*/ + public int negotiatedBurstNum; + + /** LCI information Element, only available for double side RTT. */ + public WifiInformationElement LCI; - /** LCR information Element*/ - wifiInformationElement LCR; + /** LCR information Element, only available to double side RTT. */ + public WifiInformationElement LCR; } - /** pseudo-private class used to parcel results */ + /** pseudo-private class used to parcel results. */ public static class ParcelableRttResults implements Parcelable { public RttResult mResults[]; @@ -608,10 +720,17 @@ public class RttManager { dest.writeInt(result.distanceStandardDeviation); dest.writeInt(result.distanceSpread); dest.writeInt(result.burstDuration); - //dest.writeInt(result.LCI.id); - //dest.writeString(result.LCI.data); - //dest.writeInt(result.LCR.id); - //dest.writeString(result.LCR.data); + dest.writeInt(result.negotiatedBurstNum); + dest.writeByte(result.LCI.id); + if (result.LCI.id != (byte) 0xFF) { + dest.writeByte((byte)result.LCI.data.length); + dest.writeByteArray(result.LCI.data); + } + dest.writeByte(result.LCR.id); + if (result.LCR.id != (byte) 0xFF) { + dest.writeInt((byte) result.LCR.data.length); + dest.writeByte(result.LCR.id); + } } } else { dest.writeInt(0); @@ -651,10 +770,21 @@ public class RttManager { results[i].distanceStandardDeviation = in.readInt(); results[i].distanceSpread = in.readInt(); results[i].burstDuration = in.readInt(); - //results[i].LCI.id = in.readInt(); - //results[i].LCI.data = in.readString(); - //results[i].LCR.id = in.readInt(); - //results[i].LCR.data = in.readString(); + results[i].negotiatedBurstNum = in.readInt(); + results[i].LCI = new WifiInformationElement(); + results[i].LCI.id = in.readByte(); + if (results[i].LCI.id != (byte) 0xFF) { + byte length = in.readByte(); + results[i].LCI.data = new byte[length]; + in.readByteArray(results[i].LCI.data); + } + results[i].LCR = new WifiInformationElement(); + results[i].LCR.id = in.readByte(); + if (results[i].LCR.id != (byte) 0xFF) { + byte length = in.readByte(); + results[i].LCR.data = new byte[length]; + in.readByteArray(results[i].LCR.data); + } } ParcelableRttResults parcelableResults = new ParcelableRttResults(results); @@ -696,18 +826,24 @@ public class RttManager { !mRttCapabilities.twoSided11McRttSupported) { Log.e(TAG, "Request " + index + ": two side RTT is not supported"); return false; - } else if ( params.numberBurst <= 0 ) { + } else if(params.bssid == null || params.bssid.isEmpty()) { + Log.e(TAG,"No BSSID is input"); + } else if ( params.numberBurst != 0 ) { Log.e(TAG, "Request " + index + ": Illegal number of burst: " + params.numberBurst); return false; - } else if (params.numberBurst > 1 && params.interval <= 0) { - Log.e(TAG, "Request " + index + ": Illegal interval value: " + params.interval); - return false; - } else if (params.numSamplesPerBurst <= 0) { + } else if (params.numSamplesPerBurst <= 0 || params.numSamplesPerBurst > 31) { Log.e(TAG, "Request " + index + ": Illegal sample number per burst: " + params.numSamplesPerBurst); return false; - } else if (params.numRetriesPerMeasurementFrame < 0 || params.numRetriesPerFTMR < 0) { - Log.e(TAG, "Request " + index + ": Illegal retry number"); + } else if (params.numRetriesPerMeasurementFrame < 0 || + params.numRetriesPerMeasurementFrame > 3) { + Log.e(TAG, "Request " + index + ": Illegal measurement frame retry number:" + + params.numRetriesPerMeasurementFrame); + return false; + } else if(params.numRetriesPerFTMR < 0 || + params.numRetriesPerFTMR > 3) { + Log.e(TAG, "Request " + index + ": Illegal FTMR frame retry number:" + + params.numRetriesPerFTMR); return false; } else if (params.LCIRequest && !mRttCapabilities.lciSupported) { Log.e(TAG, "Request " + index + ": LCI is not supported"); @@ -715,7 +851,8 @@ public class RttManager { } else if (params.LCRRequest && !mRttCapabilities.lcrSupported) { Log.e(TAG, "Request " + index + ": LCR is not supported"); return false; - } else if (params.burstTimeout <= 0){ + } else if (params.burstTimeout < 1 || + (params.burstTimeout > 11 && params.burstTimeout != 15)){ Log.e(TAG, "Request " + index + ": Illegal burst timeout: " + params.burstTimeout); return false; } else if ((params.preamble & mRttCapabilities.preambleSupported) == 0) { diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java index e8a51e3..5dc70bd 100644 --- a/wifi/java/android/net/wifi/ScanResult.java +++ b/wifi/java/android/net/wifi/ScanResult.java @@ -261,6 +261,12 @@ public class ScanResult implements Parcelable { return freq > 4900 && freq < 5900; } + /** + * @hide + * storing the raw bytes of full result IEs + **/ + public byte[] bytes; + /** information element from beacon * @hide */ diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 11bdebb..c6f2991 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -25,6 +25,7 @@ import android.net.StaticIpConfiguration; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.util.Log; import java.util.HashMap; import java.util.BitSet; @@ -193,6 +194,9 @@ public class WifiConfiguration implements Parcelable { /** @hide */ public static final int DISABLED_BY_WIFI_MANAGER = 5; + /** @hide */ + public static final int UNKNOWN_UID = -1; + /** * The ID number that the supplicant uses to identify this * network configuration entry. This must be passed as an argument @@ -424,13 +428,6 @@ public class WifiConfiguration implements Parcelable { */ public int userApproved = USER_UNSPECIFIED; - /** - * @hide - * BSSID list on which this configuration was seen. - * TODO: prevent this list to grow infinitely, age-out the results - */ - public HashMap<String, ScanResult> scanResultCache; - /** The Below RSSI thresholds are used to configure AutoJoin * - GOOD/LOW/BAD thresholds are used so as to calculate link score * - UNWANTED_SOFT are used by the blacklisting logic so as to handle @@ -520,7 +517,7 @@ public class WifiConfiguration implements Parcelable { * A summary of the RSSI and Band status for that configuration * This is used as a temporary value by the auto-join controller */ - public final class Visibility { + public static final class Visibility { public int rssi5; // strongest 5GHz RSSI public int rssi24; // strongest 2.4GHz RSSI public int num5; // number of BSSIDs on 5GHz @@ -596,47 +593,8 @@ public class WifiConfiguration implements Parcelable { * age in milliseconds: we will consider only ScanResults that are more recent, * i.e. younger. ***/ - public Visibility setVisibility(long age) { - if (scanResultCache == null) { - visibility = null; - return null; - } - - Visibility status = new Visibility(); - - long now_ms = System.currentTimeMillis(); - for(ScanResult result : scanResultCache.values()) { - if (result.seen == 0) - continue; - - if (result.is5GHz()) { - //strictly speaking: [4915, 5825] - //number of known BSSID on 5GHz band - status.num5 = status.num5 + 1; - } else if (result.is24GHz()) { - //strictly speaking: [2412, 2482] - //number of known BSSID on 2.4Ghz band - status.num24 = status.num24 + 1; - } - - if ((now_ms - result.seen) > age) continue; - - if (result.is5GHz()) { - if (result.level > status.rssi5) { - status.rssi5 = result.level; - status.age5 = result.seen; - status.BSSID5 = result.BSSID; - } - } else if (result.is24GHz()) { - if (result.level > status.rssi24) { - status.rssi24 = result.level; - status.age24 = result.seen; - status.BSSID24 = result.BSSID; - } - } - } + public void setVisibility(Visibility status) { visibility = status; - return status; } /** @hide */ @@ -733,6 +691,14 @@ public class WifiConfiguration implements Parcelable { } /** + * The WiFi configuration is expected not to have Internet access (e.g., a wireless printer, a + * Chromecast hotspot, etc.). This will be set if the user explicitly confirms a connection to + * this configuration and selects "don't ask again". + * @hide + */ + public boolean noInternetAccessExpected; + + /** * @hide * Last time we blacklisted the configuration */ @@ -956,41 +922,52 @@ public class WifiConfiguration implements Parcelable { * @hide */ public boolean isValid() { + String reason = strIsValid(); + if (reason != null) { + Log.e("WFII", "WiFi Config not valid: " + reason); + return false; + } + else { + return true; + } + } + + private String strIsValid() { if (allowedKeyManagement == null) - return false; + return "allowed kmgmt"; if (allowedKeyManagement.cardinality() > 1) { if (allowedKeyManagement.cardinality() != 2) { - return false; + return "cardinality != 2"; } - if (allowedKeyManagement.get(KeyMgmt.WPA_EAP) == false) { - return false; + if (!allowedKeyManagement.get(KeyMgmt.WPA_EAP)) { + return "not WPA_EAP"; } - if ((allowedKeyManagement.get(KeyMgmt.IEEE8021X) == false) - && (allowedKeyManagement.get(KeyMgmt.WPA_PSK) == false)) { - return false; + if ((!allowedKeyManagement.get(KeyMgmt.IEEE8021X)) + && (!allowedKeyManagement.get(KeyMgmt.WPA_PSK))) { + return "not PSK or 8021X"; } } - if (TextUtils.isEmpty(FQDN) == false) { + if (!TextUtils.isEmpty(FQDN)) { /* this is passpoint configuration; it must not have an SSID */ - if (TextUtils.isEmpty(SSID) == false) { - return false; + if (!TextUtils.isEmpty(SSID)) { + return "no SSID"; } /* this is passpoint configuration; it must have a providerFriendlyName */ if (TextUtils.isEmpty(providerFriendlyName)) { - return false; + return "no provider friendly name"; } /* this is passpoint configuration; it must have enterprise config */ if (enterpriseConfig == null || enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.NONE ) { - return false; + return "no enterprise config"; } } // TODO: Add more checks - return true; + return null; } /** @@ -1026,31 +1003,6 @@ public class WifiConfiguration implements Parcelable { allowedKeyManagement.get(KeyMgmt.IEEE8021X); } - /** - * most recent time we have seen this configuration - * @return most recent scanResult - * @hide - */ - public ScanResult lastSeen() { - ScanResult mostRecent = null; - - if (scanResultCache == null) { - return null; - } - - for (ScanResult result : scanResultCache.values()) { - if (mostRecent == null) { - if (result.seen != 0) - mostRecent = result; - } else { - if (result.seen > mostRecent.seen) { - mostRecent = result; - } - } - } - return mostRecent; - } - /** @hide **/ public void setAutoJoinStatus(int status) { if (status < 0) status = 0; @@ -1065,75 +1017,6 @@ public class WifiConfiguration implements Parcelable { } } - /** @hide - * trim the scan Result Cache - * @param: number of entries to keep in the cache - */ - public void trimScanResultsCache(int num) { - if (this.scanResultCache == null) { - return; - } - int currenSize = this.scanResultCache.size(); - if (currenSize <= num) { - return; // Nothing to trim - } - ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values()); - if (list.size() != 0) { - // Sort by descending timestamp - Collections.sort(list, new Comparator() { - public int compare(Object o1, Object o2) { - ScanResult a = (ScanResult)o1; - ScanResult b = (ScanResult)o2; - if (a.seen > b.seen) { - return 1; - } - if (a.seen < b.seen) { - return -1; - } - return a.BSSID.compareTo(b.BSSID); - } - }); - } - for (int i = 0; i < currenSize - num ; i++) { - // Remove oldest results from scan cache - ScanResult result = list.get(i); - this.scanResultCache.remove(result.BSSID); - } - } - - /* @hide */ - private ArrayList<ScanResult> sortScanResults() { - ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values()); - if (list.size() != 0) { - Collections.sort(list, new Comparator() { - public int compare(Object o1, Object o2) { - ScanResult a = (ScanResult)o1; - ScanResult b = (ScanResult)o2; - if (a.numIpConfigFailures > b.numIpConfigFailures) { - return 1; - } - if (a.numIpConfigFailures < b.numIpConfigFailures) { - return -1; - } - if (a.seen > b.seen) { - return -1; - } - if (a.seen < b.seen) { - return 1; - } - if (a.level > b.level) { - return -1; - } - if (a.level < b.level) { - return 1; - } - return a.BSSID.compareTo(b.BSSID); - } - }); - } - return list; - } - @Override public String toString() { StringBuilder sbuf = new StringBuilder(); @@ -1259,7 +1142,10 @@ public class WifiConfiguration implements Parcelable { if (creatorName != null) sbuf.append(" cname=" + creatorName); if (lastUpdateUid != 0) sbuf.append(" luid=" + lastUpdateUid); if (lastUpdateName != null) sbuf.append(" lname=" + lastUpdateName); - sbuf.append("userApproved=" + userApprovedAsString(userApproved)); + sbuf.append(" lcuid=" + lastConnectUid); + sbuf.append(" userApproved=" + userApprovedAsString(userApproved)); + sbuf.append(" noInternetAccessExpected=" + noInternetAccessExpected); + sbuf.append(" "); if (this.lastConnected != 0) { sbuf.append('\n'); @@ -1309,42 +1195,6 @@ public class WifiConfiguration implements Parcelable { } } } - if (this.scanResultCache != null) { - sbuf.append("Scan Cache: ").append('\n'); - ArrayList<ScanResult> list = sortScanResults(); - if (list.size() > 0) { - for (ScanResult result : list) { - long milli = now_ms - result.seen; - long ageSec = 0; - long ageMin = 0; - long ageHour = 0; - long ageMilli = 0; - long ageDay = 0; - if (now_ms > result.seen && result.seen > 0) { - ageMilli = milli % 1000; - ageSec = (milli / 1000) % 60; - ageMin = (milli / (60*1000)) % 60; - ageHour = (milli / (60*60*1000)) % 24; - ageDay = (milli / (24*60*60*1000)); - } - sbuf.append("{").append(result.BSSID).append(",").append(result.frequency); - sbuf.append(",").append(String.format("%3d", result.level)); - if (result.autoJoinStatus > 0) { - sbuf.append(",st=").append(result.autoJoinStatus); - } - if (ageSec > 0 || ageMilli > 0) { - sbuf.append(String.format(",%4d.%02d.%02d.%02d.%03dms", ageDay, - ageHour, ageMin, ageSec, ageMilli)); - } - if (result.numIpConfigFailures > 0) { - sbuf.append(",ipfail="); - sbuf.append(result.numIpConfigFailures); - } - sbuf.append("} "); - } - sbuf.append('\n'); - } - } sbuf.append("triggeredLow: ").append(this.numUserTriggeredWifiDisableLowRSSI); sbuf.append(" triggeredBad: ").append(this.numUserTriggeredWifiDisableBadRSSI); sbuf.append(" triggeredNotHigh: ").append(this.numUserTriggeredWifiDisableNotHighRSSI); @@ -1652,11 +1502,6 @@ public class WifiConfiguration implements Parcelable { mIpConfiguration = new IpConfiguration(source.mIpConfiguration); - if ((source.scanResultCache != null) && (source.scanResultCache.size() > 0)) { - scanResultCache = new HashMap<String, ScanResult>(); - scanResultCache.putAll(source.scanResultCache); - } - if ((source.connectChoices != null) && (source.connectChoices.size() > 0)) { connectChoices = new HashMap<String, Integer>(); connectChoices.putAll(source.connectChoices); @@ -1711,6 +1556,7 @@ public class WifiConfiguration implements Parcelable { dirty = source.dirty; userApproved = source.userApproved; numNoInternetAccessReports = source.numNoInternetAccessReports; + noInternetAccessExpected = source.noInternetAccessExpected; } } @@ -1789,6 +1635,7 @@ public class WifiConfiguration implements Parcelable { dest.writeInt(autoJoinBailedDueToLowRssi ? 1 : 0); dest.writeInt(userApproved); dest.writeInt(numNoInternetAccessReports); + dest.writeInt(noInternetAccessExpected ? 1 : 0); } /** Implement the Parcelable interface {@hide} */ @@ -1863,6 +1710,7 @@ public class WifiConfiguration implements Parcelable { config.autoJoinBailedDueToLowRssi = in.readInt() != 0; config.userApproved = in.readInt(); config.numNoInternetAccessReports = in.readInt(); + config.noInternetAccessExpected = in.readInt() != 0; return config; } diff --git a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java index 440ad61..6917971 100644 --- a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java +++ b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java @@ -601,7 +601,7 @@ public class WifiEnterpriseConfig implements Parcelable { } /** - * Set plmn for passpoint credential + * Get plmn for passpoint credential * @return the plmn */ public String getPlmn() { diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 275c7d1..3205351 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -20,10 +20,16 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.content.Context; +import android.net.ConnectivityManager; +import android.net.ConnectivityManager.NetworkCallback; import android.net.DhcpInfo; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkRequest; import android.net.wifi.ScanSettings; import android.net.wifi.WifiChannel; import android.os.Binder; +import android.os.Build; import android.os.IBinder; import android.os.Handler; import android.os.HandlerThread; @@ -38,6 +44,7 @@ import android.util.SparseArray; import java.net.InetAddress; import java.util.concurrent.CountDownLatch; +import com.android.internal.annotations.GuardedBy; import com.android.internal.util.AsyncChannel; import com.android.internal.util.Protocol; @@ -568,6 +575,7 @@ public class WifiManager { private Context mContext; IWifiManager mService; + private final int mTargetSdkVersion; private static final int INVALID_KEY = 0; private static int sListenerKey = 1; @@ -576,11 +584,17 @@ public class WifiManager { private static AsyncChannel sAsyncChannel; private static CountDownLatch sConnected; + private static ConnectivityManager sCM; private static final Object sThreadRefLock = new Object(); private static int sThreadRefCount; private static HandlerThread sHandlerThread; + @GuardedBy("sCM") + // TODO: Introduce refcounting and make this a per-process static callback, instead of a + // per-WifiManager callback. + private PinningNetworkCallback mNetworkCallback; + /** * Create a new WifiManager instance. * Applications will almost always want to use @@ -594,6 +608,7 @@ public class WifiManager { public WifiManager(Context context, IWifiManager service) { mContext = context; mService = service; + mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; init(); } @@ -645,6 +660,20 @@ public class WifiManager { } /** + * Returns a WifiConfiguration matching this ScanResult + * @param scanResult scanResult that represents the BSSID + * @return {@link WifiConfiguration} that matches this BSSID or null + * @hide + */ + public WifiConfiguration getMatchingWifiConfig(ScanResult scanResult) { + try { + return mService.getMatchingWifiConfig(scanResult); + } catch (RemoteException e) { + return null; + } + } + + /** * Add a new network description to the set of configured networks. * The {@code networkId} field of the supplied configuration object * is ignored. @@ -726,6 +755,20 @@ public class WifiManager { * networks are disabled, and an attempt to connect to the selected * network is initiated. This may result in the asynchronous delivery * of state change events. + * <p> + * <b>Note:</b> If an application's target SDK version is + * {@link android.os.Build.VERSION_CODES#MNC} or newer, network + * communication may not use Wi-Fi even if Wi-Fi is connected; traffic may + * instead be sent through another network, such as cellular data, + * Bluetooth tethering, or Ethernet. For example, traffic will never use a + * Wi-Fi network that does not provide Internet access (e.g. a wireless + * printer), if another network that does offer Internet access (e.g. + * cellular data) is available. Applications that need to ensure that their + * network traffic uses Wi-Fi should use APIs such as + * {@link Network#bindSocket(java.net.Socket)}, + * {@link Network#openConnection(java.net.URL)}, or + * {@link ConnectivityManager#bindProcessToNetwork} to do so. + * * @param netId the ID of the network in the list of configured networks * @param disableOthers if true, disable all other networks. The way to * select a particular network to connect to is specify {@code true} @@ -733,11 +776,23 @@ public class WifiManager { * @return {@code true} if the operation succeeded */ public boolean enableNetwork(int netId, boolean disableOthers) { + final boolean pin = disableOthers && mTargetSdkVersion < Build.VERSION_CODES.MNC; + if (pin) { + registerPinningNetworkCallback(); + } + + boolean success; try { - return mService.enableNetwork(netId, disableOthers); + success = mService.enableNetwork(netId, disableOthers); } catch (RemoteException e) { - return false; + success = false; + } + + if (pin && !success) { + unregisterPinningNetworkCallback(); } + + return success; } /** @@ -1488,6 +1543,20 @@ public class WifiManager { } /** + * Builds a WifiConfiguration from Hotspot 2.0 MIME file. + * @return AP details in WifiConfiguration + * + * @hide Dont open yet + */ + public WifiConfiguration buildWifiConfig(String uriString, String mimeType, byte[] data) { + try { + return mService.buildWifiConfig(uriString, mimeType, data); + } catch (RemoteException e) { + return null; + } + } + + /** * Sets the Wi-Fi AP Configuration. * @return {@code true} if the operation succeeded, {@code false} otherwise * @@ -1923,6 +1992,100 @@ public class WifiManager { "No permission to access and change wifi or a bad initialization"); } + private void initConnectivityManager() { + // TODO: what happens if an app calls a WifiManager API before ConnectivityManager is + // registered? Can we fix this by starting ConnectivityService before WifiService? + if (sCM == null) { + sCM = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + if (sCM == null) { + throw new IllegalStateException("Bad luck, ConnectivityService not started."); + } + } + } + + /** + * A NetworkCallback that pins the process to the first wifi network to connect. + * + * We use this to maintain compatibility with pre-M apps that call WifiManager.enableNetwork() + * to connect to a Wi-Fi network that has no Internet access, and then assume that they will be + * able to use that network because it's the system default. + * + * In order to maintain compatibility with apps that call setProcessDefaultNetwork themselves, + * we try not to set the default network unless they have already done so, and we try not to + * clear the default network unless we set it ourselves. + * + * This should maintain behaviour that's compatible with L, which would pin the whole system to + * any wifi network that was created via enableNetwork(..., true) until that network + * disconnected. + * + * Note that while this hack allows network traffic to flow, it is quite limited. For example: + * + * 1. setProcessDefaultNetwork only affects this process, so: + * - Any subprocesses spawned by this process will not be pinned to Wi-Fi. + * - If this app relies on any other apps on the device also being on Wi-Fi, that won't work + * either, because other apps on the device will not be pinned. + * 2. The behaviour of other APIs is not modified. For example: + * - getActiveNetworkInfo will return the system default network, not Wi-Fi. + * - There will be no CONNECTIVITY_ACTION broadcasts about TYPE_WIFI. + * - getProcessDefaultNetwork will not return null, so if any apps are relying on that, they + * will be surprised as well. + */ + private class PinningNetworkCallback extends NetworkCallback { + private Network mPinnedNetwork; + + @Override + public void onPreCheck(Network network) { + if (sCM.getProcessDefaultNetwork() == null && mPinnedNetwork == null) { + sCM.setProcessDefaultNetwork(network); + mPinnedNetwork = network; + Log.d(TAG, "Wifi alternate reality enabled on network " + network); + } + } + + @Override + public void onLost(Network network) { + if (network.equals(mPinnedNetwork) && network.equals(sCM.getProcessDefaultNetwork())) { + sCM.setProcessDefaultNetwork(null); + Log.d(TAG, "Wifi alternate reality disabled on network " + network); + mPinnedNetwork = null; + unregisterPinningNetworkCallback(); + } + } + } + + private void registerPinningNetworkCallback() { + initConnectivityManager(); + synchronized (sCM) { + if (mNetworkCallback == null) { + // TODO: clear all capabilities. + NetworkRequest request = new NetworkRequest.Builder() + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) + .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + .build(); + mNetworkCallback = new PinningNetworkCallback(); + try { + sCM.registerNetworkCallback(request, mNetworkCallback); + } catch (SecurityException e) { + Log.d(TAG, "Failed to register network callback", e); + } + } + } + } + + private void unregisterPinningNetworkCallback() { + initConnectivityManager(); + synchronized (sCM) { + if (mNetworkCallback != null) { + try { + sCM.unregisterNetworkCallback(mNetworkCallback); + } catch (SecurityException e) { + Log.d(TAG, "Failed to unregister network callback", e); + } + mNetworkCallback = null; + } + } + } + /** * Connect to a network with the given configuration. The network also * gets added to the supplicant configuration. @@ -2636,18 +2799,9 @@ public class WifiManager { * @hide */ public void factoryReset() { - // Enable wifi - setWifiEnabled(true); - // Delete all Wifi SSIDs - List<WifiConfiguration> networks = getConfiguredNetworks(); - if (networks != null) { - for (WifiConfiguration config : networks) { - removeNetwork(config.networkId); - } - saveConfiguration(); + try { + mService.factoryReset(); + } catch (RemoteException e) { } - - // Turn mobile hotspot off - setWifiApEnabled(null, false); } } diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index cecd738..4ead972 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -722,7 +722,7 @@ public class WifiScanner { /* private members and methods */ private static final String TAG = "WifiScanner"; - private static final boolean DBG = true; + private static final boolean DBG = false; /* commands for Wifi Service */ private static final int BASE = Protocol.BASE_WIFI_SCANNER; |
