blob: 009fc3dd9912b744e701f3e7a4fa54eee3acd2a8 [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 Lision5f1502e2013-12-02 16:21:40 -050031public class AccountDetailSrtp implements AccountDetail {
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040032
Alexandre Savard68838112012-10-30 11:34:43 -040033 private static final String TAG = "AccountDetailSrtp";
Alexandre Lision5f1502e2013-12-02 16:21:40 -050034
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";
Alexandre Lision5f1502e2013-12-02 16:21:40 -050037 public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040038 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 Lision5f1502e2013-12-02 16:21:40 -050046 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040047 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
48
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050049 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, true));
50 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, false));
51 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, true));
52 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, true));
53 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, true));
54 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, true));
55 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, true));
56 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, true));
Alexandre Savardae992932012-10-17 10:26:12 -040057
Alexandre Lision5f1502e2013-12-02 16:21:40 -050058 return preference;
Alexandre Savardae992932012-10-17 10:26:12 -040059 }
60
Alexandre Lision5f1502e2013-12-02 16:21:40 -050061 public AccountDetailSrtp() {
Alexandre Savard68838112012-10-30 11:34:43 -040062 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040063 }
64
Alexandre Lision5f1502e2013-12-02 16:21:40 -050065 public AccountDetailSrtp(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040066 privateArray = getPreferenceEntries();
Alexandre Lision5f1502e2013-12-02 16:21:40 -050067 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040068 p.mValue = pref.get(p.mKey);
69 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040070 }
71
Alexandre Lision5f1502e2013-12-02 16:21:40 -050072 public AccountDetailSrtp(ArrayList<String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040073 privateArray = getPreferenceEntries();
74
Alexandre Lision5f1502e2013-12-02 16:21:40 -050075 if (pref.size() != privateArray.size()) {
Alexandre Savard68838112012-10-30 11:34:43 -040076 Log.i(TAG, "Error list are not of equal size");
Alexandre Lision5f1502e2013-12-02 16:21:40 -050077 } else {
Alexandre Savard68838112012-10-30 11:34:43 -040078 int index = 0;
Alexandre Lision5f1502e2013-12-02 16:21:40 -050079 for (String s : pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040080 privateArray.get(index).mValue = s;
81 index++;
82 }
83 }
84 }
85
Alexandre Lision5f1502e2013-12-02 16:21:40 -050086 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -040087 return privateArray;
88 }
89
Alexandre Lision5f1502e2013-12-02 16:21:40 -050090 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -040091 ArrayList<String> valueList = new ArrayList<String>();
92
Alexandre Lision5f1502e2013-12-02 16:21:40 -050093 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040094 valueList.add(p.mValue);
95 }
96
97 return valueList;
98 }
99
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500100 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400101 HashMap<String, String> map = new HashMap<String, String>();
102
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500103 for (AccountDetail.PreferenceEntry p : privateArray) {
104 if (p.mValue == null) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400105 map.put(p.mKey, "");
106 } else {
107 map.put(p.mKey, p.mValue);
108 }
Alexandre Savard833616f2012-10-30 16:02:30 -0400109 }
110
111 return map;
112 }
113
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500114 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400115 String value = "";
116
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500117 for (AccountDetail.PreferenceEntry p : privateArray) {
118 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400119 value = p.mValue;
120 return value;
121 }
122 }
123
124 return value;
125 }
126
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500127 public void setDetailString(String key, String newValue) {
128 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400129 PreferenceEntry p = privateArray.get(i);
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500130 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400131 privateArray.get(i).mValue = newValue;
132 }
133 }
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500134
Alexandre Savard833616f2012-10-30 16:02:30 -0400135 }
136
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500137 public boolean getDetailBoolean(String srtpParam) {
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500138 for (AccountDetail.PreferenceEntry p : privateArray) {
139 if (p.mKey.equals(srtpParam)) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500140 return p.mValue.contentEquals("true");
141 }
142 }
143 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400144 }
145}