blob: 084c6af3c62b5dbd3eba8fada0f25d40d326bfb8 [file] [log] [blame]
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04001/**
Alexandre Lisionfed2a642014-01-10 12:05:47 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04003 *
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 Lision4f906b22013-10-02 10:13:45 -040027import android.util.Log;
28
Alexandre Lision5f1502e2013-12-02 16:21:40 -050029public class AccountDetailSrtp implements AccountDetail {
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040030
Alexandre Savard68838112012-10-30 11:34:43 -040031 private static final String TAG = "AccountDetailSrtp";
Alexandre Lision5f1502e2013-12-02 16:21:40 -050032
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040033 public static final String CONFIG_SRTP_ENABLE = "SRTP.enable";
34 public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
Alexandre Lision5f1502e2013-12-02 16:21:40 -050035 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 -040036 public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
37 public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable";
38 public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS";
39 public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning";
40 public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce";
41
Alexandre Savard68838112012-10-30 11:34:43 -040042 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040043
Alexandre Lision5f1502e2013-12-02 16:21:40 -050044 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040045 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
46
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050047 preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, true));
48 preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, false));
49 preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, true));
50 preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, true));
51 preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, true));
52 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, true));
53 preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, true));
54 preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, true));
Alexandre Savardae992932012-10-17 10:26:12 -040055
Alexandre Lision5f1502e2013-12-02 16:21:40 -050056 return preference;
Alexandre Savardae992932012-10-17 10:26:12 -040057 }
58
Alexandre Lision5f1502e2013-12-02 16:21:40 -050059 public AccountDetailSrtp(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040060 privateArray = getPreferenceEntries();
Alexandre Lision5f1502e2013-12-02 16:21:40 -050061 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040062 p.mValue = pref.get(p.mKey);
63 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040064 }
65
Alexandre Lision5f1502e2013-12-02 16:21:40 -050066 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -040067 return privateArray;
68 }
69
Alexandre Lision5f1502e2013-12-02 16:21:40 -050070 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -040071 ArrayList<String> valueList = new ArrayList<String>();
72
Alexandre Lision5f1502e2013-12-02 16:21:40 -050073 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040074 valueList.add(p.mValue);
75 }
76
77 return valueList;
78 }
79
Alexandre Lision5f1502e2013-12-02 16:21:40 -050080 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -040081 HashMap<String, String> map = new HashMap<String, String>();
82
Alexandre Lision5f1502e2013-12-02 16:21:40 -050083 for (AccountDetail.PreferenceEntry p : privateArray) {
84 if (p.mValue == null) {
Alexandre Lision059da9d2013-10-22 11:17:25 -040085 map.put(p.mKey, "");
86 } else {
87 map.put(p.mKey, p.mValue);
88 }
Alexandre Savard833616f2012-10-30 16:02:30 -040089 }
90
91 return map;
92 }
93
Alexandre Lision5f1502e2013-12-02 16:21:40 -050094 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -040095 String value = "";
96
Alexandre Lision5f1502e2013-12-02 16:21:40 -050097 for (AccountDetail.PreferenceEntry p : privateArray) {
98 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -040099 value = p.mValue;
100 return value;
101 }
102 }
103
104 return value;
105 }
106
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500107 public void setDetailString(String key, String newValue) {
108 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400109 PreferenceEntry p = privateArray.get(i);
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500110 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400111 privateArray.get(i).mValue = newValue;
112 }
113 }
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500114
Alexandre Savard833616f2012-10-30 16:02:30 -0400115 }
116
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500117 public boolean getDetailBoolean(String srtpParam) {
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500118 for (AccountDetail.PreferenceEntry p : privateArray) {
119 if (p.mKey.equals(srtpParam)) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500120 return p.mValue.contentEquals("true");
121 }
122 }
123 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400124 }
125}