Home | History | Annotate | Download | only in hotspot2
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package android.net.wifi.hotspot2;
     18 
     19 import android.graphics.drawable.Icon;
     20 import android.net.Uri;
     21 import android.net.wifi.WifiSsid;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 import android.text.TextUtils;
     25 
     26 import java.util.ArrayList;
     27 import java.util.Collections;
     28 import java.util.List;
     29 import java.util.Objects;
     30 
     31 /**
     32  * Contained information for a Hotspot 2.0 OSU (Online Sign-Up provider).
     33  *
     34  * @hide
     35  */
     36 public final class OsuProvider implements Parcelable {
     37     /**
     38      * OSU (Online Sign-Up) method: OMA DM (Open Mobile Alliance Device Management).
     39      * For more info, refer to Section 8.3 of the Hotspot 2.0 Release 2 Technical Specification.
     40      */
     41     public static final int METHOD_OMA_DM = 0;
     42 
     43     /**
     44      * OSU (Online Sign-Up) method: SOAP XML SPP (Subscription Provisioning Protocol).
     45      * For more info, refer to Section 8.4 of the Hotspot 2.0 Release 2 Technical Specification.
     46      */
     47     public static final int METHOD_SOAP_XML_SPP = 1;
     48 
     49     /**
     50      * SSID of the network to connect for service sign-up.
     51      */
     52     private final WifiSsid mOsuSsid;
     53 
     54     /**
     55      * Friendly name of the OSU provider.
     56      */
     57     private final String mFriendlyName;
     58 
     59     /**
     60      * Description of the OSU provider.
     61      */
     62     private final String mServiceDescription;
     63 
     64     /**
     65      * URI to browse to for service sign-up.
     66      */
     67     private final Uri mServerUri;
     68 
     69     /**
     70      * Network Access Identifier used for authenticating with the OSU network when OSEN is used.
     71      */
     72     private final String mNetworkAccessIdentifier;
     73 
     74     /**
     75      * List of OSU (Online Sign-Up) method supported.
     76      */
     77     private final List<Integer> mMethodList;
     78 
     79     /**
     80      * Icon data for the OSU (Online Sign-Up) provider.
     81      */
     82     private final Icon mIcon;
     83 
     84     public OsuProvider(WifiSsid osuSsid, String friendlyName, String serviceDescription,
     85             Uri serverUri, String nai, List<Integer> methodList, Icon icon) {
     86         mOsuSsid = osuSsid;
     87         mFriendlyName = friendlyName;
     88         mServiceDescription = serviceDescription;
     89         mServerUri = serverUri;
     90         mNetworkAccessIdentifier = nai;
     91         if (methodList == null) {
     92             mMethodList = new ArrayList<>();
     93         } else {
     94             mMethodList = new ArrayList<>(methodList);
     95         }
     96         mIcon = icon;
     97     }
     98 
     99     /**
    100      * Copy constructor.
    101      *
    102      * @param source The source to copy from
    103      */
    104     public OsuProvider(OsuProvider source) {
    105         if (source == null) {
    106             mOsuSsid = null;
    107             mFriendlyName = null;
    108             mServiceDescription = null;
    109             mServerUri = null;
    110             mNetworkAccessIdentifier = null;
    111             mMethodList = new ArrayList<>();
    112             mIcon = null;
    113             return;
    114         }
    115 
    116         mOsuSsid = source.mOsuSsid;
    117         mFriendlyName = source.mFriendlyName;
    118         mServiceDescription = source.mServiceDescription;
    119         mServerUri = source.mServerUri;
    120         mNetworkAccessIdentifier = source.mNetworkAccessIdentifier;
    121         if (source.mMethodList == null) {
    122             mMethodList = new ArrayList<>();
    123         } else {
    124             mMethodList = new ArrayList<>(source.mMethodList);
    125         }
    126         mIcon = source.mIcon;
    127     }
    128 
    129     public WifiSsid getOsuSsid() {
    130         return mOsuSsid;
    131     }
    132 
    133     public String getFriendlyName() {
    134         return mFriendlyName;
    135     }
    136 
    137     public String getServiceDescription() {
    138         return mServiceDescription;
    139     }
    140 
    141     public Uri getServerUri() {
    142         return mServerUri;
    143     }
    144 
    145     public String getNetworkAccessIdentifier() {
    146         return mNetworkAccessIdentifier;
    147     }
    148 
    149     public List<Integer> getMethodList() {
    150         return Collections.unmodifiableList(mMethodList);
    151     }
    152 
    153     public Icon getIcon() {
    154         return mIcon;
    155     }
    156 
    157     @Override
    158     public int describeContents() {
    159         return 0;
    160     }
    161 
    162     @Override
    163     public void writeToParcel(Parcel dest, int flags) {
    164         dest.writeParcelable(mOsuSsid, flags);
    165         dest.writeString(mFriendlyName);
    166         dest.writeString(mServiceDescription);
    167         dest.writeParcelable(mServerUri, flags);
    168         dest.writeString(mNetworkAccessIdentifier);
    169         dest.writeList(mMethodList);
    170         dest.writeParcelable(mIcon, flags);
    171     }
    172 
    173     @Override
    174     public boolean equals(Object thatObject) {
    175         if (this == thatObject) {
    176             return true;
    177         }
    178         if (!(thatObject instanceof OsuProvider)) {
    179             return false;
    180         }
    181         OsuProvider that = (OsuProvider) thatObject;
    182         return (mOsuSsid == null ? that.mOsuSsid == null : mOsuSsid.equals(that.mOsuSsid))
    183                 && TextUtils.equals(mFriendlyName, that.mFriendlyName)
    184                 && TextUtils.equals(mServiceDescription, that.mServiceDescription)
    185                 && (mServerUri == null ? that.mServerUri == null
    186                             : mServerUri.equals(that.mServerUri))
    187                 && TextUtils.equals(mNetworkAccessIdentifier, that.mNetworkAccessIdentifier)
    188                 && (mMethodList == null ? that.mMethodList == null
    189                             : mMethodList.equals(that.mMethodList))
    190                 && (mIcon == null ? that.mIcon == null : mIcon.sameAs(that.mIcon));
    191     }
    192 
    193     @Override
    194     public int hashCode() {
    195         return Objects.hash(mOsuSsid, mFriendlyName, mServiceDescription, mServerUri,
    196                 mNetworkAccessIdentifier, mMethodList, mIcon);
    197     }
    198 
    199     @Override
    200     public String toString() {
    201         return "OsuProvider{mOsuSsid=" + mOsuSsid
    202                 + " mFriendlyName=" + mFriendlyName
    203                 + " mServiceDescription=" + mServiceDescription
    204                 + " mServerUri=" + mServerUri
    205                 + " mNetworkAccessIdentifier=" + mNetworkAccessIdentifier
    206                 + " mMethodList=" + mMethodList
    207                 + " mIcon=" + mIcon;
    208     }
    209 
    210     public static final Creator<OsuProvider> CREATOR =
    211         new Creator<OsuProvider>() {
    212             @Override
    213             public OsuProvider createFromParcel(Parcel in) {
    214                 WifiSsid osuSsid = (WifiSsid) in.readParcelable(null);
    215                 String friendlyName = in.readString();
    216                 String serviceDescription = in.readString();
    217                 Uri serverUri = (Uri) in.readParcelable(null);
    218                 String nai = in.readString();
    219                 List<Integer> methodList = new ArrayList<>();
    220                 in.readList(methodList, null);
    221                 Icon icon = (Icon) in.readParcelable(null);
    222                 return new OsuProvider(osuSsid, friendlyName, serviceDescription, serverUri,
    223                         nai, methodList, icon);
    224             }
    225 
    226             @Override
    227             public OsuProvider[] newArray(int size) {
    228                 return new OsuProvider[size];
    229             }
    230         };
    231 }
    232