summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2016-11-30 11:38:03 -0800
committerPeter Qiu <zqiu@google.com>2016-12-06 09:32:45 -0800
commitf1b7517b04fedc6fd81f34a8cb84ce583b8ea63e (patch)
tree417a756a884c53e6a21e86497427be71797f0e33 /service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java
parentb40ba9e6ef82ac6c82869d1b562701483b8f1fc2 (diff)
downloadandroid_frameworks_opt_net_wifi-f1b7517b04fedc6fd81f34a8cb84ce583b8ea63e.tar.gz
android_frameworks_opt_net_wifi-f1b7517b04fedc6fd81f34a8cb84ce583b8ea63e.tar.bz2
android_frameworks_opt_net_wifi-f1b7517b04fedc6fd81f34a8cb84ce583b8ea63e.zip
hotspot2: simplify ANQP cache management
This makes the AnqpCache just a simple data cache, all the logic related to the ANQP query (e.g. pending query, backoff timeout) will be handled elsewhere (e.g. PasspointManager). Also simplify the cache entry expiration timeout (entries with ANQP domain ID vs entries without ANQP domain ID) by using one timeout for all entries, since this is already factored in the ANQP entry key. Entries without ANQP domain ID will be keyed per AP (SSID + BSSID) and entries with ANQP domain ID will be keyed per ESS (either SSID or HESSID). TODO: update unit tests once the cleanup for ANQP elements are completed, so that we can easily construct an ANQPElement objects (without constructing a raw byte buffer). Bug: 31348912 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I6d85f69181755afa7845f9f742c2dfb762c3194c
Diffstat (limited to 'service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java')
-rw-r--r--service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java b/service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java
new file mode 100644
index 000000000..aaaedb37d
--- /dev/null
+++ b/service/java/com/android/server/wifi/hotspot2/ANQPNetworkKey.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2;
+
+import android.text.TextUtils;
+
+/**
+ * Unique key for identifying APs that will contain the same ANQP information.
+ *
+ * APs in the same ESS (SSID or HESSID) with the same ANQP domain ID will have the same ANQP
+ * information. Thus, those APs will be keyed by the ESS identifier (SSID or HESSID) and the
+ * ANQP domain ID.
+ *
+ * APs without ANQP domain ID set will assumed to have unique ANQP information. Thus, those
+ * APs will be keyed by SSID and BSSID.
+ */
+public class ANQPNetworkKey {
+ private final String mSSID;
+ private final long mBSSID;
+ private final long mHESSID;
+ private final int mAnqpDomainID;
+
+ public ANQPNetworkKey(String ssid, long bssid, long hessid, int anqpDomainID) {
+ mSSID = ssid;
+ mBSSID = bssid;
+ mHESSID = hessid;
+ mAnqpDomainID = anqpDomainID;
+ }
+
+ /**
+ * Build an ANQP network key suitable for the granularity of the key space as follows:
+ *
+ * HESSID domainID Key content Rationale
+ * -------- ----------- ----------- --------------------
+ * n/a zero SSID/BSSID Domain ID indicates unique AP info
+ * not set set SSID/domainID Standard definition of an ESS
+ * set set HESSID/domainID The ESS is defined by the HESSID
+ *
+ * @param ssid The SSID of the AP
+ * @param bssid The BSSID of the AP
+ * @param hessid The HESSID of the AP
+ * @param anqpDomainId The ANQP Domain ID of the AP
+ * @return {@link ANQPNetworkKey}
+ */
+ public static ANQPNetworkKey buildKey(String ssid, long bssid, long hessid, int anqpDomainId) {
+ if (anqpDomainId == 0) {
+ return new ANQPNetworkKey(ssid, bssid, 0, 0);
+ } else if (hessid != 0L) {
+ return new ANQPNetworkKey(null, 0, hessid, anqpDomainId);
+ }
+ return new ANQPNetworkKey(ssid, 0, 0, anqpDomainId);
+ }
+
+ @Override
+ public int hashCode() {
+ if (mHESSID != 0) {
+ return (int) (((mHESSID >>> 32) * 31 + mHESSID) * 31 + mAnqpDomainID);
+ } else if (mBSSID != 0) {
+ return (int) ((mSSID.hashCode() * 31 + (mBSSID >>> 32)) * 31 + mBSSID);
+ } else {
+ return mSSID.hashCode() * 31 + mAnqpDomainID;
+ }
+ }
+
+ @Override
+ public boolean equals(Object thatObject) {
+ if (thatObject == this) {
+ return true;
+ }
+ if (!(thatObject instanceof ANQPNetworkKey)) {
+ return false;
+ }
+ ANQPNetworkKey that = (ANQPNetworkKey) thatObject;
+ return TextUtils.equals(that.mSSID, mSSID)
+ && that.mBSSID == mBSSID
+ && that.mHESSID == mHESSID
+ && that.mAnqpDomainID == mAnqpDomainID;
+ }
+
+ @Override
+ public String toString() {
+ if (mHESSID != 0L) {
+ return Utils.macToString(mHESSID) + ":" + mAnqpDomainID;
+ } else if (mBSSID != 0L) {
+ return Utils.macToString(mBSSID)
+ + ":<" + Utils.toUnicodeEscapedString(mSSID) + ">";
+ } else {
+ return "<" + Utils.toUnicodeEscapedString(mSSID) + ">:" + mAnqpDomainID;
+ }
+ }
+}