blob: 2585ffa23bfbb316c16b19627c83aaef2d614bc9 [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;
alision5de91782013-07-10 10:47:30 -040026import com.savoirfairelinux.sflphone.account.AccountDetail.PreferenceEntry;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040027
Alexandre Savard68838112012-10-30 11:34:43 -040028import android.util.Log;
29
Alexandre Savardae992932012-10-17 10:26:12 -040030import java.util.ArrayList;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040031import java.util.Collection;
32import java.util.Set;
33import java.util.HashMap;
34
35public class AccountDetailSrtp implements AccountDetail{
36
Alexandre Savard68838112012-10-30 11:34:43 -040037 private static final String TAG = "AccountDetailSrtp";
38 public static final String BUNDLE_TAG = "SrtpPreferenceArrayList";
39
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040040 public static final String CONFIG_SRTP_ENABLE = "SRTP.enable";
41 public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
42 public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
43 public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
44 public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable";
45 public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS";
46 public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning";
47 public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce";
48
Alexandre Savard68838112012-10-30 11:34:43 -040049 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040050
Alexandre Savardae992932012-10-17 10:26:12 -040051 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
52 {
53 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
54
55 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, R.string.account_srtp_enabled_label, true));
56 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, R.string.account_srtp_exchange_label, true));
57 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, R.string.account_encryption_algo_label, true));
58 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, R.string.account_srtp_fallback_label, true));
59 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, R.string.account_hello_hash_enable_label, true));
60 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, R.string.account_display_sas_label, true));
61 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, R.string.account_not_supported_warning_label, true));
62 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, R.string.account_display_sas_once_label, true));
63
64 return preference;
65 }
66
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040067 public AccountDetailSrtp()
68 {
Alexandre Savard68838112012-10-30 11:34:43 -040069 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040070 }
71
Alexandre Savard68838112012-10-30 11:34:43 -040072 public AccountDetailSrtp(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040073 {
Alexandre Savard68838112012-10-30 11:34:43 -040074 privateArray = getPreferenceEntries();
75
76 for(AccountDetail.PreferenceEntry p : privateArray) {
77 p.mValue = pref.get(p.mKey);
78 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040079 }
80
Alexandre Savard68838112012-10-30 11:34:43 -040081 public AccountDetailSrtp(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040082 {
Alexandre Savard68838112012-10-30 11:34:43 -040083 privateArray = getPreferenceEntries();
84
85 if(pref.size() != privateArray.size()) {
86 Log.i(TAG, "Error list are not of equal size");
87 }
88 else {
89 int index = 0;
90 for(String s : pref) {
91 privateArray.get(index).mValue = s;
92 index++;
93 }
94 }
95 }
96
97 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues()
98 {
99 return privateArray;
100 }
101
102 public ArrayList<String> getValuesOnly()
103 {
104 ArrayList<String> valueList = new ArrayList<String>();
105
106 for(AccountDetail.PreferenceEntry p : privateArray) {
107 valueList.add(p.mValue);
108 }
109
110 return valueList;
111 }
112
Alexandre Savard833616f2012-10-30 16:02:30 -0400113 public HashMap<String, String> getDetailsHashMap()
114 {
115 HashMap<String, String> map = new HashMap<String, String>();
116
117 for(AccountDetail.PreferenceEntry p : privateArray) {
118 map.put(p.mKey, p.mValue);
119 }
120
121 return map;
122 }
123
Alexandre Savard68838112012-10-30 11:34:43 -0400124 public String getDetailString(String key)
125 {
126 String value = "";
127
128 for(AccountDetail.PreferenceEntry p : privateArray) {
129 if(p.mKey.equals(key)) {
130 value = p.mValue;
131 return value;
132 }
133 }
134
135 return value;
136 }
137
alision5de91782013-07-10 10:47:30 -0400138 public void setDetailString(String key, String newValue)
Alexandre Savard833616f2012-10-30 16:02:30 -0400139 {
alision5de91782013-07-10 10:47:30 -0400140 for(int i = 0 ; i < privateArray.size() ; ++i) {
141 PreferenceEntry p = privateArray.get(i);
142 if(p.mKey.equals(key)) {
143 privateArray.get(i).mValue = newValue;
144 }
145 }
146
Alexandre Savard833616f2012-10-30 16:02:30 -0400147 }
148
149
Alexandre Savard68838112012-10-30 11:34:43 -0400150 public boolean getDetailBoolean()
151 {
152 return true;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400153 }
154}