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