diff options
Diffstat (limited to 'wifi/java/android')
| -rw-r--r-- | wifi/java/android/net/wifi/ScanResult.java | 15 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiConfiguration.java | 39 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiInfo.java | 76 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiScanner.java | 108 |
4 files changed, 202 insertions, 36 deletions
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java index 99151c3..8191edd 100644 --- a/wifi/java/android/net/wifi/ScanResult.java +++ b/wifi/java/android/net/wifi/ScanResult.java @@ -89,6 +89,21 @@ public class ScanResult implements Parcelable { * {@hide} */ public final static int UNSPECIFIED = -1; + /** + * @hide + * TODO: makes real freq boundaries + */ + public boolean is24GHz() { + return frequency > 2400 && frequency < 2500; + } + + /** + * @hide + * TODO: makes real freq boundaries + */ + public boolean is5GHz() { + return frequency > 4900 && frequency < 5900; + } /** information element from beacon * @hide diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 192cba6..48396d5 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -405,6 +405,10 @@ public class WifiConfiguration implements Parcelable { /** @hide **/ public static int INITIAL_AUTO_JOIN_ATTEMPT_MIN_5 = -70; + /** @hide + * 5GHz band is prefered over 2.4 if the 5GHz RSSI is higher than this threshold **/ + public static int A_BAND_PREFERENCE_RSSI_THRESHOLD = -65; + /** * @hide * A summary of the RSSI and Band status for that configuration @@ -481,11 +485,11 @@ public class WifiConfiguration implements Parcelable { if (result.seen == 0) continue; - if ((result.frequency > 4900) && (result.frequency < 5900)) { + if (result.is5GHz()) { //strictly speaking: [4915, 5825] //number of known BSSID on 5GHz band status.num5 = status.num5 + 1; - } else if ((result.frequency > 2400) && (result.frequency < 2500)) { + } else if (result.is24GHz()) { //strictly speaking: [2412, 2482] //number of known BSSID on 2.4Ghz band status.num24 = status.num24 + 1; @@ -493,12 +497,12 @@ public class WifiConfiguration implements Parcelable { if ((now_ms - result.seen) > age) continue; - if ((result.frequency > 4900) && (result.frequency < 5900)) { + if (result.is5GHz()) { if (result.level > status.rssi5) { status.rssi5 = result.level; status.age5 = result.seen; } - } else if ((result.frequency > 2400) && (result.frequency < 2500)) { + } else if (result.is24GHz()) { if (result.level > status.rssi24) { status.rssi24 = result.level; status.age24 = result.seen; @@ -547,6 +551,17 @@ public class WifiConfiguration implements Parcelable { */ public long blackListTimestamp; + /** + * @hide + * last time the system was connected to this configuration. + */ + public long lastConnected; + + /** + * @hide + * last time the system was disconnected to this configuration. + */ + public long lastDisconnected; /** * Set if the configuration was self added by the framework @@ -658,7 +673,20 @@ public class WifiConfiguration implements Parcelable { // TODO: Add more checks return true; + } + /** + * Helper function, identify if a configuration is linked + * @hide + */ + public boolean isLinked(WifiConfiguration config) { + if (config.linkedConfigurations != null && linkedConfigurations != null) { + if (config.linkedConfigurations.get(configKey()) != null + && linkedConfigurations.get(config.configKey()) != null) { + return true; + } + } + return false; } /** @@ -688,6 +716,7 @@ public class WifiConfiguration implements Parcelable { /** @hide **/ public void setAutoJoinStatus(int status) { + if (status < 0) status = 0; if (status == 0) { blackListTimestamp = 0; } else if (status > autoJoinStatus) { @@ -1079,6 +1108,8 @@ public class WifiConfiguration implements Parcelable { creatorUid = source.creatorUid; peerWifiConfiguration = source.peerWifiConfiguration; blackListTimestamp = source.blackListTimestamp; + lastConnected = source.lastConnected; + lastDisconnected = source.lastDisconnected; } } diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java index f6a94d0..6760c56 100644 --- a/wifi/java/android/net/wifi/WifiInfo.java +++ b/wifi/java/android/net/wifi/WifiInfo.java @@ -62,6 +62,17 @@ public class WifiInfo implements Parcelable { private String mBSSID; private WifiSsid mWifiSsid; private int mNetworkId; + + /** @hide **/ + public static final int INVALID_RSSI = -127; + + /** @hide **/ + public static final int MIN_RSSI = -126; + + /** @hide **/ + public static final int MAX_RSSI = 200; + + /** * Received Signal Strength Indicator */ @@ -131,7 +142,8 @@ public class WifiInfo implements Parcelable { public int score; /** - * @hide * + * TODO: get actual timestamp and calculate true rates + * @hide */ public void updatePacketRates(WifiLinkLayerStats stats) { if (stats != null) { @@ -156,17 +168,42 @@ public class WifiInfo implements Parcelable { rxSuccess = rxgood; txRetries = txretries; } else { - txBadRate = 0; + txBad = 0; txSuccess = 0; rxSuccess = 0; txRetries = 0; + txBadRate = 0; + txSuccessRate = 0; + rxSuccessRate = 0; + txRetriesRate = 0; } } + /** - * Flag indicating that AP has hinted that upstream connection is metered, - * and sensitive to heavy data transfers. + * This function is less powerful and used if the WifiLinkLayerStats API is not implemented + * at the Wifi HAL + * @hide */ + public void updatePacketRates(long txPackets, long rxPackets) { + //paranoia + txBad = 0; + txRetries = 0; + txBadRate = 0; + txRetriesRate = 0; + + txSuccessRate = (txSuccessRate * 0.5) + + ((double) (txPackets - txSuccess) * 0.5); + rxSuccessRate = (rxSuccessRate * 0.5) + + ((double) (rxPackets - rxSuccess) * 0.5); + txSuccess = txPackets; + rxSuccess = rxPackets; + } + + /** + * Flag indicating that AP has hinted that upstream connection is metered, + * and sensitive to heavy data transfers. + */ private boolean mMeteredHint; /** @hide */ @@ -175,9 +212,32 @@ public class WifiInfo implements Parcelable { mBSSID = null; mNetworkId = -1; mSupplicantState = SupplicantState.UNINITIALIZED; - mRssi = -9999; + mRssi = INVALID_RSSI; mLinkSpeed = -1; mFrequency = -1; + txBad = 0; + } + + /** @hide */ + public void reset() { + setInetAddress(null); + setBSSID(null); + setSSID(null); + setNetworkId(-1); + setRssi(INVALID_RSSI); + setLinkSpeed(-1); + setFrequency(-1); + setMeteredHint(false); + txSuccess = 0; + rxSuccess = 0; + txRetries = 0; + txBadRate = 0; + txSuccessRate = 0; + rxSuccessRate = 0; + txRetriesRate = 0; + lowRssiCount = 0; + badRssiCount = 0; + score = 0; } /** @@ -256,7 +316,7 @@ public class WifiInfo implements Parcelable { /** * Returns the received signal strength indicator of the current 802.11 * network, in dBm. - * @return the RSSI, in the range -110 to 10 + * @return the RSSI, in the range -127 to 200 */ public int getRssi() { return mRssi; @@ -264,6 +324,10 @@ public class WifiInfo implements Parcelable { /** @hide */ public void setRssi(int rssi) { + if (rssi < INVALID_RSSI) + rssi = INVALID_RSSI; + if (rssi > MAX_RSSI) + rssi = MAX_RSSI; mRssi = rssi; } diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index 3b65ca8..21b700d 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -153,12 +153,17 @@ public class WifiScanner { dest.writeInt(band); dest.writeInt(periodInMs); dest.writeInt(reportEvents); - dest.writeInt(channels.length); - for (int i = 0; i < channels.length; i++) { - dest.writeInt(channels[i].frequency); - dest.writeInt(channels[i].dwellTimeMS); - dest.writeInt(channels[i].passive ? 1 : 0); + if (channels != null) { + dest.writeInt(channels.length); + + for (int i = 0; i < channels.length; i++) { + dest.writeInt(channels[i].frequency); + dest.writeInt(channels[i].dwellTimeMS); + dest.writeInt(channels[i].passive ? 1 : 0); + } + } else { + dest.writeInt(0); } } @@ -211,10 +216,14 @@ public class WifiScanner { /** Implement the Parcelable interface {@hide} */ public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mResults.length); - for (int i = 0; i < mResults.length; i++) { - ScanResult result = mResults[i]; - result.writeToParcel(dest, flags); + if (mResults != null) { + dest.writeInt(mResults.length); + for (int i = 0; i < mResults.length; i++) { + ScanResult result = mResults[i]; + result.writeToParcel(dest, flags); + } + } else { + dest.writeInt(0); } } @@ -324,13 +333,17 @@ public class WifiScanner { dest.writeInt(unchangedSampleSize); dest.writeInt(minApsBreachingThreshold); dest.writeInt(periodInMs); - dest.writeInt(hotspotInfos.length); - for (int i = 0; i < hotspotInfos.length; i++) { - HotspotInfo info = hotspotInfos[i]; - dest.writeString(info.bssid); - dest.writeInt(info.low); - dest.writeInt(info.high); - dest.writeInt(info.frequencyHint); + if (hotspotInfos != null) { + dest.writeInt(hotspotInfos.length); + for (int i = 0; i < hotspotInfos.length; i++) { + HotspotInfo info = hotspotInfos[i]; + dest.writeString(info.bssid); + dest.writeInt(info.low); + dest.writeInt(info.high); + dest.writeInt(info.frequencyHint); + } + } else { + dest.writeInt(0); } } @@ -456,13 +469,18 @@ public class WifiScanner { /** Implement the Parcelable interface {@hide} */ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(apLostThreshold); - dest.writeInt(hotspotInfos.length); - for (int i = 0; i < hotspotInfos.length; i++) { - HotspotInfo info = hotspotInfos[i]; - dest.writeString(info.bssid); - dest.writeInt(info.low); - dest.writeInt(info.high); - dest.writeInt(info.frequencyHint); + + if (hotspotInfos != null) { + dest.writeInt(hotspotInfos.length); + for (int i = 0; i < hotspotInfos.length; i++) { + HotspotInfo info = hotspotInfos[i]; + dest.writeString(info.bssid); + dest.writeInt(info.low); + dest.writeInt(info.high); + dest.writeInt(info.frequencyHint); + } + } else { + dest.writeInt(0); } } @@ -680,6 +698,42 @@ public class WifiScanner { } } + /** @hide */ + public static class OperationResult implements Parcelable { + public int reason; + public String description; + + public OperationResult(int reason, String description) { + this.reason = reason; + this.description = description; + } + + /** Implement the Parcelable interface {@hide} */ + public int describeContents() { + return 0; + } + + /** Implement the Parcelable interface {@hide} */ + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(reason); + dest.writeString(description); + } + + /** Implement the Parcelable interface {@hide} */ + public static final Creator<OperationResult> CREATOR = + new Creator<OperationResult>() { + public OperationResult createFromParcel(Parcel in) { + int reason = in.readInt(); + String description = in.readString(); + return new OperationResult(reason, description); + } + + public OperationResult[] newArray(int size) { + return new OperationResult[size]; + } + }; + } + private static class ServiceHandler extends Handler { ServiceHandler(Looper looper) { super(looper); @@ -717,9 +771,11 @@ public class WifiScanner { case CMD_OP_SUCCEEDED : ((ActionListener) listener).onSuccess(); break; - case CMD_OP_FAILED : - ((ActionListener) listener).onFailure(msg.arg1, (String)msg.obj); - removeListener(msg.arg2); + case CMD_OP_FAILED : { + OperationResult result = (OperationResult)msg.obj; + ((ActionListener) listener).onFailure(result.reason, result.description); + removeListener(msg.arg2); + } break; case CMD_SCAN_RESULT : ((ScanListener) listener).onResults( |
