Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
| 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 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 | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 27 | import org.sflphone.R; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 28 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 31 | public class AccountDetailSrtp implements AccountDetail{ |
| 32 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 33 | private static final String TAG = "AccountDetailSrtp"; |
| 34 | public static final String BUNDLE_TAG = "SrtpPreferenceArrayList"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 35 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 36 | public static final String CONFIG_SRTP_ENABLE = "SRTP.enable"; |
| 37 | public static final String CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange"; |
| 38 | public static final String CONFIG_SRTP_ENCRYPTION_ALGO = "SRTP.encryptionAlgorithm"; // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8 |
| 39 | public static final String CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback"; |
| 40 | public static final String CONFIG_ZRTP_HELLO_HASH = "ZRTP.helloHashEnable"; |
| 41 | public static final String CONFIG_ZRTP_DISPLAY_SAS = "ZRTP.displaySAS"; |
| 42 | public static final String CONFIG_ZRTP_NOT_SUPP_WARNING = "ZRTP.notSuppWarning"; |
| 43 | public static final String CONFIG_ZRTP_DISPLAY_SAS_ONCE = "ZRTP.displaySasOnce"; |
| 44 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 45 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 46 | |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 47 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() |
| 48 | { |
| 49 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 50 | |
| 51 | preference.add(new PreferenceEntry(CONFIG_SRTP_ENABLE, R.string.account_srtp_enabled_label, true)); |
| 52 | preference.add(new PreferenceEntry(CONFIG_SRTP_KEY_EXCHANGE, R.string.account_srtp_exchange_label, true)); |
| 53 | preference.add(new PreferenceEntry(CONFIG_SRTP_ENCRYPTION_ALGO, R.string.account_encryption_algo_label, true)); |
| 54 | preference.add(new PreferenceEntry(CONFIG_SRTP_RTP_FALLBACK, R.string.account_srtp_fallback_label, true)); |
| 55 | preference.add(new PreferenceEntry(CONFIG_ZRTP_HELLO_HASH, R.string.account_hello_hash_enable_label, true)); |
| 56 | preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS, R.string.account_display_sas_label, true)); |
| 57 | preference.add(new PreferenceEntry(CONFIG_ZRTP_NOT_SUPP_WARNING, R.string.account_not_supported_warning_label, true)); |
| 58 | preference.add(new PreferenceEntry(CONFIG_ZRTP_DISPLAY_SAS_ONCE, R.string.account_display_sas_once_label, true)); |
| 59 | |
| 60 | return preference; |
| 61 | } |
| 62 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 63 | public AccountDetailSrtp() |
| 64 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 65 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 68 | public AccountDetailSrtp(HashMap<String, String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 69 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 70 | privateArray = getPreferenceEntries(); |
| 71 | |
| 72 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 73 | p.mValue = pref.get(p.mKey); |
| 74 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 77 | public AccountDetailSrtp(ArrayList<String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 78 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 79 | privateArray = getPreferenceEntries(); |
| 80 | |
| 81 | if(pref.size() != privateArray.size()) { |
| 82 | Log.i(TAG, "Error list are not of equal size"); |
| 83 | } |
| 84 | else { |
| 85 | int index = 0; |
| 86 | for(String s : pref) { |
| 87 | privateArray.get(index).mValue = s; |
| 88 | index++; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() |
| 94 | { |
| 95 | return privateArray; |
| 96 | } |
| 97 | |
| 98 | public ArrayList<String> getValuesOnly() |
| 99 | { |
| 100 | ArrayList<String> valueList = new ArrayList<String>(); |
| 101 | |
| 102 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 103 | valueList.add(p.mValue); |
| 104 | } |
| 105 | |
| 106 | return valueList; |
| 107 | } |
| 108 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 109 | public HashMap<String, String> getDetailsHashMap() |
| 110 | { |
| 111 | HashMap<String, String> map = new HashMap<String, String>(); |
| 112 | |
| 113 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 114 | map.put(p.mKey, p.mValue); |
| 115 | } |
| 116 | |
| 117 | return map; |
| 118 | } |
| 119 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 120 | public String getDetailString(String key) |
| 121 | { |
| 122 | String value = ""; |
| 123 | |
| 124 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 125 | if(p.mKey.equals(key)) { |
| 126 | value = p.mValue; |
| 127 | return value; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return value; |
| 132 | } |
| 133 | |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 134 | public void setDetailString(String key, String newValue) |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 135 | { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 136 | for(int i = 0 ; i < privateArray.size() ; ++i) { |
| 137 | PreferenceEntry p = privateArray.get(i); |
| 138 | if(p.mKey.equals(key)) { |
| 139 | privateArray.get(i).mValue = newValue; |
| 140 | } |
| 141 | } |
| 142 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 146 | public boolean getDetailBoolean() |
| 147 | { |
| 148 | return true; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 149 | } |
| 150 | } |