blob: 05d54514725ff06265fe56007b28a915010ea520 [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 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040022package org.sflphone.account;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040023
Alexandre Lision6e8931e2013-09-19 16:49:34 -040024import java.util.ArrayList;
25import java.util.HashMap;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040026
Alexandre Lision064e1e02013-10-01 16:18:42 -040027import org.sflphone.R;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040028
Alexandre Lision4f906b22013-10-02 10:13:45 -040029import android.util.Log;
30
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040031public class AccountDetailSrtp implements AccountDetail{
32
Alexandre Savard68838112012-10-30 11:34:43 -040033 private static final String TAG = "AccountDetailSrtp";
34 public static final String BUNDLE_TAG = "SrtpPreferenceArrayList";
alision5cfc35d2013-07-11 15:11:39 -040035
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040036 public static final String CONFIG_SRTP_ENABLE = "SRTP.enable";
37 public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
38 public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
39 public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
40 public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable";
41 public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS";
42 public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning";
43 public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce";
44
Alexandre Savard68838112012-10-30 11:34:43 -040045 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040046
Alexandre Savardae992932012-10-17 10:26:12 -040047 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
48 {
49 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
50
51 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, R.string.account_srtp_enabled_label, true));
52 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, R.string.account_srtp_exchange_label, true));
53 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, R.string.account_encryption_algo_label, true));
54 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, R.string.account_srtp_fallback_label, true));
55 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, R.string.account_hello_hash_enable_label, true));
56 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, R.string.account_display_sas_label, true));
57 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, R.string.account_not_supported_warning_label, true));
58 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, R.string.account_display_sas_once_label, true));
59
60 return preference;
61 }
62
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040063 public AccountDetailSrtp()
64 {
Alexandre Savard68838112012-10-30 11:34:43 -040065 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040066 }
67
Alexandre Savard68838112012-10-30 11:34:43 -040068 public AccountDetailSrtp(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040069 {
Alexandre Savard68838112012-10-30 11:34:43 -040070 privateArray = getPreferenceEntries();
71
72 for(AccountDetail.PreferenceEntry p : privateArray) {
73 p.mValue = pref.get(p.mKey);
74 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040075 }
76
Alexandre Savard68838112012-10-30 11:34:43 -040077 public AccountDetailSrtp(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040078 {
Alexandre Savard68838112012-10-30 11:34:43 -040079 privateArray = getPreferenceEntries();
80
81 if(pref.size() != privateArray.size()) {
82 Log.i(TAG, "Error list are not of equal size");
83 }
84 else {
85 int index = 0;
86 for(String s : pref) {
87 privateArray.get(index).mValue = s;
88 index++;
89 }
90 }
91 }
92
93 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues()
94 {
95 return privateArray;
96 }
97
98 public ArrayList<String> getValuesOnly()
99 {
100 ArrayList<String> valueList = new ArrayList<String>();
101
102 for(AccountDetail.PreferenceEntry p : privateArray) {
103 valueList.add(p.mValue);
104 }
105
106 return valueList;
107 }
108
Alexandre Savard833616f2012-10-30 16:02:30 -0400109 public HashMap<String, String> getDetailsHashMap()
110 {
111 HashMap<String, String> map = new HashMap<String, String>();
112
113 for(AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400114 if(p.mValue == null){
115 map.put(p.mKey, "");
116 } else {
117 map.put(p.mKey, p.mValue);
118 }
Alexandre Savard833616f2012-10-30 16:02:30 -0400119 }
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}