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.wifitrackerlib.WifiEntry;
23 
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27 
28 /**
29  * Represents Security protocol for WifiEntry.
30  */
31 public class WifiEntrySecurity {
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             WifiEntry.SECURITY_NONE,
37             WifiEntry.SECURITY_WEP,
38             WifiEntry.SECURITY_PSK,
39             WifiEntry.SECURITY_EAP,
40             WifiEntry.SECURITY_SAE,
41             WifiEntry.SECURITY_OWE,
42             WifiEntry.SECURITY_EAP_SUITE_B);
43 
44     /**
45      * Returns a list of security protocols for WifiEntries.
46      */
getSecurityTypes(Context context)47     public static List<WifiEntrySecurity> getSecurityTypes(Context context) {
48         List<WifiEntrySecurity> securities = new ArrayList<>();
49         for (int security : SECURITY_TYPES) {
50             securities.add(new WifiEntrySecurity(context, security));
51         }
52         return securities;
53     }
54 
WifiEntrySecurity(Context context, int securityType)55     private WifiEntrySecurity(Context context, int securityType) {
56         mContext = context;
57         mSecurityType = securityType;
58     }
59 
getSecurityType()60     public int getSecurityType() {
61         return mSecurityType;
62     }
63 
64     @Override
toString()65     public String toString() {
66         switch(mSecurityType) {
67             case WifiEntry.SECURITY_EAP_SUITE_B:
68                 return mContext.getString(R.string.wifi_security_eap_suiteb);
69             case WifiEntry.SECURITY_EAP:
70                 return mContext.getString(R.string.wifi_security_eap);
71             case WifiEntry.SECURITY_SAE:
72                 return mContext.getString(R.string.wifi_security_sae);
73             case WifiEntry.SECURITY_PSK:
74                 return mContext.getString(R.string.wifi_security_psk_generic);
75             case WifiEntry.SECURITY_WEP:
76                 return mContext.getString(R.string.wifi_security_wep);
77             case WifiEntry.SECURITY_OWE:
78                 return mContext.getString(R.string.wifi_security_owe);
79             case WifiEntry.SECURITY_NONE:
80             default:
81                 return mContext.getString(R.string.wifi_security_none);
82         }
83     }
84 }
85