From d8e8700e603e00b7004331945c4f9cdb36880abc Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 15 Jul 2016 12:32:20 +0200 Subject: [PATCH] Added chat preferences folder with lime encryption setting --- res/values/non_localizable_strings.xml | 2 + res/values/strings.xml | 10 +- res/xml/preferences.xml | 18 +++- src/org/linphone/LinphoneActivity.java | 4 +- .../linphone/LinphoneLauncherActivity.java | 2 - src/org/linphone/LinphonePreferences.java | 9 ++ src/org/linphone/SettingsFragment.java | 100 ++++++++++++++---- submodules/belle-sip | 2 +- submodules/linphone | 2 +- 9 files changed, 117 insertions(+), 32 deletions(-) diff --git a/res/values/non_localizable_strings.xml b/res/values/non_localizable_strings.xml index 9b3be0fc7..f3c4727f7 100644 --- a/res/values/non_localizable_strings.xml +++ b/res/values/non_localizable_strings.xml @@ -199,4 +199,6 @@ Send logs Cancel + + pref_use_lime_encryption_key diff --git a/res/values/strings.xml b/res/values/strings.xml index f0309c6fd..4f55d9a5b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -271,6 +271,15 @@ Send RFC2833 DTMFs Send SIP INFO DTMFs Voice mail URI + + + Chat + Sharing server + Do not edit unless you know what you are doing! + Use LIME encryption + Disabled + Mandatory + Preferred Network @@ -296,7 +305,6 @@ Enable service notification Start at boot time Incoming call hangup (in seconds) - Sharing server Remote provisioning Primary account Display name diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 3d8656fd1..be34cd865 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -141,6 +141,20 @@ android:key="@string/pref_voice_mail_key"/> + + + + + + + + @@ -224,10 +238,6 @@ android:key="@string/pref_incoming_call_timeout_key" android:layout="@layout/hidden"/> - - diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 834bb7186..8e83ed2f2 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -1250,7 +1250,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta @Override protected void onResume() { super.onResume(); - + if (!LinphoneService.isReady()) { startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); } @@ -1336,7 +1336,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - + Bundle extras = intent.getExtras(); if (extras != null && extras.getBoolean("GoToChat", false)) { LinphoneService.instance().removeMessageNotification(); diff --git a/src/org/linphone/LinphoneLauncherActivity.java b/src/org/linphone/LinphoneLauncherActivity.java index d3a56d61e..a7fa589ba 100644 --- a/src/org/linphone/LinphoneLauncherActivity.java +++ b/src/org/linphone/LinphoneLauncherActivity.java @@ -20,7 +20,6 @@ package org.linphone; import static android.content.Intent.ACTION_MAIN; -import org.linphone.mediastream.Log; import org.linphone.assistant.RemoteProvisioningActivity; import org.linphone.tutorials.TutorialLauncherActivity; @@ -83,7 +82,6 @@ public class LinphoneLauncherActivity extends Activity { }, 1000); } - private class ServiceWaitThread extends Thread { public void run() { while (!LinphoneService.isReady()) { diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index a4db6c5f7..43fc4a767 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -32,6 +32,7 @@ import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.AdaptiveRateAlgorithm; import org.linphone.core.LinphoneCore.FirewallPolicy; +import org.linphone.core.LinphoneCore.LinphoneLimeState; import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCore.Transports; import org.linphone.core.LinphoneCoreException; @@ -1310,4 +1311,12 @@ public class LinphonePreferences { public void enableOverlay(boolean enable) { getConfig().setBool("app", "display_overlay", enable); } + + public LinphoneLimeState getLimeEncryption() { + return getLc().getLimeEncryption(); + } + + public void setLimeEncryption(LinphoneLimeState lime) { + getLc().setLimeEncryption(lime); + } } diff --git a/src/org/linphone/SettingsFragment.java b/src/org/linphone/SettingsFragment.java index c45d0c256..efe897f7a 100644 --- a/src/org/linphone/SettingsFragment.java +++ b/src/org/linphone/SettingsFragment.java @@ -19,13 +19,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +import java.io.File; import java.util.ArrayList; import java.util.List; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCore; -import org.linphone.core.LinphoneCore.AdaptiveRateAlgorithm; import org.linphone.core.LinphoneCore.EcCalibratorStatus; +import org.linphone.core.LinphoneCore.LinphoneLimeState; import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreListenerBase; @@ -37,9 +38,8 @@ import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.purchase.InAppPurchaseActivity; import org.linphone.ui.LedPreference; import org.linphone.ui.PreferencesListFragment; -import android.content.Intent; -import android.net.Uri; +import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.preference.CheckBoxPreference; @@ -50,27 +50,24 @@ import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; -import android.provider.Settings; /** * @author Sylvain Berfini */ public class SettingsFragment extends PreferencesListFragment { - private static final int WIZARD_INTENT = 1; private static final int STORE_INTENT = 2; private LinphonePreferences mPrefs; private Handler mHandler = new Handler(); private LinphoneCoreListenerBase mListener; - public SettingsFragment() { - super(R.xml.preferences); - mPrefs = LinphonePreferences.instance(); - } - @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); + mPrefs = LinphonePreferences.instance(); + removePreviousPreferencesFile(); // Required when updating the preferences order + addPreferencesFromResource(R.xml.preferences); + // Init the settings page interface initSettings(); setListeners(); @@ -100,6 +97,11 @@ public class SettingsFragment extends PreferencesListFragment { } }; } + + private void removePreviousPreferencesFile() { + File dir = new File(LinphoneActivity.instance().getFilesDir().getAbsolutePath() + "shared_prefs"); + dir.delete(); + } // Inits the values or the listener on some settings private void initSettings() { @@ -107,6 +109,7 @@ public class SettingsFragment extends PreferencesListFragment { initAudioSettings(); initVideoSettings(); initCallSettings(); + initChatSettings(); initNetworkSettings(); initAdvancedSettings(); @@ -134,6 +137,7 @@ public class SettingsFragment extends PreferencesListFragment { setAudioPreferencesListener(); setVideoPreferencesListener(); setCallPreferencesListener(); + setChatPreferencesListener(); setNetworkPreferencesListener(); setAdvancedPreferencesListener(); } @@ -436,6 +440,30 @@ public class SettingsFragment extends PreferencesListFragment { pref.setSummary(value); pref.setValue(value); } + + private void initLimeEncryptionPreference(ListPreference pref) { + List entries = new ArrayList(); + List values = new ArrayList(); + entries.add(getString(R.string.lime_encryption_entry_disabled)); + values.add(LinphoneLimeState.Disabled.toString()); + + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc == null || !lc.isLimeEncryptionAvailable()) { + setListPreferenceValues(pref, entries, values); + pref.setEnabled(false); + return; + } + + entries.add(getString(R.string.lime_encryption_entry_mandatory)); + values.add(LinphoneLimeState.Mandatory.toString()); + entries.add(getString(R.string.lime_encryption_entry_preferred)); + values.add(LinphoneLimeState.Preferred.toString()); + setListPreferenceValues(pref, entries, values); + + LinphoneLimeState lime = mPrefs.getLimeEncryption(); + pref.setSummary(lime.toString()); + pref.setValue(lime.toString()); + } private static void setListPreferenceValues(ListPreference pref, List entries, List values) { CharSequence[] contents = new CharSequence[entries.size()]; @@ -776,6 +804,47 @@ public class SettingsFragment extends PreferencesListFragment { }); } + private void initChatSettings() { + setPreferenceDefaultValueAndSummary(R.string.pref_image_sharing_server_key, mPrefs.getSharingPictureServerUrl()); + initLimeEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_use_lime_encryption_key))); + } + + private void setChatPreferencesListener() { + findPreference(getString(R.string.pref_image_sharing_server_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String value = (String) newValue; + mPrefs.setSharingPictureServerUrl(value); + preference.setSummary(value); + return true; + } + }); + + findPreference(getString(R.string.pref_use_lime_encryption_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String value = newValue.toString(); + LinphoneLimeState lime = LinphoneLimeState.Disabled; + if (value.equals(LinphoneLimeState.Mandatory.toString())) + lime = LinphoneLimeState.Mandatory; + else if (value.equals(LinphoneLimeState.Preferred.toString())) + lime = LinphoneLimeState.Preferred; + mPrefs.setLimeEncryption(lime); + + lime = mPrefs.getLimeEncryption(); + if (lime == LinphoneLimeState.Disabled) { + preference.setSummary(getString(R.string.lime_encryption_entry_disabled)); + } else if (lime == LinphoneLimeState.Mandatory) { + preference.setSummary(getString(R.string.lime_encryption_entry_mandatory)); + } else if (lime == LinphoneLimeState.Preferred) { + preference.setSummary(getString(R.string.lime_encryption_entry_preferred)); + } + + return true; + } + }); + } + private void initNetworkSettings() { initMediaEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_media_encryption_key))); @@ -919,7 +988,6 @@ public class SettingsFragment extends PreferencesListFragment { ((CheckBoxPreference)findPreference(getString(R.string.pref_animation_enable_key))).setChecked(mPrefs.areAnimationsEnabled()); ((CheckBoxPreference)findPreference(getString(R.string.pref_service_notification_key))).setChecked(mPrefs.getServiceNotificationVisibility()); ((CheckBoxPreference)findPreference(getString(R.string.pref_autostart_key))).setChecked(mPrefs.isAutoStartEnabled()); - setPreferenceDefaultValueAndSummary(R.string.pref_image_sharing_server_key, mPrefs.getSharingPictureServerUrl()); setPreferenceDefaultValueAndSummary(R.string.pref_remote_provisioning_key, mPrefs.getRemoteProvisioningUrl()); setPreferenceDefaultValueAndSummary(R.string.pref_display_name_key, mPrefs.getDefaultDisplayName()); setPreferenceDefaultValueAndSummary(R.string.pref_user_name_key, mPrefs.getDefaultUsername()); @@ -976,16 +1044,6 @@ public class SettingsFragment extends PreferencesListFragment { } }); - findPreference(getString(R.string.pref_image_sharing_server_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - String value = (String) newValue; - mPrefs.setSharingPictureServerUrl(value); - preference.setSummary(value); - return true; - } - }); - findPreference(getString(R.string.pref_remote_provisioning_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { diff --git a/submodules/belle-sip b/submodules/belle-sip index 374a1ae8b..245bdae5f 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit 374a1ae8be6eea497df54e90041b11d81bb32cdf +Subproject commit 245bdae5fe12032e4d0c3041c9e0c6f0d78ed2a7 diff --git a/submodules/linphone b/submodules/linphone index e45b4fe4e..d3e8feeb6 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit e45b4fe4eb58eed27ece1ca9c33c08be35a7d993 +Subproject commit d3e8feeb605b087e33c628ebfd0c79e84d598120