Loading wifi/java/android/net/wifi/hotspot2/OsuProvider.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; parcelable OsuProvider; wifi/java/android/net/wifi/hotspot2/OsuProvider.java 0 → 100644 +231 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; import android.graphics.drawable.Icon; import android.net.Uri; import android.net.wifi.WifiSsid; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Contained information for a Hotspot 2.0 OSU (Online Sign-Up provider). * * @hide */ public final class OsuProvider implements Parcelable { /** * OSU (Online Sign-Up) method: OMA DM (Open Mobile Alliance Device Management). * For more info, refer to Section 8.3 of the Hotspot 2.0 Release 2 Technical Specification. */ public static final int METHOD_OMA_DM = 0; /** * OSU (Online Sign-Up) method: SOAP XML SPP (Subscription Provisioning Protocol). * For more info, refer to Section 8.4 of the Hotspot 2.0 Release 2 Technical Specification. */ public static final int METHOD_SOAP_XML_SPP = 1; /** * SSID of the network to connect for service sign-up. */ private final WifiSsid mOsuSsid; /** * Friendly name of the OSU provider. */ private final String mFriendlyName; /** * Description of the OSU provider. */ private final String mServiceDescription; /** * URI to browse to for service sign-up. */ private final Uri mServerUri; /** * Network Access Identifier used for authenticating with the OSU network when OSEN is used. */ private final String mNetworkAccessIdentifier; /** * List of OSU (Online Sign-Up) method supported. */ private final List<Integer> mMethodList; /** * Icon data for the OSU (Online Sign-Up) provider. */ private final Icon mIcon; public OsuProvider(WifiSsid osuSsid, String friendlyName, String serviceDescription, Uri serverUri, String nai, List<Integer> methodList, Icon icon) { mOsuSsid = osuSsid; mFriendlyName = friendlyName; mServiceDescription = serviceDescription; mServerUri = serverUri; mNetworkAccessIdentifier = nai; if (methodList == null) { mMethodList = new ArrayList<>(); } else { mMethodList = new ArrayList<>(methodList); } mIcon = icon; } /** * Copy constructor. * * @param source The source to copy from */ public OsuProvider(OsuProvider source) { if (source == null) { mOsuSsid = null; mFriendlyName = null; mServiceDescription = null; mServerUri = null; mNetworkAccessIdentifier = null; mMethodList = new ArrayList<>(); mIcon = null; return; } mOsuSsid = source.mOsuSsid; mFriendlyName = source.mFriendlyName; mServiceDescription = source.mServiceDescription; mServerUri = source.mServerUri; mNetworkAccessIdentifier = source.mNetworkAccessIdentifier; if (source.mMethodList == null) { mMethodList = new ArrayList<>(); } else { mMethodList = new ArrayList<>(source.mMethodList); } mIcon = source.mIcon; } public WifiSsid getOsuSsid() { return mOsuSsid; } public String getFriendlyName() { return mFriendlyName; } public String getServiceDescription() { return mServiceDescription; } public Uri getServerUri() { return mServerUri; } public String getNetworkAccessIdentifier() { return mNetworkAccessIdentifier; } public List<Integer> getMethodList() { return Collections.unmodifiableList(mMethodList); } public Icon getIcon() { return mIcon; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(mOsuSsid, flags); dest.writeString(mFriendlyName); dest.writeString(mServiceDescription); dest.writeParcelable(mServerUri, flags); dest.writeString(mNetworkAccessIdentifier); dest.writeList(mMethodList); dest.writeParcelable(mIcon, flags); } @Override public boolean equals(Object thatObject) { if (this == thatObject) { return true; } if (!(thatObject instanceof OsuProvider)) { return false; } OsuProvider that = (OsuProvider) thatObject; return (mOsuSsid == null ? that.mOsuSsid == null : mOsuSsid.equals(that.mOsuSsid)) && TextUtils.equals(mFriendlyName, that.mFriendlyName) && TextUtils.equals(mServiceDescription, that.mServiceDescription) && (mServerUri == null ? that.mServerUri == null : mServerUri.equals(that.mServerUri)) && TextUtils.equals(mNetworkAccessIdentifier, that.mNetworkAccessIdentifier) && (mMethodList == null ? that.mMethodList == null : mMethodList.equals(that.mMethodList)) && (mIcon == null ? that.mIcon == null : mIcon.sameAs(that.mIcon)); } @Override public int hashCode() { return Objects.hash(mOsuSsid, mFriendlyName, mServiceDescription, mServerUri, mNetworkAccessIdentifier, mMethodList, mIcon); } @Override public String toString() { return "OsuProvider{mOsuSsid=" + mOsuSsid + " mFriendlyName=" + mFriendlyName + " mServiceDescription=" + mServiceDescription + " mServerUri=" + mServerUri + " mNetworkAccessIdentifier=" + mNetworkAccessIdentifier + " mMethodList=" + mMethodList + " mIcon=" + mIcon; } public static final Creator<OsuProvider> CREATOR = new Creator<OsuProvider>() { @Override public OsuProvider createFromParcel(Parcel in) { WifiSsid osuSsid = (WifiSsid) in.readParcelable(null); String friendlyName = in.readString(); String serviceDescription = in.readString(); Uri serverUri = (Uri) in.readParcelable(null); String nai = in.readString(); List<Integer> methodList = new ArrayList<>(); in.readList(methodList, null); Icon icon = (Icon) in.readParcelable(null); return new OsuProvider(osuSsid, friendlyName, serviceDescription, serverUri, nai, methodList, icon); } @Override public OsuProvider[] newArray(int size) { return new OsuProvider[size]; } }; } wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java 0 → 100644 +125 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.graphics.drawable.Icon; import android.net.Uri; import android.net.wifi.WifiSsid; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Unit tests for {@link android.net.wifi.hotspot2.OsuProvider}. */ @SmallTest public class OsuProviderTest { private static final WifiSsid TEST_SSID = WifiSsid.createFromByteArray("TEST SSID".getBytes(StandardCharsets.UTF_8)); private static final String TEST_FRIENDLY_NAME = "Friendly Name"; private static final String TEST_SERVICE_DESCRIPTION = "Dummy Service"; private static final Uri TEST_SERVER_URI = Uri.parse("https://test.com"); private static final String TEST_NAI = "test.access.com"; private static final List<Integer> TEST_METHOD_LIST = Arrays.asList(OsuProvider.METHOD_SOAP_XML_SPP); private static final Icon TEST_ICON = Icon.createWithData(new byte[10], 0, 10); /** * Verify parcel write and read consistency for the given {@link OsuProvider}. * * @param writeInfo The {@link OsuProvider} to verify * @throws Exception */ private static void verifyParcel(OsuProvider writeInfo) throws Exception { Parcel parcel = Parcel.obtain(); writeInfo.writeToParcel(parcel, 0); parcel.setDataPosition(0); // Rewind data position back to the beginning for read. OsuProvider readInfo = OsuProvider.CREATOR.createFromParcel(parcel); assertEquals(writeInfo, readInfo); } /** * Verify parcel read/write for an OSU provider containing no information. * * @throws Exception */ @Test public void verifyParcelWithEmptyProviderInfo() throws Exception { verifyParcel(new OsuProvider(null, null, null, null, null, null, null)); } /** * Verify parcel read/write for an OSU provider containing full information. * * @throws Exception */ @Test public void verifyParcelWithFullProviderInfo() throws Exception { verifyParcel(new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON)); } /** * Verify copy constructor with a null source. * @throws Exception */ @Test public void verifyCopyConstructorWithNullSource() throws Exception { OsuProvider expected = new OsuProvider(null, null, null, null, null, null, null); assertEquals(expected, new OsuProvider(null)); } /** * Verify copy constructor with a valid source. * * @throws Exception */ @Test public void verifyCopyConstructorWithValidSource() throws Exception { OsuProvider source = new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON); assertEquals(source, new OsuProvider(source)); } /** * Verify getter methods. * * @throws Exception */ @Test public void verifyGetters() throws Exception { OsuProvider provider = new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON); assertTrue(TEST_SSID.equals(provider.getOsuSsid())); assertTrue(TEST_FRIENDLY_NAME.equals(provider.getFriendlyName())); assertTrue(TEST_SERVICE_DESCRIPTION.equals(provider.getServiceDescription())); assertTrue(TEST_SERVER_URI.equals(provider.getServerUri())); assertTrue(TEST_NAI.equals(provider.getNetworkAccessIdentifier())); assertTrue(TEST_METHOD_LIST.equals(provider.getMethodList())); assertTrue(TEST_ICON.sameAs(provider.getIcon())); } } Loading
wifi/java/android/net/wifi/hotspot2/OsuProvider.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; parcelable OsuProvider;
wifi/java/android/net/wifi/hotspot2/OsuProvider.java 0 → 100644 +231 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; import android.graphics.drawable.Icon; import android.net.Uri; import android.net.wifi.WifiSsid; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Contained information for a Hotspot 2.0 OSU (Online Sign-Up provider). * * @hide */ public final class OsuProvider implements Parcelable { /** * OSU (Online Sign-Up) method: OMA DM (Open Mobile Alliance Device Management). * For more info, refer to Section 8.3 of the Hotspot 2.0 Release 2 Technical Specification. */ public static final int METHOD_OMA_DM = 0; /** * OSU (Online Sign-Up) method: SOAP XML SPP (Subscription Provisioning Protocol). * For more info, refer to Section 8.4 of the Hotspot 2.0 Release 2 Technical Specification. */ public static final int METHOD_SOAP_XML_SPP = 1; /** * SSID of the network to connect for service sign-up. */ private final WifiSsid mOsuSsid; /** * Friendly name of the OSU provider. */ private final String mFriendlyName; /** * Description of the OSU provider. */ private final String mServiceDescription; /** * URI to browse to for service sign-up. */ private final Uri mServerUri; /** * Network Access Identifier used for authenticating with the OSU network when OSEN is used. */ private final String mNetworkAccessIdentifier; /** * List of OSU (Online Sign-Up) method supported. */ private final List<Integer> mMethodList; /** * Icon data for the OSU (Online Sign-Up) provider. */ private final Icon mIcon; public OsuProvider(WifiSsid osuSsid, String friendlyName, String serviceDescription, Uri serverUri, String nai, List<Integer> methodList, Icon icon) { mOsuSsid = osuSsid; mFriendlyName = friendlyName; mServiceDescription = serviceDescription; mServerUri = serverUri; mNetworkAccessIdentifier = nai; if (methodList == null) { mMethodList = new ArrayList<>(); } else { mMethodList = new ArrayList<>(methodList); } mIcon = icon; } /** * Copy constructor. * * @param source The source to copy from */ public OsuProvider(OsuProvider source) { if (source == null) { mOsuSsid = null; mFriendlyName = null; mServiceDescription = null; mServerUri = null; mNetworkAccessIdentifier = null; mMethodList = new ArrayList<>(); mIcon = null; return; } mOsuSsid = source.mOsuSsid; mFriendlyName = source.mFriendlyName; mServiceDescription = source.mServiceDescription; mServerUri = source.mServerUri; mNetworkAccessIdentifier = source.mNetworkAccessIdentifier; if (source.mMethodList == null) { mMethodList = new ArrayList<>(); } else { mMethodList = new ArrayList<>(source.mMethodList); } mIcon = source.mIcon; } public WifiSsid getOsuSsid() { return mOsuSsid; } public String getFriendlyName() { return mFriendlyName; } public String getServiceDescription() { return mServiceDescription; } public Uri getServerUri() { return mServerUri; } public String getNetworkAccessIdentifier() { return mNetworkAccessIdentifier; } public List<Integer> getMethodList() { return Collections.unmodifiableList(mMethodList); } public Icon getIcon() { return mIcon; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(mOsuSsid, flags); dest.writeString(mFriendlyName); dest.writeString(mServiceDescription); dest.writeParcelable(mServerUri, flags); dest.writeString(mNetworkAccessIdentifier); dest.writeList(mMethodList); dest.writeParcelable(mIcon, flags); } @Override public boolean equals(Object thatObject) { if (this == thatObject) { return true; } if (!(thatObject instanceof OsuProvider)) { return false; } OsuProvider that = (OsuProvider) thatObject; return (mOsuSsid == null ? that.mOsuSsid == null : mOsuSsid.equals(that.mOsuSsid)) && TextUtils.equals(mFriendlyName, that.mFriendlyName) && TextUtils.equals(mServiceDescription, that.mServiceDescription) && (mServerUri == null ? that.mServerUri == null : mServerUri.equals(that.mServerUri)) && TextUtils.equals(mNetworkAccessIdentifier, that.mNetworkAccessIdentifier) && (mMethodList == null ? that.mMethodList == null : mMethodList.equals(that.mMethodList)) && (mIcon == null ? that.mIcon == null : mIcon.sameAs(that.mIcon)); } @Override public int hashCode() { return Objects.hash(mOsuSsid, mFriendlyName, mServiceDescription, mServerUri, mNetworkAccessIdentifier, mMethodList, mIcon); } @Override public String toString() { return "OsuProvider{mOsuSsid=" + mOsuSsid + " mFriendlyName=" + mFriendlyName + " mServiceDescription=" + mServiceDescription + " mServerUri=" + mServerUri + " mNetworkAccessIdentifier=" + mNetworkAccessIdentifier + " mMethodList=" + mMethodList + " mIcon=" + mIcon; } public static final Creator<OsuProvider> CREATOR = new Creator<OsuProvider>() { @Override public OsuProvider createFromParcel(Parcel in) { WifiSsid osuSsid = (WifiSsid) in.readParcelable(null); String friendlyName = in.readString(); String serviceDescription = in.readString(); Uri serverUri = (Uri) in.readParcelable(null); String nai = in.readString(); List<Integer> methodList = new ArrayList<>(); in.readList(methodList, null); Icon icon = (Icon) in.readParcelable(null); return new OsuProvider(osuSsid, friendlyName, serviceDescription, serverUri, nai, methodList, icon); } @Override public OsuProvider[] newArray(int size) { return new OsuProvider[size]; } }; }
wifi/tests/src/android/net/wifi/hotspot2/OsuProviderTest.java 0 → 100644 +125 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.net.wifi.hotspot2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.graphics.drawable.Icon; import android.net.Uri; import android.net.wifi.WifiSsid; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Unit tests for {@link android.net.wifi.hotspot2.OsuProvider}. */ @SmallTest public class OsuProviderTest { private static final WifiSsid TEST_SSID = WifiSsid.createFromByteArray("TEST SSID".getBytes(StandardCharsets.UTF_8)); private static final String TEST_FRIENDLY_NAME = "Friendly Name"; private static final String TEST_SERVICE_DESCRIPTION = "Dummy Service"; private static final Uri TEST_SERVER_URI = Uri.parse("https://test.com"); private static final String TEST_NAI = "test.access.com"; private static final List<Integer> TEST_METHOD_LIST = Arrays.asList(OsuProvider.METHOD_SOAP_XML_SPP); private static final Icon TEST_ICON = Icon.createWithData(new byte[10], 0, 10); /** * Verify parcel write and read consistency for the given {@link OsuProvider}. * * @param writeInfo The {@link OsuProvider} to verify * @throws Exception */ private static void verifyParcel(OsuProvider writeInfo) throws Exception { Parcel parcel = Parcel.obtain(); writeInfo.writeToParcel(parcel, 0); parcel.setDataPosition(0); // Rewind data position back to the beginning for read. OsuProvider readInfo = OsuProvider.CREATOR.createFromParcel(parcel); assertEquals(writeInfo, readInfo); } /** * Verify parcel read/write for an OSU provider containing no information. * * @throws Exception */ @Test public void verifyParcelWithEmptyProviderInfo() throws Exception { verifyParcel(new OsuProvider(null, null, null, null, null, null, null)); } /** * Verify parcel read/write for an OSU provider containing full information. * * @throws Exception */ @Test public void verifyParcelWithFullProviderInfo() throws Exception { verifyParcel(new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON)); } /** * Verify copy constructor with a null source. * @throws Exception */ @Test public void verifyCopyConstructorWithNullSource() throws Exception { OsuProvider expected = new OsuProvider(null, null, null, null, null, null, null); assertEquals(expected, new OsuProvider(null)); } /** * Verify copy constructor with a valid source. * * @throws Exception */ @Test public void verifyCopyConstructorWithValidSource() throws Exception { OsuProvider source = new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON); assertEquals(source, new OsuProvider(source)); } /** * Verify getter methods. * * @throws Exception */ @Test public void verifyGetters() throws Exception { OsuProvider provider = new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION, TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON); assertTrue(TEST_SSID.equals(provider.getOsuSsid())); assertTrue(TEST_FRIENDLY_NAME.equals(provider.getFriendlyName())); assertTrue(TEST_SERVICE_DESCRIPTION.equals(provider.getServiceDescription())); assertTrue(TEST_SERVER_URI.equals(provider.getServerUri())); assertTrue(TEST_NAI.equals(provider.getNetworkAccessIdentifier())); assertTrue(TEST_METHOD_LIST.equals(provider.getMethodList())); assertTrue(TEST_ICON.sameAs(provider.getIcon())); } }