diff --git a/packages/Osu/Android.mk b/packages/Osu/Android.mk
deleted file mode 100644
index 63c7578b01635..0000000000000
--- a/packages/Osu/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_SRC_FILES += \
- src/com/android/hotspot2/app/IOSUAccessor.aidl \
- src/com/android/hotspot2/flow/IFlowService.aidl
-
-LOCAL_JAVA_LIBRARIES := telephony-common ims-common bouncycastle conscrypt
-
-LOCAL_PACKAGE_NAME := Osu
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-LOCAL_PRIVILEGED_MODULE := true
-
-include $(BUILD_PACKAGE)
-
-########################
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/packages/Osu/AndroidManifest.xml b/packages/Osu/AndroidManifest.xml
deleted file mode 100644
index b804739f5e42a..0000000000000
--- a/packages/Osu/AndroidManifest.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/Osu/res/layout/activity_main.xml b/packages/Osu/res/layout/activity_main.xml
deleted file mode 100644
index 7e335377dc11a..0000000000000
--- a/packages/Osu/res/layout/activity_main.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
diff --git a/packages/Osu/res/layout/list_item.xml b/packages/Osu/res/layout/list_item.xml
deleted file mode 100644
index eb431d39b517b..0000000000000
--- a/packages/Osu/res/layout/list_item.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/packages/Osu/res/layout/osu_web_view.xml b/packages/Osu/res/layout/osu_web_view.xml
deleted file mode 100644
index 4eafb39d17135..0000000000000
--- a/packages/Osu/res/layout/osu_web_view.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
diff --git a/packages/Osu/res/mipmap-hdpi/ic_launcher.png b/packages/Osu/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index cde69bcccec65..0000000000000
Binary files a/packages/Osu/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/packages/Osu/res/mipmap-mdpi/ic_launcher.png b/packages/Osu/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index c133a0cbd379f..0000000000000
Binary files a/packages/Osu/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/packages/Osu/res/mipmap-xhdpi/ic_launcher.png b/packages/Osu/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index bfa42f0e7b91d..0000000000000
Binary files a/packages/Osu/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/packages/Osu/res/mipmap-xxhdpi/ic_launcher.png b/packages/Osu/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 324e72cdd7480..0000000000000
Binary files a/packages/Osu/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/packages/Osu/res/mipmap-xxxhdpi/ic_launcher.png b/packages/Osu/res/mipmap-xxxhdpi/ic_launcher.png
deleted file mode 100644
index aee44e1384346..0000000000000
Binary files a/packages/Osu/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/packages/Osu/res/values-w820dp/dimens.xml b/packages/Osu/res/values-w820dp/dimens.xml
deleted file mode 100644
index 63fc816444614..0000000000000
--- a/packages/Osu/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 64dp
-
diff --git a/packages/Osu/res/values/colors.xml b/packages/Osu/res/values/colors.xml
deleted file mode 100644
index 3ab3e9cbce07f..0000000000000
--- a/packages/Osu/res/values/colors.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- #3F51B5
- #303F9F
- #FF4081
-
diff --git a/packages/Osu/res/values/dimens.xml b/packages/Osu/res/values/dimens.xml
deleted file mode 100644
index 47c82246738c4..0000000000000
--- a/packages/Osu/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- 16dp
- 16dp
-
diff --git a/packages/Osu/res/values/strings.xml b/packages/Osu/res/values/strings.xml
deleted file mode 100644
index 93593dc0be509..0000000000000
--- a/packages/Osu/res/values/strings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
- OSU
- No OSU available
-
diff --git a/packages/Osu/src/com/android/anqp/ANQPElement.java b/packages/Osu/src/com/android/anqp/ANQPElement.java
deleted file mode 100644
index 58aee29e106bd..0000000000000
--- a/packages/Osu/src/com/android/anqp/ANQPElement.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.android.anqp;
-
-/**
- * Base class for an IEEE802.11u ANQP element.
- */
-public abstract class ANQPElement {
- private final Constants.ANQPElementType mID;
-
- protected ANQPElement(Constants.ANQPElementType id) {
- mID = id;
- }
-
- public Constants.ANQPElementType getID() {
- return mID;
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/Constants.java b/packages/Osu/src/com/android/anqp/Constants.java
deleted file mode 100644
index 214bb93f41ddb..0000000000000
--- a/packages/Osu/src/com/android/anqp/Constants.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package com.android.anqp;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ANQP related constants (802.11-2012)
- */
-public class Constants {
-
- public static final int NIBBLE_MASK = 0x0f;
- public static final int BYTE_MASK = 0xff;
- public static final int SHORT_MASK = 0xffff;
- public static final long INT_MASK = 0xffffffffL;
- public static final int BYTES_IN_SHORT = 2;
- public static final int BYTES_IN_INT = 4;
- public static final int BYTES_IN_EUI48 = 6;
- public static final long MILLIS_IN_A_SEC = 1000L;
-
- public static final int HS20_PREFIX = 0x119a6f50; // Note that this is represented as a LE int
- public static final int HS20_FRAME_PREFIX = 0x109a6f50;
- public static final int UTF8_INDICATOR = 1;
-
- public static final int LANG_CODE_LENGTH = 3;
-
- public static final int ANQP_QUERY_LIST = 256;
- public static final int ANQP_CAPABILITY_LIST = 257;
- public static final int ANQP_VENUE_NAME = 258;
- public static final int ANQP_EMERGENCY_NUMBER = 259;
- public static final int ANQP_NWK_AUTH_TYPE = 260;
- public static final int ANQP_ROAMING_CONSORTIUM = 261;
- public static final int ANQP_IP_ADDR_AVAILABILITY = 262;
- public static final int ANQP_NAI_REALM = 263;
- public static final int ANQP_3GPP_NETWORK = 264;
- public static final int ANQP_GEO_LOC = 265;
- public static final int ANQP_CIVIC_LOC = 266;
- public static final int ANQP_LOC_URI = 267;
- public static final int ANQP_DOM_NAME = 268;
- public static final int ANQP_EMERGENCY_ALERT = 269;
- public static final int ANQP_TDLS_CAP = 270;
- public static final int ANQP_EMERGENCY_NAI = 271;
- public static final int ANQP_NEIGHBOR_REPORT = 272;
- public static final int ANQP_VENDOR_SPEC = 56797;
-
- public static final int HS_QUERY_LIST = 1;
- public static final int HS_CAPABILITY_LIST = 2;
- public static final int HS_FRIENDLY_NAME = 3;
- public static final int HS_WAN_METRICS = 4;
- public static final int HS_CONN_CAPABILITY = 5;
- public static final int HS_NAI_HOME_REALM_QUERY = 6;
- public static final int HS_OPERATING_CLASS = 7;
- public static final int HS_OSU_PROVIDERS = 8;
- public static final int HS_ICON_REQUEST = 10;
- public static final int HS_ICON_FILE = 11;
-
- public enum ANQPElementType {
- ANQPQueryList,
- ANQPCapabilityList,
- ANQPVenueName,
- ANQPEmergencyNumber,
- ANQPNwkAuthType,
- ANQPRoamingConsortium,
- ANQPIPAddrAvailability,
- ANQPNAIRealm,
- ANQP3GPPNetwork,
- ANQPGeoLoc,
- ANQPCivicLoc,
- ANQPLocURI,
- ANQPDomName,
- ANQPEmergencyAlert,
- ANQPTDLSCap,
- ANQPEmergencyNAI,
- ANQPNeighborReport,
- ANQPVendorSpec,
- HSQueryList,
- HSCapabilityList,
- HSFriendlyName,
- HSWANMetrics,
- HSConnCapability,
- HSNAIHomeRealmQuery,
- HSOperatingclass,
- HSOSUProviders,
- HSIconRequest,
- HSIconFile
- }
-
- private static final Map sAnqpMap = new HashMap<>();
- private static final Map sHs20Map = new HashMap<>();
- private static final Map sRevAnqpmap =
- new EnumMap<>(ANQPElementType.class);
- private static final Map sRevHs20map =
- new EnumMap<>(ANQPElementType.class);
-
- static {
- sAnqpMap.put(ANQP_QUERY_LIST, ANQPElementType.ANQPQueryList);
- sAnqpMap.put(ANQP_CAPABILITY_LIST, ANQPElementType.ANQPCapabilityList);
- sAnqpMap.put(ANQP_VENUE_NAME, ANQPElementType.ANQPVenueName);
- sAnqpMap.put(ANQP_EMERGENCY_NUMBER, ANQPElementType.ANQPEmergencyNumber);
- sAnqpMap.put(ANQP_NWK_AUTH_TYPE, ANQPElementType.ANQPNwkAuthType);
- sAnqpMap.put(ANQP_ROAMING_CONSORTIUM, ANQPElementType.ANQPRoamingConsortium);
- sAnqpMap.put(ANQP_IP_ADDR_AVAILABILITY, ANQPElementType.ANQPIPAddrAvailability);
- sAnqpMap.put(ANQP_NAI_REALM, ANQPElementType.ANQPNAIRealm);
- sAnqpMap.put(ANQP_3GPP_NETWORK, ANQPElementType.ANQP3GPPNetwork);
- sAnqpMap.put(ANQP_GEO_LOC, ANQPElementType.ANQPGeoLoc);
- sAnqpMap.put(ANQP_CIVIC_LOC, ANQPElementType.ANQPCivicLoc);
- sAnqpMap.put(ANQP_LOC_URI, ANQPElementType.ANQPLocURI);
- sAnqpMap.put(ANQP_DOM_NAME, ANQPElementType.ANQPDomName);
- sAnqpMap.put(ANQP_EMERGENCY_ALERT, ANQPElementType.ANQPEmergencyAlert);
- sAnqpMap.put(ANQP_TDLS_CAP, ANQPElementType.ANQPTDLSCap);
- sAnqpMap.put(ANQP_EMERGENCY_NAI, ANQPElementType.ANQPEmergencyNAI);
- sAnqpMap.put(ANQP_NEIGHBOR_REPORT, ANQPElementType.ANQPNeighborReport);
- sAnqpMap.put(ANQP_VENDOR_SPEC, ANQPElementType.ANQPVendorSpec);
-
- sHs20Map.put(HS_QUERY_LIST, ANQPElementType.HSQueryList);
- sHs20Map.put(HS_CAPABILITY_LIST, ANQPElementType.HSCapabilityList);
- sHs20Map.put(HS_FRIENDLY_NAME, ANQPElementType.HSFriendlyName);
- sHs20Map.put(HS_WAN_METRICS, ANQPElementType.HSWANMetrics);
- sHs20Map.put(HS_CONN_CAPABILITY, ANQPElementType.HSConnCapability);
- sHs20Map.put(HS_NAI_HOME_REALM_QUERY, ANQPElementType.HSNAIHomeRealmQuery);
- sHs20Map.put(HS_OPERATING_CLASS, ANQPElementType.HSOperatingclass);
- sHs20Map.put(HS_OSU_PROVIDERS, ANQPElementType.HSOSUProviders);
- sHs20Map.put(HS_ICON_REQUEST, ANQPElementType.HSIconRequest);
- sHs20Map.put(HS_ICON_FILE, ANQPElementType.HSIconFile);
-
- for (Map.Entry entry : sAnqpMap.entrySet()) {
- sRevAnqpmap.put(entry.getValue(), entry.getKey());
- }
- for (Map.Entry entry : sHs20Map.entrySet()) {
- sRevHs20map.put(entry.getValue(), entry.getKey());
- }
- }
-
- public static ANQPElementType mapANQPElement(int id) {
- return sAnqpMap.get(id);
- }
-
- public static ANQPElementType mapHS20Element(int id) {
- return sHs20Map.get(id);
- }
-
- public static Integer getANQPElementID(ANQPElementType elementType) {
- return sRevAnqpmap.get(elementType);
- }
-
- public static Integer getHS20ElementID(ANQPElementType elementType) {
- return sRevHs20map.get(elementType);
- }
-
- public static boolean hasBaseANQPElements(Collection elements) {
- if (elements == null) {
- return false;
- }
- for (ANQPElementType element : elements) {
- if (sRevAnqpmap.containsKey(element)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean hasR2Elements(List elements) {
- return elements.contains(ANQPElementType.HSOSUProviders);
- }
-
- public static long getInteger(ByteBuffer payload, ByteOrder bo, int size) {
- byte[] octets = new byte[size];
- payload.get(octets);
- long value = 0;
- if (bo == ByteOrder.LITTLE_ENDIAN) {
- for (int n = octets.length - 1; n >= 0; n--) {
- value = (value << Byte.SIZE) | (octets[n] & BYTE_MASK);
- }
- }
- else {
- for (byte octet : octets) {
- value = (value << Byte.SIZE) | (octet & BYTE_MASK);
- }
- }
- return value;
- }
-
- public static String getPrefixedString(ByteBuffer payload, int lengthLength, Charset charset)
- throws ProtocolException {
- return getPrefixedString(payload, lengthLength, charset, false);
- }
-
- public static String getPrefixedString(ByteBuffer payload, int lengthLength, Charset charset,
- boolean useNull) throws ProtocolException {
- if (payload.remaining() < lengthLength) {
- throw new ProtocolException("Runt string: " + payload.remaining());
- }
- return getString(payload, (int) getInteger(payload, ByteOrder.LITTLE_ENDIAN,
- lengthLength), charset, useNull);
- }
-
- public static String getTrimmedString(ByteBuffer payload, int length, Charset charset)
- throws ProtocolException {
- String s = getString(payload, length, charset, false);
- int zero = length - 1;
- while (zero >= 0) {
- if (s.charAt(zero) != 0) {
- break;
- }
- zero--;
- }
- return zero < length - 1 ? s.substring(0, zero + 1) : s;
- }
-
- public static String getString(ByteBuffer payload, int length, Charset charset)
- throws ProtocolException {
- return getString(payload, length, charset, false);
- }
-
- public static String getString(ByteBuffer payload, int length, Charset charset, boolean useNull)
- throws ProtocolException {
- if (length > payload.remaining()) {
- throw new ProtocolException("Bad string length: " + length);
- }
- if (useNull && length == 0) {
- return null;
- }
- byte[] octets = new byte[length];
- payload.get(octets);
- return new String(octets, charset);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/HSIconFileElement.java b/packages/Osu/src/com/android/anqp/HSIconFileElement.java
deleted file mode 100644
index 28c597a5d47a5..0000000000000
--- a/packages/Osu/src/com/android/anqp/HSIconFileElement.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package com.android.anqp;
-
-import android.os.Parcel;
-
-import com.android.hotspot2.Utils;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-import static com.android.anqp.Constants.SHORT_MASK;
-
-/**
- * The Icon Binary File vendor specific ANQP Element,
- * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
- * section 4.11
- */
-public class HSIconFileElement extends ANQPElement {
-
- public enum StatusCode {Success, FileNotFound, Unspecified}
-
- private final StatusCode mStatusCode;
- private final String mType;
- private final byte[] mIconData;
-
- public HSIconFileElement(Constants.ANQPElementType infoID, ByteBuffer payload)
- throws ProtocolException {
- super(infoID);
-
- if (payload.remaining() < 4) {
- throw new ProtocolException("Truncated icon file: " + payload.remaining());
- }
-
- int statusID = payload.get() & BYTE_MASK;
- mStatusCode = statusID < StatusCode.values().length ? StatusCode.values()[statusID] : null;
- mType = Constants.getPrefixedString(payload, 1, StandardCharsets.US_ASCII);
-
- int dataLength = payload.getShort() & SHORT_MASK;
- mIconData = new byte[dataLength];
- payload.get(mIconData);
- }
-
- public StatusCode getStatusCode() {
- return mStatusCode;
- }
-
- public String getType() {
- return mType;
- }
-
- public byte[] getIconData() {
- return mIconData;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject.getClass() != HSIconFileElement.class) {
- return false;
- }
- HSIconFileElement that = (HSIconFileElement) thatObject;
- if (getStatusCode() != that.getStatusCode() || getStatusCode() != StatusCode.Success) {
- return false;
- }
- return getType().equals(that.getType()) && Arrays.equals(getIconData(), that.getIconData());
- }
-
- @Override
- public String toString() {
- return "HSIconFile{" +
- "statusCode=" + mStatusCode +
- ", type='" + mType + '\'' +
- ", iconData=" + mIconData.length + " bytes }";
- }
-
- public HSIconFileElement(Parcel in) {
- super(Constants.ANQPElementType.HSIconFile);
- mStatusCode = Utils.mapEnum(in.readInt(), StatusCode.class);
- mType = in.readString();
- mIconData = in.readBlob();
- }
-
- public void writeParcel(Parcel out) {
- out.writeInt(mStatusCode.ordinal());
- out.writeString(mType);
- out.writeBlob(mIconData);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/HSOsuProvidersElement.java b/packages/Osu/src/com/android/anqp/HSOsuProvidersElement.java
deleted file mode 100644
index 646e003ef3507..0000000000000
--- a/packages/Osu/src/com/android/anqp/HSOsuProvidersElement.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.android.anqp;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * The OSU Providers List vendor specific ANQP Element,
- * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
- * section 4.8
- */
-public class HSOsuProvidersElement extends ANQPElement {
- private final String mSSID;
- private final List mProviders;
-
- public HSOsuProvidersElement(Constants.ANQPElementType infoID, ByteBuffer payload)
- throws ProtocolException {
- super(infoID);
-
- mSSID = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8);
- int providerCount = payload.get() & Constants.BYTE_MASK;
-
- mProviders = new ArrayList<>(providerCount);
-
- while (providerCount > 0) {
- mProviders.add(new OSUProvider(mSSID, payload));
- providerCount--;
- }
- }
-
- public String getSSID() {
- return mSSID;
- }
-
- public List getProviders() {
- return Collections.unmodifiableList(mProviders);
- }
-
- @Override
- public String toString() {
- return "HSOsuProviders{" +
- "SSID='" + mSSID + '\'' +
- ", providers=" + mProviders +
- '}';
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/I18Name.java b/packages/Osu/src/com/android/anqp/I18Name.java
deleted file mode 100644
index b048228722c5a..0000000000000
--- a/packages/Osu/src/com/android/anqp/I18Name.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.android.anqp;
-
-import android.os.Parcel;
-
-import java.io.IOException;
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.Locale;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-
-/**
- * A generic Internationalized name used in ANQP elements as specified in 802.11-2012 and
- * "Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00"
- */
-public class I18Name {
- private final String mLanguage;
- private final Locale mLocale;
- private final String mText;
-
- public I18Name(ByteBuffer payload) throws ProtocolException {
- if (payload.remaining() < Constants.LANG_CODE_LENGTH + 1) {
- throw new ProtocolException("Truncated I18Name: " + payload.remaining());
- }
- int nameLength = payload.get() & BYTE_MASK;
- if (nameLength < Constants.LANG_CODE_LENGTH) {
- throw new ProtocolException("Runt I18Name: " + nameLength);
- }
- mLanguage = Constants.getTrimmedString(payload,
- Constants.LANG_CODE_LENGTH, StandardCharsets.US_ASCII);
- mLocale = Locale.forLanguageTag(mLanguage);
- mText = Constants.getString(payload, nameLength -
- Constants.LANG_CODE_LENGTH, StandardCharsets.UTF_8);
- }
-
- public I18Name(String compoundString) throws IOException {
- if (compoundString.length() < Constants.LANG_CODE_LENGTH) {
- throw new IOException("I18String too short: '" + compoundString + "'");
- }
- mLanguage = compoundString.substring(0, Constants.LANG_CODE_LENGTH);
- mText = compoundString.substring(Constants.LANG_CODE_LENGTH);
- mLocale = Locale.forLanguageTag(mLanguage);
- }
-
- public String getLanguage() {
- return mLanguage;
- }
-
- public Locale getLocale() {
- return mLocale;
- }
-
- public String getText() {
- return mText;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (this == thatObject) {
- return true;
- }
- if (thatObject == null || getClass() != thatObject.getClass()) {
- return false;
- }
-
- I18Name that = (I18Name) thatObject;
- return mLanguage.equals(that.mLanguage) && mText.equals(that.mText);
- }
-
- @Override
- public int hashCode() {
- int result = mLanguage.hashCode();
- result = 31 * result + mText.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return mText + ':' + mLocale.getLanguage();
- }
-
- public I18Name(Parcel in) throws IOException {
- mLanguage = in.readString();
- mText = in.readString();
- mLocale = Locale.forLanguageTag(mLanguage);
- }
-
- public void writeParcel(Parcel out) {
- out.writeString(mLanguage);
- out.writeString(mText);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/IconInfo.java b/packages/Osu/src/com/android/anqp/IconInfo.java
deleted file mode 100644
index ac507c7af948e..0000000000000
--- a/packages/Osu/src/com/android/anqp/IconInfo.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.android.anqp;
-
-import android.os.Parcel;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-
-import static com.android.anqp.Constants.SHORT_MASK;
-
-/**
- * The Icons available OSU Providers sub field, as specified in
- * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
- * section 4.8.1.4
- */
-public class IconInfo {
- private final int mWidth;
- private final int mHeight;
- private final String mLanguage;
- private final String mIconType;
- private final String mFileName;
-
- public IconInfo(ByteBuffer payload) throws ProtocolException {
- if (payload.remaining() < 9) {
- throw new ProtocolException("Truncated icon meta data");
- }
-
- mWidth = payload.getShort() & SHORT_MASK;
- mHeight = payload.getShort() & SHORT_MASK;
- mLanguage = Constants.getTrimmedString(payload,
- Constants.LANG_CODE_LENGTH, StandardCharsets.US_ASCII);
- mIconType = Constants.getPrefixedString(payload, 1, StandardCharsets.US_ASCII);
- mFileName = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8);
- }
-
- public int getWidth() {
- return mWidth;
- }
-
- public int getHeight() {
- return mHeight;
- }
-
- public String getLanguage() {
- return mLanguage;
- }
-
- public String getIconType() {
- return mIconType;
- }
-
- public String getFileName() {
- return mFileName;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (this == thatObject) {
- return true;
- }
- if (thatObject == null || getClass() != thatObject.getClass()) {
- return false;
- }
-
- IconInfo that = (IconInfo) thatObject;
- return mHeight == that.mHeight &&
- mWidth == that.mWidth &&
- mFileName.equals(that.mFileName) &&
- mIconType.equals(that.mIconType) &&
- mLanguage.equals(that.mLanguage);
- }
-
- @Override
- public int hashCode() {
- int result = mWidth;
- result = 31 * result + mHeight;
- result = 31 * result + mLanguage.hashCode();
- result = 31 * result + mIconType.hashCode();
- result = 31 * result + mFileName.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return "IconInfo{" +
- "Width=" + mWidth +
- ", Height=" + mHeight +
- ", Language=" + mLanguage +
- ", IconType='" + mIconType + '\'' +
- ", FileName='" + mFileName + '\'' +
- '}';
- }
-
- public IconInfo(Parcel in) {
- mWidth = in.readInt();
- mHeight = in.readInt();
- mLanguage = in.readString();
- mIconType = in.readString();
- mFileName = in.readString();
- }
-
- public void writeParcel(Parcel out) {
- out.writeInt(mWidth);
- out.writeInt(mHeight);
- out.writeString(mLanguage);
- out.writeString(mIconType);
- out.writeString(mFileName);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/OSUProvider.java b/packages/Osu/src/com/android/anqp/OSUProvider.java
deleted file mode 100644
index 3724cf06d15bd..0000000000000
--- a/packages/Osu/src/com/android/anqp/OSUProvider.java
+++ /dev/null
@@ -1,213 +0,0 @@
-package com.android.anqp;
-
-import android.os.Parcel;
-
-import com.android.hotspot2.Utils;
-
-import java.io.IOException;
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-import static com.android.anqp.Constants.SHORT_MASK;
-
-/**
- * An OSU Provider, as specified in
- * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
- * section 4.8.1
- */
-public class OSUProvider {
-
- public enum OSUMethod {OmaDm, SoapXml}
-
- private final String mSSID;
- private final List mNames;
- private final String mOSUServer;
- private final List mOSUMethods;
- private final List mIcons;
- private final String mOsuNai;
- private final List mServiceDescriptions;
- private final int mHashCode;
-
- public OSUProvider(String ssid, ByteBuffer payload) throws ProtocolException {
- if (payload.remaining() < 11) {
- throw new ProtocolException("Truncated OSU provider: " + payload.remaining());
- }
-
- mSSID = ssid;
-
- int length = payload.getShort() & SHORT_MASK;
- int namesLength = payload.getShort() & SHORT_MASK;
-
- ByteBuffer namesBuffer = payload.duplicate().order(ByteOrder.LITTLE_ENDIAN);
- namesBuffer.limit(namesBuffer.position() + namesLength);
- payload.position(payload.position() + namesLength);
-
- mNames = new ArrayList<>();
-
- while (namesBuffer.hasRemaining()) {
- mNames.add(new I18Name(namesBuffer));
- }
-
- mOSUServer = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8);
- int methodLength = payload.get() & BYTE_MASK;
- mOSUMethods = new ArrayList<>(methodLength);
- while (methodLength > 0) {
- int methodID = payload.get() & BYTE_MASK;
- mOSUMethods.add(methodID < OSUMethod.values().length ?
- OSUMethod.values()[methodID] :
- null);
- methodLength--;
- }
-
- int iconsLength = payload.getShort() & SHORT_MASK;
- ByteBuffer iconsBuffer = payload.duplicate().order(ByteOrder.LITTLE_ENDIAN);
- iconsBuffer.limit(iconsBuffer.position() + iconsLength);
- payload.position(payload.position() + iconsLength);
-
- mIcons = new ArrayList<>();
-
- while (iconsBuffer.hasRemaining()) {
- mIcons.add(new IconInfo(iconsBuffer));
- }
-
- mOsuNai = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8, true);
-
- int descriptionsLength = payload.getShort() & SHORT_MASK;
- ByteBuffer descriptionsBuffer = payload.duplicate().order(ByteOrder.LITTLE_ENDIAN);
- descriptionsBuffer.limit(descriptionsBuffer.position() + descriptionsLength);
- payload.position(payload.position() + descriptionsLength);
-
- mServiceDescriptions = new ArrayList<>();
-
- while (descriptionsBuffer.hasRemaining()) {
- mServiceDescriptions.add(new I18Name(descriptionsBuffer));
- }
-
- int result = mNames.hashCode();
- result = 31 * result + mSSID.hashCode();
- result = 31 * result + mOSUServer.hashCode();
- result = 31 * result + mOSUMethods.hashCode();
- result = 31 * result + mIcons.hashCode();
- result = 31 * result + (mOsuNai != null ? mOsuNai.hashCode() : 0);
- result = 31 * result + mServiceDescriptions.hashCode();
- mHashCode = result;
- }
-
- public String getSSID() {
- return mSSID;
- }
-
- public List getNames() {
- return mNames;
- }
-
- public String getOSUServer() {
- return mOSUServer;
- }
-
- public List getOSUMethods() {
- return mOSUMethods;
- }
-
- public List getIcons() {
- return mIcons;
- }
-
- public String getOsuNai() {
- return mOsuNai;
- }
-
- public List getServiceDescriptions() {
- return mServiceDescriptions;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- OSUProvider that = (OSUProvider) o;
-
- if (!mSSID.equals(that.mSSID)) return false;
- if (!mOSUServer.equals(that.mOSUServer)) return false;
- if (!mNames.equals(that.mNames)) return false;
- if (!mServiceDescriptions.equals(that.mServiceDescriptions)) return false;
- if (!mIcons.equals(that.mIcons)) return false;
- if (!mOSUMethods.equals(that.mOSUMethods)) return false;
- if (mOsuNai != null ? !mOsuNai.equals(that.mOsuNai) : that.mOsuNai != null) return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- return mHashCode;
- }
-
- @Override
- public String toString() {
- return "OSUProvider{" +
- "names=" + mNames +
- ", OSUServer='" + mOSUServer + '\'' +
- ", OSUMethods=" + mOSUMethods +
- ", icons=" + mIcons +
- ", NAI='" + mOsuNai + '\'' +
- ", serviceDescriptions=" + mServiceDescriptions +
- '}';
- }
-
- public OSUProvider(Parcel in) throws IOException {
- mSSID = in.readString();
- int nameCount = in.readInt();
- mNames = new ArrayList<>(nameCount);
- for (int n = 0; n < nameCount; n++) {
- mNames.add(new I18Name(in));
- }
- mOSUServer = in.readString();
- int methodCount = in.readInt();
- mOSUMethods = new ArrayList<>(methodCount);
- for (int n = 0; n < methodCount; n++) {
- mOSUMethods.add(Utils.mapEnum(in.readInt(), OSUMethod.class));
- }
- int iconCount = in.readInt();
- mIcons = new ArrayList<>(iconCount);
- for (int n = 0; n < iconCount; n++) {
- mIcons.add(new IconInfo(in));
- }
- mOsuNai = in.readString();
- int serviceCount = in.readInt();
- mServiceDescriptions = new ArrayList<>(serviceCount);
- for (int n = 0; n < serviceCount; n++) {
- mServiceDescriptions.add(new I18Name(in));
- }
- mHashCode = in.readInt();
- }
-
- public void writeParcel(Parcel out) {
- out.writeString(mSSID);
- out.writeInt(mNames.size());
- for (I18Name name : mNames) {
- name.writeParcel(out);
- }
- out.writeString(mOSUServer);
- out.writeInt(mOSUMethods.size());
- for (OSUMethod method : mOSUMethods) {
- out.writeInt(method.ordinal());
- }
- out.writeInt(mIcons.size());
- for (IconInfo iconInfo : mIcons) {
- iconInfo.writeParcel(out);
- }
- out.writeString(mOsuNai);
- out.writeInt(mServiceDescriptions.size());
- for (I18Name serviceDescription : mServiceDescriptions) {
- serviceDescription.writeParcel(out);
- }
- out.writeInt(mHashCode);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/AuthParam.java b/packages/Osu/src/com/android/anqp/eap/AuthParam.java
deleted file mode 100644
index 4243954a61bda..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/AuthParam.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.android.anqp.eap;
-
-/**
- * An Authentication parameter, part of the NAI Realm ANQP element, specified in
- * IEEE802.11-2012 section 8.4.4.10, table 8-188
- */
-public interface AuthParam {
- public EAP.AuthInfoID getAuthInfoID();
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/Credential.java b/packages/Osu/src/com/android/anqp/eap/Credential.java
deleted file mode 100644
index 0a89f4fffe9dc..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/Credential.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.android.anqp.eap;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-
-/**
- * An EAP authentication parameter, IEEE802.11-2012, table 8-188
- */
-public class Credential implements AuthParam {
-
- public enum CredType {
- Reserved,
- SIM,
- USIM,
- NFC,
- HWToken,
- Softoken,
- Certificate,
- Username,
- None,
- Anonymous,
- VendorSpecific}
-
- private final EAP.AuthInfoID mAuthInfoID;
- private final CredType mCredType;
-
- public Credential(EAP.AuthInfoID infoID, int length, ByteBuffer payload)
- throws ProtocolException {
- if (length != 1) {
- throw new ProtocolException("Bad length: " + length);
- }
-
- mAuthInfoID = infoID;
- int typeID = payload.get() & BYTE_MASK;
-
- mCredType = typeID < CredType.values().length ?
- CredType.values()[typeID] :
- CredType.Reserved;
- }
-
- @Override
- public EAP.AuthInfoID getAuthInfoID() {
- return mAuthInfoID;
- }
-
- @Override
- public int hashCode() {
- return mAuthInfoID.hashCode() * 31 + mCredType.hashCode();
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject == null || thatObject.getClass() != Credential.class) {
- return false;
- } else {
- return ((Credential) thatObject).getCredType() == getCredType();
- }
- }
-
- public CredType getCredType() {
- return mCredType;
- }
-
- @Override
- public String toString() {
- return "Auth method " + mAuthInfoID + " = " + mCredType + "\n";
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/EAP.java b/packages/Osu/src/com/android/anqp/eap/EAP.java
deleted file mode 100644
index 4b968b6cbf39a..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/EAP.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package com.android.anqp.eap;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * EAP Related constants for the ANQP NAIRealm element, IEEE802.11-2012 section 8.4.4.10
- */
-public abstract class EAP {
-
- private static final Map sEapIds = new HashMap<>();
- private static final Map sRevEapIds = new HashMap<>();
- private static final Map sAuthIds = new HashMap<>();
-
- public static final int EAP_MD5 = 4;
- public static final int EAP_OTP = 5;
- public static final int EAP_RSA = 9;
- public static final int EAP_KEA = 11;
- public static final int EAP_KEA_VALIDATE = 12;
- public static final int EAP_TLS = 13;
- public static final int EAP_LEAP = 17;
- public static final int EAP_SIM = 18;
- public static final int EAP_TTLS = 21;
- public static final int EAP_AKA = 23;
- public static final int EAP_3Com = 24;
- public static final int EAP_MSCHAPv2 = 26;
- public static final int EAP_PEAP = 29;
- public static final int EAP_POTP = 32;
- public static final int EAP_ActiontecWireless = 35;
- public static final int EAP_HTTPDigest = 38;
- public static final int EAP_SPEKE = 41;
- public static final int EAP_MOBAC = 42;
- public static final int EAP_FAST = 43;
- public static final int EAP_ZLXEAP = 44;
- public static final int EAP_Link = 45;
- public static final int EAP_PAX = 46;
- public static final int EAP_PSK = 47;
- public static final int EAP_SAKE = 48;
- public static final int EAP_IKEv2 = 49;
- public static final int EAP_AKAPrim = 50;
- public static final int EAP_GPSK = 51;
- public static final int EAP_PWD = 52;
- public static final int EAP_EKE = 53;
- public static final int EAP_TEAP = 55;
-
- public enum EAPMethodID {
- EAP_MD5,
- EAP_OTP,
- EAP_RSA,
- EAP_KEA,
- EAP_KEA_VALIDATE,
- EAP_TLS,
- EAP_LEAP,
- EAP_SIM,
- EAP_TTLS,
- EAP_AKA,
- EAP_3Com,
- EAP_MSCHAPv2,
- EAP_PEAP,
- EAP_POTP,
- EAP_ActiontecWireless,
- EAP_HTTPDigest,
- EAP_SPEKE,
- EAP_MOBAC,
- EAP_FAST,
- EAP_ZLXEAP,
- EAP_Link,
- EAP_PAX,
- EAP_PSK,
- EAP_SAKE,
- EAP_IKEv2,
- EAP_AKAPrim,
- EAP_GPSK,
- EAP_PWD,
- EAP_EKE,
- EAP_TEAP
- }
-
- public static final int ExpandedEAPMethod = 1;
- public static final int NonEAPInnerAuthType = 2;
- public static final int InnerAuthEAPMethodType = 3;
- public static final int ExpandedInnerEAPMethod = 4;
- public static final int CredentialType = 5;
- public static final int TunneledEAPMethodCredType = 6;
- public static final int VendorSpecific = 221;
-
- public enum AuthInfoID {
- Undefined,
- ExpandedEAPMethod,
- NonEAPInnerAuthType,
- InnerAuthEAPMethodType,
- ExpandedInnerEAPMethod,
- CredentialType,
- TunneledEAPMethodCredType,
- VendorSpecific
- }
-
- static {
- sEapIds.put(EAP_MD5, EAPMethodID.EAP_MD5);
- sEapIds.put(EAP_OTP, EAPMethodID.EAP_OTP);
- sEapIds.put(EAP_RSA, EAPMethodID.EAP_RSA);
- sEapIds.put(EAP_KEA, EAPMethodID.EAP_KEA);
- sEapIds.put(EAP_KEA_VALIDATE, EAPMethodID.EAP_KEA_VALIDATE);
- sEapIds.put(EAP_TLS, EAPMethodID.EAP_TLS);
- sEapIds.put(EAP_LEAP, EAPMethodID.EAP_LEAP);
- sEapIds.put(EAP_SIM, EAPMethodID.EAP_SIM);
- sEapIds.put(EAP_TTLS, EAPMethodID.EAP_TTLS);
- sEapIds.put(EAP_AKA, EAPMethodID.EAP_AKA);
- sEapIds.put(EAP_3Com, EAPMethodID.EAP_3Com);
- sEapIds.put(EAP_MSCHAPv2, EAPMethodID.EAP_MSCHAPv2);
- sEapIds.put(EAP_PEAP, EAPMethodID.EAP_PEAP);
- sEapIds.put(EAP_POTP, EAPMethodID.EAP_POTP);
- sEapIds.put(EAP_ActiontecWireless, EAPMethodID.EAP_ActiontecWireless);
- sEapIds.put(EAP_HTTPDigest, EAPMethodID.EAP_HTTPDigest);
- sEapIds.put(EAP_SPEKE, EAPMethodID.EAP_SPEKE);
- sEapIds.put(EAP_MOBAC, EAPMethodID.EAP_MOBAC);
- sEapIds.put(EAP_FAST, EAPMethodID.EAP_FAST);
- sEapIds.put(EAP_ZLXEAP, EAPMethodID.EAP_ZLXEAP);
- sEapIds.put(EAP_Link, EAPMethodID.EAP_Link);
- sEapIds.put(EAP_PAX, EAPMethodID.EAP_PAX);
- sEapIds.put(EAP_PSK, EAPMethodID.EAP_PSK);
- sEapIds.put(EAP_SAKE, EAPMethodID.EAP_SAKE);
- sEapIds.put(EAP_IKEv2, EAPMethodID.EAP_IKEv2);
- sEapIds.put(EAP_AKAPrim, EAPMethodID.EAP_AKAPrim);
- sEapIds.put(EAP_GPSK, EAPMethodID.EAP_GPSK);
- sEapIds.put(EAP_PWD, EAPMethodID.EAP_PWD);
- sEapIds.put(EAP_EKE, EAPMethodID.EAP_EKE);
- sEapIds.put(EAP_TEAP, EAPMethodID.EAP_TEAP);
-
- for (Map.Entry entry : sEapIds.entrySet()) {
- sRevEapIds.put(entry.getValue(), entry.getKey());
- }
-
- sAuthIds.put(ExpandedEAPMethod, AuthInfoID.ExpandedEAPMethod);
- sAuthIds.put(NonEAPInnerAuthType, AuthInfoID.NonEAPInnerAuthType);
- sAuthIds.put(InnerAuthEAPMethodType, AuthInfoID.InnerAuthEAPMethodType);
- sAuthIds.put(ExpandedInnerEAPMethod, AuthInfoID.ExpandedInnerEAPMethod);
- sAuthIds.put(CredentialType, AuthInfoID.CredentialType);
- sAuthIds.put(TunneledEAPMethodCredType, AuthInfoID.TunneledEAPMethodCredType);
- sAuthIds.put(VendorSpecific, AuthInfoID.VendorSpecific);
- }
-
- public static EAPMethodID mapEAPMethod(int methodID) {
- return sEapIds.get(methodID);
- }
-
- public static Integer mapEAPMethod(EAPMethodID methodID) {
- return sRevEapIds.get(methodID);
- }
-
- public static AuthInfoID mapAuthMethod(int methodID) {
- return sAuthIds.get(methodID);
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/EAPMethod.java b/packages/Osu/src/com/android/anqp/eap/EAPMethod.java
deleted file mode 100644
index fa6c2f9dfb60a..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/EAPMethod.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package com.android.anqp.eap;
-
-import com.android.anqp.Constants;
-import com.android.hotspot2.AuthMatch;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * An EAP Method, part of the NAI Realm ANQP element, specified in
- * IEEE802.11-2012 section 8.4.4.10, figure 8-420
- */
-public class EAPMethod {
- private final EAP.EAPMethodID mEAPMethodID;
- private final Map> mAuthParams;
-
- public EAPMethod(ByteBuffer payload) throws ProtocolException {
- if (payload.remaining() < 3) {
- throw new ProtocolException("Runt EAP Method: " + payload.remaining());
- }
-
- int length = payload.get() & Constants.BYTE_MASK;
- int methodID = payload.get() & Constants.BYTE_MASK;
- int count = payload.get() & Constants.BYTE_MASK;
-
- mEAPMethodID = EAP.mapEAPMethod(methodID);
- mAuthParams = new EnumMap<>(EAP.AuthInfoID.class);
-
- int realCount = 0;
-
- ByteBuffer paramPayload = payload.duplicate().order(ByteOrder.LITTLE_ENDIAN);
- paramPayload.limit(paramPayload.position() + length - 2);
- payload.position(payload.position() + length - 2);
- while (paramPayload.hasRemaining()) {
- int id = paramPayload.get() & Constants.BYTE_MASK;
-
- EAP.AuthInfoID authInfoID = EAP.mapAuthMethod(id);
- if (authInfoID == null) {
- throw new ProtocolException("Unknown auth parameter ID: " + id);
- }
-
- int len = paramPayload.get() & Constants.BYTE_MASK;
- if (len == 0 || len > paramPayload.remaining()) {
- throw new ProtocolException("Bad auth method length: " + len);
- }
-
- switch (authInfoID) {
- case ExpandedEAPMethod:
- addAuthParam(new ExpandedEAPMethod(authInfoID, len, paramPayload));
- break;
- case NonEAPInnerAuthType:
- addAuthParam(new NonEAPInnerAuth(len, paramPayload));
- break;
- case InnerAuthEAPMethodType:
- addAuthParam(new InnerAuthEAP(len, paramPayload));
- break;
- case ExpandedInnerEAPMethod:
- addAuthParam(new ExpandedEAPMethod(authInfoID, len, paramPayload));
- break;
- case CredentialType:
- addAuthParam(new Credential(authInfoID, len, paramPayload));
- break;
- case TunneledEAPMethodCredType:
- addAuthParam(new Credential(authInfoID, len, paramPayload));
- break;
- case VendorSpecific:
- addAuthParam(new VendorSpecificAuth(len, paramPayload));
- break;
- }
-
- realCount++;
- }
- if (realCount != count)
- throw new ProtocolException("Invalid parameter count: " + realCount +
- ", expected " + count);
- }
-
- public EAPMethod(EAP.EAPMethodID eapMethodID, AuthParam authParam) {
- mEAPMethodID = eapMethodID;
- mAuthParams = new HashMap<>(1);
- if (authParam != null) {
- Set authParams = new HashSet<>();
- authParams.add(authParam);
- mAuthParams.put(authParam.getAuthInfoID(), authParams);
- }
- }
-
- private void addAuthParam(AuthParam param) {
- Set authParams = mAuthParams.get(param.getAuthInfoID());
- if (authParams == null) {
- authParams = new HashSet<>();
- mAuthParams.put(param.getAuthInfoID(), authParams);
- }
- authParams.add(param);
- }
-
- public Map> getAuthParams() {
- return Collections.unmodifiableMap(mAuthParams);
- }
-
- public EAP.EAPMethodID getEAPMethodID() {
- return mEAPMethodID;
- }
-
- public int match(com.android.hotspot2.pps.Credential credential) {
-
- EAPMethod credMethod = credential.getEAPMethod();
- if (mEAPMethodID != credMethod.getEAPMethodID()) {
- return AuthMatch.None;
- }
-
- switch (mEAPMethodID) {
- case EAP_TTLS:
- if (mAuthParams.isEmpty()) {
- return AuthMatch.Method;
- }
- int paramCount = 0;
- for (Map.Entry> entry :
- credMethod.getAuthParams().entrySet()) {
- Set params = mAuthParams.get(entry.getKey());
- if (params == null) {
- continue;
- }
-
- if (!Collections.disjoint(params, entry.getValue())) {
- return AuthMatch.MethodParam;
- }
- paramCount += params.size();
- }
- return paramCount > 0 ? AuthMatch.None : AuthMatch.Method;
- case EAP_TLS:
- return AuthMatch.MethodParam;
- case EAP_SIM:
- case EAP_AKA:
- case EAP_AKAPrim:
- return AuthMatch.Method;
- default:
- return AuthMatch.Method;
- }
- }
-
- public AuthParam getAuthParam() {
- if (mAuthParams.isEmpty()) {
- return null;
- }
- Set params = mAuthParams.values().iterator().next();
- if (params.isEmpty()) {
- return null;
- }
- return params.iterator().next();
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (this == thatObject) {
- return true;
- }
- else if (thatObject == null || getClass() != thatObject.getClass()) {
- return false;
- }
-
- EAPMethod that = (EAPMethod) thatObject;
- return mEAPMethodID == that.mEAPMethodID && mAuthParams.equals(that.mAuthParams);
- }
-
- @Override
- public int hashCode() {
- int result = mEAPMethodID.hashCode();
- result = 31 * result + mAuthParams.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("EAP Method ").append(mEAPMethodID).append('\n');
- for (Set paramSet : mAuthParams.values()) {
- for (AuthParam param : paramSet) {
- sb.append(" ").append(param.toString());
- }
- }
- return sb.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/ExpandedEAPMethod.java b/packages/Osu/src/com/android/anqp/eap/ExpandedEAPMethod.java
deleted file mode 100644
index 1358c09e2cbec..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/ExpandedEAPMethod.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.android.anqp.eap;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-import static com.android.anqp.Constants.INT_MASK;
-import static com.android.anqp.Constants.SHORT_MASK;
-
-/**
- * An EAP authentication parameter, IEEE802.11-2012, table 8-188
- */
-public class ExpandedEAPMethod implements AuthParam {
-
- private final EAP.AuthInfoID mAuthInfoID;
- private final int mVendorID;
- private final long mVendorType;
-
- public ExpandedEAPMethod(EAP.AuthInfoID authInfoID, int length, ByteBuffer payload)
- throws ProtocolException {
- if (length != 7) {
- throw new ProtocolException("Bad length: " + payload.remaining());
- }
-
- mAuthInfoID = authInfoID;
-
- ByteBuffer vndBuffer = payload.duplicate().order(ByteOrder.BIG_ENDIAN);
-
- int id = vndBuffer.getShort() & SHORT_MASK;
- id = (id << Byte.SIZE) | (vndBuffer.get() & BYTE_MASK);
- mVendorID = id;
- mVendorType = vndBuffer.getInt() & INT_MASK;
-
- payload.position(payload.position()+7);
- }
-
- public ExpandedEAPMethod(EAP.AuthInfoID authInfoID, int vendorID, long vendorType) {
- mAuthInfoID = authInfoID;
- mVendorID = vendorID;
- mVendorType = vendorType;
- }
-
- @Override
- public EAP.AuthInfoID getAuthInfoID() {
- return mAuthInfoID;
- }
-
- @Override
- public int hashCode() {
- return (mAuthInfoID.hashCode() * 31 + mVendorID) * 31 + (int) mVendorType;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject == null || thatObject.getClass() != ExpandedEAPMethod.class) {
- return false;
- } else {
- ExpandedEAPMethod that = (ExpandedEAPMethod) thatObject;
- return that.getVendorID() == getVendorID() && that.getVendorType() == getVendorType();
- }
- }
-
- public int getVendorID() {
- return mVendorID;
- }
-
- public long getVendorType() {
- return mVendorType;
- }
-
- @Override
- public String toString() {
- return "Auth method " + mAuthInfoID + ", id " + mVendorID + ", type " + mVendorType + "\n";
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/InnerAuthEAP.java b/packages/Osu/src/com/android/anqp/eap/InnerAuthEAP.java
deleted file mode 100644
index 571cf26fb72fe..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/InnerAuthEAP.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.android.anqp.eap;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-
-/**
- * An EAP authentication parameter, IEEE802.11-2012, table 8-188
- */
-public class InnerAuthEAP implements AuthParam {
-
- private final EAP.EAPMethodID mEapMethodID;
-
- public InnerAuthEAP(int length, ByteBuffer payload) throws ProtocolException {
- if (length != 1) {
- throw new ProtocolException("Bad length: " + length);
- }
- int typeID = payload.get() & BYTE_MASK;
- mEapMethodID = EAP.mapEAPMethod(typeID);
- }
-
- public InnerAuthEAP(EAP.EAPMethodID eapMethodID) {
- mEapMethodID = eapMethodID;
- }
-
- @Override
- public EAP.AuthInfoID getAuthInfoID() {
- return EAP.AuthInfoID.InnerAuthEAPMethodType;
- }
-
- public EAP.EAPMethodID getEAPMethodID() {
- return mEapMethodID;
- }
-
- @Override
- public int hashCode() {
- return mEapMethodID != null ? mEapMethodID.hashCode() : 0;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject == null || thatObject.getClass() != InnerAuthEAP.class) {
- return false;
- } else {
- return ((InnerAuthEAP) thatObject).getEAPMethodID() == getEAPMethodID();
- }
- }
-
- @Override
- public String toString() {
- return "Auth method InnerAuthEAP, inner = " + mEapMethodID + '\n';
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/NonEAPInnerAuth.java b/packages/Osu/src/com/android/anqp/eap/NonEAPInnerAuth.java
deleted file mode 100644
index 9d37b4dc15e4d..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/NonEAPInnerAuth.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.android.anqp.eap;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-
-/**
- * An EAP authentication parameter, IEEE802.11-2012, table 8-188
- */
-public class NonEAPInnerAuth implements AuthParam {
-
- public enum NonEAPType {Reserved, PAP, CHAP, MSCHAP, MSCHAPv2}
- private static final Map sOmaMap = new EnumMap<>(NonEAPType.class);
- private static final Map sRevOmaMap = new HashMap<>();
-
- private final NonEAPType mType;
-
- static {
- sOmaMap.put(NonEAPType.PAP, "PAP");
- sOmaMap.put(NonEAPType.CHAP, "CHAP");
- sOmaMap.put(NonEAPType.MSCHAP, "MS-CHAP");
- sOmaMap.put(NonEAPType.MSCHAPv2, "MS-CHAP-V2");
-
- for (Map.Entry entry : sOmaMap.entrySet()) {
- sRevOmaMap.put(entry.getValue(), entry.getKey());
- }
- }
-
- public NonEAPInnerAuth(int length, ByteBuffer payload) throws ProtocolException {
- if (length != 1) {
- throw new ProtocolException("Bad length: " + payload.remaining());
- }
-
- int typeID = payload.get() & BYTE_MASK;
- mType = typeID < NonEAPType.values().length ?
- NonEAPType.values()[typeID] :
- NonEAPType.Reserved;
- }
-
- public NonEAPInnerAuth(NonEAPType type) {
- mType = type;
- }
-
- /**
- * Construct from the OMA-DM PPS data
- * @param eapType as defined in the HS2.0 spec.
- */
- public NonEAPInnerAuth(String eapType) {
- mType = sRevOmaMap.get(eapType);
- }
-
- @Override
- public EAP.AuthInfoID getAuthInfoID() {
- return EAP.AuthInfoID.NonEAPInnerAuthType;
- }
-
- public NonEAPType getType() {
- return mType;
- }
-
- public String getOMAtype() {
- return sOmaMap.get(mType);
- }
-
- public static String mapInnerType(NonEAPType type) {
- return sOmaMap.get(type);
- }
-
- @Override
- public int hashCode() {
- return mType.hashCode();
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject == null || thatObject.getClass() != NonEAPInnerAuth.class) {
- return false;
- } else {
- return ((NonEAPInnerAuth) thatObject).getType() == getType();
- }
- }
-
- @Override
- public String toString() {
- return "Auth method NonEAPInnerAuthEAP, inner = " + mType + '\n';
- }
-}
diff --git a/packages/Osu/src/com/android/anqp/eap/VendorSpecificAuth.java b/packages/Osu/src/com/android/anqp/eap/VendorSpecificAuth.java
deleted file mode 100644
index 04a315d37896b..0000000000000
--- a/packages/Osu/src/com/android/anqp/eap/VendorSpecificAuth.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.android.anqp.eap;
-
-import java.net.ProtocolException;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-/**
- * An EAP authentication parameter, IEEE802.11-2012, table 8-188
- */
-public class VendorSpecificAuth implements AuthParam {
-
- private final byte[] mData;
-
- public VendorSpecificAuth(int length, ByteBuffer payload) throws ProtocolException {
- mData = new byte[length];
- payload.get(mData);
- }
-
- @Override
- public EAP.AuthInfoID getAuthInfoID() {
- return EAP.AuthInfoID.VendorSpecific;
- }
-
- public int hashCode() {
- return Arrays.hashCode(mData);
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (thatObject == this) {
- return true;
- } else if (thatObject == null || thatObject.getClass() != VendorSpecificAuth.class) {
- return false;
- } else {
- return Arrays.equals(((VendorSpecificAuth) thatObject).getData(), getData());
- }
- }
-
- public byte[] getData() {
- return mData;
- }
-
- @Override
- public String toString() {
- return "Auth method VendorSpecificAuth, data = " + Arrays.toString(mData) + '\n';
- }
-}
diff --git a/packages/Osu/src/com/android/configparse/ConfigBuilder.java b/packages/Osu/src/com/android/configparse/ConfigBuilder.java
deleted file mode 100644
index b760ade764e36..0000000000000
--- a/packages/Osu/src/com/android/configparse/ConfigBuilder.java
+++ /dev/null
@@ -1,258 +0,0 @@
-package com.android.configparse;
-
-import android.content.Context;
-import android.net.Uri;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiEnterpriseConfig;
-import android.util.Base64;
-import android.util.Log;
-
-import com.android.anqp.eap.AuthParam;
-import com.android.anqp.eap.EAP;
-import com.android.anqp.eap.EAPMethod;
-import com.android.anqp.eap.NonEAPInnerAuth;
-import com.android.hotspot2.IMSIParameter;
-import com.android.hotspot2.pps.Credential;
-import com.android.hotspot2.pps.HomeSP;
-
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.MessageDigest;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-
-public class ConfigBuilder {
- private static final String TAG = "WCFG";
-
- private static void dropFile(Uri uri, Context context) {
- context.getContentResolver().delete(uri, null, null);
- }
-
- public static WifiConfiguration buildConfig(HomeSP homeSP, X509Certificate caCert,
- List clientChain, PrivateKey key)
- throws IOException, GeneralSecurityException {
-
- Credential credential = homeSP.getCredential();
-
- WifiConfiguration config;
-
- EAP.EAPMethodID eapMethodID = credential.getEAPMethod().getEAPMethodID();
- switch (eapMethodID) {
- case EAP_TTLS:
- if (key != null || clientChain != null) {
- Log.w(TAG, "Client cert and/or key included with EAP-TTLS profile");
- }
- config = buildTTLSConfig(homeSP);
- break;
- case EAP_TLS:
- config = buildTLSConfig(homeSP, clientChain, key);
- break;
- case EAP_AKA:
- case EAP_AKAPrim:
- case EAP_SIM:
- if (key != null || clientChain != null || caCert != null) {
- Log.i(TAG, "Client/CA cert and/or key included with " +
- eapMethodID + " profile");
- }
- config = buildSIMConfig(homeSP);
- break;
- default:
- throw new IOException("Unsupported EAP Method: " + eapMethodID);
- }
-
- WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
-
- enterpriseConfig.setCaCertificate(caCert);
- enterpriseConfig.setAnonymousIdentity("anonymous@" + credential.getRealm());
-
- return config;
- }
-
- // Retain for debugging purposes
- /*
- private static void xIterateCerts(KeyStore ks, X509Certificate caCert)
- throws GeneralSecurityException {
- Enumeration aliases = ks.aliases();
- while (aliases.hasMoreElements()) {
- String alias = aliases.nextElement();
- Certificate cert = ks.getCertificate(alias);
- Log.d("HS2J", "Checking " + alias);
- if (cert instanceof X509Certificate) {
- X509Certificate x509Certificate = (X509Certificate) cert;
- boolean sm = x509Certificate.getSubjectX500Principal().equals(
- caCert.getSubjectX500Principal());
- boolean eq = false;
- if (sm) {
- eq = Arrays.equals(x509Certificate.getEncoded(), caCert.getEncoded());
- }
- Log.d("HS2J", "Subject: " + x509Certificate.getSubjectX500Principal() +
- ": " + sm + "/" + eq);
- }
- }
- }
- */
-
- private static WifiConfiguration buildTTLSConfig(HomeSP homeSP)
- throws IOException {
- Credential credential = homeSP.getCredential();
-
- if (credential.getUserName() == null || credential.getPassword() == null) {
- throw new IOException("EAP-TTLS provisioned without user name or password");
- }
-
- EAPMethod eapMethod = credential.getEAPMethod();
-
- AuthParam authParam = eapMethod.getAuthParam();
- if (authParam == null ||
- authParam.getAuthInfoID() != EAP.AuthInfoID.NonEAPInnerAuthType) {
- throw new IOException("Bad auth parameter for EAP-TTLS: " + authParam);
- }
-
- WifiConfiguration config = buildBaseConfiguration(homeSP);
- NonEAPInnerAuth ttlsParam = (NonEAPInnerAuth) authParam;
- WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
- enterpriseConfig.setPhase2Method(remapInnerMethod(ttlsParam.getType()));
- enterpriseConfig.setIdentity(credential.getUserName());
- enterpriseConfig.setPassword(credential.getPassword());
-
- return config;
- }
-
- private static WifiConfiguration buildTLSConfig(HomeSP homeSP,
- List clientChain,
- PrivateKey clientKey)
- throws IOException, GeneralSecurityException {
-
- Credential credential = homeSP.getCredential();
-
- X509Certificate clientCertificate = null;
-
- if (clientKey == null || clientChain == null) {
- throw new IOException("No key and/or cert passed for EAP-TLS");
- }
- if (credential.getCertType() != Credential.CertType.x509v3) {
- throw new IOException("Invalid certificate type for TLS: " +
- credential.getCertType());
- }
-
- byte[] reference = credential.getFingerPrint();
- MessageDigest digester = MessageDigest.getInstance("SHA-256");
- for (X509Certificate certificate : clientChain) {
- digester.reset();
- byte[] fingerprint = digester.digest(certificate.getEncoded());
- if (Arrays.equals(reference, fingerprint)) {
- clientCertificate = certificate;
- break;
- }
- }
- if (clientCertificate == null) {
- throw new IOException("No certificate in chain matches supplied fingerprint");
- }
-
- String alias = Base64.encodeToString(reference, Base64.DEFAULT);
-
- WifiConfiguration config = buildBaseConfiguration(homeSP);
- WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
- enterpriseConfig.setClientCertificateAlias(alias);
- enterpriseConfig.setClientKeyEntry(clientKey, clientCertificate);
-
- return config;
- }
-
- private static WifiConfiguration buildSIMConfig(HomeSP homeSP)
- throws IOException {
-
- Credential credential = homeSP.getCredential();
- IMSIParameter credImsi = credential.getImsi();
-
- /*
- * Uncomment to enforce strict IMSI matching with currently installed SIM cards.
- *
- TelephonyManager tm = TelephonyManager.from(context);
- SubscriptionManager sub = SubscriptionManager.from(context);
- boolean match = false;
-
- for (int subId : sub.getActiveSubscriptionIdList()) {
- String imsi = tm.getSubscriberId(subId);
- if (credImsi.matches(imsi)) {
- match = true;
- break;
- }
- }
- if (!match) {
- throw new IOException("Supplied IMSI does not match any SIM card");
- }
- */
-
- WifiConfiguration config = buildBaseConfiguration(homeSP);
- config.enterpriseConfig.setPlmn(credImsi.toString());
- return config;
- }
-
- private static WifiConfiguration buildBaseConfiguration(HomeSP homeSP) throws IOException {
- EAP.EAPMethodID eapMethodID = homeSP.getCredential().getEAPMethod().getEAPMethodID();
-
- WifiConfiguration config = new WifiConfiguration();
-
- config.FQDN = homeSP.getFQDN();
-
- HashSet roamingConsortiumIds = homeSP.getRoamingConsortiums();
- config.roamingConsortiumIds = new long[roamingConsortiumIds.size()];
- int i = 0;
- for (long id : roamingConsortiumIds) {
- config.roamingConsortiumIds[i] = id;
- i++;
- }
- config.providerFriendlyName = homeSP.getFriendlyName();
-
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
-
- WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
- enterpriseConfig.setEapMethod(remapEAPMethod(eapMethodID));
- enterpriseConfig.setRealm(homeSP.getCredential().getRealm());
- if (homeSP.getUpdateIdentifier() >= 0) {
- config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
- }
- config.enterpriseConfig = enterpriseConfig;
- if (homeSP.getUpdateIdentifier() >= 0) {
- config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
- }
-
- return config;
- }
-
- private static int remapEAPMethod(EAP.EAPMethodID eapMethodID) throws IOException {
- switch (eapMethodID) {
- case EAP_TTLS:
- return WifiEnterpriseConfig.Eap.TTLS;
- case EAP_TLS:
- return WifiEnterpriseConfig.Eap.TLS;
- case EAP_SIM:
- return WifiEnterpriseConfig.Eap.SIM;
- case EAP_AKA:
- return WifiEnterpriseConfig.Eap.AKA;
- case EAP_AKAPrim:
- return WifiEnterpriseConfig.Eap.AKA_PRIME;
- default:
- throw new IOException("Bad EAP method: " + eapMethodID);
- }
- }
-
- private static int remapInnerMethod(NonEAPInnerAuth.NonEAPType type) throws IOException {
- switch (type) {
- case PAP:
- return WifiEnterpriseConfig.Phase2.PAP;
- case MSCHAP:
- return WifiEnterpriseConfig.Phase2.MSCHAP;
- case MSCHAPv2:
- return WifiEnterpriseConfig.Phase2.MSCHAPV2;
- case CHAP:
- default:
- throw new IOException("Inner method " + type + " not supported");
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/AppBridge.java b/packages/Osu/src/com/android/hotspot2/AppBridge.java
deleted file mode 100644
index 81542f7fc466c..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/AppBridge.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.android.hotspot2;
-
-import android.content.Context;
-import android.content.Intent;
-
-import com.android.hotspot2.osu.OSUOperationStatus;
-
-public class AppBridge {
- public static final String ACTION_OSU_NOTIFICATION = "com.android.hotspot2.OSU_NOTIFICATION";
- public static final String OSU_COUNT = "osu-count";
- public static final String SP_NAME = "sp-name";
- public static final String PROV_SUCCESS = "prov-success";
- public static final String DEAUTH = "deauth";
- public static final String DEAUTH_DELAY = "deauth-delay";
- public static final String DEAUTH_URL = "deauth-url";
- public static final String PROV_MESSAGE = "prov-message";
- public static final String OSU_INFO = "osu-info";
-
- public static final String GET_OSUS_ACTION = "com.android.hotspot2.GET_OSUS";
-
- private final Context mContext;
-
- public AppBridge(Context context) {
- mContext = context;
- }
-
- public void showOsuCount(int osuCount) {
- Intent intent = new Intent(ACTION_OSU_NOTIFICATION);
- intent.putExtra(OSU_COUNT, osuCount);
- intent.setFlags(
- Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
-
- mContext.startActivity(intent);
- }
-
- public void showStatus(OSUOperationStatus status, String spName, String message,
- String remoteStatus) {
- Intent intent = new Intent(ACTION_OSU_NOTIFICATION);
- intent.putExtra(SP_NAME, spName);
- intent.putExtra(PROV_SUCCESS, status == OSUOperationStatus.ProvisioningSuccess);
- if (message != null) {
- intent.putExtra(PROV_MESSAGE, message);
- }
- intent.setFlags(
- Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(intent);
- }
-
- public void showDeauth(String spName, boolean ess, int delay, String url) {
- Intent intent = new Intent(ACTION_OSU_NOTIFICATION);
- intent.putExtra(SP_NAME, spName);
- intent.putExtra(DEAUTH, ess);
- intent.putExtra(DEAUTH_DELAY, delay);
- intent.putExtra(DEAUTH_URL, url);
- intent.setFlags(
- Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(intent);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/AuthMatch.java b/packages/Osu/src/com/android/hotspot2/AuthMatch.java
deleted file mode 100644
index f9c1f42955d15..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/AuthMatch.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.android.hotspot2;
-
-/**
- * Match score for EAP credentials:
- * None means that there is a distinct mismatch, i.e. realm, method or parameter is defined
- * and mismatches that of the credential.
- * Indeterminate means that there is no ANQP information to match against.
- * Note: The numeric values given to the constants are used for preference comparison and
- * must be maintained accordingly.
- */
-public abstract class AuthMatch {
- public static final int None = -1;
- public static final int Indeterminate = 0;
- public static final int Realm = 0x04;
- public static final int Method = 0x02;
- public static final int Param = 0x01;
- public static final int MethodParam = Method | Param;
- public static final int Exact = Realm | Method | Param;
-
- public static String toString(int match) {
- if (match < 0) {
- return "None";
- } else if (match == 0) {
- return "Indeterminate";
- }
-
- StringBuilder sb = new StringBuilder();
- if ((match & Realm) != 0) {
- sb.append("Realm");
- }
- if ((match & Method) != 0) {
- sb.append("Method");
- }
- if ((match & Param) != 0) {
- sb.append("Param");
- }
- return sb.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/IMSIParameter.java b/packages/Osu/src/com/android/hotspot2/IMSIParameter.java
deleted file mode 100644
index 1d5d95daadc11..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/IMSIParameter.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.android.hotspot2;
-
-import java.io.IOException;
-
-public class IMSIParameter {
- private final String mImsi;
- private final boolean mPrefix;
-
- public IMSIParameter(String imsi, boolean prefix) {
- mImsi = imsi;
- mPrefix = prefix;
- }
-
- public IMSIParameter(String imsi) throws IOException {
- if (imsi == null || imsi.length() == 0) {
- throw new IOException("Bad IMSI: '" + imsi + "'");
- }
-
- int nonDigit;
- char stopChar = '\0';
- for (nonDigit = 0; nonDigit < imsi.length(); nonDigit++) {
- stopChar = imsi.charAt(nonDigit);
- if (stopChar < '0' || stopChar > '9') {
- break;
- }
- }
-
- if (nonDigit == imsi.length()) {
- mImsi = imsi;
- mPrefix = false;
- } else if (nonDigit == imsi.length() - 1 && stopChar == '*') {
- mImsi = imsi.substring(0, nonDigit);
- mPrefix = true;
- } else {
- throw new IOException("Bad IMSI: '" + imsi + "'");
- }
- }
-
- public boolean matches(String fullIMSI) {
- if (mPrefix) {
- return mImsi.regionMatches(false, 0, fullIMSI, 0, mImsi.length());
- } else {
- return mImsi.equals(fullIMSI);
- }
- }
-
- public boolean matchesMccMnc(String mccMnc) {
- if (mPrefix) {
- // For a prefix match, the entire prefix must match the mcc+mnc
- return mImsi.regionMatches(false, 0, mccMnc, 0, mImsi.length());
- } else {
- // For regular match, the entire length of mcc+mnc must match this IMSI
- return mImsi.regionMatches(false, 0, mccMnc, 0, mccMnc.length());
- }
- }
-
- public boolean isPrefix() {
- return mPrefix;
- }
-
- public String getImsi() {
- return mImsi;
- }
-
- public int prefixLength() {
- return mImsi.length();
- }
-
- @Override
- public boolean equals(Object thatObject) {
- if (this == thatObject) {
- return true;
- } else if (thatObject == null || getClass() != thatObject.getClass()) {
- return false;
- }
-
- IMSIParameter that = (IMSIParameter) thatObject;
- return mPrefix == that.mPrefix && mImsi.equals(that.mImsi);
- }
-
- @Override
- public int hashCode() {
- int result = mImsi != null ? mImsi.hashCode() : 0;
- result = 31 * result + (mPrefix ? 1 : 0);
- return result;
- }
-
- @Override
- public String toString() {
- if (mPrefix) {
- return mImsi + '*';
- } else {
- return mImsi;
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/OMADMAdapter.java b/packages/Osu/src/com/android/hotspot2/OMADMAdapter.java
deleted file mode 100644
index 1429b0b5b427c..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/OMADMAdapter.java
+++ /dev/null
@@ -1,601 +0,0 @@
-package com.android.hotspot2;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.net.wifi.WifiManager;
-import android.os.SystemProperties;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.anqp.eap.EAP;
-import com.android.hotspot2.omadm.MOTree;
-import com.android.hotspot2.omadm.OMAConstants;
-import com.android.hotspot2.omadm.OMAConstructed;
-import com.android.hotspot2.osu.OSUManager;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static com.android.anqp.eap.NonEAPInnerAuth.NonEAPType;
-import static com.android.anqp.eap.NonEAPInnerAuth.mapInnerType;
-
-public class OMADMAdapter {
- private final Context mContext;
- private final String mImei;
- private final String mImsi;
- private final String mDevID;
- private final List mDevInfo;
- private final List mDevDetail;
-
- private static final int IMEI_Length = 14;
-
- private static final String[] ExtWiFiPath = {"DevDetail", "Ext", "org.wi-fi", "Wi-Fi"};
-
- private static final Map RTProps = new HashMap<>();
-
- private MOTree mDevInfoTree;
- private MOTree mDevDetailTree;
-
- private static OMADMAdapter sInstance;
-
- static {
- RTProps.put(ExtWiFiPath[2], "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0");
- }
-
- private static abstract class PathAccessor {
- private final String[] mPath;
- private final int mHashCode;
-
- protected PathAccessor(Object... path) {
- int length = 0;
- for (Object o : path) {
- if (o.getClass() == String[].class) {
- length += ((String[]) o).length;
- } else {
- length++;
- }
- }
- mPath = new String[length];
- int n = 0;
- for (Object o : path) {
- if (o.getClass() == String[].class) {
- for (String element : (String[]) o) {
- mPath[n++] = element;
- }
- } else if (o.getClass() == Integer.class) {
- mPath[n++] = "x" + o.toString();
- } else {
- mPath[n++] = o.toString();
- }
- }
- mHashCode = Arrays.hashCode(mPath);
- }
-
- @Override
- public int hashCode() {
- return mHashCode;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- return thatObject == this || (thatObject instanceof ConstPathAccessor &&
- Arrays.equals(mPath, ((PathAccessor) thatObject).mPath));
- }
-
- private String[] getPath() {
- return mPath;
- }
-
- protected abstract Object getValue();
- }
-
- private static class ConstPathAccessor extends PathAccessor {
- private final T mValue;
-
- protected ConstPathAccessor(T value, Object... path) {
- super(path);
- mValue = value;
- }
-
- protected Object getValue() {
- return mValue;
- }
- }
-
- public static OMADMAdapter getInstance(Context context) {
- synchronized (OMADMAdapter.class) {
- if (sInstance == null) {
- sInstance = new OMADMAdapter(context);
- }
- return sInstance;
- }
- }
-
- private OMADMAdapter(Context context) {
- mContext = context;
-
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- String simOperator = tm.getSimOperator();
- mImsi = tm.getSubscriberId();
- mImei = tm.getImei();
- String strDevId;
-
- /* Use MEID for sprint */
- if ("310120".equals(simOperator) || (mImsi != null && mImsi.startsWith("310120"))) {
- /* MEID is 14 digits. If IMEI is returned as DevId, MEID can be extracted by taking
- * first 14 characters. This is not always true but should be the case for sprint */
- strDevId = tm.getDeviceId().toUpperCase(Locale.US);
- if (strDevId != null && strDevId.length() >= IMEI_Length) {
- strDevId = strDevId.substring(0, IMEI_Length);
- } else {
- Log.w(OSUManager.TAG, "MEID cannot be extracted from DeviceId " + strDevId);
- }
- } else {
- if (isPhoneTypeLTE()) {
- strDevId = mImei;
- } else {
- strDevId = tm.getDeviceId();
- }
- if (strDevId == null) {
- strDevId = "unknown";
- }
- strDevId = strDevId.toUpperCase(Locale.US);
-
- if (!isPhoneTypeLTE()) {
- strDevId = strDevId.substring(0, IMEI_Length);
- }
- }
- mDevID = strDevId;
-
- mDevInfo = new ArrayList<>();
- mDevInfo.add(new ConstPathAccessor<>(strDevId, "DevInfo", "DevID"));
- mDevInfo.add(new ConstPathAccessor<>(getProperty(context,
- "Man", "ro.product.manufacturer", "unknown"), "DevInfo", "Man"));
- mDevInfo.add(new ConstPathAccessor<>(getProperty(context,
- "Mod", "ro.product.model", "generic"), "DevInfo", "Mod"));
- mDevInfo.add(new ConstPathAccessor<>(getLocale(context), "DevInfo", "Lang"));
- mDevInfo.add(new ConstPathAccessor<>("1.2", "DevInfo", "DmV"));
-
- mDevDetail = new ArrayList<>();
- mDevDetail.add(new ConstPathAccessor<>(getDeviceType(), "DevDetail", "DevType"));
- mDevDetail.add(new ConstPathAccessor<>(SystemProperties.get("ro.product.brand"),
- "DevDetail", "OEM"));
- mDevDetail.add(new ConstPathAccessor<>(getVersion(context, false), "DevDetail", "FwV"));
- mDevDetail.add(new ConstPathAccessor<>(getVersion(context, true), "DevDetail", "SwV"));
- mDevDetail.add(new ConstPathAccessor<>(getHwV(), "DevDetail", "HwV"));
- mDevDetail.add(new ConstPathAccessor<>("TRUE", "DevDetail", "LrgObj"));
-
- mDevDetail.add(new ConstPathAccessor<>(32, "DevDetail", "URI", "MaxDepth"));
- mDevDetail.add(new ConstPathAccessor<>(2048, "DevDetail", "URI", "MaxTotLen"));
- mDevDetail.add(new ConstPathAccessor<>(64, "DevDetail", "URI", "MaxSegLen"));
-
- AtomicInteger index = new AtomicInteger(1);
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.MSCHAPv2), ExtWiFiPath,
- "EAPMethodList", index, "InnerMethod"));
-
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.PAP), ExtWiFiPath,
- "EAPMethodList", index, "InnerMethod"));
-
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.MSCHAP), ExtWiFiPath,
- "EAPMethodList", index, "InnerMethod"));
-
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TLS, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_AKA, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_AKAPrim, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
- index.incrementAndGet();
- mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_SIM, ExtWiFiPath,
- "EAPMethodList", index, "EAPType"));
-
- mDevDetail.add(new ConstPathAccessor<>("FALSE", ExtWiFiPath, "ManufacturingCertificate"));
- mDevDetail.add(new ConstPathAccessor<>(mImsi, ExtWiFiPath, "IMSI"));
- mDevDetail.add(new ConstPathAccessor<>(mImei, ExtWiFiPath, "IMEI_MEID"));
- mDevDetail.add(new PathAccessor(ExtWiFiPath, "Wi-FiMACAddress") {
- @Override
- protected String getValue() {
- return getMAC();
- }
- });
- }
-
- private static void buildNode(PathAccessor pathAccessor, int depth, OMAConstructed parent)
- throws IOException {
- String[] path = pathAccessor.getPath();
- String name = path[depth];
- if (depth < path.length - 1) {
- OMAConstructed node = (OMAConstructed) parent.getChild(name);
- if (node == null) {
- node = (OMAConstructed) parent.addChild(name, RTProps.get(name),
- null, null);
- }
- buildNode(pathAccessor, depth + 1, node);
- } else if (pathAccessor.getValue() != null) {
- parent.addChild(name, null, pathAccessor.getValue().toString(), null);
- }
- }
-
- public String getMAC() {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- return wifiManager != null ?
- String.format("%012x",
- Utils.parseMac(wifiManager.getConnectionInfo().getMacAddress())) :
- null;
- }
-
- public String getImei() {
- return mImei;
- }
-
- public byte[] getMeid() {
- return Arrays.copyOf(mImei.getBytes(StandardCharsets.ISO_8859_1), IMEI_Length);
- }
-
- public String getDevID() {
- return mDevID;
- }
-
- public MOTree getMO(String urn) {
- try {
- switch (urn) {
- case OMAConstants.DevInfoURN:
- if (mDevInfoTree == null) {
- OMAConstructed root = new OMAConstructed(null, "DevInfo", urn);
- for (PathAccessor pathAccessor : mDevInfo) {
- buildNode(pathAccessor, 1, root);
- }
- mDevInfoTree = MOTree.buildMgmtTree(OMAConstants.DevInfoURN,
- OMAConstants.OMAVersion, root);
- }
- return mDevInfoTree;
- case OMAConstants.DevDetailURN:
- if (mDevDetailTree == null) {
- OMAConstructed root = new OMAConstructed(null, "DevDetail", urn);
- for (PathAccessor pathAccessor : mDevDetail) {
- buildNode(pathAccessor, 1, root);
- }
- mDevDetailTree = MOTree.buildMgmtTree(OMAConstants.DevDetailURN,
- OMAConstants.OMAVersion, root);
- }
- return mDevDetailTree;
- default:
- throw new IllegalArgumentException(urn);
- }
- } catch (IOException ioe) {
- Log.e(OSUManager.TAG, "Caught exception building OMA Tree: " + ioe, ioe);
- return null;
- }
-
- /*
- switch (urn) {
- case DevInfoURN: return DevInfo;
- case DevDetailURN: return DevDetail;
- default: throw new IllegalArgumentException(urn);
- }
- */
- }
-
- // TODO: For now, assume the device supports LTE.
- private static boolean isPhoneTypeLTE() {
- return true;
- }
-
- private static String getHwV() {
- try {
- return SystemProperties.get("ro.hardware", "Unknown")
- + "." + SystemProperties.get("ro.revision", "Unknown");
- } catch (RuntimeException e) {
- return "Unknown";
- }
- }
-
- private static String getDeviceType() {
- String devicetype = SystemProperties.get("ro.build.characteristics");
- if ((((TextUtils.isEmpty(devicetype)) || (!devicetype.equals("tablet"))))) {
- devicetype = "phone";
- }
- return devicetype;
- }
-
- private static String getVersion(Context context, boolean swv) {
- String version;
- try {
- if (!isSprint(context) && swv) {
- return "Android " + SystemProperties.get("ro.build.version.release");
- } else {
- version = SystemProperties.get("ro.build.version.full");
- if (null == version || version.equals("")) {
- return SystemProperties.get("ro.build.id", null) + "~"
- + SystemProperties.get("ro.build.config.version", null) + "~"
- + SystemProperties.get("gsm.version.baseband", null) + "~"
- + SystemProperties.get("ro.gsm.flexversion", null);
- }
- }
- } catch (RuntimeException e) {
- return "Unknown";
- }
- return version;
- }
-
- private static boolean isSprint(Context context) {
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- String simOperator = tm.getSimOperator();
- String imsi = tm.getSubscriberId();
- /* Use MEID for sprint */
- if ("310120".equals(simOperator) || (imsi != null && imsi.startsWith("310120"))) {
- return true;
- } else {
- return false;
- }
- }
-
- private static String getLocale(Context context) {
- String strLang = readValueFromFile(context, "Lang");
- if (strLang == null) {
- strLang = Locale.getDefault().toString();
- }
- return strLang;
- }
-
- private static String getProperty(Context context, String key, String propKey, String dflt) {
- String strMan = readValueFromFile(context, key);
- if (strMan == null) {
- strMan = SystemProperties.get(propKey, dflt);
- }
- return strMan;
- }
-
- private static String readValueFromFile(Context context, String propName) {
- String ret = null;
- // use preference instead of the system property
- SharedPreferences prefs = context.getSharedPreferences("dmconfig", 0);
- if (prefs.contains(propName)) {
- ret = prefs.getString(propName, "");
- if (ret.length() == 0) {
- ret = null;
- }
- }
- return ret;
- }
-
- private static final String DevDetail =
- "" +
- "1.2" +
- "" +
- "DevDetail" +
- "" +
- "" +
- "urn:oma:mo:oma-dm-devdetail:1.0" +
- "" +
- "" +
- "" +
- "Ext" +
- "" +
- "org.wi-fi" +
- "" +
- "" +
- "" +
- "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext :1.0" +
- "" +
- "" +
- "" +
- "" +
- "Wi-Fi" +
- "" +
- "EAPMethodList" +
- "" +
- "Method01" +
- "" +
- "" +
- "EAPType" +
- "21" +
- "" +
- "" +
- "InnerMethod" +
- "MS-CHAP-V2" +
- "" +
- "" +
- "" +
- "Method02" +
- "" +
- "" +
- "EAPType" +
- "13" +
- "" +
- "" +
- "" +
- "Method03" +
- "" +
- "" +
- "EAPType" +
- "18" +
- "" +
- "" +
- "" +
- "Method04" +
- "" +
- "" +
- "EAPType" +
- "23" +
- "" +
- "" +
- "" +
- "Method05" +
- "" +
- "" +
- "EAPType" +
- "50" +
- "" +
- "" +
- "" +
- "Method06" +
- "" +
- "" +
- "EAPType" +
- "21" +
- "" +
- "" +
- "InnerMethod" +
- "PAP" +
- "" +
- "" +
- "" +
- "Method07" +
- "" +
- "" +
- "EAPType" +
- "25" +
- "" +
- "" +
- "InnerEAPType" +
- "6" +
- "" +
- "" +
- "" +
- "" +
- "SPCertificate" +
- "" +
- "Cert01" +
- "" +
- "CertificateIssuerName" +
- "CN=RuckusCA" +
- "" +
- "" +
- "" +
- "" +
- "ManufacturingCertificate" +
- "FALSE" +
- "" +
- "" +
- "Wi-FiMACAddress" +
- "001d2e112233" +
- "" +
- "" +
- "ClientTriggerRedirectURI" +
- "http://127.0.0.1:12345/index.htm" +
- "" +
- "" +
- "Ops" +
- "" +
- "launchBrowserToURI" +
- "" +
- "" +
- "" +
- "negotiateClientCertTLS" +
- "" +
- "" +
- "" +
- "getCertificate" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "URI" +
- "" +
- "MaxDepth" +
- "32" +
- "" +
- "" +
- "MaxTotLen" +
- "2048" +
- "" +
- "" +
- "MaxSegLen" +
- "64" +
- "" +
- "" +
- "" +
- "DevType" +
- "Smartphone" +
- "" +
- "" +
- "OEM" +
- "ACME" +
- "" +
- "" +
- "FwV" +
- "1.2.100.5" +
- "" +
- "" +
- "SwV" +
- "9.11.130" +
- "" +
- "" +
- "HwV" +
- "1.0" +
- "" +
- "" +
- "LrgObj" +
- "TRUE" +
- "" +
- "" +
- "";
-
-
- private static final String DevInfo =
- "" +
- "1.2" +
- "" +
- "DevInfo" +
- "" +
- "" +
- "urn:oma:mo:oma-dm-devinfo:1.0" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "DevID" +
- "DevInfo" +
- "urn:acme:00-11-22-33-44-55" +
- "" +
- "" +
- "Man" +
- "DevInfo" +
- "ACME" +
- "" +
- "" +
- "Mod" +
- "DevInfo" +
- "HS2.0-01" +
- "" +
- "" +
- "DmV" +
- "DevInfo" +
- "1.2" +
- "" +
- "" +
- "Lang" +
- "DevInfo" +
- "en-US" +
- "" +
- "";
-}
diff --git a/packages/Osu/src/com/android/hotspot2/PasspointMatch.java b/packages/Osu/src/com/android/hotspot2/PasspointMatch.java
deleted file mode 100644
index 8330283a7d2a8..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/PasspointMatch.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.android.hotspot2;
-
-public enum PasspointMatch {
- HomeProvider,
- RoamingProvider,
- Incomplete,
- None,
- Declined
-}
diff --git a/packages/Osu/src/com/android/hotspot2/Utils.java b/packages/Osu/src/com/android/hotspot2/Utils.java
deleted file mode 100644
index 880007f6e392b..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/Utils.java
+++ /dev/null
@@ -1,407 +0,0 @@
-package com.android.hotspot2;
-
-import com.android.anqp.Constants;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.TimeZone;
-
-import static com.android.anqp.Constants.BYTE_MASK;
-import static com.android.anqp.Constants.NIBBLE_MASK;
-
-public abstract class Utils {
-
- public static final long UNSET_TIME = -1;
-
- private static final int EUI48Length = 6;
- private static final int EUI64Length = 8;
- private static final long EUI48Mask = 0xffffffffffffL;
- private static final String[] PLMNText = {"org", "3gppnetwork", "mcc*", "mnc*", "wlan"};
-
- public static List splitDomain(String domain) {
-
- if (domain.endsWith("."))
- domain = domain.substring(0, domain.length() - 1);
- int at = domain.indexOf('@');
- if (at >= 0)
- domain = domain.substring(at + 1);
-
- String[] labels = domain.toLowerCase().split("\\.");
- LinkedList labelList = new LinkedList();
- for (String label : labels) {
- labelList.addFirst(label);
- }
-
- return labelList;
- }
-
- public static long parseMac(String s) {
-
- long mac = 0;
- int count = 0;
- for (int n = 0; n < s.length(); n++) {
- int nibble = Utils.fromHex(s.charAt(n), true); // Set lenient to not blow up on ':'
- if (nibble >= 0) { // ... and use only legit hex.
- mac = (mac << 4) | nibble;
- count++;
- }
- }
- if (count < 12 || (count & 1) == 1) {
- throw new IllegalArgumentException("Bad MAC address: '" + s + "'");
- }
- return mac;
- }
-
- public static String macToString(long mac) {
- int len = (mac & ~EUI48Mask) != 0 ? EUI64Length : EUI48Length;
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (int n = (len - 1) * Byte.SIZE; n >= 0; n -= Byte.SIZE) {
- if (first) {
- first = false;
- } else {
- sb.append(':');
- }
- sb.append(String.format("%02x", (mac >>> n) & Constants.BYTE_MASK));
- }
- return sb.toString();
- }
-
- public static String getMccMnc(List domain) {
- if (domain.size() != PLMNText.length) {
- return null;
- }
-
- for (int n = 0; n < PLMNText.length; n++) {
- String expect = PLMNText[n];
- int len = expect.endsWith("*") ? expect.length() - 1 : expect.length();
- if (!domain.get(n).regionMatches(0, expect, 0, len)) {
- return null;
- }
- }
-
- String prefix = domain.get(2).substring(3) + domain.get(3).substring(3);
- for (int n = 0; n < prefix.length(); n++) {
- char ch = prefix.charAt(n);
- if (ch < '0' || ch > '9') {
- return null;
- }
- }
- return prefix;
- }
-
- public static String toIpString(int leIp) {
- return String.format("%d.%d.%d.%d",
- leIp & BYTE_MASK,
- (leIp >> 8) & BYTE_MASK,
- (leIp >> 16) & BYTE_MASK,
- (leIp >> 24) & BYTE_MASK);
- }
-
- public static String bssidsToString(Collection bssids) {
- StringBuilder sb = new StringBuilder();
- for (Long bssid : bssids) {
- sb.append(String.format(" %012x", bssid));
- }
- return sb.toString();
- }
-
- public static String roamingConsortiumsToString(long[] ois) {
- if (ois == null) {
- return "null";
- }
- List list = new ArrayList(ois.length);
- for (long oi : ois) {
- list.add(oi);
- }
- return roamingConsortiumsToString(list);
- }
-
- public static String roamingConsortiumsToString(Collection ois) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (long oi : ois) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- if (Long.numberOfLeadingZeros(oi) > 40) {
- sb.append(String.format("%06x", oi));
- } else {
- sb.append(String.format("%010x", oi));
- }
- }
- return sb.toString();
- }
-
- public static String toUnicodeEscapedString(String s) {
- StringBuilder sb = new StringBuilder(s.length());
- for (int n = 0; n < s.length(); n++) {
- char ch = s.charAt(n);
- if (ch >= ' ' && ch < 127) {
- sb.append(ch);
- } else {
- sb.append("\\u").append(String.format("%04x", (int) ch));
- }
- }
- return sb.toString();
- }
-
- public static String toHexString(byte[] data) {
- if (data == null) {
- return "null";
- }
- StringBuilder sb = new StringBuilder(data.length * 3);
-
- boolean first = true;
- for (byte b : data) {
- if (first) {
- first = false;
- } else {
- sb.append(' ');
- }
- sb.append(String.format("%02x", b & BYTE_MASK));
- }
- return sb.toString();
- }
-
- public static String toHex(byte[] octets) {
- StringBuilder sb = new StringBuilder(octets.length * 2);
- for (byte o : octets) {
- sb.append(String.format("%02x", o & BYTE_MASK));
- }
- return sb.toString();
- }
-
- public static byte[] hexToBytes(String text) {
- if ((text.length() & 1) == 1) {
- throw new NumberFormatException("Odd length hex string: " + text.length());
- }
- byte[] data = new byte[text.length() >> 1];
- int position = 0;
- for (int n = 0; n < text.length(); n += 2) {
- data[position] =
- (byte) (((fromHex(text.charAt(n), false) & NIBBLE_MASK) << 4) |
- (fromHex(text.charAt(n + 1), false) & NIBBLE_MASK));
- position++;
- }
- return data;
- }
-
- public static int fromHex(char ch, boolean lenient) throws NumberFormatException {
- if (ch <= '9' && ch >= '0') {
- return ch - '0';
- } else if (ch >= 'a' && ch <= 'f') {
- return ch + 10 - 'a';
- } else if (ch <= 'F' && ch >= 'A') {
- return ch + 10 - 'A';
- } else if (lenient) {
- return -1;
- } else {
- throw new NumberFormatException("Bad hex-character: " + ch);
- }
- }
-
- private static char toAscii(int b) {
- return b >= ' ' && b < 0x7f ? (char) b : '.';
- }
-
- static boolean isDecimal(String s) {
- for (int n = 0; n < s.length(); n++) {
- char ch = s.charAt(n);
- if (ch < '0' || ch > '9') {
- return false;
- }
- }
- return true;
- }
-
- public static int compare(Comparable c1, T c2) {
- if (c1 == null) {
- return c2 == null ? 0 : -1;
- } else if (c2 == null) {
- return 1;
- } else {
- return c1.compareTo(c2);
- }
- }
-
- public static String bytesToBingoCard(ByteBuffer data, int len) {
- ByteBuffer dup = data.duplicate();
- dup.limit(dup.position() + len);
- return bytesToBingoCard(dup);
- }
-
- public static String bytesToBingoCard(ByteBuffer data) {
- ByteBuffer dup = data.duplicate();
- StringBuilder sbx = new StringBuilder();
- while (dup.hasRemaining()) {
- sbx.append(String.format("%02x ", dup.get() & BYTE_MASK));
- }
- dup = data.duplicate();
- sbx.append(' ');
- while (dup.hasRemaining()) {
- sbx.append(String.format("%c", toAscii(dup.get() & BYTE_MASK)));
- }
- return sbx.toString();
- }
-
- public static String toHMS(long millis) {
- long time = millis >= 0 ? millis : -millis;
- long tmp = time / 1000L;
- long ms = time - tmp * 1000L;
-
- time = tmp;
- tmp /= 60L;
- long s = time - tmp * 60L;
-
- time = tmp;
- tmp /= 60L;
- long m = time - tmp * 60L;
-
- return String.format("%s%d:%02d:%02d.%03d", millis < 0 ? "-" : "", tmp, m, s, ms);
- }
-
- public static String toUTCString(long ms) {
- if (ms < 0) {
- return "unset";
- }
- Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- c.setTimeInMillis(ms);
- return String.format("%4d/%02d/%02d %2d:%02d:%02dZ",
- c.get(Calendar.YEAR),
- c.get(Calendar.MONTH) + 1,
- c.get(Calendar.DAY_OF_MONTH),
- c.get(Calendar.HOUR_OF_DAY),
- c.get(Calendar.MINUTE),
- c.get(Calendar.SECOND));
- }
-
- /**
- * Decode a wpa_supplicant SSID. wpa_supplicant uses double quotes around plain strings, or
- * expects a hex-string if no quotes appear.
- * For Ascii encoded string, any octet < 32 or > 127 is encoded as
- * a "\x" followed by the hex representation of the octet.
- * Exception chars are ", \, \e, \n, \r, \t which are escaped by a \
- * See src/utils/common.c for the implementation in the supplicant.
- *
- * @param ssid The SSID from the config.
- * @return The actual string content of the SSID
- */
- public static String decodeSsid(String ssid) {
- if (ssid.length() <= 1) {
- return ssid;
- } else if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
- return unescapeSsid(ssid.substring(1, ssid.length() - 1));
- } else if ((ssid.length() & 1) == 1) {
- return ssid;
- }
-
- byte[] codepoints;
- try {
- codepoints = new byte[ssid.length() / 2];
- for (int n = 0; n < ssid.length(); n += 2) {
- codepoints[n / 2] = (byte) decodeHexPair(ssid, n);
- }
- } catch (NumberFormatException nfe) {
- return ssid;
- }
-
- try {
- CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
- return decoder.decode(ByteBuffer.wrap(codepoints)).toString();
- } catch (CharacterCodingException cce) {
- /* Do nothing, try LATIN-1 */
- }
- try {
- CharsetDecoder decoder = StandardCharsets.ISO_8859_1.newDecoder();
- return decoder.decode(ByteBuffer.wrap(codepoints)).toString();
- } catch (CharacterCodingException cce) { // Should not be possible.
- return ssid;
- }
- }
-
- private static String unescapeSsid(String s) {
- StringBuilder sb = new StringBuilder();
- for (int n = 0; n < s.length(); n++) {
- char ch = s.charAt(n);
- if (ch != '\\' || n >= s.length() - 1) {
- sb.append(ch);
- } else {
- n++;
- ch = s.charAt(n);
- switch (ch) {
- case '"':
- case '\\':
- default:
- sb.append(ch);
- break;
- case 'e':
- sb.append((char) 27); // Escape char
- break;
- case 'n':
- sb.append('\n');
- break;
- case 'r':
- sb.append('\r');
- break;
- case 't':
- sb.append('\t');
- break;
- case 'x':
- if (s.length() - n < 3) {
- sb.append('\\').append(ch);
- } else {
- n++;
- sb.append((char) decodeHexPair(s, n));
- n++;
- }
- break;
- }
- }
- }
- return sb.toString();
- }
-
- private static int decodeHexPair(String s, int position) {
- return fromHex(s.charAt(position)) << 4 | fromHex(s.charAt(position + 1));
- }
-
- private static int fromHex(char ch) {
- if (ch >= '0' && ch <= '9') {
- return ch - '0';
- } else if (ch >= 'A' && ch <= 'F') {
- return ch - 'A' + 10;
- } else if (ch >= 'a' && ch <= 'f') {
- return ch - 'a' + 10;
- } else {
- throw new NumberFormatException(String.format("Not hex: '%c'", ch));
- }
- }
-
- public static void delay(long ms) {
- long until = System.currentTimeMillis() + ms;
- for (; ; ) {
- long remainder = until - System.currentTimeMillis();
- if (remainder <= 0) {
- break;
- }
- try {
- Thread.sleep(remainder);
- } catch (InterruptedException ie) { /**/ }
- }
- }
-
- public static > T mapEnum(int ordinal, Class enumClass) {
- T[] constants = enumClass.getEnumConstants();
- return ordinal >= 0 && ordinal < constants.length ? constants[ordinal]: null;
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/app/IOSUAccessor.aidl b/packages/Osu/src/com/android/hotspot2/app/IOSUAccessor.aidl
deleted file mode 100644
index 500dd2ee32c48..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/IOSUAccessor.aidl
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.android.hotspot2.app;
-
-import com.android.hotspot2.app.OSUData;
-
-interface IOSUAccessor {
- List getOsuData();
- void selectOsu(int id);
-}
diff --git a/packages/Osu/src/com/android/hotspot2/app/LocalServiceBinder.java b/packages/Osu/src/com/android/hotspot2/app/LocalServiceBinder.java
deleted file mode 100644
index 8801839fe2624..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/LocalServiceBinder.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.android.hotspot2.app;
-
-import android.os.Binder;
-
-public class LocalServiceBinder extends Binder {
- private final OSUService mDelegate;
-
- public LocalServiceBinder(OSUService delegate) {
- mDelegate = delegate;
- }
-
- public OSUService getService() {
- return mDelegate;
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/app/MainActivity.java b/packages/Osu/src/com/android/hotspot2/app/MainActivity.java
deleted file mode 100644
index 7fd2238703f1f..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/MainActivity.java
+++ /dev/null
@@ -1,303 +0,0 @@
-package com.android.hotspot2.app;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.TaskStackBuilder;
-import android.content.ComponentName;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import com.android.hotspot2.AppBridge;
-import com.android.hotspot2.R;
-import com.android.hotspot2.osu.OSUManager;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Main activity.
- */
-public class MainActivity extends Activity {
- private static final int NOTIFICATION_ID = 0; // Used for OSU count
- private static final int NOTIFICATION_MESSAGE_ID = 1; // Used for other messages
- private static final String ACTION_SVC_BOUND = "SVC_BOUND";
-
- private volatile OSUService mLocalService;
-
- private final ServiceConnection mConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- LocalServiceBinder binder = (LocalServiceBinder) service;
- mLocalService = binder.getService();
- showOsuSelection(mLocalService);
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mLocalService = null;
- }
- };
-
- private ListView osuListView;
- private OsuListAdapter osuListAdapter;
- private String message;
-
- public MainActivity() {
-
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- if (mLocalService != null) {
- unbindService(mConnection);
- mLocalService = null;
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (message != null) {
- showDialog(message);
- message = null;
- }
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- final Intent intent = getIntent();
- Bundle bundle = intent.getExtras();
-
- if (intent.getAction() == null) {
- if (mLocalService == null) {
- bindService(new Intent(this, OSUService.class), mConnection, 0);
- }
- } else if (intent.getAction().equals(AppBridge.ACTION_OSU_NOTIFICATION)) {
- if (bundle == null) {
- Log.d(OSUManager.TAG, "No parameters for OSU notification");
- return;
- }
- if (bundle.containsKey(AppBridge.OSU_COUNT)) {
- showOsuCount(bundle.getInt("osu-count", 0), Collections.emptyList());
- } else if (bundle.containsKey(AppBridge.PROV_SUCCESS)) {
- showStatus(bundle.getBoolean(AppBridge.PROV_SUCCESS),
- bundle.getString(AppBridge.SP_NAME),
- bundle.getString(AppBridge.PROV_MESSAGE),
- null);
- } else if (bundle.containsKey(AppBridge.DEAUTH)) {
- showDeauth(bundle.getString(AppBridge.SP_NAME),
- bundle.getBoolean(AppBridge.DEAUTH),
- bundle.getInt(AppBridge.DEAUTH_DELAY),
- bundle.getString(AppBridge.DEAUTH_URL));
- }
- }
- }
-
- private void showOsuSelection(final OSUService osuService) {
- List osuData = osuService.getOsuData();
-
- setContentView(R.layout.activity_main);
- Log.d("osu", "osu count:" + osuData.size());
- View noOsuView = findViewById(R.id.no_osu);
- if (osuData.size() > 0) {
- noOsuView.setVisibility(View.GONE);
- osuListAdapter = new OsuListAdapter(this, osuData);
- osuListView = findViewById(R.id.profile_list);
- osuListView.setAdapter(osuListAdapter);
- osuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
- OSUData osuData = (OSUData) adapterView.getAdapter().getItem(position);
- Log.d("osu", "launch osu:" + osuData.getName()
- + " id:" + osuData.getId());
- osuService.selectOsu(osuData.getId());
- finish();
- }
- });
- } else {
- noOsuView.setVisibility(View.VISIBLE);
- }
- }
-
- private void showOsuCount(int osuCount, List osus) {
- if (osuCount > 0) {
- printOsuDataList(osus);
- sendNotification(osuCount);
- } else {
- cancelNotification();
- }
- finish();
- }
-
- private void showStatus(boolean provSuccess, String spName, String provMessage,
- String remoteStatus) {
- if (provSuccess) {
- sendDialogMessage(
- String.format("Credentials for %s was successfully installed", spName));
- } else {
- if (spName != null) {
- if (remoteStatus != null) {
- sendDialogMessage(
- String.format("Failed to install credentials for %s: %s: %s",
- spName, provMessage, remoteStatus));
- } else {
- sendDialogMessage(
- String.format("Failed to install credentials for %s: %s",
- spName, provMessage));
- }
- } else {
- sendDialogMessage(
- String.format("Failed to contact OSU: %s", provMessage));
- }
- }
- }
-
- private void showDeauth(String spName, boolean ess, int delay, String url) {
- String delayReadable = getReadableTimeInSeconds(delay);
- if (ess) {
- if (delay > 60) {
- sendDialogMessage(
- String.format("There is an issue connecting to %s [for the next %s]. " +
- "Please visit %s for details", spName, delayReadable, url));
- } else {
- sendDialogMessage(
- String.format("There is an issue connecting to %s. " +
- "Please visit %s for details", spName, url));
- }
- } else {
- sendDialogMessage(
- String.format("There is an issue with the closest Access Point for %s. " +
- "You may wait %s or move to another Access Point to " +
- "regain access. Please visit %s for details.",
- spName, delayReadable, url));
- }
- }
-
- private String getReadableTimeInSeconds(int timeSeconds) {
- long hours = TimeUnit.SECONDS.toHours(timeSeconds);
- long minutes = TimeUnit.SECONDS.toMinutes(timeSeconds) - TimeUnit.HOURS.toMinutes(hours);
- long seconds =
- timeSeconds - TimeUnit.HOURS.toSeconds(hours) - TimeUnit.MINUTES.toSeconds(minutes);
- if (hours > 0) {
- return String.format("%02d:%02d:%02d", hours, minutes, seconds);
- } else {
- return String.format("%ds", seconds);
- }
- }
-
- private void sendNotification(int count) {
- Notification.Builder builder =
- new Notification.Builder(this)
- .setContentTitle(String.format("%s OSU available", count))
- .setContentText("Choose one to connect")
- .setSmallIcon(android.R.drawable.ic_dialog_info)
- .setAutoCancel(false);
- Intent resultIntent = new Intent(this, MainActivity.class);
-
- TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
- stackBuilder.addParentStack(MainActivity.class);
- stackBuilder.addNextIntent(resultIntent);
- PendingIntent resultPendingIntent =
- stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
- builder.setContentIntent(resultPendingIntent);
- NotificationManager notificationManager =
- (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.notify(NOTIFICATION_ID, builder.build());
- }
-
- private void cancelNotification() {
- NotificationManager notificationManager =
- (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.cancel(NOTIFICATION_ID);
- }
-
- private void sendDialogMessage(String message) {
-// sendNotificationMessage(message);
- this.message = message;
- }
-
- private void showDialog(String message) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(message)
- .setTitle("OSU");
- builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialogInterface) {
- dialogInterface.cancel();
- finish();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
-
- private void sendNotificationMessage(String title) {
- Notification.Builder builder =
- new Notification.Builder(this)
- .setContentTitle(title)
- .setContentText("Click to dismiss.")
- .setSmallIcon(android.R.drawable.ic_dialog_info)
- .setAutoCancel(true);
- NotificationManager notificationManager =
- (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.notify(NOTIFICATION_MESSAGE_ID, builder.build());
- }
-
- private static class OsuListAdapter extends ArrayAdapter {
- private Activity activity;
-
- public OsuListAdapter(Activity activity, List osuDataList) {
- super(activity, R.layout.list_item, osuDataList);
- this.activity = activity;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if (view == null) {
- view = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
- }
- OSUData osuData = getItem(position);
- TextView osuName = (TextView) view.findViewById(R.id.profile_name);
- osuName.setText(osuData.getName());
- TextView osuDetail = (TextView) view.findViewById(R.id.profile_detail);
- osuDetail.setText(osuData.getServiceDescription());
- ImageView osuIcon = (ImageView) view.findViewById(R.id.profile_logo);
- byte[] iconData = osuData.getIconData();
- osuIcon.setImageDrawable(
- new BitmapDrawable(activity.getResources(),
- BitmapFactory.decodeByteArray(iconData, 0, iconData.length)));
- return view;
- }
- }
-
- private void printOsuDataList(List osuDataList) {
- for (OSUData osuData : osuDataList) {
- Log.d("osu", String.format("OSUData:[%s][%s][%d]",
- osuData.getName(), osuData.getServiceDescription(),
- osuData.getId()));
- }
- }
-
-}
diff --git a/packages/Osu/src/com/android/hotspot2/app/OSUData.aidl b/packages/Osu/src/com/android/hotspot2/app/OSUData.aidl
deleted file mode 100644
index 3407f47cbd627..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/OSUData.aidl
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.android.hotspot2.app;
-
-parcelable OSUData;
-
diff --git a/packages/Osu/src/com/android/hotspot2/app/OSUData.java b/packages/Osu/src/com/android/hotspot2/app/OSUData.java
deleted file mode 100644
index 17cc49b773348..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/OSUData.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.android.hotspot2.app;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import com.android.hotspot2.flow.OSUInfo;
-import com.android.hotspot2.osu.OSUManager;
-
-public class OSUData implements Parcelable {
- private final String mName;
- private final String mServiceDescription;
- private final byte[] mIconData;
- private final int mId;
-
- public OSUData(OSUInfo osuInfo) {
- mName = osuInfo.getName(OSUManager.LOCALE);
- mServiceDescription = osuInfo.getServiceDescription(OSUManager.LOCALE);
- mIconData = osuInfo.getIconFileElement().getIconData();
- mId = osuInfo.getOsuID();
- }
-
- public String getName() {
- return mName;
- }
-
- public String getServiceDescription() {
- return mServiceDescription;
- }
-
- public byte[] getIconData() {
- return mIconData;
- }
-
- public int getId() {
- return mId;
- }
-
- private OSUData(Parcel in) {
- mName = in.readString();
- mServiceDescription = in.readString();
- int iconSize = in.readInt();
- mIconData = new byte[iconSize];
- in.readByteArray(mIconData);
- mId = in.readInt();
- }
-
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public OSUData createFromParcel(Parcel in) {
- return new OSUData(in);
- }
-
- public OSUData[] newArray(int size) {
- return new OSUData[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(mName);
- dest.writeString(mServiceDescription);
- dest.writeByteArray(mIconData);
- dest.writeInt(mId);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/app/OSUService.java b/packages/Osu/src/com/android/hotspot2/app/OSUService.java
deleted file mode 100644
index e9da113af747b..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/app/OSUService.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package com.android.hotspot2.app;
-
-import android.app.IntentService;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.util.Log;
-
-import com.android.anqp.OSUProvider;
-import com.android.hotspot2.PasspointMatch;
-import com.android.hotspot2.osu.OSUManager;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * This is the Hotspot 2.0 release 2 OSU background service that is continuously running and caches
- * OSU information.
- *
- * The OSU App is made up of two services; FlowService and OSUService.
- *
- * OSUService is a long running light weight service, kept alive throughout the lifetime of the
- * operating system by being bound from the framework (in WifiManager in stage
- * PHASE_THIRD_PARTY_APPS_CAN_START), and is responsible for continuously caching OSU information
- * and notifying the UI when OSUs are available.
- *
- * FlowService is only started on demand from OSUService and is responsible for handling actual
- * provisioning and remediation flows, and requires a fairly significant memory footprint.
- *
- * FlowService is defined to run in its own process through the definition
- *
- * in the AndroidManifest.
- * This is done as a means to keep total app memory footprint low (pss < 10M) and only start the
- * FlowService on demand and make it available for "garbage collection" by the OS when not in use.
- */
-public class OSUService extends IntentService {
- public static final String REMEDIATION_DONE_ACTION = "com.android.hotspot2.REMEDIATION_DONE";
- public static final String REMEDIATION_FQDN_EXTRA = "com.android.hotspot2.REMEDIATION_FQDN";
- public static final String REMEDIATION_POLICY_EXTRA = "com.android.hotspot2.REMEDIATION_POLICY";
-
- private static final String[] INTENTS = {
- WifiManager.SCAN_RESULTS_AVAILABLE_ACTION,
- // TODO(b/32883320): use updated intent definitions.
- //WifiManager.PASSPOINT_WNM_FRAME_RECEIVED_ACTION,
- //WifiManager.PASSPOINT_ICON_RECEIVED_ACTION,
- WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION,
- WifiManager.WIFI_STATE_CHANGED_ACTION,
- WifiManager.NETWORK_STATE_CHANGED_ACTION,
- REMEDIATION_DONE_ACTION
- };
-
- private OSUManager mOsuManager;
- private final LocalServiceBinder mLocalServiceBinder;
-
- public OSUService() {
- super("OSUService");
- mLocalServiceBinder = new LocalServiceBinder(this);
- }
-
- /*
- public final class OSUAccessorImpl extends IOSUAccessor.Stub {
- public List getOsuData() {
- List infos = getOsuInfos();
- List data = new ArrayList<>(infos.size());
- for (OSUInfo osuInfo : infos) {
- data.add(new OSUData(osuInfo));
- }
- return data;
- }
-
- public void selectOsu(int id) {
- OSUService.this.selectOsu(id);
- }
- }
- */
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- onHandleIntent(intent);
- return START_STICKY;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- handleIntent(intent.getAction(), intent);
- }
- };
- for (String intentString : INTENTS) {
- registerReceiver(receiver, new IntentFilter(intentString));
- }
- return mLocalServiceBinder;
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- if (intent == null) {
- Log.d(OSUManager.TAG, "Null intent!");
- return;
- }
- //handleIntent(intent.getStringExtra(MainActivity.ACTION_KEY), intent);
- }
-
- private void handleIntent(String action, Intent intent) {
- WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- Bundle bundle = intent.getExtras();
- if (mOsuManager == null) {
- mOsuManager = new OSUManager(this);
- }
- Log.d(OSUManager.TAG, "Got intent " + intent.getAction());
-
- switch (action) {
- case WifiManager.SCAN_RESULTS_AVAILABLE_ACTION:
- mOsuManager.pushScanResults(wifiManager.getScanResults());
- break;
- // TODO(b/32883320): use updated intent definitions.
- /*
- case WifiManager.PASSPOINT_WNM_FRAME_RECEIVED_ACTION:
- long bssid = bundle.getLong(WifiManager.EXTRA_PASSPOINT_WNM_BSSID);
- String url = bundle.getString(WifiManager.EXTRA_PASSPOINT_WNM_URL);
-
- try {
- if (bundle.containsKey(WifiManager.EXTRA_PASSPOINT_WNM_METHOD)) {
- int method = bundle.getInt(WifiManager.EXTRA_PASSPOINT_WNM_METHOD);
- if (method != OSUProvider.OSUMethod.SoapXml.ordinal()) {
- Log.w(OSUManager.TAG, "Unsupported remediation method: " + method);
- return;
- }
- PasspointMatch match = null;
- if (bundle.containsKey(WifiManager.EXTRA_PASSPOINT_WNM_PPOINT_MATCH)) {
- int ordinal =
- bundle.getInt(WifiManager.EXTRA_PASSPOINT_WNM_PPOINT_MATCH);
- if (ordinal >= 0 && ordinal < PasspointMatch.values().length) {
- match = PasspointMatch.values()[ordinal];
- }
- }
- mOsuManager.wnmRemediate(bssid, url, match);
- } else if (bundle.containsKey(WifiManager.EXTRA_PASSPOINT_WNM_ESS)) {
- boolean ess = bundle.getBoolean(WifiManager.EXTRA_PASSPOINT_WNM_ESS);
- int delay = bundle.getInt(WifiManager.EXTRA_PASSPOINT_WNM_DELAY);
- mOsuManager.deauth(bssid, ess, delay, url);
- } else {
- Log.w(OSUManager.TAG, "Unknown WNM event");
- }
- } catch (IOException e) {
- Log.w(OSUManager.TAG, "Remediation event failed to parse: " + e);
- }
- break;
- case WifiManager.PASSPOINT_ICON_RECEIVED_ACTION:
- mOsuManager.notifyIconReceived(
- bundle.getLong(WifiManager.EXTRA_PASSPOINT_ICON_BSSID),
- bundle.getString(WifiManager.EXTRA_PASSPOINT_ICON_FILE),
- bundle.getByteArray(WifiManager.EXTRA_PASSPOINT_ICON_DATA));
- break;
- */
- case WifiManager.NETWORK_STATE_CHANGED_ACTION:
- mOsuManager.networkConnectChange(
- (WifiInfo) intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO));
- break;
- case WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION:
- boolean multiNetwork =
- bundle.getBoolean(WifiManager.EXTRA_MULTIPLE_NETWORKS_CHANGED, false);
- if (multiNetwork) {
- mOsuManager.networkConfigChanged();
- } else if (bundle.getInt(WifiManager.EXTRA_CHANGE_REASON,
- WifiManager.CHANGE_REASON_CONFIG_CHANGE)
- == WifiManager.CHANGE_REASON_REMOVED) {
- WifiConfiguration configuration =
- intent.getParcelableExtra(WifiManager.EXTRA_WIFI_CONFIGURATION);
- mOsuManager.networkDeleted(configuration);
- } else {
- mOsuManager.networkConfigChanged();
- }
- break;
- case WifiManager.WIFI_STATE_CHANGED_ACTION:
- int state = bundle.getInt(WifiManager.EXTRA_WIFI_STATE);
- if (state == WifiManager.WIFI_STATE_DISABLED) {
- mOsuManager.wifiStateChange(false);
- } else if (state == WifiManager.WIFI_STATE_ENABLED) {
- mOsuManager.wifiStateChange(true);
- }
- break;
- case REMEDIATION_DONE_ACTION:
- String fqdn = bundle.getString(REMEDIATION_FQDN_EXTRA);
- boolean policy = bundle.getBoolean(REMEDIATION_POLICY_EXTRA);
- mOsuManager.remediationDone(fqdn, policy);
- break;
- }
- }
-
- public List getOsuData() {
- return mOsuManager.getAvailableOSUs();
- }
-
- public void selectOsu(int id) {
- mOsuManager.setOSUSelection(id);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Boolean.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Boolean.java
deleted file mode 100644
index 18af3b80f7c47..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Boolean.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-
-public class Asn1Boolean extends Asn1Object {
- private final boolean mBoolean;
-
- public Asn1Boolean(int tag, Asn1Class asn1Class, int length, ByteBuffer data)
- throws DecodeException {
- super(tag, asn1Class, false, length);
- if (length != 1) {
- throw new DecodeException("Boolean length != 1: " + length, data.position());
- }
- mBoolean = data.get() != 0;
- }
-
- public boolean getValue() {
- return mBoolean;
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString() {
- return super.toString() + "=" + Boolean.toString(mBoolean);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Class.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Class.java
deleted file mode 100644
index 8a4d8a803245d..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Class.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.android.hotspot2.asn1;
-
-public enum Asn1Class {
- Universal, Application, Context, Private
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Constructed.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Constructed.java
deleted file mode 100644
index 69b65dcd241a1..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Constructed.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.*;
-
-public class Asn1Constructed extends Asn1Object {
- private final int mTagPosition;
- private final List mChildren;
-
- public Asn1Constructed(int tag, Asn1Class asn1Class, int length,
- ByteBuffer payload, int tagPosition) {
- super(tag, asn1Class, true, length, payload);
- mTagPosition = tagPosition;
- mChildren = new ArrayList<>();
- }
-
- public void addChild(Asn1Object object) {
- mChildren.add(object);
- }
-
- @Override
- public Collection getChildren() {
- return Collections.unmodifiableCollection(mChildren);
- }
-
- public ByteBuffer getEncoding() {
- return getPayload(mTagPosition);
- }
-
- private void toString(int level, StringBuilder sb) {
- sb.append(indent(level)).append(super.toString()).append(":\n");
- for (Asn1Object child : mChildren) {
- if (child.isConstructed()) {
- ((Asn1Constructed) child).toString(level + 1, sb);
- } else {
- sb.append(indent(level + 1)).append(child.toString()).append('\n');
- }
- }
- }
-
- public static String indent(int level) {
- char[] indent = new char[level * 2];
- Arrays.fill(indent, ' ');
- return new String(indent);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- toString(0, sb);
- return sb.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Decoder.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Decoder.java
deleted file mode 100644
index 53452e79ab15c..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Decoder.java
+++ /dev/null
@@ -1,211 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-public class Asn1Decoder {
- public static final int TAG_UNIVZERO = 0x00;
- public static final int TAG_BOOLEAN = 0x01;
- public static final int TAG_INTEGER = 0x02;
- public static final int TAG_BITSTRING = 0x03;
- public static final int TAG_OCTET_STRING = 0x04;
- public static final int TAG_NULL = 0x05;
- public static final int TAG_OID = 0x06;
- public static final int TAG_ObjectDescriptor = 0x07;
- public static final int TAG_EXTERNAL = 0x08;
- public static final int TAG_REAL = 0x09;
- public static final int TAG_ENUMERATED = 0x0a;
- public static final int TAG_UTF8String = 0x0c; // * (*) are X.509 DirectoryString's
- public static final int TAG_RelativeOID = 0x0d;
- public static final int TAG_SEQ = 0x10; // 30 if constructed
- public static final int TAG_SET = 0x11;
- public static final int TAG_NumericString = 0x12; // [UNIVERSAL 18]
- public static final int TAG_PrintableString = 0x13; // * [UNIVERSAL 19]
- public static final int TAG_T61String = 0x14; // * TeletexString [UNIVERSAL 20]
- public static final int TAG_VideotexString = 0x15; // [UNIVERSAL 21]
- public static final int TAG_IA5String = 0x16; // [UNIVERSAL 22]
- public static final int TAG_UTCTime = 0x17;
- public static final int TAG_GeneralizedTime = 0x18;
- public static final int TAG_GraphicString = 0x19; // [UNIVERSAL 25]
- public static final int TAG_VisibleString = 0x1a; // ISO64String [UNIVERSAL 26]
- public static final int TAG_GeneralString = 0x1b; // [UNIVERSAL 27]
- public static final int TAG_UniversalString = 0x1c; // * [UNIVERSAL 28]
- public static final int TAG_BMPString = 0x1e; // * [UNIVERSAL 30]
-
- public static final int IntOverflow = 0xffff0000;
- public static final int MoreBit = 0x80;
- public static final int MoreData = 0x7f;
- public static final int ConstructedBit = 0x20;
- public static final int ClassShift = 6;
- public static final int ClassMask = 0x3;
- public static final int MoreWidth = 7;
- public static final int ByteWidth = 8;
- public static final int ByteMask = 0xff;
- public static final int ContinuationTag = 31;
-
- public static final int IndefiniteLength = -1;
-
- private static final Map sTagMap = new HashMap<>();
-
- static {
- sTagMap.put(TAG_UNIVZERO, Asn1Tag.UNIVZERO);
- sTagMap.put(TAG_BOOLEAN, Asn1Tag.BOOLEAN);
- sTagMap.put(TAG_INTEGER, Asn1Tag.INTEGER);
- sTagMap.put(TAG_BITSTRING, Asn1Tag.BITSTRING);
- sTagMap.put(TAG_OCTET_STRING, Asn1Tag.OCTET_STRING);
- sTagMap.put(TAG_NULL, Asn1Tag.NULL);
- sTagMap.put(TAG_OID, Asn1Tag.OID);
- sTagMap.put(TAG_ObjectDescriptor, Asn1Tag.ObjectDescriptor);
- sTagMap.put(TAG_EXTERNAL, Asn1Tag.EXTERNAL);
- sTagMap.put(TAG_REAL, Asn1Tag.REAL);
- sTagMap.put(TAG_ENUMERATED, Asn1Tag.ENUMERATED);
- sTagMap.put(TAG_UTF8String, Asn1Tag.UTF8String);
- sTagMap.put(TAG_RelativeOID, Asn1Tag.RelativeOID);
- sTagMap.put(TAG_SEQ, Asn1Tag.SEQUENCE);
- sTagMap.put(TAG_SET, Asn1Tag.SET);
- sTagMap.put(TAG_NumericString, Asn1Tag.NumericString);
- sTagMap.put(TAG_PrintableString, Asn1Tag.PrintableString);
- sTagMap.put(TAG_T61String, Asn1Tag.T61String);
- sTagMap.put(TAG_VideotexString, Asn1Tag.VideotexString);
- sTagMap.put(TAG_IA5String, Asn1Tag.IA5String);
- sTagMap.put(TAG_UTCTime, Asn1Tag.UTCTime);
- sTagMap.put(TAG_GeneralizedTime, Asn1Tag.GeneralizedTime);
- sTagMap.put(TAG_GraphicString, Asn1Tag.GraphicString);
- sTagMap.put(TAG_VisibleString, Asn1Tag.VisibleString);
- sTagMap.put(TAG_GeneralString, Asn1Tag.GeneralString);
- sTagMap.put(TAG_UniversalString, Asn1Tag.UniversalString);
- sTagMap.put(TAG_BMPString, Asn1Tag.BMPString);
- }
-
- public static Asn1Tag mapTag(int tag) {
- return sTagMap.get(tag);
- }
-
- public static Collection decode(ByteBuffer data) throws DecodeException {
- Asn1Constructed root =
- new Asn1Constructed(0, null, data.remaining(), data, data.position());
- decode(0, root);
- return root.getChildren();
- }
-
- private static void decode(int level, Asn1Constructed parent) throws DecodeException {
- ByteBuffer data = parent.getPayload();
- while (data.hasRemaining()) {
- int tagPosition = data.position();
- int propMask = data.get(tagPosition) & ByteMask;
- if (propMask == 0 && parent.isIndefiniteLength() && data.get(tagPosition + 1) == 0) {
- parent.setEndOfData(tagPosition);
- return;
- }
- Asn1Class asn1Class = Asn1Class.values()[(propMask >> ClassShift) & ClassMask];
- boolean constructed = (propMask & ConstructedBit) != 0;
-
- int tag = decodeTag(data);
- int length = decodeLength(data);
-
- if (constructed) {
- ByteBuffer payload = peelOff(data, length);
- Asn1Constructed root =
- new Asn1Constructed(tag, asn1Class, length, payload, tagPosition);
- decode(level + 1, root);
- if (length == IndefiniteLength) {
- data.position(root.getEndOfData() + 2); // advance past '00'
- }
- parent.addChild(root);
- } else {
- if (asn1Class != Asn1Class.Universal) {
- parent.addChild(new Asn1Octets(tag, asn1Class, length, data));
- } else {
- parent.addChild(buildScalar(tag, asn1Class, length, data));
- }
- }
- }
- }
-
- private static ByteBuffer peelOff(ByteBuffer base, int length) {
- ByteBuffer copy = base.duplicate();
- if (length == IndefiniteLength) {
- return copy;
- }
- copy.limit(copy.position() + length);
- base.position(base.position() + length);
- return copy;
- }
-
- private static Asn1Object buildScalar(int tag, Asn1Class asn1Class, int length, ByteBuffer data)
- throws DecodeException {
- switch (tag) {
- case TAG_BOOLEAN:
- return new Asn1Boolean(tag, asn1Class, length, data);
- case TAG_INTEGER:
- case TAG_ENUMERATED:
- return new Asn1Integer(tag, asn1Class, length, data);
- case TAG_BITSTRING:
- int bitResidual = data.get() & ByteMask;
- return new Asn1Octets(tag, asn1Class, length, data, bitResidual);
- case TAG_OCTET_STRING:
- return new Asn1Octets(tag, asn1Class, length, data);
- case TAG_OID:
- return new Asn1Oid(tag, asn1Class, length, data);
- case TAG_UTF8String:
- case TAG_NumericString:
- case TAG_PrintableString:
- case TAG_T61String:
- case TAG_VideotexString:
- case TAG_IA5String:
- case TAG_GraphicString:
- case TAG_VisibleString:
- case TAG_GeneralString:
- case TAG_UniversalString:
- case TAG_BMPString:
- return new Asn1String(tag, asn1Class, length, data);
- case TAG_GeneralizedTime:
- case TAG_UTCTime:
- // Should really be a dedicated time object
- return new Asn1String(tag, asn1Class, length, data);
- default:
- return new Asn1Octets(tag, asn1Class, length, data);
- }
- }
-
- private static int decodeTag(ByteBuffer data) throws DecodeException {
- int tag;
- byte tag0 = data.get();
-
- if ((tag = (tag0 & ContinuationTag)) == ContinuationTag) {
- int tagByte;
- tag = 0;
- while (((tagByte = data.get() & ByteMask) & MoreBit) != 0) {
- tag = (tag << MoreWidth) | (tagByte & MoreData);
- if ((tag & IntOverflow) != 0)
- throw new DecodeException("Tag overflow", data.position());
- }
- tag = (tag << MoreWidth) | tagByte;
- }
- return tag;
- }
-
- private static int decodeLength(ByteBuffer data) throws DecodeException {
- int length;
- int lenlen = data.get() & ByteMask;
-
- if ((lenlen & MoreBit) == 0) // One byte encoding
- length = lenlen;
- else {
- lenlen &= MoreData;
- if (lenlen == 0) {
- return IndefiniteLength;
- }
- length = 0;
- while (lenlen-- > 0) {
- length = (length << ByteWidth) | (data.get() & ByteMask);
- if ((length & IntOverflow) != 0 && lenlen > 0)
- throw new DecodeException("Length overflow", data.position());
- }
- }
- return length;
- }
-
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1ID.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1ID.java
deleted file mode 100644
index 452d85ca30fdf..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1ID.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.android.hotspot2.asn1;
-
-public class Asn1ID {
- private final int mTag;
- private final Asn1Class mClass;
-
- public Asn1ID(int tag, Asn1Class asn1Class) {
- mTag = tag;
- mClass = asn1Class;
- }
-
- public int getTag() {
- return mTag;
- }
-
- public Asn1Class getAsn1Class() {
- return mClass;
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Integer.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Integer.java
deleted file mode 100644
index 5180a4d5819a8..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Integer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-
-public class Asn1Integer extends Asn1Object {
- private static final int SignBit = 0x80;
-
- private final long mValue;
- private final BigInteger mBigValue;
-
- public Asn1Integer(int tag, Asn1Class asn1Class, int length, ByteBuffer data) {
- super(tag, asn1Class, false, length);
-
- if (length <= 8) {
- long value = (data.get(data.position()) & SignBit) != 0 ? -1 : 0;
- for (int n = 0; n < length; n++) {
- value = (value << Byte.SIZE) | data.get();
- }
- mValue = value;
- mBigValue = null;
- } else {
- byte[] payload = new byte[length];
- data.get(payload);
- mValue = 0;
- mBigValue = new BigInteger(payload);
- }
- }
-
- public boolean isBigValue() {
- return mBigValue != null;
- }
-
- public long getValue() {
- return mValue;
- }
-
- public BigInteger getBigValue() {
- return mBigValue;
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString() {
- if (isBigValue()) {
- return super.toString() + '=' + mBigValue.toString(16);
- } else {
- return super.toString() + '=' + mValue;
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Object.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Object.java
deleted file mode 100644
index 813758367cb90..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Object.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-
-public abstract class Asn1Object {
- private final int mTag;
- private final Asn1Class mClass;
- private final boolean mConstructed;
- private final int mLength;
- private final ByteBuffer mPayload;
-
- protected Asn1Object(int tag, Asn1Class asn1Class, boolean constructed, int length) {
- this(tag, asn1Class, constructed, length, null);
- }
-
- protected Asn1Object(int tag, Asn1Class asn1Class, boolean constructed,
- int length, ByteBuffer payload) {
- mTag = tag;
- mClass = asn1Class;
- mConstructed = constructed;
- mLength = length;
- mPayload = payload != null ? payload.duplicate() : null;
- }
-
- public int getTag() {
- return mTag;
- }
-
- public Asn1Class getAsn1Class() {
- return mClass;
- }
-
- public boolean isConstructed() {
- return mConstructed;
- }
-
- public boolean isIndefiniteLength() {
- return mLength == Asn1Decoder.IndefiniteLength;
- }
-
- public int getLength() {
- return mLength;
- }
-
- public ByteBuffer getPayload() {
- return mPayload != null ? mPayload.duplicate() : null;
- }
-
- protected ByteBuffer getPayload(int position) {
- if (mPayload == null) {
- return null;
- }
- ByteBuffer encoding = mPayload.duplicate();
- encoding.position(position);
- return encoding;
- }
-
- protected void setEndOfData(int position) {
- mPayload.limit(position);
- }
-
- protected int getEndOfData() {
- return mPayload.limit();
- }
-
- public boolean matches(Asn1ID id) {
- return mTag == id.getTag() && mClass == id.getAsn1Class();
- }
-
- public String toSimpleString() {
- Asn1Tag tag = mClass == Asn1Class.Universal ? Asn1Decoder.mapTag(mTag) : null;
- if (tag != null) {
- return tag.name();
- } else if (mClass == Asn1Class.Universal) {
- return String.format("[%d]", mTag);
- } else {
- return String.format("[%s %d]", mClass, mTag);
- }
- }
-
- public abstract Collection getChildren();
-
- @Override
- public String toString() {
- return toSimpleString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Octets.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Octets.java
deleted file mode 100644
index 1e1995315a8f7..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Octets.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-
-public class Asn1Octets extends Asn1Object {
- private final byte[] mOctets;
- private final int mBitResidual;
-
- public Asn1Octets(int tag, Asn1Class asn1Class, int length, ByteBuffer data) {
- super(tag, asn1Class, false, length);
- mOctets = new byte[length];
- data.get(mOctets);
- mBitResidual = -1;
- }
-
- public Asn1Octets(int tag, Asn1Class asn1Class, int length, ByteBuffer data, int bitResidual) {
- super(tag, asn1Class, false, length);
- mOctets = new byte[length - 1];
- data.get(mOctets);
- mBitResidual = bitResidual;
- }
-
- public byte[] getOctets() {
- return mOctets;
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- for (byte b : mOctets) {
- sb.append(String.format(" %02x", b & Asn1Decoder.ByteMask));
- }
- if (mBitResidual >= 0) {
- return super.toString() + '=' + sb + '/' + mBitResidual;
- } else if (getTag() == Asn1Decoder.TAG_NULL && getLength() == 0) {
- return super.toString();
- } else {
- return super.toString() + '=' + sb;
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Oid.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Oid.java
deleted file mode 100644
index 50f0553689796..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Oid.java
+++ /dev/null
@@ -1,212 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Asn1Oid extends Asn1Object {
- public static final int OidMaxOctet1 = 2;
- public static final int OidOctet1Modulus = 40;
-
- private final List mArcs;
- private final int mHashcode;
-
- private static final Map sOidMap = new HashMap<>();
-
- public Asn1Oid(int tag, Asn1Class asn1Class, int length, ByteBuffer data)
- throws DecodeException {
- super(tag, asn1Class, false, length);
-
- if (length == 0)
- throw new DecodeException("oid-encoding length is zero", data.position());
-
- mArcs = new ArrayList<>();
-
- ByteBuffer payload = data.duplicate();
- payload.limit(payload.position() + length);
- data.position(data.position() + length);
-
- byte current = payload.get();
- long seg01 = current & Asn1Decoder.ByteMask;
- long segValue = seg01 / OidOctet1Modulus;
- int hashcode = (int) segValue;
- mArcs.add(segValue);
- segValue = seg01 - segValue * OidOctet1Modulus;
- hashcode = hashcode * 31 + (int) segValue;
- mArcs.add(segValue);
-
- current = 0;
- segValue = 0L;
-
- while (payload.hasRemaining()) {
- current = payload.get();
- segValue |= current & Asn1Decoder.MoreData;
- if ((current & Asn1Decoder.MoreBit) == 0) {
- hashcode = hashcode * 31 + (int) segValue;
- mArcs.add(segValue);
- segValue = 0L;
- } else
- segValue <<= Asn1Decoder.MoreWidth;
- }
- if ((current & Asn1Decoder.MoreBit) != 0)
- throw new DecodeException("Illegal (end of) oid-encoding", payload.position());
- mHashcode = hashcode;
- }
-
- public Asn1Oid(Long... arcs) {
- super(Asn1Decoder.TAG_OID, Asn1Class.Universal, false, -1);
- mArcs = Arrays.asList(arcs);
- int hashcode = 0;
- for (long arc : arcs) {
- hashcode = hashcode * 31 + (int) arc;
- }
- mHashcode = hashcode;
- }
-
- @Override
- public int hashCode() {
- return mHashcode;
- }
-
- @Override
- public boolean equals(Object thatObject) {
- return !(thatObject == null || thatObject.getClass() != Asn1Oid.class) &&
- mArcs.equals(((Asn1Oid) thatObject).mArcs);
- }
-
- public String toOIDString() {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (long arc : mArcs) {
- if (first) {
- first = false;
- } else {
- sb.append('.');
- }
- sb.append(arc);
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(toOIDString());
- String name = sOidMap.get(this);
- if (name != null) {
- sb.append(" (").append(name).append(')');
- }
- return super.toString() + '=' + sb.toString();
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- public static final Asn1Oid PKCS7Data = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 7L, 1L);
- public static final Asn1Oid PKCS7SignedData = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 7L, 2L);
- // encoded as an IA5STRING type
- public static final Asn1Oid OidMacAddress = new Asn1Oid(1L, 3L, 6L, 1L, 1L, 1L, 1L, 22L);
- // encoded as an IA5STRING type
- public static final Asn1Oid OidImei = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 3L);
- // encoded as a BITSTRING type
- public static final Asn1Oid OidMeid = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 4L);
- // encoded as a PRINTABLESTRING type
- public static final Asn1Oid OidDevId = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 5L);
-
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 1L), "algo_id_dsa");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 3L), "algo_id_dsawithsha1");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10045L, 2L, 1L), "algo_id_ecPublicKey");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 3L), "eccdaWithSHA384");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 1L), "algo_id_rsaEncryption");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 2L), "algo_id_md2WithRSAEncryption");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 4L), "algo_id_md5WithRSAEncryption");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 5L), "algo_id_sha1WithRSAEncryption");
- //sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 11L),
- // "algo_id_sha256WithRSAEncryption");
-
- static {
- sOidMap.put(new Asn1Oid(0L, 0L), "NullOid");
- sOidMap.put(new Asn1Oid(0L, 9L, 2342L, 19200300L, 100L, 1L, 25L), "domComp");
-
- sOidMap.put(OidMacAddress, "mac-address");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 1L), "algo_id_dsa");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 3L), "algo_id_dsawithsha1");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10045L, 2L, 1L), "algo_id_ecPublicKey");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 3L), "eccdaWithSHA384");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 10046L, 2L, 1L), "algo_id_dhpublicnumber");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 1L), "algo_id_rsaEncryption");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 2L), "algo_id_md2WithRSAEncryption");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 4L), "algo_id_md5WithRSAEncryption");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 5L),
- "algo_id_sha1WithRSAEncryption");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 11L),
- "algo_id_sha256WithRSAEncryption");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 7L), "pkcs7");
- sOidMap.put(PKCS7Data, "pkcs7-data");
- sOidMap.put(PKCS7SignedData, "pkcs7-signedData");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 9L, 1L), "emailAddress");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 9L, 7L), "challengePassword");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 9L, 14L), "extensionRequest");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 3L, 2L), "algo_id_RC2_CBC");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 3L, 4L), "algo_id_RC4_ENC");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 3L, 7L), "algo_id_DES_EDE3_CBC");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 3L, 9L), "algo_id_RC5_CBC_PAD");
- sOidMap.put(new Asn1Oid(1L, 2L, 840L, 113549L, 3L, 10L), "algo_id_desCDMF");
- sOidMap.put(new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 2L), "id-kp-HS2.0Auth");
- sOidMap.put(OidImei, "imei");
- sOidMap.put(OidMeid, "meid");
- sOidMap.put(OidDevId, "DevId");
- sOidMap.put(new Asn1Oid(1L, 3L, 6L, 1L, 5L, 5L, 7L, 1L, 1L),
- "certAuthorityInfoAccessSyntax");
- sOidMap.put(new Asn1Oid(1L, 3L, 6L, 1L, 5L, 5L, 7L, 1L, 11L),
- "certSubjectInfoAccessSyntax");
- sOidMap.put(new Asn1Oid(1L, 3L, 14L, 3L, 2L, 26L), "algo_id_SHA1");
- sOidMap.put(new Asn1Oid(1L, 3L, 132L, 0L, 34L), "secp384r1");
-
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 3L), "x500_CN");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 4L), "x500_SN");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 5L), "x500_serialNum");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 6L), "x500_C");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 7L), "x500_L");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 8L), "x500_ST");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 9L), "x500_STREET");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 10L), "x500_O");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 11L), "x500_OU");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 12L), "x500_title");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 13L), "x500_description");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 17L), "x500_postalCode");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 18L), "x500_poBox");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 20L), "x500_phone");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 41L), "x500_name");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 42L), "x500_givenName");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 44L), "x500_genQual");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 43L), "x500_initials");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 46L), "x500_dnQualifier");
- sOidMap.put(new Asn1Oid(2L, 5L, 4L, 65L), "x500_pseudonym");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 9L), "certSubjectDirectoryAttributes");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 14L), "certSubjectKeyIdentifier ");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 15L), "certKeyUsage");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 16L), "certPrivateKeyUsagePeriod");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 17L), "certSubjectAltName");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 18L), "certIssuerAltName");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 19L), "certBasicConstraints");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 30L), "certNameConstraints");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 31L), "certCRLDistributionPoints");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 32L), "certificatePolicies");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 33L), "certPolicyMappings");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 35L), "certAuthorityKeyIdentifier ");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 36L), "certPolicyConstraints");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 37L), "certExtKeyUsageSyntax");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 46L), "certFreshestCRL");
- sOidMap.put(new Asn1Oid(2L, 5L, 29L, 54L), "certInhibitAnyPolicy");
- sOidMap.put(new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 1L, 2L), "algo_id_aes128");
- sOidMap.put(new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 1L, 22L), "algo_id_aes192");
- sOidMap.put(new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 1L, 42L), "algo_id_aes256");
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1String.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1String.java
deleted file mode 100644
index 37ed2b28c780e..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1String.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-
-public class Asn1String extends Asn1Object {
- private final String mString;
-
- public Asn1String(int tag, Asn1Class asn1Class, int length, ByteBuffer data) {
- super(tag, asn1Class, false, length);
-
- byte[] octets = new byte[length];
- data.get(octets);
- Charset charset = tag == Asn1Decoder.TAG_UTF8String
- ? StandardCharsets.UTF_8 : StandardCharsets.ISO_8859_1;
- mString = new String(octets, charset);
- }
-
- public String getString() {
- return mString;
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String toString() {
- return super.toString() + "='" + mString + '\'';
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Tag.java b/packages/Osu/src/com/android/hotspot2/asn1/Asn1Tag.java
deleted file mode 100644
index 812948195c092..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/Asn1Tag.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.android.hotspot2.asn1;
-
-public enum Asn1Tag {
- UNIVZERO,
- BOOLEAN,
- INTEGER,
- BITSTRING,
- OCTET_STRING,
- NULL,
- OID,
- ObjectDescriptor,
- EXTERNAL,
- REAL,
- ENUMERATED,
- UTF8String,
- RelativeOID,
- SEQUENCE,
- SET,
- NumericString,
- PrintableString,
- T61String,
- VideotexString,
- IA5String,
- UTCTime,
- GeneralizedTime,
- GraphicString,
- VisibleString,
- GeneralString,
- UniversalString,
- BMPString
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/DecodeException.java b/packages/Osu/src/com/android/hotspot2/asn1/DecodeException.java
deleted file mode 100644
index 1f10ee4f6334b..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/DecodeException.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.io.IOException;
-
-public class DecodeException extends IOException {
- private final int mOffset;
-
- public DecodeException(String message, int offset) {
- super(message);
- mOffset = offset;
- }
-
- @Override
- public String toString() {
- return super.toString() + " at " + mOffset;
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/asn1/OidMappings.java b/packages/Osu/src/com/android/hotspot2/asn1/OidMappings.java
deleted file mode 100644
index 01a6fd696e567..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/asn1/OidMappings.java
+++ /dev/null
@@ -1,197 +0,0 @@
-package com.android.hotspot2.asn1;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-public class OidMappings {
- public static class SigEntry {
- private final String mSigAlgo;
- private final Asn1Oid mKeyAlgo;
-
- private SigEntry(String sigAlgo, Asn1Oid keyAlgo) {
- mSigAlgo = sigAlgo;
- mKeyAlgo = keyAlgo;
- }
-
- public String getSigAlgo() {
- return mSigAlgo;
- }
-
- public Asn1Oid getKeyAlgo() {
- return mKeyAlgo;
- }
- }
-
- public static final String IdPeLogotype = "1.3.6.1.5.5.7.1.12";
- public static final String IdCeSubjectAltName = "2.5.29.17";
-
- private static final Map sCryptoMapping = new HashMap<>();
- private static final Map sNameMapping = new HashMap<>();
- private static final Set sIDMapping = new HashSet<>();
- private static final Map sSigAlgos = new HashMap<>();
-
- // DSA
- private static final Asn1Oid sAlgo_DSA = new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 1L);
- private static final Asn1Oid sAlgo_SHA1withDSA = new Asn1Oid(1L, 2L, 840L, 10040L, 4L, 3L);
-
- // RSA
- public static final Asn1Oid sAlgo_RSA = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 1L);
- private static final Asn1Oid sAlgo_MD2withRSA = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 2L);
- private static final Asn1Oid sAlgo_MD5withRSA = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 4L);
- private static final Asn1Oid sAlgo_SHA1withRSA = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 5L);
- private static final Asn1Oid sAlgo_SHA224withRSA =
- new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 14L); // n/a
- private static final Asn1Oid sAlgo_SHA256withRSA =
- new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 11L);
- private static final Asn1Oid sAlgo_SHA384withRSA =
- new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 12L);
- private static final Asn1Oid sAlgo_SHA512withRSA =
- new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 1L, 13L);
-
- // ECC
- public static final Asn1Oid sAlgo_EC = new Asn1Oid(1L, 2L, 840L, 10045L, 2L, 1L);
- private static final Asn1Oid sAlgo_SHA1withECDSA = new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 1L);
- private static final Asn1Oid sAlgo_SHA224withECDSA =
- new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 1L); // n/a
- private static final Asn1Oid sAlgo_SHA256withECDSA =
- new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 2L);
- private static final Asn1Oid sAlgo_SHA384withECDSA =
- new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 3L);
- private static final Asn1Oid sAlgo_SHA512withECDSA =
- new Asn1Oid(1L, 2L, 840L, 10045L, 4L, 3L, 4L);
-
- private static final Asn1Oid sAlgo_MD2 = new Asn1Oid(1L, 2L, 840L, 113549L, 2L, 2L);
- private static final Asn1Oid sAlgo_MD5 = new Asn1Oid(1L, 2L, 840L, 113549L, 2L, 5L);
- private static final Asn1Oid sAlgo_SHA1 = new Asn1Oid(1L, 3L, 14L, 3L, 2L, 26L);
- private static final Asn1Oid sAlgo_SHA256 =
- new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 2L, 1L);
- private static final Asn1Oid sAlgo_SHA384 =
- new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 2L, 2L);
- private static final Asn1Oid sAlgo_SHA512 =
- new Asn1Oid(2L, 16L, 840L, 1L, 101L, 3L, 4L, 2L, 3L);
-
- // HS2.0 stuff:
- public static final Asn1Oid sPkcs9AtChallengePassword =
- new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 9L, 7L);
- public static final Asn1Oid sExtensionRequest = new Asn1Oid(1L, 2L, 840L, 113549L, 1L, 9L, 14L);
-
- public static final Asn1Oid sMAC = new Asn1Oid(1L, 3L, 6L, 1L, 1L, 1L, 1L, 22L);
- public static final Asn1Oid sIMEI = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 3L);
- public static final Asn1Oid sMEID = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 4L);
- public static final Asn1Oid sDevID = new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 5L);
-
- public static final Asn1Oid sIdWfaHotspotFriendlyName =
- new Asn1Oid(1L, 3L, 6L, 1L, 4L, 1L, 40808L, 1L, 1L, 1L);
-
- static {
- sCryptoMapping.put(sAlgo_DSA, "DSA");
- sCryptoMapping.put(sAlgo_RSA, "RSA");
- sCryptoMapping.put(sAlgo_EC, "EC");
-
- sSigAlgos.put(sAlgo_SHA1withDSA, new SigEntry("SHA1withDSA", sAlgo_DSA));
-
- sSigAlgos.put(sAlgo_MD2withRSA, new SigEntry("MD2withRSA", sAlgo_RSA));
- sSigAlgos.put(sAlgo_MD5withRSA, new SigEntry("MD5withRSA", sAlgo_RSA));
- sSigAlgos.put(sAlgo_SHA1withRSA, new SigEntry("SHA1withRSA", sAlgo_RSA));
- sSigAlgos.put(sAlgo_SHA224withRSA, new SigEntry(null, sAlgo_RSA));
- sSigAlgos.put(sAlgo_SHA256withRSA, new SigEntry("SHA256withRSA", sAlgo_RSA));
- sSigAlgos.put(sAlgo_SHA384withRSA, new SigEntry("SHA384withRSA", sAlgo_RSA));
- sSigAlgos.put(sAlgo_SHA512withRSA, new SigEntry("SHA512withRSA", sAlgo_RSA));
-
- sSigAlgos.put(sAlgo_SHA1withECDSA, new SigEntry("SHA1withECDSA", sAlgo_EC));
- sSigAlgos.put(sAlgo_SHA224withECDSA, new SigEntry(null, sAlgo_EC));
- sSigAlgos.put(sAlgo_SHA256withECDSA, new SigEntry("SHA256withECDSA", sAlgo_EC));
- sSigAlgos.put(sAlgo_SHA384withECDSA, new SigEntry("SHA384withECDSA", sAlgo_EC));
- sSigAlgos.put(sAlgo_SHA512withECDSA, new SigEntry("SHA512withECDSA", sAlgo_EC));
-
- sIDMapping.add(sMAC);
- sIDMapping.add(sIMEI);
- sIDMapping.add(sMEID);
- sIDMapping.add(sDevID);
-
- for (Map.Entry entry : sCryptoMapping.entrySet()) {
- sNameMapping.put(entry.getKey(), entry.getValue());
- }
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 1L), "sect163k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 2L), "sect163r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 3L), "sect239k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 4L), "sect113r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 5L), "sect113r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 6L), "secp112r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 7L), "secp112r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 8L), "secp160r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 9L), "secp160k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 10L), "secp256k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 15L), "sect163r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 16L), "sect283k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 17L), "sect283r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 22L), "sect131r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 23L), "sect131r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 24L), "sect193r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 25L), "sect193r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 26L), "sect233k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 27L), "sect233r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 28L), "secp128r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 29L), "secp128r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 30L), "secp160r2");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 31L), "secp192k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 32L), "secp224k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 33L), "secp224r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 34L), "secp384r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 35L), "secp521r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 36L), "sect409k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 37L), "sect409r1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 38L), "sect571k1");
- sNameMapping.put(new Asn1Oid(1L, 3L, 132L, 0L, 39L), "sect571r1");
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 1L), "secp192r1");
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 7L), "secp256r1");
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 2L), "prime192v2"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 3L), "prime192v3"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 4L), "prime239v1"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 5L), "prime239v2"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 1L, 6L), "prime239v3"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 5L), "c2tnb191v1"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 6L), "c2tnb191v2"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 7L), "c2tnb191v3"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 11L), "c2tnb239v1"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 12L), "c2tnb239v2"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 13L), "c2tnb239v3"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 18L), "c2tnb359v1"); // X9.62
- sNameMapping.put(new Asn1Oid(1L, 2L, 840L, 10045L, 3L, 0L, 20L), "c2tnb431r1"); // X9.62
-
- sNameMapping.put(sAlgo_MD2, "MD2");
- sNameMapping.put(sAlgo_MD5, "MD5");
- sNameMapping.put(sAlgo_SHA1, "SHA-1");
- sNameMapping.put(sAlgo_SHA256, "SHA-256");
- sNameMapping.put(sAlgo_SHA384, "SHA-384");
- sNameMapping.put(sAlgo_SHA512, "SHA-512");
- }
-
- public static SigEntry getSigEntry(Asn1Oid oid) {
- return sSigAlgos.get(oid);
- }
-
- public static String getCryptoID(Asn1Oid oid) {
- return sCryptoMapping.get(oid);
- }
-
- public static String getJCEName(Asn1Oid oid) {
- return sNameMapping.get(oid);
- }
-
- public static String getSigAlgoName(Asn1Oid oid) {
- SigEntry sigEntry = sSigAlgos.get(oid);
- return sigEntry != null ? sigEntry.getSigAlgo() : null;
- }
-
- public static String getKeyAlgoName(Asn1Oid oid) {
- SigEntry sigEntry = sSigAlgos.get(oid);
- return sigEntry != null ? sNameMapping.get(sigEntry.getKeyAlgo()) : null;
- }
-
- public static boolean isIDAttribute(Asn1Oid oid) {
- return sIDMapping.contains(oid);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/est/ESTHandler.java b/packages/Osu/src/com/android/hotspot2/est/ESTHandler.java
deleted file mode 100644
index cdcff80174975..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/est/ESTHandler.java
+++ /dev/null
@@ -1,501 +0,0 @@
-package com.android.hotspot2.est;
-
-import android.net.Network;
-import android.util.Base64;
-import android.util.Log;
-
-import com.android.hotspot2.OMADMAdapter;
-import com.android.hotspot2.asn1.Asn1Class;
-import com.android.hotspot2.asn1.Asn1Constructed;
-import com.android.hotspot2.asn1.Asn1Decoder;
-import com.android.hotspot2.asn1.Asn1ID;
-import com.android.hotspot2.asn1.Asn1Integer;
-import com.android.hotspot2.asn1.Asn1Object;
-import com.android.hotspot2.asn1.Asn1Oid;
-import com.android.hotspot2.asn1.OidMappings;
-import com.android.hotspot2.osu.HTTPHandler;
-import com.android.hotspot2.osu.OSUFlowManager;
-import com.android.hotspot2.osu.OSUSocketFactory;
-import com.android.hotspot2.osu.commands.GetCertData;
-import com.android.hotspot2.pps.HomeSP;
-import com.android.hotspot2.utils.HTTPMessage;
-import com.android.hotspot2.utils.HTTPResponse;
-import com.android.org.bouncycastle.asn1.ASN1Encodable;
-import com.android.org.bouncycastle.asn1.ASN1EncodableVector;
-import com.android.org.bouncycastle.asn1.ASN1Set;
-import com.android.org.bouncycastle.asn1.DERBitString;
-import com.android.org.bouncycastle.asn1.DEREncodableVector;
-import com.android.org.bouncycastle.asn1.DERIA5String;
-import com.android.org.bouncycastle.asn1.DERObjectIdentifier;
-import com.android.org.bouncycastle.asn1.DERPrintableString;
-import com.android.org.bouncycastle.asn1.DERSet;
-import com.android.org.bouncycastle.asn1.x509.Attribute;
-import com.android.org.bouncycastle.jce.PKCS10CertificationRequest;
-import com.android.org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.security.AlgorithmParameters;
-import java.security.GeneralSecurityException;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.KeyStore;
-import java.security.PrivateKey;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.net.ssl.KeyManager;
-import javax.security.auth.x500.X500Principal;
-
-//import com.android.org.bouncycastle.jce.provider.BouncyCastleProvider;
-
-public class ESTHandler implements AutoCloseable {
- private static final String TAG = "HS2EST";
- private static final int MinRSAKeySize = 2048;
-
- private static final String CACERT_PATH = "/cacerts";
- private static final String CSR_PATH = "/csrattrs";
- private static final String SIMPLE_ENROLL_PATH = "/simpleenroll";
- private static final String SIMPLE_REENROLL_PATH = "/simplereenroll";
-
- private final URL mURL;
- private final String mUser;
- private final byte[] mPassword;
- private final OSUSocketFactory mSocketFactory;
- private final OMADMAdapter mOMADMAdapter;
-
- private final List mCACerts = new ArrayList<>();
- private final List mClientCerts = new ArrayList<>();
- private PrivateKey mClientKey;
-
- public ESTHandler(GetCertData certData, Network network, OMADMAdapter omadmAdapter,
- KeyManager km, KeyStore ks, HomeSP homeSP, OSUFlowManager.FlowType flowType)
- throws IOException, GeneralSecurityException {
- mURL = new URL(certData.getServer());
- mUser = certData.getUserName();
- mPassword = certData.getPassword();
- mSocketFactory = OSUSocketFactory.getSocketFactory(ks, homeSP, flowType,
- network, mURL, km, true);
- mOMADMAdapter = omadmAdapter;
- }
-
- @Override
- public void close() throws IOException {
- }
-
- public List getCACerts() {
- return mCACerts;
- }
-
- public List getClientCerts() {
- return mClientCerts;
- }
-
- public PrivateKey getClientKey() {
- return mClientKey;
- }
-
- private static String indent(int amount) {
- char[] indent = new char[amount * 2];
- Arrays.fill(indent, ' ');
- return new String(indent);
- }
-
- public void execute(boolean reenroll) throws IOException, GeneralSecurityException {
- URL caURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(),
- mURL.getFile() + CACERT_PATH);
-
- HTTPResponse response;
- try (HTTPHandler httpHandler = new HTTPHandler(StandardCharsets.ISO_8859_1, mSocketFactory,
- mUser, mPassword)) {
- response = httpHandler.doGetHTTP(caURL);
-
- if (!"application/pkcs7-mime".equals(response.getHeaders().
- get(HTTPMessage.ContentTypeHeader))) {
- throw new IOException("Unexpected Content-Type: " +
- response.getHeaders().get(HTTPMessage.ContentTypeHeader));
- }
- ByteBuffer octetBuffer = response.getBinaryPayload();
- Collection pkcs7Content1 = Asn1Decoder.decode(octetBuffer);
- for (Asn1Object asn1Object : pkcs7Content1) {
- Log.d(TAG, "---");
- Log.d(TAG, asn1Object.toString());
- }
- Log.d(TAG, CACERT_PATH);
-
- mCACerts.addAll(unpackPkcs7(octetBuffer));
- for (X509Certificate certificate : mCACerts) {
- Log.d(TAG, "CA-Cert: " + certificate.getSubjectX500Principal());
- }
-
- /*
- byte[] octets = new byte[octetBuffer.remaining()];
- octetBuffer.duplicate().get(octets);
- for (byte b : octets) {
- System.out.printf("%02x ", b & 0xff);
- }
- Log.d(TAG, );
- */
-
- /* + BC
- try {
- byte[] octets = new byte[octetBuffer.remaining()];
- octetBuffer.duplicate().get(octets);
- ASN1InputStream asnin = new ASN1InputStream(octets);
- for (int n = 0; n < 100; n++) {
- ASN1Primitive object = asnin.readObject();
- if (object == null) {
- break;
- }
- parseObject(object, 0);
- }
- }
- catch (Throwable t) {
- t.printStackTrace();
- }
-
- Collection pkcs7Content = Asn1Decoder.decode(octetBuffer);
- for (Asn1Object asn1Object : pkcs7Content) {
- Log.d(TAG, asn1Object);
- }
-
- if (pkcs7Content.size() != 1) {
- throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
- }
-
- Asn1Constructed pkcs7Root = (Asn1Constructed) pkcs7Content.iterator().next();
- Iterator certPath = Arrays.asList(Pkcs7CertPath).iterator();
- Asn1Object certObject = pkcs7Root.findObject(certPath);
- if (certObject == null || certPath.hasNext()) {
- throw new IOException("Failed to find cert; returned object " + certObject +
- ", path " + (certPath.hasNext() ? "short" : "exhausted"));
- }
-
- ByteBuffer certOctets = certObject.getPayload();
- if (certOctets == null) {
- throw new IOException("No cert payload in: " + certObject);
- }
-
- byte[] certBytes = new byte[certOctets.remaining()];
- certOctets.get(certBytes);
-
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(certBytes));
- Log.d(TAG, "EST Cert: " + cert);
- */
-
- URL csrURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(),
- mURL.getFile() + CSR_PATH);
- response = httpHandler.doGetHTTP(csrURL);
-
- octetBuffer = response.getBinaryPayload();
- byte[] csrData = buildCSR(octetBuffer, mOMADMAdapter, httpHandler);
-
- /**/
- Collection o = Asn1Decoder.decode(ByteBuffer.wrap(csrData));
- Log.d(TAG, "CSR:");
- Log.d(TAG, o.iterator().next().toString());
- Log.d(TAG, "End CSR.");
- /**/
-
- URL enrollURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(),
- mURL.getFile() + (reenroll ? SIMPLE_REENROLL_PATH : SIMPLE_ENROLL_PATH));
- String data = Base64.encodeToString(csrData, Base64.DEFAULT);
- octetBuffer = httpHandler.exchangeBinary(enrollURL, data, "application/pkcs10");
-
- Collection pkcs7Content2 = Asn1Decoder.decode(octetBuffer);
- for (Asn1Object asn1Object : pkcs7Content2) {
- Log.d(TAG, "---");
- Log.d(TAG, asn1Object.toString());
- }
- mClientCerts.addAll(unpackPkcs7(octetBuffer));
- for (X509Certificate cert : mClientCerts) {
- Log.d(TAG, cert.toString());
- }
- }
- }
-
- private static final Asn1ID sSEQUENCE = new Asn1ID(Asn1Decoder.TAG_SEQ, Asn1Class.Universal);
- private static final Asn1ID sCTXT0 = new Asn1ID(0, Asn1Class.Context);
- private static final int PKCS7DataVersion = 1;
- private static final int PKCS7SignedDataVersion = 3;
-
- private static List unpackPkcs7(ByteBuffer pkcs7)
- throws IOException, GeneralSecurityException {
- Collection pkcs7Content = Asn1Decoder.decode(pkcs7);
-
- if (pkcs7Content.size() != 1) {
- throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
- }
-
- Asn1Object data = pkcs7Content.iterator().next();
- if (!data.isConstructed() || !data.matches(sSEQUENCE)) {
- throw new IOException("Expected SEQ OF, got " + data.toSimpleString());
- } else if (data.getChildren().size() != 2) {
- throw new IOException("Expected content info to have two children, got " +
- data.getChildren().size());
- }
-
- Iterator children = data.getChildren().iterator();
- Asn1Object contentType = children.next();
- if (!contentType.equals(Asn1Oid.PKCS7SignedData)) {
- throw new IOException("Content not PKCS7 signed data");
- }
- Asn1Object content = children.next();
- if (!content.isConstructed() || !content.matches(sCTXT0)) {
- throw new IOException("Expected [CONTEXT 0] with one child, got " +
- content.toSimpleString() + ", " + content.getChildren().size());
- }
-
- Asn1Object signedData = content.getChildren().iterator().next();
- Map itemMap = new HashMap<>();
- for (Asn1Object item : signedData.getChildren()) {
- if (itemMap.put(item.getTag(), item) != null && item.getTag() != Asn1Decoder.TAG_SET) {
- throw new IOException("Duplicate item in SignedData: " + item.toSimpleString());
- }
- }
-
- Asn1Object versionObject = itemMap.get(Asn1Decoder.TAG_INTEGER);
- if (versionObject == null || !(versionObject instanceof Asn1Integer)) {
- throw new IOException("Bad or missing PKCS7 version: " + versionObject);
- }
- int pkcs7version = (int) ((Asn1Integer) versionObject).getValue();
- Asn1Object innerContentInfo = itemMap.get(Asn1Decoder.TAG_SEQ);
- if (innerContentInfo == null ||
- !innerContentInfo.isConstructed() ||
- !innerContentInfo.matches(sSEQUENCE) ||
- innerContentInfo.getChildren().size() != 1) {
- throw new IOException("Bad or missing PKCS7 contentInfo");
- }
- Asn1Object contentID = innerContentInfo.getChildren().iterator().next();
- if (pkcs7version == PKCS7DataVersion && !contentID.equals(Asn1Oid.PKCS7Data) ||
- pkcs7version == PKCS7SignedDataVersion && !contentID.equals(Asn1Oid.PKCS7SignedData)) {
- throw new IOException("Inner PKCS7 content (" + contentID +
- ") not expected for version " + pkcs7version);
- }
- Asn1Object certWrapper = itemMap.get(0);
- if (certWrapper == null || !certWrapper.isConstructed() || !certWrapper.matches(sCTXT0)) {
- throw new IOException("Expected [CONTEXT 0], got: " + certWrapper);
- }
-
- List certList = new ArrayList<>(certWrapper.getChildren().size());
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- for (Asn1Object certObject : certWrapper.getChildren()) {
- ByteBuffer certOctets = ((Asn1Constructed) certObject).getEncoding();
- if (certOctets == null) {
- throw new IOException("No cert payload in: " + certObject);
- }
- byte[] certBytes = new byte[certOctets.remaining()];
- certOctets.get(certBytes);
-
- certList.add((X509Certificate) certFactory.
- generateCertificate(new ByteArrayInputStream(certBytes)));
- }
- return certList;
- }
-
- private byte[] buildCSR(ByteBuffer octetBuffer, OMADMAdapter omadmAdapter,
- HTTPHandler httpHandler) throws IOException, GeneralSecurityException {
-
- //Security.addProvider(new BouncyCastleProvider());
-
- Log.d(TAG, "/csrattrs:");
- /*
- byte[] octets = new byte[octetBuffer.remaining()];
- octetBuffer.duplicate().get(octets);
- for (byte b : octets) {
- System.out.printf("%02x ", b & 0xff);
- }
- */
- Collection csrs = Asn1Decoder.decode(octetBuffer);
- for (Asn1Object asn1Object : csrs) {
- Log.d(TAG, asn1Object.toString());
- }
-
- if (csrs.size() != 1) {
- throw new IOException("Unexpected object count in CSR attributes response: " +
- csrs.size());
- }
- Asn1Object sequence = csrs.iterator().next();
- if (sequence.getClass() != Asn1Constructed.class) {
- throw new IOException("Unexpected CSR attribute container: " + sequence);
- }
-
- String keyAlgo = null;
- Asn1Oid keyAlgoOID = null;
- String sigAlgo = null;
- String curveName = null;
- Asn1Oid pubCrypto = null;
- int keySize = -1;
- Map idAttributes = new HashMap<>();
-
- for (Asn1Object child : sequence.getChildren()) {
- if (child.getTag() == Asn1Decoder.TAG_OID) {
- Asn1Oid oid = (Asn1Oid) child;
- OidMappings.SigEntry sigEntry = OidMappings.getSigEntry(oid);
- if (sigEntry != null) {
- sigAlgo = sigEntry.getSigAlgo();
- keyAlgoOID = sigEntry.getKeyAlgo();
- keyAlgo = OidMappings.getJCEName(keyAlgoOID);
- } else if (oid.equals(OidMappings.sPkcs9AtChallengePassword)) {
- byte[] tlsUnique = httpHandler.getTLSUnique();
- if (tlsUnique != null) {
- idAttributes.put(oid, new DERPrintableString(
- Base64.encodeToString(tlsUnique, Base64.DEFAULT)));
- } else {
- Log.w(TAG, "Cannot retrieve TLS unique channel binding");
- }
- }
- } else if (child.getTag() == Asn1Decoder.TAG_SEQ) {
- Asn1Oid oid = null;
- Set oidValues = new HashSet<>();
- List values = new ArrayList<>();
-
- for (Asn1Object attributeSeq : child.getChildren()) {
- if (attributeSeq.getTag() == Asn1Decoder.TAG_OID) {
- oid = (Asn1Oid) attributeSeq;
- } else if (attributeSeq.getTag() == Asn1Decoder.TAG_SET) {
- for (Asn1Object value : attributeSeq.getChildren()) {
- if (value.getTag() == Asn1Decoder.TAG_OID) {
- oidValues.add((Asn1Oid) value);
- } else {
- values.add(value);
- }
- }
- }
- }
- if (oid == null) {
- throw new IOException("Invalid attribute, no OID");
- }
- if (oid.equals(OidMappings.sExtensionRequest)) {
- for (Asn1Oid subOid : oidValues) {
- if (OidMappings.isIDAttribute(subOid)) {
- if (subOid.equals(OidMappings.sMAC)) {
- idAttributes.put(subOid, new DERIA5String(omadmAdapter.getMAC()));
- } else if (subOid.equals(OidMappings.sIMEI)) {
- idAttributes.put(subOid, new DERIA5String(omadmAdapter.getImei()));
- } else if (subOid.equals(OidMappings.sMEID)) {
- idAttributes.put(subOid, new DERBitString(omadmAdapter.getMeid()));
- } else if (subOid.equals(OidMappings.sDevID)) {
- idAttributes.put(subOid,
- new DERPrintableString(omadmAdapter.getDevID()));
- }
- }
- }
- } else if (OidMappings.getCryptoID(oid) != null) {
- pubCrypto = oid;
- if (!values.isEmpty()) {
- for (Asn1Object value : values) {
- if (value.getTag() == Asn1Decoder.TAG_INTEGER) {
- keySize = (int) ((Asn1Integer) value).getValue();
- }
- }
- }
- if (oid.equals(OidMappings.sAlgo_EC)) {
- if (oidValues.isEmpty()) {
- throw new IOException("No ECC curve name provided");
- }
- for (Asn1Oid value : oidValues) {
- curveName = OidMappings.getJCEName(value);
- if (curveName != null) {
- break;
- }
- }
- if (curveName == null) {
- throw new IOException("Found no ECC curve for " + oidValues);
- }
- }
- }
- }
- }
-
- if (keyAlgoOID == null) {
- throw new IOException("No public key algorithm specified");
- }
- if (pubCrypto != null && !pubCrypto.equals(keyAlgoOID)) {
- throw new IOException("Mismatching key algorithms");
- }
-
- if (keyAlgoOID.equals(OidMappings.sAlgo_RSA)) {
- if (keySize < MinRSAKeySize) {
- if (keySize >= 0) {
- Log.i(TAG, "Upgrading suggested RSA key size from " +
- keySize + " to " + MinRSAKeySize);
- }
- keySize = MinRSAKeySize;
- }
- }
-
- Log.d(TAG, String.format("pub key '%s', signature '%s', ECC curve '%s', id-atts %s",
- keyAlgo, sigAlgo, curveName, idAttributes));
-
- /*
- Ruckus:
- SEQUENCE:
- OID=1.2.840.113549.1.1.11 (algo_id_sha256WithRSAEncryption)
-
- RFC-7030:
- SEQUENCE:
- OID=1.2.840.113549.1.9.7 (challengePassword)
- SEQUENCE:
- OID=1.2.840.10045.2.1 (algo_id_ecPublicKey)
- SET:
- OID=1.3.132.0.34 (secp384r1)
- SEQUENCE:
- OID=1.2.840.113549.1.9.14 (extensionRequest)
- SET:
- OID=1.3.6.1.1.1.1.22 (mac-address)
- OID=1.2.840.10045.4.3.3 (eccdaWithSHA384)
-
- 1L, 3L, 6L, 1L, 1L, 1L, 1L, 22
- */
-
- // ECC Does not appear to be supported currently
- KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlgo);
- if (curveName != null) {
- AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(keyAlgo);
- algorithmParameters.init(new ECNamedCurveGenParameterSpec(curveName));
- kpg.initialize(algorithmParameters
- .getParameterSpec(ECNamedCurveGenParameterSpec.class));
- } else {
- kpg.initialize(keySize);
- }
- KeyPair kp = kpg.generateKeyPair();
-
- X500Principal subject = new X500Principal("CN=Android, O=Google, C=US");
-
- mClientKey = kp.getPrivate();
-
- // !!! Map the idAttributes into an ASN1Set of values to pass to
- // the PKCS10CertificationRequest - this code is using outdated BC classes and
- // has *not* been tested.
- ASN1Set attributes;
- if (!idAttributes.isEmpty()) {
- ASN1EncodableVector payload = new DEREncodableVector();
- for (Map.Entry entry : idAttributes.entrySet()) {
- DERObjectIdentifier type = new DERObjectIdentifier(entry.getKey().toOIDString());
- ASN1Set values = new DERSet(entry.getValue());
- Attribute attribute = new Attribute(type, values);
- payload.add(attribute);
- }
- attributes = new DERSet(payload);
- } else {
- attributes = null;
- }
-
- return new PKCS10CertificationRequest(sigAlgo, subject, kp.getPublic(),
- attributes, mClientKey).getEncoded();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/flow/FlowService.java b/packages/Osu/src/com/android/hotspot2/flow/FlowService.java
deleted file mode 100644
index 8bbbf06344d56..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/flow/FlowService.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package com.android.hotspot2.flow;
-
-import android.annotation.Nullable;
-import android.app.IntentService;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.Network;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.IBinder;
-import android.util.Log;
-
-import com.android.hotspot2.osu.OSUFlowManager;
-import com.android.hotspot2.osu.OSUManager;
-import com.android.hotspot2.osu.OSUOperationStatus;
-import com.android.hotspot2.pps.HomeSP;
-
-import java.io.IOException;
-
-/**
- * This is the Hotspot 2.0 release 2 service that handles actual provisioning and remediation flows.
- *
- * The OSU App is made up of two services; FlowService and OSUService.
- *
- * OSUService is a long running light weight service, kept alive throughout the lifetime of the
- * operating system by being bound from the framework (in WifiManager in stage
- * PHASE_THIRD_PARTY_APPS_CAN_START), and is responsible for continuously caching OSU information
- * and notifying the UI when OSUs are available.
- *
- * FlowService is only started on demand from OSUService and is responsible for handling actual
- * provisioning and remediation flows, and requires a fairly significant memory footprint.
- *
- * FlowService is defined to run in its own process through the definition
- *
- * in the AndroidManifest.
- * This is done as a means to keep total app memory footprint low (pss < 10M) and only start the
- * FlowService on demand and make it available for "garbage collection" by the OS when not in use.
- */
-public class FlowService extends IntentService {
- private static final String[] INTENTS = {
- WifiManager.NETWORK_STATE_CHANGED_ACTION
- };
-
- private OSUFlowManager mOSUFlowManager;
- private PlatformAdapter mPlatformAdapter;
- private final FlowServiceImpl mOSUAccessor = new FlowServiceImpl();
-
- /*
- public FlowService(Context context) {
- super("FlowService");
- mOSUFlowManager = new OSUFlowManager();
- mPlatformAdapter = new PlatformAdapter(context);
- BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- handleIntent(intent.getAction(), intent);
- }
- };
- for (String intentString : INTENTS) {
- context.registerReceiver(receiver, new IntentFilter(intentString));
- }
- }
- */
-
- public FlowService() {
- super("FlowService");
- }
-
- public final class FlowServiceImpl extends IFlowService.Stub {
- public void provision(OSUInfo osuInfo) {
- FlowService.this.provision(osuInfo);
- }
-
- public void remediate(String spFqdn, String url, boolean policy, Network network) {
- FlowService.this.remediate(spFqdn, url, policy, network);
- }
-
- public void spDeleted(String fqdn) {
- FlowService.this.serviceProviderDeleted(fqdn);
- }
- }
-
- public void provision(OSUInfo osuInfo) {
- try {
- mOSUFlowManager.appendFlow(new OSUFlowManager.OSUFlow(osuInfo, mPlatformAdapter,
- mPlatformAdapter.getKeyManager(null)));
- } catch (IOException ioe) {
- mPlatformAdapter.notifyUser(OSUOperationStatus.ProvisioningFailure, ioe.getMessage(),
- osuInfo.getName(PlatformAdapter.LOCALE));
- }
- }
-
- /**
- * Initiate remediation
- * @param spFqdn The FQDN of the current SP, not set for WNM based remediation
- * @param url The URL of the remediation server
- * @param policy Set if this is a policy update rather than a subscription update
- * @param network The network to use for remediation
- */
- public void remediate(String spFqdn, String url, boolean policy, Network network) {
- Log.d(OSUManager.TAG, "Starting remediation for " + spFqdn + " to " + url);
- if (spFqdn != null) {
- HomeSP homeSP = mPlatformAdapter.getHomeSP(spFqdn);
- if (homeSP == null) {
- Log.e(OSUManager.TAG, "No HomeSP object matches '" + spFqdn + "'");
- return;
- }
-
- try {
- mOSUFlowManager.appendFlow(new OSUFlowManager.OSUFlow(network, url,
- mPlatformAdapter, mPlatformAdapter.getKeyManager(homeSP),
- homeSP, policy
- ? OSUFlowManager.FlowType.Policy : OSUFlowManager.FlowType.Remediation));
- } catch (IOException ioe) {
- Log.e(OSUManager.TAG, "Failed to remediate: " + ioe, ioe);
- }
- } else {
- HomeSP homeSP = mPlatformAdapter.getCurrentSP();
- if (homeSP == null) {
- Log.e(OSUManager.TAG, "Remediation request on unidentified Passpoint network ");
- return;
- }
-
- try {
- mOSUFlowManager.appendFlow(new OSUFlowManager.OSUFlow(network, url,
- mPlatformAdapter, mPlatformAdapter.getKeyManager(homeSP), homeSP,
- OSUFlowManager.FlowType.Remediation));
- } catch (IOException ioe) {
- Log.e(OSUManager.TAG, "Failed to start remediation: " + ioe, ioe);
- }
- }
- }
-
- public void serviceProviderDeleted(String fqdn) {
- mPlatformAdapter.serviceProviderDeleted(fqdn);
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- mOSUFlowManager = new OSUFlowManager(this);
- mPlatformAdapter = new PlatformAdapter(this);
- BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- handleIntent(intent.getAction(), intent);
- }
- };
- for (String intentString : INTENTS) {
- registerReceiver(receiver, new IntentFilter(intentString));
- }
- return mOSUAccessor;
- }
-
- @Override
- protected void onHandleIntent(@Nullable Intent intent) {
- }
-
- private void handleIntent(String action, Intent intent) {
- if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
- WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
- if (wifiInfo != null) {
- mOSUFlowManager.networkChange();
- }
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/flow/IFlowService.aidl b/packages/Osu/src/com/android/hotspot2/flow/IFlowService.aidl
deleted file mode 100644
index a61274fe88125..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/flow/IFlowService.aidl
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.android.hotspot2.flow;
-
-import com.android.hotspot2.flow.OSUInfo;
-import android.net.Network;
-
-interface IFlowService {
- void provision(in OSUInfo osuInfo);
- void remediate(String spFqdn, String url, boolean policy, in Network network);
- void spDeleted(String fqdn);
-}
diff --git a/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.aidl b/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.aidl
deleted file mode 100644
index 172486e3f3bf3..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.aidl
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.android.hotspot2.flow;
-
-parcelable OSUInfo;
diff --git a/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.java b/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.java
deleted file mode 100644
index 401eccb96d050..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/flow/OSUInfo.java
+++ /dev/null
@@ -1,321 +0,0 @@
-package com.android.hotspot2.flow;
-
-import android.net.wifi.ScanResult;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-import com.android.anqp.HSIconFileElement;
-import com.android.anqp.I18Name;
-import com.android.anqp.IconInfo;
-import com.android.anqp.OSUProvider;
-import com.android.hotspot2.Utils;
-import com.android.hotspot2.osu.OSUManager;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Locale;
-import java.util.Set;
-
-public class OSUInfo implements Parcelable {
- public static final String GenericLocale = "zxx";
-
- public enum IconStatus {
- NotQueried, //
- InProgress, // Query pending
- NotAvailable, // Deterministically unavailable
- Available // Icon data retrieved
- }
-
- private final long mBSSID;
- private final long mHESSID;
- private final int mAnqpDomID;
- private final String mAdvertisingSSID;
- private final OSUProvider mOSUProvider;
- private final int mOsuID;
- private long mOSUBssid;
- private IconStatus mIconStatus = IconStatus.NotQueried;
- private HSIconFileElement mIconFileElement;
- private String mIconFileName;
- private IconInfo mIconInfo;
-
- public OSUInfo(ScanResult scanResult, OSUProvider osuProvider, int osuID) {
- mOsuID = osuID;
- mBSSID = Utils.parseMac(scanResult.BSSID);
- mHESSID = scanResult.hessid;
- mAnqpDomID = scanResult.anqpDomainId;
- mAdvertisingSSID = scanResult.SSID;
- mOSUProvider = osuProvider;
- }
-
- public long getOSUBssid() {
- return mOSUBssid;
- }
-
- public void setOSUBssid(long OSUBssid) {
- mOSUBssid = OSUBssid;
- }
-
- public long getHESSID() {
- return mHESSID;
- }
-
- public int getAnqpDomID() {
- return mAnqpDomID;
- }
-
- public String getAdvertisingSsid() {
- return mAdvertisingSSID;
- }
-
- public Set getNameLocales() {
- Set locales = new HashSet<>(mOSUProvider.getNames().size());
- for (I18Name name : mOSUProvider.getNames()) {
- locales.add(name.getLocale());
- }
- return locales;
- }
-
- public Set getServiceLocales() {
- Set locales = new HashSet<>(mOSUProvider.getServiceDescriptions().size());
- for (I18Name name : mOSUProvider.getServiceDescriptions()) {
- locales.add(name.getLocale());
- }
- return locales;
- }
-
- public Set getIconLanguages() {
- Set locales = new HashSet<>(mOSUProvider.getIcons().size());
- for (IconInfo iconInfo : mOSUProvider.getIcons()) {
- locales.add(iconInfo.getLanguage());
- }
- return locales;
- }
-
- public String getName(Locale locale) {
- List> scoreList = new ArrayList<>();
- for (I18Name name : mOSUProvider.getNames()) {
- if (locale == null || name.getLocale().equals(locale)) {
- return name.getText();
- }
- scoreList.add(new ScoreEntry<>(name.getText(),
- languageScore(name.getLanguage(), locale)));
- }
- Collections.sort(scoreList);
- return scoreList.isEmpty() ? null : scoreList.get(scoreList.size() - 1).getData();
- }
-
- public String getServiceDescription(Locale locale) {
- List> scoreList = new ArrayList<>();
- for (I18Name service : mOSUProvider.getServiceDescriptions()) {
- if (locale == null || service.getLocale().equals(locale)) {
- return service.getText();
- }
- scoreList.add(new ScoreEntry<>(service.getText(),
- languageScore(service.getLanguage(), locale)));
- }
- Collections.sort(scoreList);
- return scoreList.isEmpty() ? null : scoreList.get(scoreList.size() - 1).getData();
- }
-
- public int getOsuID() {
- return mOsuID;
- }
-
- public void setIconStatus(IconStatus iconStatus) {
- synchronized (mOSUProvider) {
- mIconStatus = iconStatus;
- }
- }
-
- public IconStatus getIconStatus() {
- synchronized (mOSUProvider) {
- return mIconStatus;
- }
- }
-
- public HSIconFileElement getIconFileElement() {
- synchronized (mOSUProvider) {
- return mIconFileElement;
- }
- }
-
- public IconInfo getIconInfo() {
- synchronized (mOSUProvider) {
- return mIconInfo;
- }
- }
-
- public String getIconFileName() {
- return mIconFileName;
- }
-
- public void setIconFileElement(HSIconFileElement iconFileElement, String fileName) {
- synchronized (mOSUProvider) {
- mIconFileElement = iconFileElement;
- for (IconInfo iconInfo : mOSUProvider.getIcons()) {
- if (iconInfo.getFileName().equals(fileName)) {
- mIconInfo = iconInfo;
- mIconFileName = fileName;
- break;
- }
- }
- mIconStatus = IconStatus.Available;
- }
- }
-
- private static class ScoreEntry implements Comparable {
- private final T mData;
- private final int mScore;
-
- private ScoreEntry(T data, int score) {
- mData = data;
- mScore = score;
- }
-
- public T getData() {
- return mData;
- }
-
- @Override
- public int compareTo(ScoreEntry other) {
- return Integer.compare(mScore, other.mScore);
- }
-
- @Override
- public String toString() {
- return String.format("%d for '%s'", mScore, mData);
- }
- }
-
- public List getIconInfo(Locale locale, Set types, int width, int height) {
- if (mOSUProvider.getIcons().isEmpty()) {
- return null;
- }
- Log.d(OSUManager.TAG, "Matching icons against " + locale
- + ", types " + types + ", " + width + "*" + height);
-
- List> matches = new ArrayList<>();
- for (IconInfo iconInfo : mOSUProvider.getIcons()) {
- Log.d(OSUManager.TAG, "Checking icon " + iconInfo.toString());
- if (!types.contains(iconInfo.getIconType())) {
- continue;
- }
-
- int score = languageScore(iconInfo.getLanguage(), locale);
- int delta = iconInfo.getWidth() - width;
- // Best size score is 1024 for a exact match, i.e. 2048 if both sides match
- if (delta >= 0) {
- score += (256 - delta) * 4; // Prefer down-scaling
- } else {
- score += 256 + delta; // Before up-scaling
- }
- delta = iconInfo.getHeight() - height;
- if (delta >= 0) {
- score += (256 - delta) * 4;
- } else {
- score += 256 + delta;
- }
- matches.add(new ScoreEntry<>(iconInfo, score));
- }
- if (matches.isEmpty()) {
- return Collections.emptyList();
- }
- Collections.sort(matches);
- List icons = new ArrayList<>(matches.size());
- ListIterator> matchIterator = matches.listIterator(matches.size());
- while (matchIterator.hasPrevious()) {
- icons.add(matchIterator.previous().getData());
- }
- return icons;
- }
-
- private static int languageScore(String language, Locale locale) {
- if (language.length() == 3 && language.equalsIgnoreCase(locale.getISO3Language()) ||
- language.length() == 2 && language.equalsIgnoreCase(locale.getLanguage())) {
- return 4096;
- } else if (language.equalsIgnoreCase(GenericLocale)) {
- return 3072;
- } else if (language.equalsIgnoreCase("eng")) {
- return 2048;
- } else {
- return 1024;
- }
- }
-
- public long getBSSID() {
- return mBSSID;
- }
-
- public String getOsuSsid() {
- return mOSUProvider.getSSID();
- }
-
- public OSUProvider getOSUProvider() {
- return mOSUProvider;
- }
-
- @Override
- public String toString() {
- return String.format("OSU Info '%s' %012x -> %s, icon %s",
- getOsuSsid(), mBSSID, getServiceDescription(null), mIconStatus);
- }
-
- private OSUInfo(Parcel in) {
- mBSSID = in.readLong();
- mHESSID = in.readLong();
- mAnqpDomID = in.readInt();
- mAdvertisingSSID = in.readString();
- mOsuID = in.readInt();
- mOSUBssid = in.readLong();
- mIconFileName = in.readString();
- mIconStatus = Utils.mapEnum(in.readInt(), IconStatus.class);
- OSUProvider osuProvider;
- try {
- osuProvider = new OSUProvider(in);
- } catch (IOException ioe) {
- osuProvider = null;
- }
- mOSUProvider = osuProvider;
- if (osuProvider == null) {
- return;
- }
- mIconFileElement = new HSIconFileElement(in);
- int iconIndex = in.readInt();
- mIconInfo = iconIndex >= 0 && iconIndex < mOSUProvider.getIcons().size()
- ? mOSUProvider.getIcons().get(iconIndex) : null;
- }
-
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public OSUInfo createFromParcel(Parcel in) {
- return new OSUInfo(in);
- }
-
- public OSUInfo[] newArray(int size) {
- return new OSUInfo[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeLong(mBSSID);
- dest.writeLong(mHESSID);
- dest.writeInt(mAnqpDomID);
- dest.writeString(mAdvertisingSSID);
- dest.writeInt(mOsuID);
- dest.writeLong(mOSUBssid);
- dest.writeString(mIconFileName);
- dest.writeInt(mIconStatus.ordinal());
- mOSUProvider.writeParcel(dest);
- mIconFileElement.writeParcel(dest);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/flow/PlatformAdapter.java b/packages/Osu/src/com/android/hotspot2/flow/PlatformAdapter.java
deleted file mode 100644
index d95af61a27c1e..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/flow/PlatformAdapter.java
+++ /dev/null
@@ -1,620 +0,0 @@
-package com.android.hotspot2.flow;
-
-import android.content.Context;
-import android.content.Intent;
-import android.net.Network;
-import android.net.wifi.PasspointManagementObjectDefinition;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiEnterpriseConfig;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.util.Log;
-
-import com.android.configparse.ConfigBuilder;
-import com.android.hotspot2.AppBridge;
-import com.android.hotspot2.Utils;
-import com.android.hotspot2.app.OSUService;
-import com.android.hotspot2.omadm.MOManager;
-import com.android.hotspot2.omadm.MOTree;
-import com.android.hotspot2.omadm.OMAConstants;
-import com.android.hotspot2.omadm.OMAException;
-import com.android.hotspot2.omadm.OMAParser;
-import com.android.hotspot2.osu.ClientKeyManager;
-import com.android.hotspot2.osu.OSUCertType;
-import com.android.hotspot2.osu.OSUManager;
-import com.android.hotspot2.osu.OSUOperationStatus;
-import com.android.hotspot2.osu.OSUSocketFactory;
-import com.android.hotspot2.osu.WiFiKeyManager;
-import com.android.hotspot2.osu.commands.MOData;
-import com.android.hotspot2.pps.HomeSP;
-
-import org.xml.sax.SAXException;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.PrivateKey;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import javax.net.ssl.KeyManager;
-
-public class PlatformAdapter {
- private static final String TAG = "OSUFLOW";
-
- public static final Locale LOCALE = Locale.getDefault();
-
- public static final String CERT_WFA_ALIAS = "wfa-root-";
- public static final String CERT_REM_ALIAS = "rem-";
- public static final String CERT_POLICY_ALIAS = "pol-";
- public static final String CERT_SHARED_ALIAS = "shr-";
- public static final String CERT_CLT_CERT_ALIAS = "clt-";
- public static final String CERT_CLT_KEY_ALIAS = "prv-";
- public static final String CERT_CLT_CA_ALIAS = "aaa-";
-
- private static final String KEYSTORE_FILE = "passpoint.ks";
-
- private final Context mContext;
- private final File mKeyStoreFile;
- private final KeyStore mKeyStore;
- private final AppBridge mAppBridge;
- private final Map mPasspointConfigs;
-
- public PlatformAdapter(Context context) {
- mContext = context;
- mAppBridge = new AppBridge(context);
-
- File appFolder = context.getFilesDir();
- mKeyStoreFile = new File(appFolder, KEYSTORE_FILE);
- Log.d(TAG, "KS file: " + mKeyStoreFile.getPath());
- KeyStore ks = null;
- try {
- //ks = loadKeyStore(KEYSTORE_FILE, readCertsFromDisk(WFA_CA_LOC));
- ks = loadKeyStore(mKeyStoreFile, OSUSocketFactory.buildCertSet());
- } catch (IOException e) {
- Log.e(TAG, "Failed to initialize Passpoint keystore, OSU disabled", e);
- }
- mKeyStore = ks;
-
- mPasspointConfigs = loadAllSps(context);
- }
-
- private static KeyStore loadKeyStore(File ksFile, Set diskCerts)
- throws IOException {
- try {
- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
- if (ksFile.exists()) {
- try (FileInputStream in = new FileInputStream(ksFile)) {
- keyStore.load(in, null);
- }
-
- // Note: comparing two sets of certs does not work.
- boolean mismatch = false;
- int loadCount = 0;
- for (int n = 0; n < 1000; n++) {
- String alias = String.format("%s%d", CERT_WFA_ALIAS, n);
- Certificate cert = keyStore.getCertificate(alias);
- if (cert == null) {
- break;
- }
-
- loadCount++;
- boolean matched = false;
- Iterator iter = diskCerts.iterator();
- while (iter.hasNext()) {
- X509Certificate diskCert = iter.next();
- if (cert.equals(diskCert)) {
- iter.remove();
- matched = true;
- break;
- }
- }
- if (!matched) {
- mismatch = true;
- break;
- }
- }
- if (mismatch || !diskCerts.isEmpty()) {
- Log.d(TAG, "Re-seeding Passpoint key store with " +
- diskCerts.size() + " WFA certs");
- for (int n = 0; n < 1000; n++) {
- String alias = String.format("%s%d", CERT_WFA_ALIAS, n);
- Certificate cert = keyStore.getCertificate(alias);
- if (cert == null) {
- break;
- } else {
- keyStore.deleteEntry(alias);
- }
- }
- int index = 0;
- for (X509Certificate caCert : diskCerts) {
- keyStore.setCertificateEntry(
- String.format("%s%d", CERT_WFA_ALIAS, index), caCert);
- index++;
- }
-
- try (FileOutputStream out = new FileOutputStream(ksFile)) {
- keyStore.store(out, null);
- }
- } else {
- Log.d(TAG, "Loaded Passpoint key store with " + loadCount + " CA certs");
- Enumeration aliases = keyStore.aliases();
- while (aliases.hasMoreElements()) {
- Log.d("ZXC", "KS Alias '" + aliases.nextElement() + "'");
- }
- }
- } else {
- keyStore.load(null, null);
- int index = 0;
- for (X509Certificate caCert : diskCerts) {
- keyStore.setCertificateEntry(
- String.format("%s%d", CERT_WFA_ALIAS, index), caCert);
- index++;
- }
-
- try (FileOutputStream out = new FileOutputStream(ksFile)) {
- keyStore.store(out, null);
- }
- Log.d(TAG, "Initialized Passpoint key store with " +
- diskCerts.size() + " CA certs");
- }
- return keyStore;
- } catch (GeneralSecurityException gse) {
- throw new IOException(gse);
- }
- }
-
- private static Map loadAllSps(Context context) {
- Map passpointConfigs = new HashMap<>();
-
- WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- List configs = wifiManager.getPrivilegedConfiguredNetworks();
- if (configs == null) {
- return passpointConfigs;
- }
- int count = 0;
- for (WifiConfiguration config : configs) {
- String moTree = config.getMoTree();
- if (moTree != null) {
- try {
- passpointConfigs.put(config.FQDN, new PasspointConfig(config));
- count++;
- } catch (IOException | SAXException e) {
- Log.w(OSUManager.TAG, "Failed to parse MO: " + e);
- }
- }
- }
- Log.d(OSUManager.TAG, "Loaded " + count + " SPs");
- return passpointConfigs;
- }
-
- public KeyStore getKeyStore() {
- return mKeyStore;
- }
-
- public Context getContext() {
- return mContext;
- }
-
- /**
- * Connect to an OSU provisioning network. The connection should not bring down other existing
- * connection and the network should not be made the default network since the connection
- * is solely for sign up and is neither intended for nor likely provides access to any
- * generic resources.
- *
- * @param osuInfo The OSU info object that defines the parameters for the network. An OSU
- * network is either an open network, or, if the OSU NAI is set, an "OSEN"
- * network, which is an anonymous EAP-TLS network with special keys.
- * @return an Integer holding the network-id of the just added network configuration, or null
- * if the network existed prior to this call (was not added by the OSU infrastructure).
- * The value will be used at the end of the OSU flow to delete the network as applicable.
- * @throws IOException Issues:
- * 1. The network id is not returned. addNetwork cannot be called from here since the method
- * runs in the context of the app and doesn't have the appropriate permission.
- * 2. The connection is not immediately usable if the network was not previously selected
- * manually.
- */
- public Integer connect(OSUInfo osuInfo) throws IOException {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
-
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = '"' + osuInfo.getOsuSsid() + '"';
- if (osuInfo.getOSUBssid() != 0) {
- config.BSSID = Utils.macToString(osuInfo.getOSUBssid());
- Log.d(OSUManager.TAG, String.format("Setting BSSID of '%s' to %012x",
- osuInfo.getOsuSsid(), osuInfo.getOSUBssid()));
- }
-
- if (osuInfo.getOSUProvider().getOsuNai() == null) {
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- } else {
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OSEN);
- config.allowedProtocols.set(WifiConfiguration.Protocol.OSEN);
- config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
- config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GTK_NOT_USED);
- config.enterpriseConfig = new WifiEnterpriseConfig();
- config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.UNAUTH_TLS);
- config.enterpriseConfig.setIdentity(osuInfo.getOSUProvider().getOsuNai());
- Set cas = OSUSocketFactory.buildCertSet();
- config.enterpriseConfig.setCaCertificates(cas.toArray(new X509Certificate[cas.size()]));
- }
-
- int networkId = wifiManager.addNetwork(config);
- if (networkId < 0) {
- throw new IOException("Failed to add OSU network");
- }
- if (wifiManager.enableNetwork(networkId, true)) {
- return networkId;
- } else {
- throw new IOException("Failed to enable OSU network");
- }
- }
-
- /**
- * @param homeSP The Home SP associated with the keying material in question. Passing
- * null returns a "system wide" KeyManager to support pre-provisioned certs based
- * on names retrieved from the ClientCertInfo request.
- * @return A key manager suitable for the given configuration (or pre-provisioned keys).
- */
- public KeyManager getKeyManager(HomeSP homeSP) throws IOException {
- return homeSP != null
- ? new ClientKeyManager(homeSP, mKeyStore) : new WiFiKeyManager(mKeyStore);
- }
-
- public void provisioningComplete(OSUInfo osuInfo,
- MOData moData, Map> certs,
- PrivateKey privateKey, Network osuNetwork) {
- try {
- String xml = moData.getMOTree().toXml();
- HomeSP homeSP = MOManager.buildSP(xml);
-
- Integer spNwk = addNetwork(homeSP, certs, privateKey, osuNetwork);
- if (spNwk == null) {
- notifyUser(OSUOperationStatus.ProvisioningFailure,
- "Failed to save network configuration", osuInfo.getName(LOCALE));
- } else {
- if (addSP(xml) < 0) {
- deleteNetwork(spNwk);
- Log.e(TAG, "Failed to provision: " + homeSP.getFQDN());
- notifyUser(OSUOperationStatus.ProvisioningFailure, "Failed to add MO",
- osuInfo.getName(LOCALE));
- return;
- }
- Set rootCerts = OSUSocketFactory.getRootCerts(mKeyStore);
- X509Certificate remCert = getCert(certs, OSUCertType.Remediation);
- X509Certificate polCert = getCert(certs, OSUCertType.Policy);
- int newCerts = 0;
- if (privateKey != null) {
- X509Certificate cltCert = getCert(certs, OSUCertType.Client);
- mKeyStore.setKeyEntry(CERT_CLT_KEY_ALIAS + homeSP.getFQDN(),
- privateKey, null, new X509Certificate[]{cltCert});
- mKeyStore.setCertificateEntry(CERT_CLT_CERT_ALIAS + homeSP.getFQDN(), cltCert);
- newCerts++;
- }
- boolean usingShared = false;
- if (remCert != null) {
- if (!rootCerts.contains(remCert)) {
- if (remCert.equals(polCert)) {
- mKeyStore.setCertificateEntry(CERT_SHARED_ALIAS + homeSP.getFQDN(),
- remCert);
- usingShared = true;
- newCerts++;
- } else {
- mKeyStore.setCertificateEntry(CERT_REM_ALIAS + homeSP.getFQDN(),
- remCert);
- newCerts++;
- }
- }
- }
- if (!usingShared && polCert != null) {
- if (!rootCerts.contains(polCert)) {
- mKeyStore.setCertificateEntry(CERT_POLICY_ALIAS + homeSP.getFQDN(),
- remCert);
- newCerts++;
- }
- }
-
-
- if (newCerts > 0) {
- try (FileOutputStream out = new FileOutputStream(mKeyStoreFile)) {
- mKeyStore.store(out, null);
- }
- }
- notifyUser(OSUOperationStatus.ProvisioningSuccess, null, osuInfo.getName(LOCALE));
- Log.d(TAG, "Provisioning complete.");
- }
- } catch (IOException | GeneralSecurityException | SAXException e) {
- Log.e(TAG, "Failed to provision: " + e, e);
- notifyUser(OSUOperationStatus.ProvisioningFailure, e.toString(),
- osuInfo.getName(LOCALE));
- }
- }
-
- public void remediationComplete(HomeSP homeSP, Collection mods,
- Map> certs,
- PrivateKey privateKey, boolean policy)
- throws IOException, GeneralSecurityException {
-
- HomeSP altSP = null;
- if (modifySP(homeSP, mods) > 0) {
- altSP = MOManager.modifySP(homeSP, getMOTree(homeSP), mods);
- }
-
- X509Certificate caCert = null;
- List clientCerts = null;
- if (certs != null) {
- List certList = certs.get(OSUCertType.AAA);
- caCert = certList != null && !certList.isEmpty() ? certList.iterator().next() : null;
- clientCerts = certs.get(OSUCertType.Client);
- }
- if (altSP != null || certs != null) {
- if (altSP == null) {
- altSP = homeSP;
- }
- updateNetwork(altSP, caCert, clientCerts, privateKey);
-
- if (privateKey != null) {
- X509Certificate cltCert = getCert(certs, OSUCertType.Client);
- mKeyStore.setKeyEntry(CERT_CLT_KEY_ALIAS + homeSP.getFQDN(),
- privateKey, null, new X509Certificate[]{cltCert});
- mKeyStore.setCertificateEntry(CERT_CLT_CERT_ALIAS + homeSP.getFQDN(), cltCert);
- }
- }
-
- Intent intent = new Intent(OSUService.REMEDIATION_DONE_ACTION);
- intent.putExtra(OSUService.REMEDIATION_FQDN_EXTRA, homeSP.getFQDN());
- intent.putExtra(OSUService.REMEDIATION_POLICY_EXTRA, policy);
- mContext.sendBroadcast(intent);
-
- notifyUser(OSUOperationStatus.ProvisioningSuccess, null, homeSP.getFriendlyName());
- }
-
- public void serviceProviderDeleted(String fqdn) {
- int count = deleteCerts(mKeyStore, fqdn,
- CERT_REM_ALIAS, CERT_POLICY_ALIAS, CERT_SHARED_ALIAS, CERT_CLT_CERT_ALIAS);
-
- Log.d(TAG, "Passpoint network deleted, removing " + count + " key store entries");
-
- try {
- if (mKeyStore.getKey(CERT_CLT_KEY_ALIAS + fqdn, null) != null) {
- mKeyStore.deleteEntry(CERT_CLT_KEY_ALIAS + fqdn);
- }
- } catch (GeneralSecurityException e) {
- /**/
- }
-
- if (count > 0) {
- try (FileOutputStream out = new FileOutputStream(mKeyStoreFile)) {
- mKeyStore.store(out, null);
- } catch (IOException | GeneralSecurityException e) {
- Log.w(TAG, "Failed to remove certs from key store: " + e);
- }
- }
- }
-
- private static int deleteCerts(KeyStore keyStore, String fqdn, String... prefixes) {
- int count = 0;
- for (String prefix : prefixes) {
- try {
- String alias = prefix + fqdn;
- Certificate cert = keyStore.getCertificate(alias);
- if (cert != null) {
- keyStore.deleteEntry(alias);
- count++;
- }
- } catch (KeyStoreException kse) {
- /**/
- }
- }
- return count;
- }
-
- private static X509Certificate getCert(Map> certMap,
- OSUCertType certType) {
- List certs = certMap.get(certType);
- if (certs == null || certs.isEmpty()) {
- return null;
- }
- return certs.iterator().next();
- }
-
- public String notifyUser(OSUOperationStatus status, String message, String spName) {
- if (status == OSUOperationStatus.UserInputComplete) {
- return null;
- }
- mAppBridge.showStatus(status, spName, message, null);
- return null;
- }
-
- public void provisioningFailed(String spName, String message) {
- notifyUser(OSUOperationStatus.ProvisioningFailure, message, spName);
- }
-
- private Integer addNetwork(HomeSP homeSP, Map> certs,
- PrivateKey privateKey, Network osuNetwork)
- throws IOException, GeneralSecurityException {
-
- List aaaTrust = certs.get(OSUCertType.AAA);
- if (aaaTrust.isEmpty()) {
- aaaTrust = certs.get(OSUCertType.CA); // Get the CAs from the EST flow.
- }
-
- WifiConfiguration config = ConfigBuilder.buildConfig(homeSP,
- aaaTrust.iterator().next(),
- certs.get(OSUCertType.Client), privateKey);
-
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- int nwkId = wifiManager.addNetwork(config);
- boolean saved = false;
- if (nwkId >= 0) {
- saved = wifiManager.saveConfiguration();
- }
- Log.d(OSUManager.TAG, "Wifi configuration " + nwkId +
- " " + (saved ? "saved" : "not saved"));
-
- if (saved) {
- reconnect(osuNetwork, nwkId);
- return nwkId;
- } else {
- return null;
- }
- }
-
- private void updateNetwork(HomeSP homeSP, X509Certificate caCert,
- List clientCerts, PrivateKey privateKey)
- throws IOException, GeneralSecurityException {
-
- WifiConfiguration config = getWifiConfig(homeSP);
- if (config == null) {
- throw new IOException("Failed to find matching network config");
- }
- Log.d(OSUManager.TAG, "Found matching config " + config.networkId + ", updating");
-
- WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
- WifiConfiguration newConfig = ConfigBuilder.buildConfig(homeSP,
- caCert != null ? caCert : enterpriseConfig.getCaCertificate(),
- clientCerts, privateKey);
- newConfig.networkId = config.networkId;
-
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- wifiManager.save(newConfig, null);
- wifiManager.saveConfiguration();
- }
-
- private WifiConfiguration getWifiConfig(HomeSP homeSP) {
- PasspointConfig passpointConfig = mPasspointConfigs.get(homeSP.getFQDN());
- return passpointConfig != null ? passpointConfig.getWifiConfiguration() : null;
- }
-
- public MOTree getMOTree(HomeSP homeSP) {
- PasspointConfig config = mPasspointConfigs.get(homeSP.getFQDN());
- return config != null ? config.getmMOTree() : null;
- }
-
- public HomeSP getHomeSP(String fqdn) {
- PasspointConfig passpointConfig = mPasspointConfigs.get(fqdn);
- return passpointConfig != null ? passpointConfig.getHomeSP() : null;
- }
-
- public HomeSP getCurrentSP() {
- PasspointConfig passpointConfig = getActivePasspointConfig();
- return passpointConfig != null ? passpointConfig.getHomeSP() : null;
- }
-
- private PasspointConfig getActivePasspointConfig() {
- WifiInfo wifiInfo = getConnectionInfo();
- if (wifiInfo == null) {
- return null;
- }
-
- for (PasspointConfig passpointConfig : mPasspointConfigs.values()) {
- if (passpointConfig.getWifiConfiguration().networkId == wifiInfo.getNetworkId()) {
- return passpointConfig;
- }
- }
- return null;
- }
-
- private int addSP(String xml) throws IOException, SAXException {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- // TODO(b/32883320): use the new API for adding Passpoint configuration.
- return 0;
- }
-
- private int modifySP(HomeSP homeSP, Collection mods) throws IOException {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- List defMods = new ArrayList<>(mods.size());
- for (MOData mod : mods) {
- defMods.add(new PasspointManagementObjectDefinition(mod.getBaseURI(),
- mod.getURN(), mod.getMOTree().toXml()));
- }
- // TODO(b/32883320): use the new API to update Passpoint configuration.
- return 0;
- }
-
- private void reconnect(Network osuNetwork, int newNwkId) {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- if (osuNetwork != null) {
- wifiManager.disableNetwork(osuNetwork.netId);
- }
- if (newNwkId != WifiConfiguration.INVALID_NETWORK_ID) {
- wifiManager.enableNetwork(newNwkId, true);
- }
- }
-
- public void deleteNetwork(int id) {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- wifiManager.disableNetwork(id);
- wifiManager.forget(id, null);
- }
-
- public WifiInfo getConnectionInfo() {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- return wifiManager.getConnectionInfo();
- }
-
- public Network getCurrentNetwork() {
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- return wifiManager.getCurrentNetwork();
- }
-
- public WifiConfiguration getActiveWifiConfig() {
- WifiInfo wifiInfo = getConnectionInfo();
- if (wifiInfo == null) {
- return null;
- }
- WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- List configs = wifiManager.getConfiguredNetworks();
- if (configs == null) {
- return null;
- }
- for (WifiConfiguration config : configs) {
- if (config.networkId == wifiInfo.getNetworkId()) {
- return config;
- }
- }
- return null;
- }
-
- private static class PasspointConfig {
- private final WifiConfiguration mWifiConfiguration;
- private final MOTree mMOTree;
- private final HomeSP mHomeSP;
-
- private PasspointConfig(WifiConfiguration config) throws IOException, SAXException {
- mWifiConfiguration = config;
- OMAParser omaParser = new OMAParser();
- mMOTree = omaParser.parse(config.getMoTree(), OMAConstants.PPS_URN);
- List spList = MOManager.buildSPs(mMOTree);
- if (spList.size() != 1) {
- throw new OMAException("Expected exactly one HomeSP, got " + spList.size());
- }
- mHomeSP = spList.iterator().next();
- }
-
- public WifiConfiguration getWifiConfiguration() {
- return mWifiConfiguration;
- }
-
- public HomeSP getHomeSP() {
- return mHomeSP;
- }
-
- public MOTree getmMOTree() {
- return mMOTree;
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/MOManager.java b/packages/Osu/src/com/android/hotspot2/omadm/MOManager.java
deleted file mode 100644
index 8a1eef4463dae..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/MOManager.java
+++ /dev/null
@@ -1,1037 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import android.util.Base64;
-import android.util.Log;
-
-import com.android.anqp.eap.EAP;
-import com.android.anqp.eap.EAPMethod;
-import com.android.anqp.eap.ExpandedEAPMethod;
-import com.android.anqp.eap.InnerAuthEAP;
-import com.android.anqp.eap.NonEAPInnerAuth;
-import com.android.hotspot2.IMSIParameter;
-import com.android.hotspot2.Utils;
-import com.android.hotspot2.osu.OSUManager;
-import com.android.hotspot2.osu.commands.MOData;
-import com.android.hotspot2.pps.Credential;
-import com.android.hotspot2.pps.HomeSP;
-import com.android.hotspot2.pps.Policy;
-import com.android.hotspot2.pps.SubscriptionParameters;
-import com.android.hotspot2.pps.UpdateInfo;
-
-import org.xml.sax.SAXException;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TimeZone;
-
-/**
- * Handles provisioning of PerProviderSubscription data.
- */
-public class MOManager {
-
- public static final String TAG_AAAServerTrustRoot = "AAAServerTrustRoot";
- public static final String TAG_AbleToShare = "AbleToShare";
- public static final String TAG_CertificateType = "CertificateType";
- public static final String TAG_CertSHA256Fingerprint = "CertSHA256Fingerprint";
- public static final String TAG_CertURL = "CertURL";
- public static final String TAG_CheckAAAServerCertStatus = "CheckAAAServerCertStatus";
- public static final String TAG_Country = "Country";
- public static final String TAG_CreationDate = "CreationDate";
- public static final String TAG_Credential = "Credential";
- public static final String TAG_CredentialPriority = "CredentialPriority";
- public static final String TAG_DataLimit = "DataLimit";
- public static final String TAG_DigitalCertificate = "DigitalCertificate";
- public static final String TAG_DLBandwidth = "DLBandwidth";
- public static final String TAG_EAPMethod = "EAPMethod";
- public static final String TAG_EAPType = "EAPType";
- public static final String TAG_ExpirationDate = "ExpirationDate";
- public static final String TAG_Extension = "Extension";
- public static final String TAG_FQDN = "FQDN";
- public static final String TAG_FQDN_Match = "FQDN_Match";
- public static final String TAG_FriendlyName = "FriendlyName";
- public static final String TAG_HESSID = "HESSID";
- public static final String TAG_HomeOI = "HomeOI";
- public static final String TAG_HomeOIList = "HomeOIList";
- public static final String TAG_HomeOIRequired = "HomeOIRequired";
- public static final String TAG_HomeSP = "HomeSP";
- public static final String TAG_IconURL = "IconURL";
- public static final String TAG_IMSI = "IMSI";
- public static final String TAG_InnerEAPType = "InnerEAPType";
- public static final String TAG_InnerMethod = "InnerMethod";
- public static final String TAG_InnerVendorID = "InnerVendorID";
- public static final String TAG_InnerVendorType = "InnerVendorType";
- public static final String TAG_IPProtocol = "IPProtocol";
- public static final String TAG_MachineManaged = "MachineManaged";
- public static final String TAG_MaximumBSSLoadValue = "MaximumBSSLoadValue";
- public static final String TAG_MinBackhaulThreshold = "MinBackhaulThreshold";
- public static final String TAG_NetworkID = "NetworkID";
- public static final String TAG_NetworkType = "NetworkType";
- public static final String TAG_Other = "Other";
- public static final String TAG_OtherHomePartners = "OtherHomePartners";
- public static final String TAG_Password = "Password";
- public static final String TAG_PerProviderSubscription = "PerProviderSubscription";
- public static final String TAG_Policy = "Policy";
- public static final String TAG_PolicyUpdate = "PolicyUpdate";
- public static final String TAG_PortNumber = "PortNumber";
- public static final String TAG_PreferredRoamingPartnerList = "PreferredRoamingPartnerList";
- public static final String TAG_Priority = "Priority";
- public static final String TAG_Realm = "Realm";
- public static final String TAG_RequiredProtoPortTuple = "RequiredProtoPortTuple";
- public static final String TAG_Restriction = "Restriction";
- public static final String TAG_RoamingConsortiumOI = "RoamingConsortiumOI";
- public static final String TAG_SIM = "SIM";
- public static final String TAG_SoftTokenApp = "SoftTokenApp";
- public static final String TAG_SPExclusionList = "SPExclusionList";
- public static final String TAG_SSID = "SSID";
- public static final String TAG_StartDate = "StartDate";
- public static final String TAG_SubscriptionParameters = "SubscriptionParameters";
- public static final String TAG_SubscriptionUpdate = "SubscriptionUpdate";
- public static final String TAG_TimeLimit = "TimeLimit";
- public static final String TAG_TrustRoot = "TrustRoot";
- public static final String TAG_TypeOfSubscription = "TypeOfSubscription";
- public static final String TAG_ULBandwidth = "ULBandwidth";
- public static final String TAG_UpdateIdentifier = "UpdateIdentifier";
- public static final String TAG_UpdateInterval = "UpdateInterval";
- public static final String TAG_UpdateMethod = "UpdateMethod";
- public static final String TAG_URI = "URI";
- public static final String TAG_UsageLimits = "UsageLimits";
- public static final String TAG_UsageTimePeriod = "UsageTimePeriod";
- public static final String TAG_Username = "Username";
- public static final String TAG_UsernamePassword = "UsernamePassword";
- public static final String TAG_VendorId = "VendorId";
- public static final String TAG_VendorType = "VendorType";
-
- public static final long IntervalFactor = 60000L; // All MO intervals are in minutes
-
- private static final DateFormat DTFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-
- private static final Map> sSelectionMap;
-
- static {
- DTFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- sSelectionMap = new HashMap<>();
-
- setSelections(TAG_FQDN_Match,
- "exactmatch", Boolean.FALSE,
- "includesubdomains", Boolean.TRUE);
- setSelections(TAG_UpdateMethod,
- "oma-dm-clientinitiated", Boolean.FALSE,
- "spp-clientinitiated", Boolean.TRUE);
- setSelections(TAG_Restriction,
- "homesp", UpdateInfo.UpdateRestriction.HomeSP,
- "roamingpartner", UpdateInfo.UpdateRestriction.RoamingPartner,
- "unrestricted", UpdateInfo.UpdateRestriction.Unrestricted);
- }
-
- private static void setSelections(String key, Object... pairs) {
- Map kvp = new HashMap<>();
- sSelectionMap.put(key, kvp);
- for (int n = 0; n < pairs.length; n += 2) {
- kvp.put(pairs[n].toString(), pairs[n + 1]);
- }
- }
-
- private final File mPpsFile;
- private final boolean mEnabled;
- private final Map mSPs;
-
- public MOManager(File ppsFile, boolean hs2enabled) {
- mPpsFile = ppsFile;
- mEnabled = hs2enabled;
- mSPs = new HashMap<>();
- }
-
- public File getPpsFile() {
- return mPpsFile;
- }
-
- public boolean isEnabled() {
- return mEnabled;
- }
-
- public boolean isConfigured() {
- return mEnabled && !mSPs.isEmpty();
- }
-
- public Map getLoadedSPs() {
- return Collections.unmodifiableMap(mSPs);
- }
-
- public List loadAllSPs() throws IOException {
-
- if (!mEnabled || !mPpsFile.exists()) {
- return Collections.emptyList();
- }
-
- try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
- MOTree moTree = MOTree.unmarshal(in);
- mSPs.clear();
- if (moTree == null) {
- return Collections.emptyList(); // Empty file
- }
-
- List sps = buildSPs(moTree);
- if (sps != null) {
- for (HomeSP sp : sps) {
- if (mSPs.put(sp.getFQDN(), sp) != null) {
- throw new OMAException("Multiple SPs for FQDN '" + sp.getFQDN() + "'");
- } else {
- Log.d(OSUManager.TAG, "retrieved " + sp.getFQDN() + " from PPS");
- }
- }
- return sps;
-
- } else {
- throw new OMAException("Failed to build HomeSP");
- }
- }
- }
-
- public static HomeSP buildSP(String xml) throws IOException, SAXException {
- OMAParser omaParser = new OMAParser();
- MOTree tree = omaParser.parse(xml, OMAConstants.PPS_URN);
- List spList = buildSPs(tree);
- if (spList.size() != 1) {
- throw new OMAException("Expected exactly one HomeSP, got " + spList.size());
- }
- return spList.iterator().next();
- }
-
- public HomeSP addSP(String xml, OSUManager osuManager) throws IOException, SAXException {
- OMAParser omaParser = new OMAParser();
- return addSP(omaParser.parse(xml, OMAConstants.PPS_URN));
- }
-
- private static final List FQDNPath = Arrays.asList(TAG_HomeSP, TAG_FQDN);
-
- /**
- * R1 *only* addSP method.
- *
- * @param homeSP
- * @throws IOException
- */
- public void addSP(HomeSP homeSP) throws IOException {
- if (!mEnabled) {
- throw new IOException("HS2.0 not enabled on this device");
- }
- if (mSPs.containsKey(homeSP.getFQDN())) {
- Log.d(OSUManager.TAG, "HS20 profile for " +
- homeSP.getFQDN() + " already exists");
- return;
- }
- Log.d(OSUManager.TAG, "Adding new HS20 profile for " + homeSP.getFQDN());
-
- OMAConstructed dummyRoot = new OMAConstructed(null, TAG_PerProviderSubscription, null);
- buildHomeSPTree(homeSP, dummyRoot, mSPs.size() + 1);
- try {
- addSP(dummyRoot);
- } catch (FileNotFoundException fnfe) {
- MOTree tree =
- MOTree.buildMgmtTree(OMAConstants.PPS_URN, OMAConstants.OMAVersion, dummyRoot);
- // No file to load a pre-build MO tree from, create a new one and save it.
- //MOTree tree = new MOTree(OMAConstants.PPS_URN, OMAConstants.OMAVersion, dummyRoot);
- writeMO(tree, mPpsFile);
- }
- mSPs.put(homeSP.getFQDN(), homeSP);
- }
-
- public HomeSP addSP(MOTree instanceTree) throws IOException {
- List spList = buildSPs(instanceTree);
- if (spList.size() != 1) {
- throw new OMAException("Expected exactly one HomeSP, got " + spList.size());
- }
-
- HomeSP sp = spList.iterator().next();
- String fqdn = sp.getFQDN();
- if (mSPs.put(fqdn, sp) != null) {
- throw new OMAException("SP " + fqdn + " already exists");
- }
-
- OMAConstructed pps = (OMAConstructed) instanceTree.getRoot().
- getChild(TAG_PerProviderSubscription);
-
- try {
- addSP(pps);
- } catch (FileNotFoundException fnfe) {
- MOTree tree = new MOTree(instanceTree.getUrn(), instanceTree.getDtdRev(),
- instanceTree.getRoot());
- writeMO(tree, mPpsFile);
- }
-
- return sp;
- }
-
- /**
- * Add an SP sub-tree. mo must be PPS with an immediate instance child (e.g. Cred01) and an
- * optional UpdateIdentifier,
- *
- * @param mo The new MO
- * @throws IOException
- */
- private void addSP(OMANode mo) throws IOException {
- MOTree moTree;
- try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
- moTree = MOTree.unmarshal(in);
- moTree.getRoot().addChild(mo);
-
- /*
- OMAConstructed ppsRoot = (OMAConstructed)
- moTree.getRoot().addChild(TAG_PerProviderSubscription, "", null, null);
- for (OMANode child : mo.getChildren()) {
- ppsRoot.addChild(child);
- if (!child.isLeaf()) {
- moTree.getRoot().addChild(child);
- }
- else if (child.getName().equals(TAG_UpdateIdentifier)) {
- OMANode currentUD = moTree.getRoot().getChild(TAG_UpdateIdentifier);
- if (currentUD != null) {
- moTree.getRoot().replaceNode(currentUD, child);
- }
- else {
- moTree.getRoot().addChild(child);
- }
- }
- }
- */
- }
- writeMO(moTree, mPpsFile);
- }
-
- private static OMAConstructed findTargetTree(MOTree moTree, String fqdn) throws OMAException {
- OMANode pps = moTree.getRoot();
- for (OMANode node : pps.getChildren()) {
- OMANode instance = null;
- if (node.getName().equals(TAG_PerProviderSubscription)) {
- instance = getInstanceNode((OMAConstructed) node);
- } else if (!node.isLeaf()) {
- instance = node;
- }
- if (instance != null) {
- String nodeFqdn = getString(instance.getListValue(FQDNPath.iterator()));
- if (fqdn.equalsIgnoreCase(nodeFqdn)) {
- return (OMAConstructed) node;
- // targetTree is rooted at the PPS
- }
- }
- }
- return null;
- }
-
- private static OMAConstructed getInstanceNode(OMAConstructed root) throws OMAException {
- for (OMANode child : root.getChildren()) {
- if (!child.isLeaf()) {
- return (OMAConstructed) child;
- }
- }
- throw new OMAException("Cannot find instance node");
- }
-
- public static HomeSP modifySP(HomeSP homeSP, MOTree moTree, Collection mods)
- throws OMAException {
-
- OMAConstructed ppsTree =
- (OMAConstructed) moTree.getRoot().getChildren().iterator().next();
- OMAConstructed instance = getInstanceNode(ppsTree);
-
- int ppsMods = 0;
- int updateIdentifier = homeSP.getUpdateIdentifier();
- for (MOData mod : mods) {
- LinkedList tailPath =
- getTailPath(mod.getBaseURI(), TAG_PerProviderSubscription);
- OMAConstructed modRoot = mod.getMOTree().getRoot();
- // modRoot is the MgmtTree with the actual object as a direct child
- // (e.g. Credential)
-
- if (tailPath.getFirst().equals(TAG_UpdateIdentifier)) {
- updateIdentifier = getInteger(modRoot.getChildren().iterator().next());
- OMANode oldUdi = ppsTree.getChild(TAG_UpdateIdentifier);
- if (getInteger(oldUdi) != updateIdentifier) {
- ppsMods++;
- }
- if (oldUdi != null) {
- ppsTree.replaceNode(oldUdi, modRoot.getChild(TAG_UpdateIdentifier));
- } else {
- ppsTree.addChild(modRoot.getChild(TAG_UpdateIdentifier));
- }
- } else {
- tailPath.removeFirst(); // Drop the instance
- OMANode current = instance.getListValue(tailPath.iterator());
- if (current == null) {
- throw new OMAException("No previous node for " + tailPath + " in "
- + homeSP.getFQDN());
- }
- for (OMANode newNode : modRoot.getChildren()) {
- // newNode is something like Credential
- // current is the same existing node
- OMANode old = current.getParent().replaceNode(current, newNode);
- ppsMods++;
- }
- }
- }
-
- return ppsMods > 0 ? buildHomeSP(instance, updateIdentifier) : null;
- }
-
- public HomeSP modifySP(HomeSP homeSP, Collection mods)
- throws IOException {
-
- Log.d(OSUManager.TAG, "modifying SP: " + mods);
- MOTree moTree;
- int ppsMods = 0;
- int updateIdentifier = 0;
- try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
- moTree = MOTree.unmarshal(in);
- // moTree is PPS/?/provider-data
-
- OMAConstructed targetTree = findTargetTree(moTree, homeSP.getFQDN());
- if (targetTree == null) {
- throw new IOException("Failed to find PPS tree for " + homeSP.getFQDN());
- }
- OMAConstructed instance = getInstanceNode(targetTree);
-
- for (MOData mod : mods) {
- LinkedList tailPath =
- getTailPath(mod.getBaseURI(), TAG_PerProviderSubscription);
- OMAConstructed modRoot = mod.getMOTree().getRoot();
- // modRoot is the MgmtTree with the actual object as a direct child
- // (e.g. Credential)
-
- if (tailPath.getFirst().equals(TAG_UpdateIdentifier)) {
- updateIdentifier = getInteger(modRoot.getChildren().iterator().next());
- OMANode oldUdi = targetTree.getChild(TAG_UpdateIdentifier);
- if (getInteger(oldUdi) != updateIdentifier) {
- ppsMods++;
- }
- if (oldUdi != null) {
- targetTree.replaceNode(oldUdi, modRoot.getChild(TAG_UpdateIdentifier));
- } else {
- targetTree.addChild(modRoot.getChild(TAG_UpdateIdentifier));
- }
- } else {
- tailPath.removeFirst(); // Drop the instance
- OMANode current = instance.getListValue(tailPath.iterator());
- if (current == null) {
- throw new IOException("No previous node for " + tailPath + " in " +
- homeSP.getFQDN());
- }
- for (OMANode newNode : modRoot.getChildren()) {
- // newNode is something like Credential
- // current is the same existing node
- OMANode old = current.getParent().replaceNode(current, newNode);
- ppsMods++;
- }
- }
- }
- }
- writeMO(moTree, mPpsFile);
-
- if (ppsMods == 0) {
- return null; // HomeSP not modified.
- }
-
- // Return a new rebuilt HomeSP
- List sps = buildSPs(moTree);
- if (sps != null) {
- for (HomeSP sp : sps) {
- if (sp.getFQDN().equals(homeSP.getFQDN())) {
- return sp;
- }
- }
- } else {
- throw new OMAException("Failed to build HomeSP");
- }
- return null;
- }
-
- private static LinkedList getTailPath(String pathString, String rootName)
- throws OMAException {
- String[] path = pathString.split("/");
- int pathIndex;
- for (pathIndex = 0; pathIndex < path.length; pathIndex++) {
- if (path[pathIndex].equalsIgnoreCase(rootName)) {
- pathIndex++;
- break;
- }
- }
- if (pathIndex >= path.length) {
- throw new OMAException("Bad node-path: " + pathString);
- }
- LinkedList tailPath = new LinkedList<>();
- while (pathIndex < path.length) {
- tailPath.add(path[pathIndex]);
- pathIndex++;
- }
- return tailPath;
- }
-
- public HomeSP getHomeSP(String fqdn) {
- return mSPs.get(fqdn);
- }
-
- public void removeSP(String fqdn) throws IOException {
- if (mSPs.remove(fqdn) == null) {
- Log.d(OSUManager.TAG, "No HS20 profile to delete for " + fqdn);
- return;
- }
-
- Log.d(OSUManager.TAG, "Deleting HS20 profile for " + fqdn);
-
- MOTree moTree;
- try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
- moTree = MOTree.unmarshal(in);
- OMAConstructed tbd = findTargetTree(moTree, fqdn);
- if (tbd == null) {
- throw new IOException("Node " + fqdn + " doesn't exist in MO tree");
- }
- OMAConstructed pps = moTree.getRoot();
- OMANode removed = pps.removeNode("?", tbd);
- if (removed == null) {
- throw new IOException("Failed to remove " + fqdn + " out of MO tree");
- }
- }
- writeMO(moTree, mPpsFile);
- }
-
- public MOTree getMOTree(HomeSP homeSP) throws IOException {
- try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
- MOTree moTree = MOTree.unmarshal(in);
- OMAConstructed target = findTargetTree(moTree, homeSP.getFQDN());
- if (target == null) {
- throw new IOException("Can't find " + homeSP.getFQDN() + " in MO tree");
- }
- return MOTree.buildMgmtTree(OMAConstants.PPS_URN, OMAConstants.OMAVersion, target);
- }
- }
-
- private static void writeMO(MOTree moTree, File f) throws IOException {
- try (BufferedOutputStream out =
- new BufferedOutputStream(new FileOutputStream(f, false))) {
- moTree.marshal(out);
- out.flush();
- }
- }
-
- private static String fqdnList(Collection sps) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (HomeSP sp : sps) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(sp.getFQDN());
- }
- return sb.toString();
- }
-
- private static OMANode buildHomeSPTree(HomeSP homeSP, OMAConstructed root, int instanceID)
- throws IOException {
- OMANode providerSubNode = root.addChild(getInstanceString(instanceID),
- null, null, null);
-
- // The HomeSP:
- OMANode homeSpNode = providerSubNode.addChild(TAG_HomeSP, null, null, null);
- if (!homeSP.getSSIDs().isEmpty()) {
- OMAConstructed nwkIDNode =
- (OMAConstructed) homeSpNode.addChild(TAG_NetworkID, null, null, null);
- int instance = 0;
- for (Map.Entry entry : homeSP.getSSIDs().entrySet()) {
- OMAConstructed inode =
- (OMAConstructed) nwkIDNode
- .addChild(getInstanceString(instance++), null, null, null);
- inode.addChild(TAG_SSID, null, entry.getKey(), null);
- if (entry.getValue() != null) {
- inode.addChild(TAG_HESSID, null,
- String.format("%012x", entry.getValue()), null);
- }
- }
- }
-
- homeSpNode.addChild(TAG_FriendlyName, null, homeSP.getFriendlyName(), null);
-
- if (homeSP.getIconURL() != null) {
- homeSpNode.addChild(TAG_IconURL, null, homeSP.getIconURL(), null);
- }
-
- homeSpNode.addChild(TAG_FQDN, null, homeSP.getFQDN(), null);
-
- if (!homeSP.getMatchAllOIs().isEmpty() || !homeSP.getMatchAnyOIs().isEmpty()) {
- OMAConstructed homeOIList =
- (OMAConstructed) homeSpNode.addChild(TAG_HomeOIList, null, null, null);
-
- int instance = 0;
- for (Long oi : homeSP.getMatchAllOIs()) {
- OMAConstructed inode =
- (OMAConstructed) homeOIList.addChild(getInstanceString(instance++),
- null, null, null);
- inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null);
- inode.addChild(TAG_HomeOIRequired, null, "TRUE", null);
- }
- for (Long oi : homeSP.getMatchAnyOIs()) {
- OMAConstructed inode =
- (OMAConstructed) homeOIList.addChild(getInstanceString(instance++),
- null, null, null);
- inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null);
- inode.addChild(TAG_HomeOIRequired, null, "FALSE", null);
- }
- }
-
- if (!homeSP.getOtherHomePartners().isEmpty()) {
- OMAConstructed otherPartners =
- (OMAConstructed) homeSpNode.addChild(TAG_OtherHomePartners, null, null, null);
- int instance = 0;
- for (String fqdn : homeSP.getOtherHomePartners()) {
- OMAConstructed inode =
- (OMAConstructed) otherPartners.addChild(getInstanceString(instance++),
- null, null, null);
- inode.addChild(TAG_FQDN, null, fqdn, null);
- }
- }
-
- if (!homeSP.getRoamingConsortiums().isEmpty()) {
- homeSpNode.addChild(TAG_RoamingConsortiumOI, null,
- getRCList(homeSP.getRoamingConsortiums()), null);
- }
-
- // The Credential:
- OMANode credentialNode = providerSubNode.addChild(TAG_Credential, null, null, null);
- Credential cred = homeSP.getCredential();
- EAPMethod method = cred.getEAPMethod();
-
- if (cred.getCtime() > 0) {
- credentialNode.addChild(TAG_CreationDate,
- null, DTFormat.format(new Date(cred.getCtime())), null);
- }
- if (cred.getExpTime() > 0) {
- credentialNode.addChild(TAG_ExpirationDate,
- null, DTFormat.format(new Date(cred.getExpTime())), null);
- }
-
- if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_SIM
- || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKA
- || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKAPrim) {
-
- OMANode simNode = credentialNode.addChild(TAG_SIM, null, null, null);
- simNode.addChild(TAG_IMSI, null, cred.getImsi().toString(), null);
- simNode.addChild(TAG_EAPType, null,
- Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null);
-
- } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TTLS) {
-
- OMANode unpNode = credentialNode.addChild(TAG_UsernamePassword, null, null, null);
- unpNode.addChild(TAG_Username, null, cred.getUserName(), null);
- unpNode.addChild(TAG_Password, null,
- Base64.encodeToString(cred.getPassword().getBytes(StandardCharsets.UTF_8),
- Base64.DEFAULT), null);
- OMANode eapNode = unpNode.addChild(TAG_EAPMethod, null, null, null);
- eapNode.addChild(TAG_EAPType, null,
- Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null);
- eapNode.addChild(TAG_InnerMethod, null,
- ((NonEAPInnerAuth) method.getAuthParam()).getOMAtype(), null);
-
- } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TLS) {
-
- OMANode certNode = credentialNode.addChild(TAG_DigitalCertificate, null, null, null);
- certNode.addChild(TAG_CertificateType, null, Credential.CertTypeX509, null);
- certNode.addChild(TAG_CertSHA256Fingerprint, null,
- Utils.toHex(cred.getFingerPrint()), null);
-
- } else {
- throw new OMAException("Invalid credential on " + homeSP.getFQDN());
- }
-
- credentialNode.addChild(TAG_Realm, null, cred.getRealm(), null);
-
- // !!! Note: This node defines CRL checking through OSCP, I suspect we won't be able
- // to do that so it is commented out:
- //credentialNode.addChild(TAG_CheckAAAServerCertStatus, null, "TRUE", null);
- return providerSubNode;
- }
-
- private static String getInstanceString(int instance) {
- return "r1i" + instance;
- }
-
- private static String getRCList(Collection rcs) {
- StringBuilder builder = new StringBuilder();
- boolean first = true;
- for (Long roamingConsortium : rcs) {
- if (first) {
- first = false;
- } else {
- builder.append(',');
- }
- builder.append(String.format("%x", roamingConsortium));
- }
- return builder.toString();
- }
-
- public static List buildSPs(MOTree moTree) throws OMAException {
- OMAConstructed spList;
- List homeSPs = new ArrayList<>();
- if (moTree.getRoot().getName().equals(TAG_PerProviderSubscription)) {
- // The old PPS file was rooted at PPS instead of MgmtTree to conserve space
- spList = moTree.getRoot();
-
- if (spList == null) {
- return homeSPs;
- }
-
- for (OMANode node : spList.getChildren()) {
- if (!node.isLeaf()) {
- homeSPs.add(buildHomeSP(node, 0));
- }
- }
- } else {
- for (OMANode ppsRoot : moTree.getRoot().getChildren()) {
- if (ppsRoot.getName().equals(TAG_PerProviderSubscription)) {
- Integer updateIdentifier = null;
- OMANode instance = null;
- for (OMANode child : ppsRoot.getChildren()) {
- if (child.getName().equals(TAG_UpdateIdentifier)) {
- updateIdentifier = getInteger(child);
- } else if (!child.isLeaf()) {
- instance = child;
- }
- }
- if (instance == null) {
- throw new OMAException("PPS node missing instance node");
- }
- homeSPs.add(buildHomeSP(instance,
- updateIdentifier != null ? updateIdentifier : 0));
- }
- }
- }
-
- return homeSPs;
- }
-
- private static HomeSP buildHomeSP(OMANode ppsRoot, int updateIdentifier) throws OMAException {
- OMANode spRoot = ppsRoot.getChild(TAG_HomeSP);
-
- String fqdn = spRoot.getScalarValue(Arrays.asList(TAG_FQDN).iterator());
- String friendlyName = spRoot.getScalarValue(Arrays.asList(TAG_FriendlyName).iterator());
- String iconURL = spRoot.getScalarValue(Arrays.asList(TAG_IconURL).iterator());
-
- HashSet roamingConsortiums = new HashSet<>();
- String oiString = spRoot.getScalarValue(Arrays.asList(TAG_RoamingConsortiumOI).iterator());
- if (oiString != null) {
- for (String oi : oiString.split(",")) {
- roamingConsortiums.add(Long.parseLong(oi.trim(), 16));
- }
- }
-
- Map ssids = new HashMap<>();
-
- OMANode ssidListNode = spRoot.getListValue(Arrays.asList(TAG_NetworkID).iterator());
- if (ssidListNode != null) {
- for (OMANode ssidRoot : ssidListNode.getChildren()) {
- OMANode hessidNode = ssidRoot.getChild(TAG_HESSID);
- ssids.put(ssidRoot.getChild(TAG_SSID).getValue(), getMac(hessidNode));
- }
- }
-
- Set matchAnyOIs = new HashSet<>();
- List matchAllOIs = new ArrayList<>();
- OMANode homeOIListNode = spRoot.getListValue(Arrays.asList(TAG_HomeOIList).iterator());
- if (homeOIListNode != null) {
- for (OMANode homeOIRoot : homeOIListNode.getChildren()) {
- String homeOI = homeOIRoot.getChild(TAG_HomeOI).getValue();
- if (Boolean.parseBoolean(homeOIRoot.getChild(TAG_HomeOIRequired).getValue())) {
- matchAllOIs.add(Long.parseLong(homeOI, 16));
- } else {
- matchAnyOIs.add(Long.parseLong(homeOI, 16));
- }
- }
- }
-
- Set otherHomePartners = new HashSet<>();
- OMANode otherListNode =
- spRoot.getListValue(Arrays.asList(TAG_OtherHomePartners).iterator());
- if (otherListNode != null) {
- for (OMANode fqdnNode : otherListNode.getChildren()) {
- otherHomePartners.add(fqdnNode.getChild(TAG_FQDN).getValue());
- }
- }
-
- Credential credential = buildCredential(ppsRoot.getChild(TAG_Credential));
-
- OMANode policyNode = ppsRoot.getChild(TAG_Policy);
- Policy policy = policyNode != null ? new Policy(policyNode) : null;
-
- Map aaaTrustRoots;
- OMANode aaaRootNode = ppsRoot.getChild(TAG_AAAServerTrustRoot);
- if (aaaRootNode == null) {
- aaaTrustRoots = null;
- } else {
- aaaTrustRoots = new HashMap<>(aaaRootNode.getChildren().size());
- for (OMANode child : aaaRootNode.getChildren()) {
- aaaTrustRoots.put(getString(child, TAG_CertURL),
- getString(child, TAG_CertSHA256Fingerprint));
- }
- }
-
- OMANode updateNode = ppsRoot.getChild(TAG_SubscriptionUpdate);
- UpdateInfo subscriptionUpdate = updateNode != null ? new UpdateInfo(updateNode) : null;
- OMANode subNode = ppsRoot.getChild(TAG_SubscriptionParameters);
- SubscriptionParameters subscriptionParameters = subNode != null ?
- new SubscriptionParameters(subNode) : null;
-
- return new HomeSP(ssids, fqdn, roamingConsortiums, otherHomePartners,
- matchAnyOIs, matchAllOIs, friendlyName, iconURL, credential,
- policy, getInteger(ppsRoot.getChild(TAG_CredentialPriority), 0),
- aaaTrustRoots, subscriptionUpdate, subscriptionParameters, updateIdentifier);
- }
-
- private static Credential buildCredential(OMANode credNode) throws OMAException {
- long ctime = getTime(credNode.getChild(TAG_CreationDate));
- long expTime = getTime(credNode.getChild(TAG_ExpirationDate));
- String realm = getString(credNode.getChild(TAG_Realm));
- boolean checkAAACert = getBoolean(credNode.getChild(TAG_CheckAAAServerCertStatus));
-
- OMANode unNode = credNode.getChild(TAG_UsernamePassword);
- OMANode certNode = credNode.getChild(TAG_DigitalCertificate);
- OMANode simNode = credNode.getChild(TAG_SIM);
-
- int alternatives = 0;
- alternatives += unNode != null ? 1 : 0;
- alternatives += certNode != null ? 1 : 0;
- alternatives += simNode != null ? 1 : 0;
- if (alternatives != 1) {
- throw new OMAException("Expected exactly one credential type, got " + alternatives);
- }
-
- if (unNode != null) {
- String userName = getString(unNode.getChild(TAG_Username));
- String password = getString(unNode.getChild(TAG_Password));
- boolean machineManaged = getBoolean(unNode.getChild(TAG_MachineManaged));
- String softTokenApp = getString(unNode.getChild(TAG_SoftTokenApp));
- boolean ableToShare = getBoolean(unNode.getChild(TAG_AbleToShare));
-
- OMANode eapMethodNode = unNode.getChild(TAG_EAPMethod);
- int eapID = getInteger(eapMethodNode.getChild(TAG_EAPType));
-
- EAP.EAPMethodID eapMethodID = EAP.mapEAPMethod(eapID);
- if (eapMethodID == null) {
- throw new OMAException("Unknown EAP method: " + eapID);
- }
-
- Long vid = getOptionalInteger(eapMethodNode.getChild(TAG_VendorId));
- Long vtype = getOptionalInteger(eapMethodNode.getChild(TAG_VendorType));
- Long innerEAPType = getOptionalInteger(eapMethodNode.getChild(TAG_InnerEAPType));
- EAP.EAPMethodID innerEAPMethod = null;
- if (innerEAPType != null) {
- innerEAPMethod = EAP.mapEAPMethod(innerEAPType.intValue());
- if (innerEAPMethod == null) {
- throw new OMAException("Bad inner EAP method: " + innerEAPType);
- }
- }
-
- Long innerVid = getOptionalInteger(eapMethodNode.getChild(TAG_InnerVendorID));
- Long innerVtype = getOptionalInteger(eapMethodNode.getChild(TAG_InnerVendorType));
- String innerNonEAPMethod = getString(eapMethodNode.getChild(TAG_InnerMethod));
-
- EAPMethod eapMethod;
- if (innerEAPMethod != null) {
- eapMethod = new EAPMethod(eapMethodID, new InnerAuthEAP(innerEAPMethod));
- } else if (vid != null) {
- eapMethod = new EAPMethod(eapMethodID,
- new ExpandedEAPMethod(EAP.AuthInfoID.ExpandedEAPMethod,
- vid.intValue(), vtype));
- } else if (innerVid != null) {
- eapMethod =
- new EAPMethod(eapMethodID, new ExpandedEAPMethod(EAP.AuthInfoID
- .ExpandedInnerEAPMethod, innerVid.intValue(), innerVtype));
- } else if (innerNonEAPMethod != null) {
- eapMethod = new EAPMethod(eapMethodID, new NonEAPInnerAuth(innerNonEAPMethod));
- } else {
- throw new OMAException("Incomplete set of EAP parameters");
- }
-
- return new Credential(ctime, expTime, realm, checkAAACert, eapMethod, userName,
- password, machineManaged, softTokenApp, ableToShare);
- }
- if (certNode != null) {
- try {
- String certTypeString = getString(certNode.getChild(TAG_CertificateType));
- byte[] fingerPrint = getOctets(certNode.getChild(TAG_CertSHA256Fingerprint));
-
- EAPMethod eapMethod = new EAPMethod(EAP.EAPMethodID.EAP_TLS, null);
-
- return new Credential(ctime, expTime, realm, checkAAACert, eapMethod,
- Credential.mapCertType(certTypeString), fingerPrint);
- } catch (NumberFormatException nfe) {
- throw new OMAException("Bad hex string: " + nfe.toString());
- }
- }
- if (simNode != null) {
- try {
- IMSIParameter imsi = new IMSIParameter(getString(simNode.getChild(TAG_IMSI)));
-
- EAPMethod eapMethod =
- new EAPMethod(EAP.mapEAPMethod(getInteger(simNode.getChild(TAG_EAPType))),
- null);
-
- return new Credential(ctime, expTime, realm, checkAAACert, eapMethod, imsi);
- } catch (IOException ioe) {
- throw new OMAException("Failed to parse IMSI: " + ioe);
- }
- }
- throw new OMAException("Missing credential parameters");
- }
-
- public static OMANode getChild(OMANode node, String key) throws OMAException {
- OMANode child = node.getChild(key);
- if (child == null) {
- throw new OMAException("No such node: " + key);
- }
- return child;
- }
-
- public static String getString(OMANode node, String key) throws OMAException {
- OMANode child = node.getChild(key);
- if (child == null) {
- throw new OMAException("Missing value for " + key);
- } else if (!child.isLeaf()) {
- throw new OMAException(key + " is not a leaf node");
- }
- return child.getValue();
- }
-
- public static long getLong(OMANode node, String key, Long dflt) throws OMAException {
- OMANode child = node.getChild(key);
- if (child == null) {
- if (dflt != null) {
- return dflt;
- } else {
- throw new OMAException("Missing value for " + key);
- }
- } else {
- if (!child.isLeaf()) {
- throw new OMAException(key + " is not a leaf node");
- }
- String value = child.getValue();
- try {
- long result = Long.parseLong(value);
- if (result < 0) {
- throw new OMAException("Negative value for " + key);
- }
- return result;
- } catch (NumberFormatException nfe) {
- throw new OMAException("Value for " + key + " is non-numeric: " + value);
- }
- }
- }
-
- public static T getSelection(OMANode node, String key) throws OMAException {
- OMANode child = node.getChild(key);
- if (child == null) {
- throw new OMAException("Missing value for " + key);
- } else if (!child.isLeaf()) {
- throw new OMAException(key + " is not a leaf node");
- }
- return getSelection(key, child.getValue());
- }
-
- public static T getSelection(String key, String value) throws OMAException {
- if (value == null) {
- throw new OMAException("No value for " + key);
- }
- Map kvp = sSelectionMap.get(key);
- T result = (T) kvp.get(value.toLowerCase());
- if (result == null) {
- throw new OMAException("Invalid value '" + value + "' for " + key);
- }
- return result;
- }
-
- private static boolean getBoolean(OMANode boolNode) {
- return boolNode != null && Boolean.parseBoolean(boolNode.getValue());
- }
-
- public static String getString(OMANode stringNode) {
- return stringNode != null ? stringNode.getValue() : null;
- }
-
- private static int getInteger(OMANode intNode, int dflt) throws OMAException {
- if (intNode == null) {
- return dflt;
- }
- return getInteger(intNode);
- }
-
- private static int getInteger(OMANode intNode) throws OMAException {
- if (intNode == null) {
- throw new OMAException("Missing integer value");
- }
- try {
- return Integer.parseInt(intNode.getValue());
- } catch (NumberFormatException nfe) {
- throw new OMAException("Invalid integer: " + intNode.getValue());
- }
- }
-
- private static Long getMac(OMANode macNode) throws OMAException {
- if (macNode == null) {
- return null;
- }
- try {
- return Long.parseLong(macNode.getValue(), 16);
- } catch (NumberFormatException nfe) {
- throw new OMAException("Invalid MAC: " + macNode.getValue());
- }
- }
-
- private static Long getOptionalInteger(OMANode intNode) throws OMAException {
- if (intNode == null) {
- return null;
- }
- try {
- return Long.parseLong(intNode.getValue());
- } catch (NumberFormatException nfe) {
- throw new OMAException("Invalid integer: " + intNode.getValue());
- }
- }
-
- public static long getTime(OMANode timeNode) throws OMAException {
- if (timeNode == null) {
- return Utils.UNSET_TIME;
- }
- String timeText = timeNode.getValue();
- try {
- Date date = DTFormat.parse(timeText);
- return date.getTime();
- } catch (ParseException pe) {
- throw new OMAException("Badly formatted time: " + timeText);
- }
- }
-
- private static byte[] getOctets(OMANode octetNode) throws OMAException {
- if (octetNode == null) {
- throw new OMAException("Missing byte value");
- }
- return Utils.hexToBytes(octetNode.getValue());
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/MOTree.java b/packages/Osu/src/com/android/hotspot2/omadm/MOTree.java
deleted file mode 100644
index 0c5ce4065239d..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/MOTree.java
+++ /dev/null
@@ -1,269 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import org.xml.sax.SAXException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public class MOTree {
- public static final String MgmtTreeTag = "MgmtTree";
-
- public static final String NodeTag = "Node";
- public static final String NodeNameTag = "NodeName";
- public static final String PathTag = "Path";
- public static final String ValueTag = "Value";
- public static final String RTPropTag = "RTProperties";
- public static final String TypeTag = "Type";
- public static final String DDFNameTag = "DDFName";
-
- private final String mUrn;
- private final String mDtdRev;
- private final OMAConstructed mRoot;
-
- public MOTree(XMLNode node, String urn) throws IOException, SAXException {
- Iterator children = node.getChildren().iterator();
-
- String dtdRev = null;
-
- while (children.hasNext()) {
- XMLNode child = children.next();
- if (child.getTag().equals(OMAConstants.SyncMLVersionTag)) {
- dtdRev = child.getText();
- children.remove();
- break;
- }
- }
-
- mUrn = urn;
- mDtdRev = dtdRev;
-
- mRoot = new MgmtTreeRoot(node, dtdRev);
-
- for (XMLNode child : node.getChildren()) {
- buildNode(mRoot, child);
- }
- }
-
- public MOTree(String urn, String rev, OMAConstructed root) throws IOException {
- mUrn = urn;
- mDtdRev = rev;
- mRoot = root;
- }
-
- public static MOTree buildMgmtTree(String urn, String rev, OMAConstructed root)
- throws IOException {
- OMAConstructed realRoot;
- switch (urn) {
- case OMAConstants.PPS_URN:
- case OMAConstants.DevInfoURN:
- case OMAConstants.DevDetailURN:
- case OMAConstants.DevDetailXURN:
- realRoot = new MgmtTreeRoot(OMAConstants.OMAVersion);
- realRoot.addChild(root);
- return new MOTree(urn, rev, realRoot);
- default:
- return new MOTree(urn, rev, root);
- }
- }
-
- public static boolean hasMgmtTreeTag(String text) {
- for (int n = 0; n < text.length(); n++) {
- char ch = text.charAt(n);
- if (ch > ' ') {
- return text.regionMatches(true, n, '<' + MgmtTreeTag + '>',
- 0, MgmtTreeTag.length() + 2);
- }
- }
- return false;
- }
-
- private static class NodeData {
- private final String mName;
- private String mPath;
- private String mValue;
-
- private NodeData(String name) {
- mName = name;
- }
-
- private void setPath(String path) {
- mPath = path;
- }
-
- private void setValue(String value) {
- mValue = value;
- }
-
- public String getName() {
- return mName;
- }
-
- public String getPath() {
- return mPath;
- }
-
- public String getValue() {
- return mValue;
- }
- }
-
- private static void buildNode(OMANode parent, XMLNode node) throws IOException {
- if (!node.getTag().equals(NodeTag))
- throw new IOException("Node is a '" + node.getTag() + "' instead of a 'Node'");
-
- Map checkMap = new HashMap<>(3);
- String context = null;
- List values = new ArrayList<>();
- List children = new ArrayList<>();
-
- NodeData curValue = null;
-
- for (XMLNode child : node.getChildren()) {
- XMLNode old = checkMap.put(child.getTag(), child);
-
- switch (child.getTag()) {
- case NodeNameTag:
- if (curValue != null)
- throw new IOException(NodeNameTag + " not expected");
- curValue = new NodeData(child.getText());
-
- break;
- case PathTag:
- if (curValue == null || curValue.getPath() != null)
- throw new IOException(PathTag + " not expected");
- curValue.setPath(child.getText());
-
- break;
- case ValueTag:
- if (!children.isEmpty())
- throw new IOException(ValueTag + " in constructed node");
- if (curValue == null || curValue.getValue() != null)
- throw new IOException(ValueTag + " not expected");
- curValue.setValue(child.getText());
- values.add(curValue);
- curValue = null;
-
- break;
- case RTPropTag:
- if (old != null)
- throw new IOException("Duplicate " + RTPropTag);
- XMLNode typeNode = getNextNode(child, TypeTag);
- XMLNode ddfName = getNextNode(typeNode, DDFNameTag);
- context = ddfName.getText();
- if (context == null)
- throw new IOException("No text in " + DDFNameTag);
-
- break;
- case NodeTag:
- if (!values.isEmpty())
- throw new IOException("Scalar node " + node.getText() + " has Node child");
- children.add(child);
-
- break;
- }
- }
-
- if (values.isEmpty()) {
- if (curValue == null)
- throw new IOException("Missing name");
-
- OMANode subNode = parent.addChild(curValue.getName(),
- context, null, curValue.getPath());
-
- for (XMLNode child : children) {
- buildNode(subNode, child);
- }
- } else {
- if (!children.isEmpty())
- throw new IOException("Got both sub nodes and value(s)");
-
- for (NodeData nodeData : values) {
- parent.addChild(nodeData.getName(), context,
- nodeData.getValue(), nodeData.getPath());
- }
- }
- }
-
- private static XMLNode getNextNode(XMLNode node, String tag) throws IOException {
- if (node == null)
- throw new IOException("No node for " + tag);
- if (node.getChildren().size() != 1)
- throw new IOException("Expected " + node.getTag() + " to have exactly one child");
- XMLNode child = node.getChildren().iterator().next();
- if (!child.getTag().equals(tag))
- throw new IOException("Expected " + node.getTag() + " to have child '" + tag +
- "' instead of '" + child.getTag() + "'");
- return child;
- }
-
- public String getUrn() {
- return mUrn;
- }
-
- public String getDtdRev() {
- return mDtdRev;
- }
-
- public OMAConstructed getRoot() {
- return mRoot;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("MO Tree v").append(mDtdRev).append(", urn ").append(mUrn).append(")\n");
- sb.append(mRoot);
-
- return sb.toString();
- }
-
- public void marshal(OutputStream out) throws IOException {
- out.write("tree ".getBytes(StandardCharsets.UTF_8));
- OMAConstants.serializeString(mDtdRev, out);
- out.write(String.format("(%s)\n", mUrn).getBytes(StandardCharsets.UTF_8));
- mRoot.marshal(out, 0);
- }
-
- public static MOTree unmarshal(InputStream in) throws IOException {
- boolean strip = true;
- StringBuilder tree = new StringBuilder();
- for (; ; ) {
- int octet = in.read();
- if (octet < 0) {
- return null;
- } else if (octet > ' ') {
- tree.append((char) octet);
- strip = false;
- } else if (!strip) {
- break;
- }
- }
- if (!tree.toString().equals("tree")) {
- throw new IOException("Not a tree: " + tree);
- }
-
- String version = OMAConstants.deserializeString(in);
- int next = in.read();
- if (next != '(') {
- throw new IOException("Expected URN in tree definition");
- }
- String urn = OMAConstants.readURN(in);
-
- OMAConstructed root = OMANode.unmarshal(in);
-
- return new MOTree(urn, version, root);
- }
-
- public String toXml() {
- StringBuilder sb = new StringBuilder();
- mRoot.toXml(sb);
- return sb.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/MgmtTreeRoot.java b/packages/Osu/src/com/android/hotspot2/omadm/MgmtTreeRoot.java
deleted file mode 100644
index 9416140e9e182..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/MgmtTreeRoot.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.util.Map;
-
-public class MgmtTreeRoot extends OMAConstructed {
- private final String mDtdRev;
-
- public MgmtTreeRoot(XMLNode node, String dtdRev) {
- super(null, MOTree.MgmtTreeTag, null, new MultiValueMap(),
- node.getTextualAttributes());
- mDtdRev = dtdRev;
- }
-
- public MgmtTreeRoot(String dtdRev) {
- super(null, MOTree.MgmtTreeTag, null, "xmlns", OMAConstants.SyncML);
- mDtdRev = dtdRev;
- }
-
- @Override
- public void toXml(StringBuilder sb) {
- sb.append('<').append(MOTree.MgmtTreeTag);
- if (getAttributes() != null && !getAttributes().isEmpty()) {
- for (Map.Entry avp : getAttributes().entrySet()) {
- sb.append(' ').append(avp.getKey()).append("=\"")
- .append(avp.getValue()).append('"');
- }
- }
- sb.append(">\n");
-
- sb.append('<').append(OMAConstants.SyncMLVersionTag).append('>').append(mDtdRev)
- .append("").append(OMAConstants.SyncMLVersionTag).append(">\n");
- for (OMANode child : getChildren()) {
- child.toXml(sb);
- }
- sb.append("").append(MOTree.MgmtTreeTag).append(">\n");
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/MultiValueMap.java b/packages/Osu/src/com/android/hotspot2/omadm/MultiValueMap.java
deleted file mode 100644
index ead0dbc79d6a0..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/MultiValueMap.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class MultiValueMap {
- private final Map> mMap = new LinkedHashMap<>();
-
- public void put(String key, T value) {
- key = key.toLowerCase();
- ArrayList values = mMap.get(key);
- if (values == null) {
- values = new ArrayList<>();
- mMap.put(key, values);
- }
- values.add(value);
- }
-
- public T get(String key) {
- key = key.toLowerCase();
- List values = mMap.get(key);
- if (values == null) {
- return null;
- } else if (values.size() == 1) {
- return values.get(0);
- } else {
- throw new IllegalArgumentException("Cannot do get on multi-value");
- }
- }
-
- public T replace(String key, T oldValue, T newValue) {
- key = key.toLowerCase();
- List values = mMap.get(key);
- if (values == null) {
- return null;
- }
-
- for (int n = 0; n < values.size(); n++) {
- T value = values.get(n);
- if (value == oldValue) {
- values.set(n, newValue);
- return value;
- }
- }
- return null;
- }
-
- public T remove(String key, T value) {
- key = key.toLowerCase();
- List values = mMap.get(key);
- if (values == null) {
- return null;
- }
-
- T result = null;
- Iterator valueIterator = values.iterator();
- while (valueIterator.hasNext()) {
- if (valueIterator.next() == value) {
- valueIterator.remove();
- result = value;
- break;
- }
- }
- if (values.isEmpty()) {
- mMap.remove(key);
- }
- return result;
- }
-
- public T remove(T value) {
- T result = null;
- Iterator>> iterator = mMap.entrySet().iterator();
- while (iterator.hasNext()) {
- ArrayList values = iterator.next().getValue();
- Iterator valueIterator = values.iterator();
- while (valueIterator.hasNext()) {
- if (valueIterator.next() == value) {
- valueIterator.remove();
- result = value;
- break;
- }
- }
- if (result != null) {
- if (values.isEmpty()) {
- iterator.remove();
- }
- break;
- }
- }
- return result;
- }
-
- public Collection values() {
- List allValues = new ArrayList<>(mMap.size());
- for (List values : mMap.values()) {
- for (T value : values) {
- allValues.add(value);
- }
- }
- return allValues;
- }
-
- public T getSingletonValue() {
- if (mMap.size() != 1) {
- throw new IllegalArgumentException("Map is not a single entry map");
- }
- List values = mMap.values().iterator().next();
- if (values.size() != 1) {
- throw new IllegalArgumentException("Map is not a single entry map");
- }
- return values.iterator().next();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/NodeAttribute.java b/packages/Osu/src/com/android/hotspot2/omadm/NodeAttribute.java
deleted file mode 100644
index e4a08b37ae8ab..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/NodeAttribute.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.android.hotspot2.omadm;
-
-public class NodeAttribute {
- private final String mName;
- private final String mType;
- private final String mValue;
-
- public NodeAttribute(String name, String type, String value) {
- mName = name;
- mType = type;
- mValue = value;
- }
-
- public String getName() {
- return mName;
- }
-
- public String getValue() {
- return mValue;
- }
-
- public String getType() {
- return mType;
- }
-
- @Override
- public String toString() {
- return String.format("%s (%s) = '%s'", mName, mType, mValue);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMAConstants.java b/packages/Osu/src/com/android/hotspot2/omadm/OMAConstants.java
deleted file mode 100644
index 92d8ed7e991b7..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMAConstants.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import com.android.hotspot2.osu.OSUError;
-import com.android.hotspot2.osu.OSUStatus;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-
-public class OMAConstants {
- private OMAConstants() {
- }
-
- public static final String MOVersion = "1.0";
- public static final String PPS_URN = "urn:wfa:mo:hotspot2dot0-perprovidersubscription:1.0";
- public static final String DevInfoURN = "urn:oma:mo:oma-dm-devinfo:1.0";
- public static final String DevDetailURN = "urn:oma:mo:oma-dm-devdetail:1.0";
- public static final String DevDetailXURN = "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0";
-
- public static final String[] SupportedMO_URNs = {
- PPS_URN, DevInfoURN, DevDetailURN, DevDetailXURN
- };
-
- public static final String SppMOAttribute = "spp:moURN";
- public static final String TAG_PostDevData = "spp:sppPostDevData";
- public static final String TAG_SupportedVersions = "spp:supportedSPPVersions";
- public static final String TAG_SupportedMOs = "spp:supportedMOList";
- public static final String TAG_UpdateResponse = "spp:sppUpdateResponse";
- public static final String TAG_MOContainer = "spp:moContainer";
- public static final String TAG_Version = "spp:sppVersion";
-
- public static final String TAG_SessionID = "spp:sessionID";
- public static final String TAG_Status = "spp:sppStatus";
- public static final String TAG_Error = "spp:sppError";
-
- public static final String SyncMLVersionTag = "VerDTD";
- public static final String OMAVersion = "1.2";
- public static final String SyncML = "syncml:dmddf1.2";
-
- private static final byte[] INDENT = new byte[1024];
-
- private static final Map sStatusStrings = new EnumMap<>(OSUStatus.class);
- private static final Map sStatusEnums = new HashMap<>();
- private static final Map sErrorStrings = new EnumMap<>(OSUError.class);
- private static final Map sErrorEnums = new HashMap<>();
-
- static {
- sStatusStrings.put(OSUStatus.OK, "OK");
- sStatusStrings.put(OSUStatus.ProvComplete,
- "Provisioning complete, request sppUpdateResponse");
- sStatusStrings.put(OSUStatus.RemediationComplete,
- "Remediation complete, request sppUpdateResponse");
- sStatusStrings.put(OSUStatus.UpdateComplete, "Update complete, request sppUpdateResponse");
- sStatusStrings.put(OSUStatus.ExchangeComplete, "Exchange complete, release TLS connection");
- sStatusStrings.put(OSUStatus.Unknown, "No update available at this time");
- sStatusStrings.put(OSUStatus.Error, "Error occurred");
-
- for (Map.Entry entry : sStatusStrings.entrySet()) {
- sStatusEnums.put(entry.getValue().toLowerCase(), entry.getKey());
- }
-
- sErrorStrings.put(OSUError.SPPversionNotSupported, "SPP version not supported");
- sErrorStrings.put(OSUError.MOsNotSupported, "One or more mandatory MOs not supported");
- sErrorStrings.put(OSUError.CredentialsFailure,
- "Credentials cannot be provisioned at this time");
- sErrorStrings.put(OSUError.RemediationFailure,
- "Remediation cannot be completed at this time");
- sErrorStrings.put(OSUError.ProvisioningFailed,
- "Provisioning cannot be completed at this time");
- sErrorStrings.put(OSUError.ExistingCertificate, "Continue to use existing certificate");
- sErrorStrings.put(OSUError.CookieInvalid, "Cookie invalid");
- sErrorStrings.put(OSUError.WebSessionID,
- "No corresponding web-browser-connection Session ID");
- sErrorStrings.put(OSUError.PermissionDenied, "Permission denied");
- sErrorStrings.put(OSUError.CommandFailed, "Command failed");
- sErrorStrings.put(OSUError.MOaddOrUpdateFailed, "MO addition or update failed");
- sErrorStrings.put(OSUError.DeviceFull, "Device full");
- sErrorStrings.put(OSUError.BadTreeURI, "Bad management tree URI");
- sErrorStrings.put(OSUError.TooLarge, "Requested entity too large");
- sErrorStrings.put(OSUError.CommandNotAllowed, "Command not allowed");
- sErrorStrings.put(OSUError.UserAborted, "Command not executed due to user");
- sErrorStrings.put(OSUError.NotFound, "Not found");
- sErrorStrings.put(OSUError.Other, "Other");
-
- for (Map.Entry entry : sErrorStrings.entrySet()) {
- sErrorEnums.put(entry.getValue().toLowerCase(), entry.getKey());
- }
- Arrays.fill(INDENT, (byte) ' ');
- }
-
- public static String mapStatus(OSUStatus status) {
- return sStatusStrings.get(status);
- }
-
- public static OSUStatus mapStatus(String status) {
- return sStatusEnums.get(status.toLowerCase());
- }
-
- public static String mapError(OSUError error) {
- return sErrorStrings.get(error);
- }
-
- public static OSUError mapError(String error) {
- return sErrorEnums.get(error.toLowerCase());
- }
-
- public static void serializeString(String s, OutputStream out) throws IOException {
- byte[] octets = s.getBytes(StandardCharsets.UTF_8);
- byte[] prefix = String.format("%x:", octets.length).getBytes(StandardCharsets.UTF_8);
- out.write(prefix);
- out.write(octets);
- }
-
- public static void indent(int level, OutputStream out) throws IOException {
- out.write(INDENT, 0, level);
- }
-
- public static String deserializeString(InputStream in) throws IOException {
- StringBuilder prefix = new StringBuilder();
- for (; ; ) {
- byte b = (byte) in.read();
- if (b == '.')
- return null;
- else if (b == ':')
- break;
- else if (b > ' ')
- prefix.append((char) b);
- }
- int length = Integer.parseInt(prefix.toString(), 16);
- byte[] octets = new byte[length];
- int offset = 0;
- while (offset < octets.length) {
- int amount = in.read(octets, offset, octets.length - offset);
- if (amount <= 0)
- throw new EOFException();
- offset += amount;
- }
- return new String(octets, StandardCharsets.UTF_8);
- }
-
- public static String readURN(InputStream in) throws IOException {
- StringBuilder urn = new StringBuilder();
-
- for (; ; ) {
- byte b = (byte) in.read();
- if (b == ')')
- break;
- urn.append((char) b);
- }
- return urn.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMAConstructed.java b/packages/Osu/src/com/android/hotspot2/omadm/OMAConstructed.java
deleted file mode 100644
index e5285f294f9b5..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMAConstructed.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-
-public class OMAConstructed extends OMANode {
- private final MultiValueMap mChildren;
-
- public OMAConstructed(OMAConstructed parent, String name, String context, String... avps) {
- this(parent, name, context, new MultiValueMap(), buildAttributes(avps));
- }
-
- protected OMAConstructed(OMAConstructed parent, String name, String context,
- MultiValueMap children, Map avps) {
- super(parent, name, context, avps);
- mChildren = children;
- }
-
- @Override
- public OMANode addChild(String name, String context, String value, String pathString)
- throws IOException {
- if (pathString == null) {
- OMANode child = value != null ?
- new OMAScalar(this, name, context, value) :
- new OMAConstructed(this, name, context);
- mChildren.put(name, child);
- return child;
- } else {
- OMANode target = this;
- while (target.getParent() != null)
- target = target.getParent();
-
- for (String element : pathString.split("/")) {
- target = target.getChild(element);
- if (target == null)
- throw new IOException("No child node '" + element + "' in " + getPathString());
- else if (target.isLeaf())
- throw new IOException("Cannot add child to leaf node: " + getPathString());
- }
- return target.addChild(name, context, value, null);
- }
- }
-
- @Override
- public OMAConstructed reparent(OMAConstructed parent) {
- return new OMAConstructed(parent, getName(), getContext(), mChildren, getAttributes());
- }
-
- public void addChild(OMANode child) {
- mChildren.put(child.getName(), child.reparent(this));
- }
-
- public String getScalarValue(Iterator path) throws OMAException {
- if (!path.hasNext()) {
- throw new OMAException("Path too short for " + getPathString());
- }
- String tag = path.next();
- OMANode child = mChildren.get(tag);
- if (child != null) {
- return child.getScalarValue(path);
- } else {
- return null;
- }
- }
-
- @Override
- public OMANode getListValue(Iterator path) throws OMAException {
- if (!path.hasNext()) {
- return null;
- }
- String tag = path.next();
- OMANode child;
- if (tag.equals("?")) {
- child = mChildren.getSingletonValue();
- } else {
- child = mChildren.get(tag);
- }
-
- if (child == null) {
- return null;
- } else if (path.hasNext()) {
- return child.getListValue(path);
- } else {
- return child;
- }
- }
-
- @Override
- public boolean isLeaf() {
- return false;
- }
-
- @Override
- public Collection getChildren() {
- return Collections.unmodifiableCollection(mChildren.values());
- }
-
- public OMANode getChild(String name) {
- return mChildren.get(name);
- }
-
- public OMANode replaceNode(OMANode oldNode, OMANode newNode) {
- return mChildren.replace(oldNode.getName(), oldNode, newNode);
- }
-
- public OMANode removeNode(String key, OMANode node) {
- if (key.equals("?")) {
- return mChildren.remove(node);
- } else {
- return mChildren.remove(key, node);
- }
- }
-
- @Override
- public String getValue() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void toString(StringBuilder sb, int level) {
- sb.append(getPathString());
- if (getContext() != null) {
- sb.append(" (").append(getContext()).append(')');
- }
- sb.append('\n');
-
- for (OMANode node : mChildren.values()) {
- node.toString(sb, level + 1);
- }
- }
-
- @Override
- public void marshal(OutputStream out, int level) throws IOException {
- OMAConstants.indent(level, out);
- OMAConstants.serializeString(getName(), out);
- if (getContext() != null) {
- out.write(String.format("(%s)", getContext()).getBytes(StandardCharsets.UTF_8));
- }
- out.write(new byte[]{'+', '\n'});
-
- for (OMANode child : mChildren.values()) {
- child.marshal(out, level + 1);
- }
- OMAConstants.indent(level, out);
- out.write(".\n".getBytes(StandardCharsets.UTF_8));
- }
-
- @Override
- public void fillPayload(StringBuilder sb) {
- if (getContext() != null) {
- sb.append('<').append(MOTree.RTPropTag).append(">\n");
- sb.append('<').append(MOTree.TypeTag).append(">\n");
- sb.append('<').append(MOTree.DDFNameTag).append(">");
- sb.append(getContext());
- sb.append("").append(MOTree.DDFNameTag).append(">\n");
- sb.append("").append(MOTree.TypeTag).append(">\n");
- sb.append("").append(MOTree.RTPropTag).append(">\n");
- }
-
- for (OMANode child : getChildren()) {
- child.toXml(sb);
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMAException.java b/packages/Osu/src/com/android/hotspot2/omadm/OMAException.java
deleted file mode 100644
index 33a6e37970ed0..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMAException.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.io.IOException;
-
-public class OMAException extends IOException {
- public OMAException(String message) {
- super(message);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMANode.java b/packages/Osu/src/com/android/hotspot2/omadm/OMANode.java
deleted file mode 100644
index a00f433aff511..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMANode.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public abstract class OMANode {
- private final OMAConstructed mParent;
- private final String mName;
- private final String mContext;
- private final Map mAttributes;
-
- protected OMANode(OMAConstructed parent, String name, String context, Map avps) {
- mParent = parent;
- mName = name;
- mContext = context;
- mAttributes = avps;
- }
-
- protected static Map buildAttributes(String[] avps) {
- if (avps == null) {
- return null;
- }
- Map attributes = new HashMap<>();
- for (int n = 0; n < avps.length; n += 2) {
- attributes.put(avps[n], avps[n + 1]);
- }
- return attributes;
- }
-
- protected Map getAttributes() {
- return mAttributes;
- }
-
- public OMAConstructed getParent() {
- return mParent;
- }
-
- public String getName() {
- return mName;
- }
-
- public String getContext() {
- return mContext;
- }
-
- public List getPath() {
- LinkedList path = new LinkedList<>();
- for (OMANode node = this; node != null; node = node.getParent()) {
- path.addFirst(node.getName());
- }
- return path;
- }
-
- public String getPathString() {
- StringBuilder sb = new StringBuilder();
- for (String element : getPath()) {
- sb.append('/').append(element);
- }
- return sb.toString();
- }
-
- public abstract OMANode reparent(OMAConstructed parent);
-
- public abstract String getScalarValue(Iterator path) throws OMAException;
-
- public abstract OMANode getListValue(Iterator path) throws OMAException;
-
- public abstract boolean isLeaf();
-
- public abstract Collection getChildren();
-
- public abstract OMANode getChild(String name) throws OMAException;
-
- public abstract String getValue();
-
- public abstract OMANode addChild(String name, String context, String value, String path)
- throws IOException;
-
- public abstract void marshal(OutputStream out, int level) throws IOException;
-
- public abstract void toString(StringBuilder sb, int level);
-
- public abstract void fillPayload(StringBuilder sb);
-
- public void toXml(StringBuilder sb) {
- sb.append('<').append(MOTree.NodeTag);
- if (mAttributes != null && !mAttributes.isEmpty()) {
- for (Map.Entry avp : mAttributes.entrySet()) {
- sb.append(' ').append(avp.getKey()).append("=\"").append(avp.getValue()).append('"');
- }
- }
- sb.append(">\n");
-
- sb.append('<').append(MOTree.NodeNameTag).append('>');
- sb.append(getName());
- sb.append("").append(MOTree.NodeNameTag).append(">\n");
-
- fillPayload(sb);
-
- sb.append("").append(MOTree.NodeTag).append(">\n");
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- toString(sb, 0);
- return sb.toString();
- }
-
- public static OMAConstructed unmarshal(InputStream in) throws IOException {
- OMANode node = buildNode(in, null);
- if (node == null || node.isLeaf()) {
- throw new IOException("Bad OMA tree");
- }
- unmarshal(in, (OMAConstructed) node);
- return (OMAConstructed) node;
- }
-
- private static void unmarshal(InputStream in, OMAConstructed parent) throws IOException {
- for (; ; ) {
- OMANode node = buildNode(in, parent);
- if (node == null) {
- return;
- } else if (!node.isLeaf()) {
- unmarshal(in, (OMAConstructed) node);
- }
- }
- }
-
- private static OMANode buildNode(InputStream in, OMAConstructed parent) throws IOException {
- String name = OMAConstants.deserializeString(in);
- if (name == null) {
- return null;
- }
-
- String urn = null;
- int next = in.read();
- if (next == '(') {
- urn = OMAConstants.readURN(in);
- next = in.read();
- }
-
- if (next == '=') {
- String value = OMAConstants.deserializeString(in);
- return parent.addChild(name, urn, value, null);
- } else if (next == '+') {
- if (parent != null) {
- return parent.addChild(name, urn, null, null);
- } else {
- return new OMAConstructed(null, name, urn);
- }
- } else {
- throw new IOException("Parse error: expected = or + after node name");
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMAParser.java b/packages/Osu/src/com/android/hotspot2/omadm/OMAParser.java
deleted file mode 100644
index 21cc19a42ec2d..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMAParser.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- * Parses an OMA-DM XML tree.
- */
-public class OMAParser extends DefaultHandler {
- private XMLNode mRoot;
- private XMLNode mCurrent;
-
- public OMAParser() {
- mRoot = null;
- mCurrent = null;
- }
-
- public MOTree parse(String text, String urn) throws IOException, SAXException {
- try {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(new InputSource(new StringReader(text)), this);
- return new MOTree(mRoot, urn);
- } catch (ParserConfigurationException pce) {
- throw new SAXException(pce);
- }
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes)
- throws SAXException {
- XMLNode parent = mCurrent;
-
- mCurrent = new XMLNode(mCurrent, qName, attributes);
-
- if (mRoot == null)
- mRoot = mCurrent;
- else
- parent.addChild(mCurrent);
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (!qName.equals(mCurrent.getTag()))
- throw new SAXException("End tag '" + qName + "' doesn't match current node: " +
- mCurrent);
-
- try {
- mCurrent.close();
- } catch (IOException ioe) {
- throw new SAXException("Failed to close element", ioe);
- }
-
- mCurrent = mCurrent.getParent();
- }
-
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException {
- mCurrent.addText(ch, start, length);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/OMAScalar.java b/packages/Osu/src/com/android/hotspot2/omadm/OMAScalar.java
deleted file mode 100644
index a971ac4d7f3fb..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/OMAScalar.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-public class OMAScalar extends OMANode {
- private final String mValue;
-
- public OMAScalar(OMAConstructed parent, String name, String context, String value,
- String ... avps) {
- this(parent, name, context, value, buildAttributes(avps));
- }
-
- public OMAScalar(OMAConstructed parent, String name, String context, String value,
- Map avps) {
- super(parent, name, context, avps);
- mValue = value;
- }
-
- @Override
- public OMAScalar reparent(OMAConstructed parent) {
- return new OMAScalar(parent, getName(), getContext(), mValue, getAttributes());
- }
-
- public String getScalarValue(Iterator path) throws OMAException {
- return mValue;
- }
-
- @Override
- public OMANode getListValue(Iterator path) throws OMAException {
- throw new OMAException("Scalar encountered in list path: " + getPathString());
- }
-
- @Override
- public boolean isLeaf() {
- return true;
- }
-
- @Override
- public Collection getChildren() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String getValue() {
- return mValue;
- }
-
- @Override
- public OMANode getChild(String name) throws OMAException {
- throw new OMAException("'" + getName() + "' is a scalar node");
- }
-
- @Override
- public OMANode addChild(String name, String context, String value, String path)
- throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void toString(StringBuilder sb, int level) {
- sb.append(getPathString()).append('=').append(mValue);
- if (getContext() != null) {
- sb.append(" (").append(getContext()).append(')');
- }
- sb.append('\n');
- }
-
- @Override
- public void marshal(OutputStream out, int level) throws IOException {
- OMAConstants.indent(level, out);
- OMAConstants.serializeString(getName(), out);
- out.write((byte) '=');
- OMAConstants.serializeString(getValue(), out);
- out.write((byte) '\n');
- }
-
- @Override
- public void fillPayload(StringBuilder sb) {
- sb.append('<').append(MOTree.ValueTag).append('>');
- sb.append(mValue);
- sb.append("").append(MOTree.ValueTag).append(">\n");
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/omadm/XMLNode.java b/packages/Osu/src/com/android/hotspot2/omadm/XMLNode.java
deleted file mode 100644
index b77c820691a45..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/omadm/XMLNode.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package com.android.hotspot2.omadm;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class XMLNode {
- private final String mTag;
- private final Map mAttributes;
- private final List mChildren;
- private final XMLNode mParent;
- private MOTree mMO;
- private StringBuilder mTextBuilder;
- private String mText;
-
- private static final String XML_SPECIAL_CHARS = "\"'<>&";
- private static final Set XML_SPECIAL = new HashSet<>();
- private static final String CDATA_OPEN = "";
-
- static {
- for (int n = 0; n < XML_SPECIAL_CHARS.length(); n++) {
- XML_SPECIAL.add(XML_SPECIAL_CHARS.charAt(n));
- }
- }
-
- public XMLNode(XMLNode parent, String tag, Attributes attributes) throws SAXException {
- mTag = tag;
-
- mAttributes = new HashMap<>();
-
- if (attributes.getLength() > 0) {
- for (int n = 0; n < attributes.getLength(); n++)
- mAttributes.put(attributes.getQName(n), new NodeAttribute(attributes.getQName(n),
- attributes.getType(n), attributes.getValue(n)));
- }
-
- mParent = parent;
- mChildren = new ArrayList<>();
-
- mTextBuilder = new StringBuilder();
- }
-
- public XMLNode(XMLNode parent, String tag, Map attributes) {
- mTag = tag;
-
- mAttributes = new HashMap<>(attributes == null ? 0 : attributes.size());
-
- if (attributes != null) {
- for (Map.Entry entry : attributes.entrySet()) {
- mAttributes.put(entry.getKey(),
- new NodeAttribute(entry.getKey(), "", entry.getValue()));
- }
- }
-
- mParent = parent;
- mChildren = new ArrayList<>();
-
- mTextBuilder = new StringBuilder();
- }
-
- public void setText(String text) {
- mText = text;
- mTextBuilder = null;
- }
-
- public void addText(char[] chs, int start, int length) {
- String s = new String(chs, start, length);
- String trimmed = s.trim();
- if (trimmed.isEmpty())
- return;
-
- if (s.charAt(0) != trimmed.charAt(0))
- mTextBuilder.append(' ');
- mTextBuilder.append(trimmed);
- if (s.charAt(s.length() - 1) != trimmed.charAt(trimmed.length() - 1))
- mTextBuilder.append(' ');
- }
-
- public void addChild(XMLNode child) {
- mChildren.add(child);
- }
-
- public void close() throws IOException, SAXException {
- String text = mTextBuilder.toString().trim();
- StringBuilder filtered = new StringBuilder(text.length());
- for (int n = 0; n < text.length(); n++) {
- char ch = text.charAt(n);
- if (ch >= ' ')
- filtered.append(ch);
- }
-
- mText = filtered.toString();
- mTextBuilder = null;
-
- if (MOTree.hasMgmtTreeTag(mText)) {
- try {
- NodeAttribute urn = mAttributes.get(OMAConstants.SppMOAttribute);
- OMAParser omaParser = new OMAParser();
- mMO = omaParser.parse(mText, urn != null ? urn.getValue() : null);
- } catch (SAXException | IOException e) {
- mMO = null;
- }
- }
- }
-
- public String getTag() {
- return mTag;
- }
-
- public String getNameSpace() throws OMAException {
- String[] nsn = mTag.split(":");
- if (nsn.length != 2) {
- throw new OMAException("Non-namespaced tag: '" + mTag + "'");
- }
- return nsn[0];
- }
-
- public String getStrippedTag() throws OMAException {
- String[] nsn = mTag.split(":");
- if (nsn.length != 2) {
- throw new OMAException("Non-namespaced tag: '" + mTag + "'");
- }
- return nsn[1].toLowerCase();
- }
-
- public XMLNode getSoleChild() throws OMAException {
- if (mChildren.size() != 1) {
- throw new OMAException("Expected exactly one child to " + mTag);
- }
- return mChildren.get(0);
- }
-
- public XMLNode getParent() {
- return mParent;
- }
-
- public String getText() {
- return mText;
- }
-
- public Map getAttributes() {
- return Collections.unmodifiableMap(mAttributes);
- }
-
- public Map getTextualAttributes() {
- Map map = new HashMap<>(mAttributes.size());
- for (Map.Entry entry : mAttributes.entrySet()) {
- map.put(entry.getKey(), entry.getValue().getValue());
- }
- return map;
- }
-
- public String getAttributeValue(String name) {
- NodeAttribute nodeAttribute = mAttributes.get(name);
- return nodeAttribute != null ? nodeAttribute.getValue() : null;
- }
-
- public List getChildren() {
- return mChildren;
- }
-
- public MOTree getMOTree() {
- return mMO;
- }
-
- private void toString(char[] indent, StringBuilder sb) {
- Arrays.fill(indent, ' ');
-
- sb.append(indent).append('<').append(mTag);
- for (Map.Entry entry : mAttributes.entrySet()) {
- sb.append(' ').append(entry.getKey()).append("='")
- .append(entry.getValue().getValue()).append('\'');
- }
-
- if (mText != null && !mText.isEmpty()) {
- sb.append('>').append(escapeCdata(mText)).append("").append(mTag).append(">\n");
- } else if (mChildren.isEmpty()) {
- sb.append("/>\n");
- } else {
- sb.append(">\n");
- char[] subIndent = Arrays.copyOf(indent, indent.length + 2);
- for (XMLNode child : mChildren) {
- child.toString(subIndent, sb);
- }
- sb.append(indent).append("").append(mTag).append(">\n");
- }
- }
-
- private static String escapeCdata(String text) {
- if (!escapable(text)) {
- return text;
- }
-
- // Any appearance of ]]> in the text must be split into "]]" | "]]>" | "
- // i.e. "split the sequence by putting a close CDATA and a new open CDATA before the '>'
- StringBuilder sb = new StringBuilder();
- sb.append(CDATA_OPEN);
- int start = 0;
- for (; ; ) {
- int etoken = text.indexOf(CDATA_CLOSE);
- if (etoken >= 0) {
- sb.append(text.substring(start, etoken + 2)).append(CDATA_CLOSE).append(CDATA_OPEN);
- start = etoken + 2;
- } else {
- if (start < text.length() - 1) {
- sb.append(text.substring(start));
- }
- break;
- }
- }
- sb.append(CDATA_CLOSE);
- return sb.toString();
- }
-
- private static boolean escapable(String s) {
- for (int n = 0; n < s.length(); n++) {
- if (XML_SPECIAL.contains(s.charAt(n))) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- toString(new char[0], sb);
- return sb.toString();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/osu/ClientKeyManager.java b/packages/Osu/src/com/android/hotspot2/osu/ClientKeyManager.java
deleted file mode 100644
index cfc84bbc62259..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/osu/ClientKeyManager.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package com.android.hotspot2.osu;
-
-import android.util.Log;
-
-import com.android.hotspot2.flow.PlatformAdapter;
-import com.android.hotspot2.pps.HomeSP;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.net.ssl.X509KeyManager;
-
-public class ClientKeyManager implements X509KeyManager {
- private final KeyStore mKeyStore;
- private final Map mAliasMap;
- private final Map mTempKeys;
-
- private static final String sTempAlias = "client-alias";
-
- public ClientKeyManager(HomeSP homeSP, KeyStore keyStore) throws IOException {
- mKeyStore = keyStore;
- mAliasMap = new HashMap<>();
- mAliasMap.put(OSUCertType.AAA, PlatformAdapter.CERT_CLT_CA_ALIAS + homeSP.getFQDN());
- mAliasMap.put(OSUCertType.Client, PlatformAdapter.CERT_CLT_CERT_ALIAS + homeSP.getFQDN());
- mAliasMap.put(OSUCertType.PrivateKey, PlatformAdapter.CERT_CLT_KEY_ALIAS + homeSP.getFQDN());
- mTempKeys = new HashMap<>();
- }
-
- public void reloadKeys(Map> certs, PrivateKey key)
- throws IOException {
- List clientCerts = certs.get(OSUCertType.Client);
- X509Certificate[] certArray = new X509Certificate[clientCerts.size()];
- int n = 0;
- for (X509Certificate cert : clientCerts) {
- certArray[n++] = cert;
- }
- mTempKeys.put(OSUCertType.Client, certArray);
- mTempKeys.put(OSUCertType.PrivateKey, key);
- }
-
- @Override
- public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
- if (mTempKeys.isEmpty()) {
- return mAliasMap.get(OSUCertType.Client);
- } else {
- return sTempAlias;
- }
- }
-
- @Override
- public String[] getClientAliases(String keyType, Principal[] issuers) {
- if (mTempKeys.isEmpty()) {
- String alias = mAliasMap.get(OSUCertType.Client);
- return alias != null ? new String[]{alias} : null;
- } else {
- return new String[]{sTempAlias};
- }
- }
-
- @Override
- public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String[] getServerAliases(String keyType, Principal[] issuers) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public X509Certificate[] getCertificateChain(String alias) {
- if (mTempKeys.isEmpty()) {
- if (!mAliasMap.get(OSUCertType.Client).equals(alias)) {
- Log.w(OSUManager.TAG, "Bad cert alias requested: '" + alias + "'");
- return null;
- }
- try {
- Certificate cert = mKeyStore.getCertificate(alias);
- return new X509Certificate[] {(X509Certificate) cert};
- } catch (KeyStoreException kse) {
- Log.w(OSUManager.TAG, "Failed to retrieve certificates: " + kse);
- return null;
- }
- } else if (sTempAlias.equals(alias)) {
- return (X509Certificate[]) mTempKeys.get(OSUCertType.Client);
- } else {
- Log.w(OSUManager.TAG, "Bad cert alias requested: '" + alias + "'");
- return null;
- }
- }
-
- @Override
- public PrivateKey getPrivateKey(String alias) {
- if (mTempKeys.isEmpty()) {
- if (!mAliasMap.get(OSUCertType.Client).equals(alias)) {
- Log.w(OSUManager.TAG, "Bad key alias requested: '" + alias + "'");
- }
- try {
- return (PrivateKey) mKeyStore.getKey(mAliasMap.get(OSUCertType.PrivateKey), null);
- } catch (GeneralSecurityException gse) {
- Log.w(OSUManager.TAG, "Failed to retrieve private key: " + gse);
- return null;
- }
- } else if (sTempAlias.equals(alias)) {
- return (PrivateKey) mTempKeys.get(OSUCertType.PrivateKey);
- } else {
- Log.w(OSUManager.TAG, "Bad cert alias requested: '" + alias + "'");
- return null;
- }
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/osu/ExchangeCompleteResponse.java b/packages/Osu/src/com/android/hotspot2/osu/ExchangeCompleteResponse.java
deleted file mode 100644
index fe23b5c043917..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/osu/ExchangeCompleteResponse.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.android.hotspot2.osu;
-
-import com.android.hotspot2.omadm.OMAException;
-import com.android.hotspot2.omadm.XMLNode;
-
- /*
-
-
- SOAP method used by SPP server to end session.
-
-
-
-
-
-
-
-
-
-
-
-
- */
-
-public class ExchangeCompleteResponse extends OSUResponse {
- public ExchangeCompleteResponse(XMLNode root) throws OMAException {
- super(root, OSUMessageType.ExchangeComplete);
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/osu/ExecCommand.java b/packages/Osu/src/com/android/hotspot2/osu/ExecCommand.java
deleted file mode 100644
index 38a394727f547..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/osu/ExecCommand.java
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.android.hotspot2.osu;
-
-public enum ExecCommand {Browser, GetCert, UseClientCertTLS, UploadMO}
diff --git a/packages/Osu/src/com/android/hotspot2/osu/HTTPHandler.java b/packages/Osu/src/com/android/hotspot2/osu/HTTPHandler.java
deleted file mode 100644
index 4b583df1ce443..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/osu/HTTPHandler.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package com.android.hotspot2.osu;
-
-import android.util.Log;
-
-import com.android.hotspot2.utils.HTTPMessage;
-import com.android.hotspot2.utils.HTTPRequest;
-import com.android.hotspot2.utils.HTTPResponse;
-
-import com.android.org.conscrypt.OpenSSLSocketImpl;
-
-import org.xml.sax.SAXException;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.Socket;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSocket;
-import javax.xml.parsers.ParserConfigurationException;
-
-public class HTTPHandler implements AutoCloseable {
- private final Charset mCharset;
- private final OSUSocketFactory mSocketFactory;
- private Socket mSocket;
- private BufferedOutputStream mOut;
- private BufferedInputStream mIn;
- private final String mUser;
- private final byte[] mPassword;
- private boolean mHTTPAuthPerformed;
- private static final AtomicInteger sSequence = new AtomicInteger();
-
- public HTTPHandler(Charset charset, OSUSocketFactory socketFactory) throws IOException {
- this(charset, socketFactory, null, null);
- }
-
- public HTTPHandler(Charset charset, OSUSocketFactory socketFactory,
- String user, byte[] password) throws IOException {
- mCharset = charset;
- mSocketFactory = socketFactory;
- mSocket = mSocketFactory.createSocket();
- mOut = new BufferedOutputStream(mSocket.getOutputStream());
- mIn = new BufferedInputStream(mSocket.getInputStream());
- mUser = user;
- mPassword = password;
- }
-
- public boolean isHTTPAuthPerformed() {
- return mHTTPAuthPerformed;
- }
-
- public X509Certificate getOSUCertificate(URL osu) throws GeneralSecurityException {
- return mSocketFactory.getOSUCertificate(osu);
- }
-
- public void renegotiate(Map> certs, PrivateKey key)
- throws IOException {
- if (!(mSocket instanceof SSLSocket)) {
- throw new IOException("Not a TLS connection");
- }
- if (certs != null) {
- mSocketFactory.reloadKeys(certs, key);
- }
- ((SSLSocket) mSocket).startHandshake();
- }
-
- public byte[] getTLSUnique() throws SSLException {
- if (mSocket instanceof OpenSSLSocketImpl) {
- return ((OpenSSLSocketImpl) mSocket).getChannelId();
- }
- return null;
- }
-
- public OSUResponse exchangeSOAP(URL url, String message) throws IOException {
- HTTPResponse response = exchangeWithRetry(url, message, HTTPMessage.Method.POST,
- HTTPMessage.ContentTypeSOAP);
- if (response.getStatusCode() >= 300) {
- throw new IOException("Bad HTTP status code " + response.getStatusCode());
- }
- try {
- SOAPParser parser = new SOAPParser(response.getPayloadStream());
- return parser.getResponse();
- } catch (ParserConfigurationException | SAXException e) {
- ByteBuffer x = response.getPayload();
- byte[] b = new byte[x.remaining()];
- x.get(b);
- Log.w("XML", "Bad: '" + new String(b, StandardCharsets.ISO_8859_1));
- throw new IOException(e);
- }
- }
-
- public ByteBuffer exchangeBinary(URL url, String message, String contentType)
- throws IOException {
- HTTPResponse response =
- exchangeWithRetry(url, message, HTTPMessage.Method.POST, contentType);
- return response.getBinaryPayload();
- }
-
- public InputStream doGet(URL url) throws IOException {
- HTTPResponse response = exchangeWithRetry(url, null, HTTPMessage.Method.GET, null);
- return response.getPayloadStream();
- }
-
- public HTTPResponse doGetHTTP(URL url) throws IOException {
- return exchangeWithRetry(url, null, HTTPMessage.Method.GET, null);
- }
-
- private HTTPResponse exchangeWithRetry(URL url, String message, HTTPMessage.Method method,
- String contentType) throws IOException {
- HTTPResponse response = null;
- int retry = 0;
- for (; ; ) {
- try {
- response = httpExchange(url, message, method, contentType);
- break;
- } catch (IOException ioe) {
- close();
- retry++;
- if (retry > 3) {
- break;
- }
- Log.d(OSUManager.TAG, "Failed HTTP exchange, retry " + retry);
- mSocket = mSocketFactory.createSocket();
- mOut = new BufferedOutputStream(mSocket.getOutputStream());
- mIn = new BufferedInputStream(mSocket.getInputStream());
- }
- }
- if (response == null) {
- throw new IOException("Failed to establish connection to peer");
- }
- return response;
- }
-
- private HTTPResponse httpExchange(URL url, String message, HTTPMessage.Method method,
- String contentType)
- throws IOException {
- HTTPRequest request = new HTTPRequest(message, mCharset, method, url, contentType, false);
- request.send(mOut);
- HTTPResponse response = new HTTPResponse(mIn);
- Log.d(OSUManager.TAG, "HTTP code " + response.getStatusCode() + ", user " + mUser +
- ", pw " + (mPassword != null ? '\'' + new String(mPassword) + '\'' : "-"));
- if (response.getStatusCode() == 401) {
- if (mUser == null) {
- throw new IOException("Missing user name for HTTP authentication");
- }
- try {
- request = new HTTPRequest(message, StandardCharsets.ISO_8859_1, method, url,
- contentType, true);
- request.doAuthenticate(response, mUser, mPassword, url,
- sSequence.incrementAndGet());
- request.send(mOut);
- mHTTPAuthPerformed = true;
- } catch (GeneralSecurityException gse) {
- throw new IOException(gse);
- }
-
- response = new HTTPResponse(mIn);
- }
- return response;
- }
-
- public void close() throws IOException {
- mSocket.shutdownInput();
- mSocket.shutdownOutput();
- mSocket.close();
- mIn.close();
- mOut.close();
- }
-}
diff --git a/packages/Osu/src/com/android/hotspot2/osu/IconCache.java b/packages/Osu/src/com/android/hotspot2/osu/IconCache.java
deleted file mode 100644
index bd8a018a5f0be..0000000000000
--- a/packages/Osu/src/com/android/hotspot2/osu/IconCache.java
+++ /dev/null
@@ -1,337 +0,0 @@
-package com.android.hotspot2.osu;
-
-import android.util.Log;
-
-import com.android.anqp.HSIconFileElement;
-import com.android.anqp.IconInfo;
-import com.android.hotspot2.Utils;
-import com.android.hotspot2.flow.OSUInfo;
-
-import java.net.ProtocolException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static com.android.anqp.Constants.ANQPElementType.HSIconFile;
-
-public class IconCache extends Thread {
- // Preferred icon parameters
- private static final Set ICON_TYPES =
- new HashSet<>(Arrays.asList("image/png", "image/jpeg"));
- private static final int ICON_WIDTH = 64;
- private static final int ICON_HEIGHT = 64;
- public static final Locale LOCALE = java.util.Locale.getDefault();
-
- private static final int MAX_RETRY = 3;
- private static final long REQUERY_TIME = 5000L;
- private static final long REQUERY_TIMEOUT = 120000L;
-
- private final OSUManager mOsuManager;
- private final Map> mPending;
- private final Map> mCache;
-
- private static class EssKey {
- private final int mAnqpDomainId;
- private final long mBssid;
- private final long mHessid;
- private final String mSsid;
-
- private EssKey(OSUInfo osuInfo) {
- mAnqpDomainId = osuInfo.getAnqpDomID();
- mBssid = osuInfo.getBSSID();
- mHessid = osuInfo.getHESSID();
- mSsid = osuInfo.getAdvertisingSsid();
- }
-
- /*
- * ANQP ID 1 ANQP ID 2
- * 0 0 BSSID equality
- * 0 X BSSID equality
- * Y X BSSID equality
- * X X Then:
- *
- * HESSID1 HESSID2
- * 0 0 compare SSIDs
- * 0 X not equal
- * Y X not equal
- * X X equal
- */
-
- @Override
- public boolean equals(Object thatObject) {
- if (this == thatObject) {
- return true;
- }
- if (thatObject == null || getClass() != thatObject.getClass()) {
- return false;
- }
-
- EssKey that = (EssKey) thatObject;
- if (mAnqpDomainId != 0 && mAnqpDomainId == that.mAnqpDomainId) {
- return mHessid == that.mHessid
- && (mHessid != 0 || mSsid.equals(that.mSsid));
- } else {
- return mBssid == that.mBssid;
- }
- }
-
- @Override
- public int hashCode() {
- if (mAnqpDomainId == 0) {
- return (int) (mBssid ^ (mBssid >>> 32));
- } else if (mHessid != 0) {
- return mAnqpDomainId * 31 + (int) (mHessid ^ (mHessid >>> 32));
- } else {
- return mAnqpDomainId * 31 + mSsid.hashCode();
- }
- }
-
- @Override
- public String toString() {
- if (mAnqpDomainId == 0) {
- return String.format("BSS %012x", mBssid);
- } else if (mHessid != 0) {
- return String.format("ESS %012x [%d]", mBssid, mAnqpDomainId);
- } else {
- return String.format("ESS '%s' [%d]", mSsid, mAnqpDomainId);
- }
- }
- }
-
- private static class FileEntry {
- private final String mFileName;
- private int mRetry = 0;
- private final long mTimestamp;
- private final LinkedList mQueued;
- private final Set mBssids;
-
- private FileEntry(OSUInfo osuInfo, String fileName) {
- mFileName = fileName;
- mQueued = new LinkedList<>();
- mBssids = new HashSet<>();
- mQueued.addLast(osuInfo);
- mBssids.add(osuInfo.getBSSID());
- mTimestamp = System.currentTimeMillis();
- }
-
- private void enqueu(OSUInfo osuInfo) {
- mQueued.addLast(osuInfo);
- mBssids.add(osuInfo.getBSSID());
- }
-
- private int update(long bssid, HSIconFileElement iconFileElement) {
- if (!mBssids.contains(bssid)) {
- return 0;
- }
- Log.d(OSUManager.TAG, "Updating icon on " + mQueued.size() + " osus");
- for (OSUInfo osuInfo : mQueued) {
- osuInfo.setIconFileElement(iconFileElement, mFileName);
- }
- return mQueued.size();
- }
-
- private int getAndIncrementRetry() {
- return mRetry++;
- }
-
- private long getTimestamp() {
- return mTimestamp;
- }
-
- public String getFileName() {
- return mFileName;
- }
-
- private long getLastBssid() {
- return mQueued.getLast().getBSSID();
- }
-
- @Override
- public String toString() {
- return String.format("'%s', retry %d, age %d, BSSIDs: %s",
- mFileName, mRetry,
- System.currentTimeMillis() - mTimestamp, Utils.bssidsToString(mBssids));
- }
- }
-
- public IconCache(OSUManager osuManager) {
- mOsuManager = osuManager;
- mPending = new HashMap<>();
- mCache = new HashMap<>();
- }
-
- public int resolveIcons(Collection osuInfos) {
- Set current = new HashSet<>();
- int modCount = 0;
- for (OSUInfo osuInfo : osuInfos) {
- EssKey key = new EssKey(osuInfo);
- current.add(key);
-
- if (osuInfo.getIconStatus() == OSUInfo.IconStatus.NotQueried) {
- List iconInfo =
- osuInfo.getIconInfo(LOCALE, ICON_TYPES, ICON_WIDTH, ICON_HEIGHT);
- if (iconInfo.isEmpty()) {
- osuInfo.setIconStatus(OSUInfo.IconStatus.NotAvailable);
- continue;
- }
-
- String fileName = iconInfo.get(0).getFileName();
- HSIconFileElement iconFileElement = get(key, fileName);
- if (iconFileElement != null) {
- osuInfo.setIconFileElement(iconFileElement, fileName);
- Log.d(OSUManager.TAG, "Icon cache hit for " + osuInfo + "/" + fileName);
- modCount++;
- } else {
- FileEntry fileEntry = enqueue(key, fileName, osuInfo);
- if (fileEntry != null) {
- Log.d(OSUManager.TAG, "Initiating icon query for "
- + osuInfo + "/" + fileName);
- mOsuManager.doIconQuery(osuInfo.getBSSID(), fileName);
- } else {
- Log.d(OSUManager.TAG, "Piggybacking icon query for "
- + osuInfo + "/" + fileName);
- }
- }
- }
- }
-
- // Drop all non-current ESS's
- Iterator pendingKeys = mPending.keySet().iterator();
- while (pendingKeys.hasNext()) {
- EssKey key = pendingKeys.next();
- if (!current.contains(key)) {
- pendingKeys.remove();
- }
- }
- Iterator cacheKeys = mCache.keySet().iterator();
- while (cacheKeys.hasNext()) {
- EssKey key = cacheKeys.next();
- if (!current.contains(key)) {
- cacheKeys.remove();
- }
- }
- return modCount;
- }
-
- public HSIconFileElement getIcon(OSUInfo osuInfo) {
- List iconInfos = osuInfo.getIconInfo(LOCALE, ICON_TYPES, ICON_WIDTH, ICON_HEIGHT);
- if (iconInfos == null || iconInfos.isEmpty()) {
- return null;
- }
- EssKey key = new EssKey(osuInfo);
- Map fileMap = mCache.get(key);
- return fileMap != null ? fileMap.get(iconInfos.get(0).getFileName()) : null;
- }
-
- public int notifyIconReceived(long bssid, String fileName, byte[] iconData) {
- Log.d(OSUManager.TAG, String.format("Icon '%s':%d received from %012x",
- fileName, iconData != null ? iconData.length : -1, bssid));
- if (fileName == null || iconData == null) {
- return 0;
- }
-
- HSIconFileElement iconFileElement;
- try {
- iconFileElement = new HSIconFileElement(HSIconFile,
- ByteBuffer.wrap(iconData).order(ByteOrder.LITTLE_ENDIAN));
- } catch (ProtocolException | BufferUnderflowException e) {
- Log.e(OSUManager.TAG, "Failed to parse ANQP icon file: " + e);
- return 0;
- }
-
- int updates = 0;
- Iterator>> entries =
- mPending.entrySet().iterator();
-
- while (entries.hasNext()) {
- Map.Entry> entry = entries.next();
-
- Map fileMap = entry.getValue();
- FileEntry fileEntry = fileMap.get(fileName);
- updates = fileEntry.update(bssid, iconFileElement);
- if (updates > 0) {
- put(entry.getKey(), fileName, iconFileElement);
- fileMap.remove(fileName);
- if (fileMap.isEmpty()) {
- entries.remove();
- }
- break;
- }
- }
- return updates;
- }
-
- public void tick(boolean wifiOff) {
- if (wifiOff) {
- mPending.clear();
- mCache.clear();
- return;
- }
-
- Iterator>> entries =
- mPending.entrySet().iterator();
-
- long now = System.currentTimeMillis();
- while (entries.hasNext()) {
- Map