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