PasspointMatchInfo.java revision 77f2b82a2e80af8da52c22d69a76def6d4209757
1package com.android.server.wifi.hotspot2; 2 3import com.android.server.wifi.hotspot2.pps.HomeSP; 4 5import java.util.HashMap; 6import java.util.Map; 7 8public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { 9 private final PasspointMatch mPasspointMatch; 10 private final NetworkDetail mNetworkDetail; 11 private final HomeSP mHomeSP; 12 13 private static final Map<NetworkDetail.Ant, Integer> sAntScores = 14 new HashMap<NetworkDetail.Ant, Integer>(); 15 16 static { 17 sAntScores.put(NetworkDetail.Ant.FreePublic, 7); 18 sAntScores.put(NetworkDetail.Ant.ChargeablePublic, 6); 19 sAntScores.put(NetworkDetail.Ant.PrivateWithGuest, 5); 20 sAntScores.put(NetworkDetail.Ant.Private, 4); 21 sAntScores.put(NetworkDetail.Ant.Personal, 3); 22 sAntScores.put(NetworkDetail.Ant.EmergencyOnly, 2); 23 sAntScores.put(NetworkDetail.Ant.Wildcard, 1); 24 sAntScores.put(NetworkDetail.Ant.TestOrExperimental, 0); 25 } 26 27 public PasspointMatchInfo(PasspointMatch passpointMatch, 28 NetworkDetail networkDetail, HomeSP homeSP) { 29 mPasspointMatch = passpointMatch; 30 mNetworkDetail = networkDetail; 31 mHomeSP = homeSP; 32 } 33 34 public PasspointMatch getPasspointMatch() { 35 return mPasspointMatch; 36 } 37 38 public NetworkDetail getNetworkDetail() { 39 return mNetworkDetail; 40 } 41 42 public HomeSP getHomeSP() { 43 return mHomeSP; 44 } 45 46 @Override 47 public int compareTo(PasspointMatchInfo that) { 48 if (getPasspointMatch() != that.getPasspointMatch()) { 49 return getPasspointMatch().compareTo(that.getPasspointMatch()); 50 } 51 52 // WAN Metrics 53 // IP Address Type Availability (802.11) 54 // Connection capability 55 56 NetworkDetail n1 = getNetworkDetail(); 57 NetworkDetail n2 = that.getNetworkDetail(); 58 59 if (n1.isInternet() != n2.isInternet()) { 60 return n1.isInternet() ? 1 : -1; 61 } 62 63 if (n1.hasInterworking() && n2.hasInterworking() && n1.getAnt() != n2.getAnt()) { 64 int an1 = sAntScores.get(n1.getAnt()); 65 int an2 = sAntScores.get(n2.getAnt()); 66 return an1 - an2; 67 } 68 69 long score1 = n1.getCapacity() * n1.getChannelUtilization() * n1.getStationCount(); 70 long score2 = n2.getCapacity() * n2.getChannelUtilization() * n2.getStationCount(); 71 72 if (score1 != score2) { 73 return score1 < score2 ? 1 : -1; 74 } 75 76 return Utils.compare(n1.getHSRelease(), n2.getHSRelease()); 77 } 78 79 @Override 80 public boolean equals(Object thatObject) { 81 if (this == thatObject) { 82 return true; 83 } 84 if (thatObject == null || getClass() != thatObject.getClass()) { 85 return false; 86 } 87 88 PasspointMatchInfo that = (PasspointMatchInfo)thatObject; 89 90 return getNetworkDetail().equals(that.getNetworkDetail()) && 91 getHomeSP().equals(that.getHomeSP()) && 92 getPasspointMatch().equals(that.getPasspointMatch()); 93 } 94 95 @Override 96 public int hashCode() { 97 int result = mPasspointMatch != null ? mPasspointMatch.hashCode() : 0; 98 result = 31 * result + mNetworkDetail.hashCode(); 99 result = 31 * result + (mHomeSP != null ? mHomeSP.hashCode() : 0); 100 return result; 101 } 102 103 @Override 104 public String toString() { 105 return "PasspointMatchInfo{" + 106 ", mPasspointMatch=" + mPasspointMatch + 107 ", mNetworkInfo=" + mNetworkDetail.getSSID() + 108 ", mHomeSP=" + mHomeSP.getFQDN() + 109 '}'; 110 } 111} 112