Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 22 | package org.sflphone.account; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 23 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 26 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 29 | public class AccountDetailSrtp implements AccountDetail { |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 30 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 31 | private static final String TAG = "AccountDetailSrtp"; |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 32 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 33 | public static final String CONFIG_SRTP_ENABLE = "SRTP.enable"; |
| 34 | public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange"; |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 35 | public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8 |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 36 | 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 Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 42 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 43 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 44 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 45 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 46 | |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 47 | 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 Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 55 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 56 | return preference; |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 59 | public AccountDetailSrtp(HashMap<String, String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 60 | privateArray = getPreferenceEntries(); |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 61 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 62 | p.mValue = pref.get(p.mKey); |
| 63 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 64 | } |
| 65 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 66 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 67 | return privateArray; |
| 68 | } |
| 69 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 70 | public ArrayList<String> getValuesOnly() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 71 | ArrayList<String> valueList = new ArrayList<String>(); |
| 72 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 73 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 74 | valueList.add(p.mValue); |
| 75 | } |
| 76 | |
| 77 | return valueList; |
| 78 | } |
| 79 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 80 | public HashMap<String, String> getDetailsHashMap() { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 81 | HashMap<String, String> map = new HashMap<String, String>(); |
| 82 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 83 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 84 | if (p.mValue == null) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 85 | map.put(p.mKey, ""); |
| 86 | } else { |
| 87 | map.put(p.mKey, p.mValue); |
| 88 | } |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | return map; |
| 92 | } |
| 93 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 94 | public String getDetailString(String key) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 95 | String value = ""; |
| 96 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 97 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 98 | if (p.mKey.equals(key)) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 99 | value = p.mValue; |
| 100 | return value; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return value; |
| 105 | } |
| 106 | |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 107 | public void setDetailString(String key, String newValue) { |
| 108 | for (int i = 0; i < privateArray.size(); ++i) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 109 | PreferenceEntry p = privateArray.get(i); |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 110 | if (p.mKey.equals(key)) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 111 | privateArray.get(i).mValue = newValue; |
| 112 | } |
| 113 | } |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 114 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 117 | public boolean getDetailBoolean(String srtpParam) { |
Alexandre Lision | 5f1502e | 2013-12-02 16:21:40 -0500 | [diff] [blame] | 118 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 119 | if (p.mKey.equals(srtpParam)) { |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 120 | return p.mValue.contentEquals("true"); |
| 121 | } |
| 122 | } |
| 123 | return false; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 124 | } |
| 125 | } |