Fix incorrect comparator implementation leading to IllegalArgumentException.
The current comparator implementation does not implement the compare()
function according to the interface definition. In particular, the
following clause is violated:
"The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x))
for all x and y."
If a.priority == b.priority, the comparator throws.
Bug: 24223197
Change-Id: Ibff94067de272d8c9372474fa24a161bf95bf6f1
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index 652899e..b751081 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -1311,7 +1311,12 @@
// Sort by descending priority
Collections.sort(sortedWifiConfigurations, new Comparator<WifiConfiguration>() {
public int compare(WifiConfiguration a, WifiConfiguration b) {
- return a.priority >= b.priority ? 1 : -1;
+ if (a.priority < b.priority) {
+ return -1;
+ } else if (a.priority > b.priority) {
+ return 1;
+ }
+ return 0;
}
});
}