blob: 016e7133c6f1bf0867f3c18093cc67739166b77e [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";
alision5cfc35d2013-07-11 15:11:39 -040034
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040035 public static final String CONFIG_SRTP_ENABLE = "SRTP.enable";
36 public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
37 public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
38 public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
39 public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable";
40 public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS";
41 public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning";
42 public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce";
43
Alexandre Savard68838112012-10-30 11:34:43 -040044 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040045
Alexandre Savardae992932012-10-17 10:26:12 -040046 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
47 {
48 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
49
50 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, R.string.account_srtp_enabled_label, true));
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050051 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, R.string.account_srtp_exchange_label, false));
Alexandre Savardae992932012-10-17 10:26:12 -040052 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, R.string.account_encryption_algo_label, true));
53 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, R.string.account_srtp_fallback_label, true));
54 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, R.string.account_hello_hash_enable_label, true));
55 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, R.string.account_display_sas_label, true));
56 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, R.string.account_not_supported_warning_label, true));
57 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, R.string.account_display_sas_once_label, true));
58
59 return preference;
60 }
61
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040062 public AccountDetailSrtp()
63 {
Alexandre Savard68838112012-10-30 11:34:43 -040064 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040065 }
66
Alexandre Savard68838112012-10-30 11:34:43 -040067 public AccountDetailSrtp(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040068 {
Alexandre Savard68838112012-10-30 11:34:43 -040069 privateArray = getPreferenceEntries();
Alexandre Savard68838112012-10-30 11:34:43 -040070 for(AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050071
Alexandre Savard68838112012-10-30 11:34:43 -040072 p.mValue = pref.get(p.mKey);
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050073 Log.i(TAG,p.mKey+" : "+p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -040074 }
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
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500149 public boolean getDetailBoolean(String srtpParam) {
150 for(AccountDetail.PreferenceEntry p : privateArray) {
151 if(p.mKey.equals(srtpParam)) {
152 return p.mValue.contentEquals("true");
153 }
154 }
155 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400156 }
157}