blob: 49accb5ac0f0195ccad5531f45f4c3f89ceb5961 [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 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() {
Alexandre Savard68838112012-10-30 11:34:43 -040060 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040061 }
62
Alexandre Lision5f1502e2013-12-02 16:21:40 -050063 public AccountDetailSrtp(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040064 privateArray = getPreferenceEntries();
Alexandre Lision5f1502e2013-12-02 16:21:40 -050065 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040066 p.mValue = pref.get(p.mKey);
67 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040068 }
69
Alexandre Lision5f1502e2013-12-02 16:21:40 -050070 public AccountDetailSrtp(ArrayList<String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040071 privateArray = getPreferenceEntries();
72
Alexandre Lision5f1502e2013-12-02 16:21:40 -050073 if (pref.size() != privateArray.size()) {
Alexandre Savard68838112012-10-30 11:34:43 -040074 Log.i(TAG, "Error list are not of equal size");
Alexandre Lision5f1502e2013-12-02 16:21:40 -050075 } else {
Alexandre Savard68838112012-10-30 11:34:43 -040076 int index = 0;
Alexandre Lision5f1502e2013-12-02 16:21:40 -050077 for (String s : pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040078 privateArray.get(index).mValue = s;
79 index++;
80 }
81 }
82 }
83
Alexandre Lision5f1502e2013-12-02 16:21:40 -050084 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -040085 return privateArray;
86 }
87
Alexandre Lision5f1502e2013-12-02 16:21:40 -050088 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -040089 ArrayList<String> valueList = new ArrayList<String>();
90
Alexandre Lision5f1502e2013-12-02 16:21:40 -050091 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040092 valueList.add(p.mValue);
93 }
94
95 return valueList;
96 }
97
Alexandre Lision5f1502e2013-12-02 16:21:40 -050098 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -040099 HashMap<String, String> map = new HashMap<String, String>();
100
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500101 for (AccountDetail.PreferenceEntry p : privateArray) {
102 if (p.mValue == null) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400103 map.put(p.mKey, "");
104 } else {
105 map.put(p.mKey, p.mValue);
106 }
Alexandre Savard833616f2012-10-30 16:02:30 -0400107 }
108
109 return map;
110 }
111
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500112 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400113 String value = "";
114
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500115 for (AccountDetail.PreferenceEntry p : privateArray) {
116 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400117 value = p.mValue;
118 return value;
119 }
120 }
121
122 return value;
123 }
124
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500125 public void setDetailString(String key, String newValue) {
126 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400127 PreferenceEntry p = privateArray.get(i);
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500128 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400129 privateArray.get(i).mValue = newValue;
130 }
131 }
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500132
Alexandre Savard833616f2012-10-30 16:02:30 -0400133 }
134
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500135 public boolean getDetailBoolean(String srtpParam) {
Alexandre Lision5f1502e2013-12-02 16:21:40 -0500136 for (AccountDetail.PreferenceEntry p : privateArray) {
137 if (p.mKey.equals(srtpParam)) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500138 return p.mValue.contentEquals("true");
139 }
140 }
141 return false;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400142 }
143}