[go: nahoru, domu]

1package com.android.hotspot2.pps;
2
3import com.android.hotspot2.Utils;
4
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Map;
10import java.util.Set;
11
12public class HomeSP {
13    private final Map<String, Long> mSSIDs;        // SSID, HESSID, [0,N]
14    private final String mFQDN;
15    private final DomainMatcher mDomainMatcher;
16    private final Set<String> mOtherHomePartners;
17    private final HashSet<Long> mRoamingConsortiums;    // [0,N]
18    private final Set<Long> mMatchAnyOIs;           // [0,N]
19    private final List<Long> mMatchAllOIs;          // [0,N]
20
21    private final Credential mCredential;
22
23    // Informational:
24    private final String mFriendlyName;             // [1]
25    private final String mIconURL;                  // [0,1]
26
27    private final Policy mPolicy;
28    private final int mCredentialPriority;
29    private final Map<String, String> mAAATrustRoots;
30    private final UpdateInfo mSubscriptionUpdate;
31    private final SubscriptionParameters mSubscriptionParameters;
32    private final int mUpdateIdentifier;
33
34    @Deprecated
35    public HomeSP(Map<String, Long> ssidMap,
36                   /*@NotNull*/ String fqdn,
37                   /*@NotNull*/ HashSet<Long> roamingConsortiums,
38                   /*@NotNull*/ Set<String> otherHomePartners,
39                   /*@NotNull*/ Set<Long> matchAnyOIs,
40                   /*@NotNull*/ List<Long> matchAllOIs,
41                   String friendlyName,
42                   String iconURL,
43                   Credential credential) {
44
45        mSSIDs = ssidMap;
46        List<List<String>> otherPartners = new ArrayList<>(otherHomePartners.size());
47        for (String otherPartner : otherHomePartners) {
48            otherPartners.add(Utils.splitDomain(otherPartner));
49        }
50        mOtherHomePartners = otherHomePartners;
51        mFQDN = fqdn;
52        mDomainMatcher = new DomainMatcher(Utils.splitDomain(fqdn), otherPartners);
53        mRoamingConsortiums = roamingConsortiums;
54        mMatchAnyOIs = matchAnyOIs;
55        mMatchAllOIs = matchAllOIs;
56        mFriendlyName = friendlyName;
57        mIconURL = iconURL;
58        mCredential = credential;
59
60        mPolicy = null;
61        mCredentialPriority = -1;
62        mAAATrustRoots = null;
63        mSubscriptionUpdate = null;
64        mSubscriptionParameters = null;
65        mUpdateIdentifier = -1;
66    }
67
68    public HomeSP(Map<String, Long> ssidMap,
69                   /*@NotNull*/ String fqdn,
70                   /*@NotNull*/ HashSet<Long> roamingConsortiums,
71                   /*@NotNull*/ Set<String> otherHomePartners,
72                   /*@NotNull*/ Set<Long> matchAnyOIs,
73                   /*@NotNull*/ List<Long> matchAllOIs,
74                   String friendlyName,
75                   String iconURL,
76                   Credential credential,
77
78                   Policy policy,
79                   int credentialPriority,
80                   Map<String, String> AAATrustRoots,
81                   UpdateInfo subscriptionUpdate,
82                   SubscriptionParameters subscriptionParameters,
83                   int updateIdentifier) {
84
85        mSSIDs = ssidMap;
86        List<List<String>> otherPartners = new ArrayList<>(otherHomePartners.size());
87        for (String otherPartner : otherHomePartners) {
88            otherPartners.add(Utils.splitDomain(otherPartner));
89        }
90        mOtherHomePartners = otherHomePartners;
91        mFQDN = fqdn;
92        mDomainMatcher = new DomainMatcher(Utils.splitDomain(fqdn), otherPartners);
93        mRoamingConsortiums = roamingConsortiums;
94        mMatchAnyOIs = matchAnyOIs;
95        mMatchAllOIs = matchAllOIs;
96        mFriendlyName = friendlyName;
97        mIconURL = iconURL;
98        mCredential = credential;
99
100        mPolicy = policy;
101        mCredentialPriority = credentialPriority;
102        mAAATrustRoots = AAATrustRoots;
103        mSubscriptionUpdate = subscriptionUpdate;
104        mSubscriptionParameters = subscriptionParameters;
105        mUpdateIdentifier = updateIdentifier;
106    }
107
108    public int getUpdateIdentifier() {
109        return mUpdateIdentifier;
110    }
111
112    public UpdateInfo getSubscriptionUpdate() {
113        return mSubscriptionUpdate;
114    }
115
116    public Policy getPolicy() {
117        return mPolicy;
118    }
119
120    private String imsiMatch(List<String> imsis, String mccMnc) {
121        if (mCredential.getImsi().matchesMccMnc(mccMnc)) {
122            for (String imsi : imsis) {
123                if (imsi.startsWith(mccMnc)) {
124                    return imsi;
125                }
126            }
127        }
128        return null;
129    }
130
131    public String getFQDN() {
132        return mFQDN;
133    }
134
135    public String getFriendlyName() {
136        return mFriendlyName;
137    }
138
139    public HashSet<Long> getRoamingConsortiums() {
140        return mRoamingConsortiums;
141    }
142
143    public Credential getCredential() {
144        return mCredential;
145    }
146
147    public Map<String, Long> getSSIDs() {
148        return mSSIDs;
149    }
150
151    public Collection<String> getOtherHomePartners() {
152        return mOtherHomePartners;
153    }
154
155    public Set<Long> getMatchAnyOIs() {
156        return mMatchAnyOIs;
157    }
158
159    public List<Long> getMatchAllOIs() {
160        return mMatchAllOIs;
161    }
162
163    public String getIconURL() {
164        return mIconURL;
165    }
166
167    public boolean deepEquals(HomeSP other) {
168        return mFQDN.equals(other.mFQDN) &&
169                mSSIDs.equals(other.mSSIDs) &&
170                mOtherHomePartners.equals(other.mOtherHomePartners) &&
171                mRoamingConsortiums.equals(other.mRoamingConsortiums) &&
172                mMatchAnyOIs.equals(other.mMatchAnyOIs) &&
173                mMatchAllOIs.equals(other.mMatchAllOIs) &&
174                mFriendlyName.equals(other.mFriendlyName) &&
175                Utils.compare(mIconURL, other.mIconURL) == 0 &&
176                mCredential.equals(other.mCredential);
177    }
178
179    @Override
180    public boolean equals(Object thatObject) {
181        if (this == thatObject) {
182            return true;
183        } else if (thatObject == null || getClass() != thatObject.getClass()) {
184            return false;
185        }
186
187        HomeSP that = (HomeSP) thatObject;
188        return mFQDN.equals(that.mFQDN);
189    }
190
191    @Override
192    public int hashCode() {
193        return mFQDN.hashCode();
194    }
195
196    @Override
197    public String toString() {
198        return "HomeSP{" +
199                "SSIDs=" + mSSIDs +
200                ", FQDN='" + mFQDN + '\'' +
201                ", DomainMatcher=" + mDomainMatcher +
202                ", RoamingConsortiums={" + Utils.roamingConsortiumsToString(mRoamingConsortiums) +
203                '}' +
204                ", MatchAnyOIs={" + Utils.roamingConsortiumsToString(mMatchAnyOIs) + '}' +
205                ", MatchAllOIs={" + Utils.roamingConsortiumsToString(mMatchAllOIs) + '}' +
206                ", Credential=" + mCredential +
207                ", FriendlyName='" + mFriendlyName + '\'' +
208                ", IconURL='" + mIconURL + '\'' +
209                '}';
210    }
211}
212