blob: d0b67ec7d8e5c2c0e86b552ec61e2941c2fa42b3 [file] [log] [blame]
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04001/**
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * If you own a pjsip commercial license you can also redistribute it
11 * and/or modify it under the terms of the GNU Lesser General Public License
12 * as an android library.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
alisionf76de3b2013-04-16 15:35:22 -040022package com.savoirfairelinux.sflphone.account;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040023
24import com.savoirfairelinux.sflphone.R;
alisionf76de3b2013-04-16 15:35:22 -040025import com.savoirfairelinux.sflphone.account.AccountDetail;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040026
Alexandre Savard68838112012-10-30 11:34:43 -040027import android.util.Log;
28
Alexandre Savardae992932012-10-17 10:26:12 -040029import java.util.ArrayList;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040030import java.util.Collection;
31import java.util.Set;
32import java.util.HashMap;
33
34public class AccountDetailSrtp implements AccountDetail{
35
Alexandre Savard68838112012-10-30 11:34:43 -040036 private static final String TAG = "AccountDetailSrtp";
37 public static final String BUNDLE_TAG = "SrtpPreferenceArrayList";
38
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040039 public static final String CONFIG_SRTP_ENABLE = "SRTP.enable";
40 public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
41 public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
42 public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
43 public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable";
44 public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS";
45 public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning";
46 public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce";
47
Alexandre Savard68838112012-10-30 11:34:43 -040048 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040049
Alexandre Savardae992932012-10-17 10:26:12 -040050 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
51 {
52 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
53
54 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, R.string.account_srtp_enabled_label, true));
55 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, R.string.account_srtp_exchange_label, true));
56 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, R.string.account_encryption_algo_label, true));
57 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, R.string.account_srtp_fallback_label, true));
58 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, R.string.account_hello_hash_enable_label, true));
59 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, R.string.account_display_sas_label, true));
60 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, R.string.account_not_supported_warning_label, true));
61 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, R.string.account_display_sas_once_label, true));
62
63 return preference;
64 }
65
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040066 public AccountDetailSrtp()
67 {
Alexandre Savard68838112012-10-30 11:34:43 -040068 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040069 }
70
Alexandre Savard68838112012-10-30 11:34:43 -040071 public AccountDetailSrtp(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040072 {
Alexandre Savard68838112012-10-30 11:34:43 -040073 privateArray = getPreferenceEntries();
74
75 for(AccountDetail.PreferenceEntry p : privateArray) {
76 p.mValue = pref.get(p.mKey);
77 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040078 }
79
Alexandre Savard68838112012-10-30 11:34:43 -040080 public AccountDetailSrtp(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040081 {
Alexandre Savard68838112012-10-30 11:34:43 -040082 privateArray = getPreferenceEntries();
83
84 if(pref.size() != privateArray.size()) {
85 Log.i(TAG, "Error list are not of equal size");
86 }
87 else {
88 int index = 0;
89 for(String s : pref) {
90 privateArray.get(index).mValue = s;
91 index++;
92 }
93 }
94 }
95
96 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues()
97 {
98 return privateArray;
99 }
100
101 public ArrayList<String> getValuesOnly()
102 {
103 ArrayList<String> valueList = new ArrayList<String>();
104
105 for(AccountDetail.PreferenceEntry p : privateArray) {
106 valueList.add(p.mValue);
107 }
108
109 return valueList;
110 }
111
Alexandre Savard833616f2012-10-30 16:02:30 -0400112 public HashMap<String, String> getDetailsHashMap()
113 {
114 HashMap<String, String> map = new HashMap<String, String>();
115
116 for(AccountDetail.PreferenceEntry p : privateArray) {
117 map.put(p.mKey, p.mValue);
118 }
119
120 return map;
121 }
122
Alexandre Savard68838112012-10-30 11:34:43 -0400123 public String getDetailString(String key)
124 {
125 String value = "";
126
127 for(AccountDetail.PreferenceEntry p : privateArray) {
128 if(p.mKey.equals(key)) {
129 value = p.mValue;
130 return value;
131 }
132 }
133
134 return value;
135 }
136
Alexandre Savard833616f2012-10-30 16:02:30 -0400137 public void setDetailString(int position, String newValue)
138 {
139 privateArray.get(position).mValue = newValue;
140 }
141
142
Alexandre Savard68838112012-10-30 11:34:43 -0400143 public boolean getDetailBoolean()
144 {
145 return true;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400146 }
147}