Home | History | Annotate | Download | only in wifi
      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 com.android.car.settings.wifi;
     18 
     19 import android.content.Context;
     20 
     21 import com.android.car.settings.R;
     22 import com.android.settingslib.wifi.AccessPoint;
     23 
     24 import java.util.ArrayList;
     25 import java.util.Arrays;
     26 import java.util.List;
     27 
     28 /**
     29  * Represents Security protocol for AccessPoint.
     30  */
     31 public class AccessPointSecurity {
     32     public static final int SECURITY_NONE_POSITION = 0;
     33     private final int mSecurityType;
     34     private final Context mContext;
     35     private static final List<Integer> SECURITY_TYPES = Arrays.asList(
     36             AccessPoint.SECURITY_NONE,
     37             AccessPoint.SECURITY_WEP,
     38             AccessPoint.SECURITY_PSK,
     39             AccessPoint.SECURITY_EAP);
     40 
     41     public static List<AccessPointSecurity> getSecurityTypes(Context context) {
     42         List<AccessPointSecurity> securities = new ArrayList<>();
     43         for (int security : SECURITY_TYPES) {
     44             securities.add(new AccessPointSecurity(context, security));
     45         }
     46         return securities;
     47     }
     48 
     49     private AccessPointSecurity(Context context, int securityType) {
     50         mContext = context;
     51         mSecurityType = securityType;
     52     }
     53 
     54     public int getSecurityType() {
     55         return mSecurityType;
     56     }
     57 
     58     @Override
     59     public String toString() {
     60         switch(mSecurityType) {
     61             case AccessPoint.SECURITY_EAP:
     62                 return mContext.getString(R.string.wifi_security_eap);
     63             case AccessPoint.SECURITY_PSK:
     64                 return mContext.getString(R.string.wifi_security_psk_generic);
     65             case AccessPoint.SECURITY_WEP:
     66                 return mContext.getString(R.string.wifi_security_wep);
     67             case AccessPoint.SECURITY_NONE:
     68             default:
     69                 return mContext.getString(R.string.wifi_security_none);
     70         }
     71     }
     72 }
     73