Manager encryption using new API
This commit is contained in:
parent
61749c28bc
commit
51e063b0a7
5 changed files with 127 additions and 107 deletions
|
@ -94,6 +94,7 @@
|
||||||
<string name="pref_stun_server_key">pref_stun_server_key</string>
|
<string name="pref_stun_server_key">pref_stun_server_key</string>
|
||||||
<string name="pref_ice_enable_key">pref_ice_enable_key</string>
|
<string name="pref_ice_enable_key">pref_ice_enable_key</string>
|
||||||
<string name="pref_video_codec_vp8_key">pref_video_codec_vp8_key</string>
|
<string name="pref_video_codec_vp8_key">pref_video_codec_vp8_key</string>
|
||||||
|
<string name="pref_media_encryption_key">pref_media_encryption_key</string>
|
||||||
<string name="pref_media_encryption_key_none">none</string>
|
<string name="pref_media_encryption_key_none">none</string>
|
||||||
<string name="pref_media_encryption_key_srtp">srtp</string>
|
<string name="pref_media_encryption_key_srtp">srtp</string>
|
||||||
<string name="pref_media_encryption_key_zrtp">zrtp</string>
|
<string name="pref_media_encryption_key_zrtp">zrtp</string>
|
||||||
|
@ -121,8 +122,6 @@
|
||||||
|
|
||||||
<string name="pref_first_time_linphone_chat_storage">pref_first_time_linphone_chat_storage</string>
|
<string name="pref_first_time_linphone_chat_storage">pref_first_time_linphone_chat_storage</string>
|
||||||
|
|
||||||
<!-- LP Config bindings from Android preferences -->
|
|
||||||
<string name="pref_media_encryption_key">lpconfig_sip_media_enc_key</string>
|
|
||||||
|
|
||||||
<!-- LP Config preferences names -->
|
<!-- LP Config preferences names -->
|
||||||
<string name="lpconfig_net_downloadbw_key">download_bw</string>
|
<string name="lpconfig_net_downloadbw_key">download_bw</string>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:title="Root">
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/pref_preferences">
|
android:title="@string/pref_preferences">
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:title="@string/pref_media_encryption"
|
android:title="@string/pref_media_encryption"
|
||||||
android:key="@string/pref_media_encryption_key"
|
android:key="@string/lpconfig_sip_media_enc_key" />
|
||||||
android:defaultValue="@string/pref_media_encryption_default" />
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
|
@ -545,7 +545,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
copyAssetsFromPackage();
|
copyAssetsFromPackage();
|
||||||
//traces alway start with traces enable to not missed first initialization
|
//traces alway start with traces enable to not missed first initialization
|
||||||
|
|
||||||
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && getPrefBoolean(R.string.pref_debug_key, mR.getBoolean(R.bool.pref_debug_default));
|
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log));
|
||||||
LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name));
|
LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name));
|
||||||
|
|
||||||
// Try to get remote provisioning
|
// Try to get remote provisioning
|
||||||
|
@ -567,7 +567,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
Log.e(e, "cannot get version name");
|
Log.e(e, "cannot get version name");
|
||||||
}
|
}
|
||||||
|
|
||||||
mLc.enableIpv6(getPrefBoolean(R.string.pref_ipv6_key, false));
|
|
||||||
mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets");
|
mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets");
|
||||||
|
|
||||||
mLc.setRing(null);
|
mLc.setRing(null);
|
||||||
|
@ -647,17 +646,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initMediaEncryption(){
|
|
||||||
String pref = getPrefString(R.string.pref_media_encryption_key, R.string.pref_media_encryption_key_none);
|
|
||||||
MediaEncryption me=MediaEncryption.None;
|
|
||||||
if (pref.equals(getString(R.string.pref_media_encryption_key_srtp)))
|
|
||||||
me = MediaEncryption.SRTP;
|
|
||||||
else if (pref.equals(getString(R.string.pref_media_encryption_key_zrtp)))
|
|
||||||
me = MediaEncryption.ZRTP;
|
|
||||||
Log.i("Media encryption set to " + pref);
|
|
||||||
mLc.setMediaEncryption(me);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initFromConfTunnel(){
|
private void initFromConfTunnel(){
|
||||||
if (!mLc.isTunnelAvailable())
|
if (!mLc.isTunnelAvailable())
|
||||||
return;
|
return;
|
||||||
|
@ -827,76 +815,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
initialTransports = mLc.getSignalingTransportPorts();
|
initialTransports = mLc.getSignalingTransportPorts();
|
||||||
|
|
||||||
setSignalingTransportsFromConfiguration(initialTransports);
|
setSignalingTransportsFromConfiguration(initialTransports);
|
||||||
initMediaEncryption();
|
|
||||||
|
|
||||||
mLc.setVideoPolicy(isAutoInitiateVideoCalls(), isAutoAcceptCamera());
|
|
||||||
|
|
||||||
readAndSetAudioAndVideoPorts();
|
|
||||||
|
|
||||||
String defaultIncomingCallTimeout = getString(R.string.pref_incoming_call_timeout_default);
|
|
||||||
int incomingCallTimeout = tryToParseIntValue(getPrefString(R.string.pref_incoming_call_timeout_key, defaultIncomingCallTimeout), defaultIncomingCallTimeout);
|
|
||||||
mLc.setIncomingTimeout(incomingCallTimeout);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Configure audio codecs
|
|
||||||
// enableDisableAudioCodec("speex", 32000, 1, R.string.pref_codec_speex32_key);
|
|
||||||
enableDisableAudioCodec("speex", 32000, 1, false);
|
|
||||||
enableDisableAudioCodec("speex", 16000, 1, R.string.pref_codec_speex16_key);
|
|
||||||
enableDisableAudioCodec("speex", 8000, 1, R.string.pref_codec_speex8_key);
|
|
||||||
enableDisableAudioCodec("iLBC", 8000, 1, R.string.pref_codec_ilbc_key);
|
|
||||||
enableDisableAudioCodec("GSM", 8000, 1, R.string.pref_codec_gsm_key);
|
|
||||||
enableDisableAudioCodec("G722", 8000, 1, R.string.pref_codec_g722_key);
|
|
||||||
enableDisableAudioCodec("G729", 8000, 1, R.string.pref_codec_g729_key);
|
|
||||||
enableDisableAudioCodec("PCMU", 8000, 1, R.string.pref_codec_pcmu_key);
|
|
||||||
enableDisableAudioCodec("PCMA", 8000, 1, R.string.pref_codec_pcma_key);
|
|
||||||
enableDisableAudioCodec("AMR", 8000, 1, R.string.pref_codec_amr_key);
|
|
||||||
enableDisableAudioCodec("AMR-WB", 16000, 1, R.string.pref_codec_amrwb_key);
|
|
||||||
//enableDisableAudioCodec("SILK", 24000, 1, R.string.pref_codec_silk24_key);
|
|
||||||
enableDisableAudioCodec("SILK", 24000, 1, false);
|
|
||||||
enableDisableAudioCodec("SILK", 16000, 1, R.string.pref_codec_silk16_key);
|
|
||||||
//enableDisableAudioCodec("SILK", 12000, 1, R.string.pref_codec_silk12_key);
|
|
||||||
enableDisableAudioCodec("SILK", 12000, 1, false);
|
|
||||||
enableDisableAudioCodec("SILK", 8000, 1, R.string.pref_codec_silk8_key);
|
|
||||||
enableDisableAudioCodec("OPUS", 48000, 1, R.string.pref_codec_opus_key);
|
|
||||||
|
|
||||||
// Configure video codecs
|
|
||||||
for (PayloadType videoCodec : mLc.getVideoCodecs()) {
|
|
||||||
enableDisableVideoCodecs(videoCodec);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean useEC = getPrefBoolean(R.string.pref_echo_cancellation_key, mR.getBoolean(R.bool.pref_echo_canceller_default));
|
|
||||||
mLc.enableEchoCancellation(useEC);
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
throw new LinphoneConfigException(getString(R.string.wrong_settings),e);
|
|
||||||
}
|
|
||||||
boolean isVideoEnabled = isVideoEnabled();
|
|
||||||
mLc.enableVideo(isVideoEnabled, isVideoEnabled);
|
|
||||||
setPreferredVideoSizeFromConfiguration();
|
setPreferredVideoSizeFromConfiguration();
|
||||||
|
|
||||||
//stun server
|
|
||||||
String lStun = getPrefString(R.string.pref_stun_server_key, getString(R.string.default_stun));
|
|
||||||
boolean useICE = getPrefBoolean(R.string.pref_ice_enable_key, mR.getBoolean(R.bool.pref_ice_enabled_default));
|
|
||||||
boolean useUpnp = getPrefBoolean(R.string.pref_upnp_enable_key, mR.getBoolean(R.bool.pref_upnp_enabled_default));
|
|
||||||
|
|
||||||
mLc.setStunServer(lStun);
|
|
||||||
if (lStun!=null && lStun.length()>0 && useICE) {
|
|
||||||
mLc.setFirewallPolicy(FirewallPolicy.UseIce);
|
|
||||||
if (useUpnp) Log.e("Cannot have both ice and upnp enabled, disabling upnp");
|
|
||||||
} else if (useUpnp) {
|
|
||||||
mLc.setFirewallPolicy(FirewallPolicy.UseUpnp);
|
|
||||||
} else if (lStun!=null && lStun.length()>0){
|
|
||||||
mLc.setFirewallPolicy(FirewallPolicy.UseStun);
|
|
||||||
} else {
|
|
||||||
mLc.setFirewallPolicy(FirewallPolicy.NoFirewall);
|
|
||||||
}
|
|
||||||
|
|
||||||
mLc.setUseRfc2833ForDtmfs(getPrefBoolean(R.string.pref_rfc2833_dtmf_key, mR.getBoolean(R.bool.pref_rfc2833_dtmf_default)));
|
|
||||||
mLc.setUseSipInfoForDtmfs(getPrefBoolean(R.string.pref_sipinfo_dtmf_key, mR.getBoolean(R.bool.pref_sipinfo_dtmf_default)));
|
|
||||||
|
|
||||||
String displayName = getPrefString(R.string.pref_display_name_key, getString(R.string.pref_display_name_default));
|
|
||||||
String username = getPrefString(R.string.pref_user_name_key, getString(R.string.pref_user_name_default));
|
|
||||||
mLc.setPrimaryContact(displayName, username);
|
|
||||||
|
|
||||||
//accounts
|
//accounts
|
||||||
try {
|
try {
|
||||||
initAccounts();
|
initAccounts();
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LpConfig;
|
import org.linphone.core.LpConfig;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class LinphonePreferences {
|
||||||
public static final synchronized LinphonePreferences getInstance() {
|
public static final synchronized LinphonePreferences getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new LinphonePreferences();
|
instance = new LinphonePreferences();
|
||||||
instance.Load();
|
instance.load();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -81,18 +82,30 @@ public class LinphonePreferences {
|
||||||
return changesDict.containsKey(key);
|
return changesDict.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load() {
|
public void load() {
|
||||||
Resources res = LinphoneService.instance().getResources();
|
Log.w("Preferences loading...");
|
||||||
for (String key : res.getStringArray(R.array.lpconfig_net_keys)) {
|
loadSection("sip", R.array.lpconfig_sip_keys);
|
||||||
dict.put(key, config.getString("net", key, null));
|
}
|
||||||
|
|
||||||
|
private void loadSection(String section, int resourcesID) {
|
||||||
|
Log.w("Preferences loading for section " + section);
|
||||||
|
for (String key : LinphoneService.instance().getResources().getStringArray(resourcesID)) {
|
||||||
|
Log.w("Looking for value for key " + key);
|
||||||
|
String value = config.getString("sip", key, "");
|
||||||
|
if (value != null && value.length() > 0) {
|
||||||
|
Log.w("Value read for key " + key + " : " + value);
|
||||||
|
dict.put(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save() {
|
public void save() {
|
||||||
|
Log.w("Preferences saving...");
|
||||||
Resources res = LinphoneService.instance().getResources();
|
Resources res = LinphoneService.instance().getResources();
|
||||||
for (String key : res.getStringArray(R.array.lpconfig_net_keys)) {
|
for (String key : res.getStringArray(R.array.lpconfig_sip_keys)) {
|
||||||
if (hasValueChanged(key)) {
|
if (hasValueChanged(key)) {
|
||||||
config.setString("net", key, getNew(key));
|
Log.w("Saving changed preference : " + getNew(key));
|
||||||
|
config.setString("sip", key, getNew(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.sync();
|
config.sync();
|
||||||
|
|
|
@ -1,14 +1,25 @@
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.LinphoneManager.EcCalibrationListener;
|
import org.linphone.LinphoneManager.EcCalibrationListener;
|
||||||
|
import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
||||||
|
import org.linphone.core.LinphoneCore.MediaEncryption;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.ui.PreferencesListFragment;
|
import org.linphone.ui.PreferencesListFragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
|
||||||
public class SettingsFragment extends PreferencesListFragment implements EcCalibrationListener {
|
public class SettingsFragment extends PreferencesListFragment implements EcCalibrationListener {
|
||||||
|
private LinphonePreferences mPrefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
|
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
|
||||||
|
|
||||||
|
@ -21,21 +32,98 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle bundle) {
|
public void onCreate(Bundle bundle) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
|
PreferenceScreen screen = getPreferenceScreen();
|
||||||
|
|
||||||
|
mPrefs = LinphonePreferences.getInstance();
|
||||||
|
mPrefs.load();
|
||||||
|
|
||||||
|
// Init some settings
|
||||||
|
initMediaEncryptionPreference((ListPreference) screen.findPreference(getString(R.string.lpconfig_sip_media_enc_key)));
|
||||||
|
|
||||||
|
// Sets default values and value change listener for each of them
|
||||||
|
setListenerForPreference(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setListenerForPreference(Preference pref) {
|
||||||
|
// FIXME: first display doesn't match the linphonerc values
|
||||||
|
|
||||||
final LinphonePreferences prefs = LinphonePreferences.getInstance();
|
|
||||||
int count = getPreferenceScreen().getPreferenceCount();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
|
||||||
if (pref.hasKey()) {
|
if (pref.hasKey()) {
|
||||||
pref.setDefaultValue(prefs.get(pref.getKey()));
|
Log.w("Preference key = " + pref.getKey());
|
||||||
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
prefs.set(preference.getKey(), newValue.toString());
|
Log.w("New value for preference key " + preference.getKey() + ":" + newValue.toString());
|
||||||
|
mPrefs.set(preference.getKey(), newValue.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if (pref instanceof PreferenceCategory) {
|
||||||
|
Log.w("Preference is a category (" + pref.getTitle() + "), let's recurse!");
|
||||||
|
PreferenceCategory cat = (PreferenceCategory) pref;
|
||||||
|
int count = cat.getPreferenceCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
Preference p = cat.getPreference(i);
|
||||||
|
setListenerForPreference(p);
|
||||||
|
}
|
||||||
|
} else if (pref instanceof PreferenceScreen) {
|
||||||
|
Log.w("Preference is a screen (" + pref.getTitle() + "), let's recurse!");
|
||||||
|
PreferenceScreen screen = (PreferenceScreen) pref;
|
||||||
|
int count = screen.getPreferenceCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
Preference p = screen.getPreference(i);
|
||||||
|
setListenerForPreference(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMediaEncryptionPreference(ListPreference pref) {
|
||||||
|
LinphoneCore lc = null;
|
||||||
|
try {
|
||||||
|
lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
List<CharSequence> mencEntries=new ArrayList<CharSequence>();
|
||||||
|
List<CharSequence> mencEntryValues=new ArrayList<CharSequence>();
|
||||||
|
mencEntries.add(getString(R.string.media_encryption_none));
|
||||||
|
mencEntryValues.add(getString(R.string.pref_media_encryption_key_none));
|
||||||
|
|
||||||
|
if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
|
||||||
|
CharSequence[] contents = new CharSequence[mencEntries.size()];
|
||||||
|
mencEntries.toArray(contents);
|
||||||
|
pref.setEntries(contents);
|
||||||
|
contents = new CharSequence[mencEntryValues.size()];
|
||||||
|
mencEntryValues.toArray(contents);
|
||||||
|
pref.setEntryValues(contents);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
|
||||||
|
boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
|
||||||
|
if (!hasSrtp && !hasZrtp) {
|
||||||
|
pref.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
if (hasSrtp){
|
||||||
|
mencEntries.add(getString(R.string.media_encryption_srtp));
|
||||||
|
mencEntryValues.add(getString(R.string.pref_media_encryption_key_srtp));
|
||||||
|
}
|
||||||
|
if (hasZrtp){
|
||||||
|
mencEntries.add(getString(R.string.media_encryption_zrtp));
|
||||||
|
mencEntryValues.add(getString(R.string.pref_media_encryption_key_zrtp));
|
||||||
|
}
|
||||||
|
CharSequence[] contents=new CharSequence[mencEntries.size()];
|
||||||
|
mencEntries.toArray(contents);
|
||||||
|
pref.setEntries(contents);
|
||||||
|
contents=new CharSequence[mencEntryValues.size()];
|
||||||
|
mencEntryValues.toArray(contents);
|
||||||
|
pref.setEntryValues(contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
LinphonePreferences.getInstance().save();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue