Adrien BĂ©raud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2004-2014 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 | */ |
| 22 | package cx.ring.model.account; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
| 26 | |
| 27 | public class AccountDetailSrtp implements AccountDetail { |
| 28 | |
| 29 | private static final String TAG = "AccountDetailSrtp"; |
| 30 | |
| 31 | public static final String CONFIG_SRTP_ENABLE = "SRTP.enable"; |
| 32 | public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange"; |
| 33 | public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8 |
| 34 | public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback"; |
| 35 | public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable"; |
| 36 | public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS"; |
| 37 | public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning"; |
| 38 | public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce"; |
| 39 | |
| 40 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
| 41 | |
| 42 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
| 43 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 44 | |
| 45 | preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, true)); |
| 46 | preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, false)); |
| 47 | preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, true)); |
| 48 | preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, true)); |
| 49 | preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, true)); |
| 50 | preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, true)); |
| 51 | preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, true)); |
| 52 | preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, true)); |
| 53 | |
| 54 | return preference; |
| 55 | } |
| 56 | |
| 57 | public AccountDetailSrtp(HashMap<String, String> pref) { |
| 58 | privateArray = getPreferenceEntries(); |
| 59 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 60 | p.mValue = pref.get(p.mKey); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
| 65 | return privateArray; |
| 66 | } |
| 67 | |
| 68 | public ArrayList<String> getValuesOnly() { |
| 69 | ArrayList<String> valueList = new ArrayList<String>(); |
| 70 | |
| 71 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 72 | valueList.add(p.mValue); |
| 73 | } |
| 74 | |
| 75 | return valueList; |
| 76 | } |
| 77 | |
| 78 | public HashMap<String, String> getDetailsHashMap() { |
| 79 | HashMap<String, String> map = new HashMap<String, String>(); |
| 80 | |
| 81 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 82 | if (p.mValue == null) { |
| 83 | map.put(p.mKey, ""); |
| 84 | } else { |
| 85 | map.put(p.mKey, p.mValue); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return map; |
| 90 | } |
| 91 | |
| 92 | public String getDetailString(String key) { |
| 93 | String value = ""; |
| 94 | |
| 95 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 96 | if (p.mKey.equals(key)) { |
| 97 | value = p.mValue; |
| 98 | return value; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return value; |
| 103 | } |
| 104 | |
| 105 | public void setDetailString(String key, String newValue) { |
| 106 | for (int i = 0; i < privateArray.size(); ++i) { |
| 107 | PreferenceEntry p = privateArray.get(i); |
| 108 | if (p.mKey.equals(key)) { |
| 109 | privateArray.get(i).mValue = newValue; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | public boolean getDetailBoolean(String srtpParam) { |
| 116 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 117 | if (p.mKey.equals(srtpParam)) { |
| 118 | return p.mValue.contentEquals("true"); |
| 119 | } |
| 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | } |