am f197105e
: Merge "Fix wifi compareTo" into jb-mr1-dev
* commit 'f197105e3bd83a1f244cb690a1aa615624629961': Fix wifi compareTo
This commit is contained in:
@@ -224,17 +224,19 @@ class AccessPoint extends Preference {
|
|||||||
}
|
}
|
||||||
AccessPoint other = (AccessPoint) preference;
|
AccessPoint other = (AccessPoint) preference;
|
||||||
// Active one goes first.
|
// Active one goes first.
|
||||||
if (mInfo != other.mInfo) {
|
if (mInfo != null && other.mInfo == null) return -1;
|
||||||
return (mInfo != null) ? -1 : 1;
|
if (mInfo == null && other.mInfo != null) return 1;
|
||||||
}
|
|
||||||
// Reachable one goes before unreachable one.
|
// Reachable one goes before unreachable one.
|
||||||
if ((mRssi ^ other.mRssi) < 0) {
|
if (mRssi != Integer.MAX_VALUE && other.mRssi == Integer.MAX_VALUE) return -1;
|
||||||
return (mRssi != Integer.MAX_VALUE) ? -1 : 1;
|
if (mRssi == Integer.MAX_VALUE && other.mRssi != Integer.MAX_VALUE) return 1;
|
||||||
}
|
|
||||||
// Configured one goes before unconfigured one.
|
// Configured one goes before unconfigured one.
|
||||||
if ((networkId ^ other.networkId) < 0) {
|
if (networkId != WifiConfiguration.INVALID_NETWORK_ID
|
||||||
return (networkId != -1) ? -1 : 1;
|
&& other.networkId == WifiConfiguration.INVALID_NETWORK_ID) return -1;
|
||||||
}
|
if (networkId == WifiConfiguration.INVALID_NETWORK_ID
|
||||||
|
&& other.networkId != WifiConfiguration.INVALID_NETWORK_ID) return 1;
|
||||||
|
|
||||||
// Sort by signal strength.
|
// Sort by signal strength.
|
||||||
int difference = WifiManager.compareSignalLevel(other.mRssi, mRssi);
|
int difference = WifiManager.compareSignalLevel(other.mRssi, mRssi);
|
||||||
if (difference != 0) {
|
if (difference != 0) {
|
||||||
@@ -244,6 +246,22 @@ class AccessPoint extends Preference {
|
|||||||
return ssid.compareToIgnoreCase(other.ssid);
|
return ssid.compareToIgnoreCase(other.ssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof AccessPoint)) return false;
|
||||||
|
return (this.compareTo((AccessPoint) other) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = 0;
|
||||||
|
if (mInfo != null) result += 13 * mInfo.hashCode();
|
||||||
|
result += 19 * mRssi;
|
||||||
|
result += 23 * networkId;
|
||||||
|
result += 29 * ssid.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
boolean update(ScanResult result) {
|
boolean update(ScanResult result) {
|
||||||
if (ssid.equals(result.SSID) && security == getSecurity(result)) {
|
if (ssid.equals(result.SSID) && security == getSecurity(result)) {
|
||||||
if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
|
if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
|
||||||
|
Reference in New Issue
Block a user