From a7fb6e73d3bbf0d59fd92cb72e3e3a8ba9d3109c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 8 Oct 2013 12:21:33 +0200 Subject: [PATCH] Changed way of using linphone to store settings --- res/values/non_localizable_strings.xml | 27 - res/xml/preferences.xml | 206 +++----- res/xml/settings.xml | 14 - .../linphone/AccountPreferencesFragment.java | 152 +++--- src/org/linphone/BootReceiver.java | 3 +- src/org/linphone/ChatFragment.java | 5 +- src/org/linphone/InCallActivity.java | 17 +- src/org/linphone/IncomingCallActivity.java | 4 +- src/org/linphone/LinphoneActivity.java | 39 +- src/org/linphone/LinphoneManager.java | 467 ++---------------- .../linphone/LinphonePreferenceManager.java | 66 --- src/org/linphone/LinphonePreferences.java | 217 +++++--- src/org/linphone/LinphoneService.java | 13 +- src/org/linphone/PreferencesFragment.java | 53 +- src/org/linphone/SettingsFragment.java | 133 ++--- src/org/linphone/StatusFragment.java | 62 +-- .../linphone/compatibility/ApiEightPlus.java | 16 +- src/org/linphone/gcm/GCMService.java | 22 +- src/org/linphone/setup/SetupActivity.java | 33 +- submodules/linphone | 2 +- 20 files changed, 479 insertions(+), 1072 deletions(-) delete mode 100644 res/xml/settings.xml delete mode 100644 src/org/linphone/LinphonePreferenceManager.java diff --git a/res/values/non_localizable_strings.xml b/res/values/non_localizable_strings.xml index 84ce36f8f..557f9092a 100644 --- a/res/values/non_localizable_strings.xml +++ b/res/values/non_localizable_strings.xml @@ -121,31 +121,4 @@ pref_upnp_enable_key pref_first_time_linphone_chat_storage - - - - - - - media_encryption - - @string/lpconfig_sip_media_enc_key - - - - - - - - - - - - - - - - - - diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 66262852a..18d9771eb 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -14,25 +14,22 @@ android:key="@string/setup_key"/> + android:title="@string/pref_tunnel" + android:key="@string/pref_tunnel_key"> + android:key="@string/pref_tunnel_host_key"/> + android:key="@string/pref_tunnel_port_key"/> + android:entryValues="@array/tunnel_mode_entry_values"/> @@ -40,65 +37,57 @@ android:title="@string/pref_preferences"> + android:key="@string/pref_video_enable_key"/> + android:title="@string/pref_echo_canceller_calibration" + android:key="@string/pref_echo_canceller_calibration_key"/> + android:title="@string/pref_codec_opus" + android:key="@string/pref_codec_opus_key"/> + android:title="@string/pref_codec_speex16" + android:key="@string/pref_codec_speex16_key"/> + + + android:title="@string/pref_codec_amr" + android:key="@string/pref_codec_amr_key"/> + android:key="@string/pref_codec_g729_key"/> + android:key="@string/pref_codec_amrwb_key"/> + android:title="@string/pref_codec_gsm" + android:key="@string/pref_codec_gsm_key"/> + android:title="@string/pref_codec_silk8" + android:key="@string/pref_codec_silk8_key"/> + android:title="@string/pref_codec_silk16" + android:key="@string/pref_codec_silk16_key"/> + android:title="@string/pref_codec_pcmu" + android:key="@string/pref_codec_pcmu_key"/> + android:title="@string/pref_codec_pcma" + android:key="@string/pref_codec_pcma_key"/> @@ -131,69 +116,60 @@ + android:key="@string/pref_preferred_video_size_key"/> + android:dependency="@string/pref_video_enable_key" + android:shouldDisableView="true" > + android:key="@string/pref_video_codec_vp8_key"/> + android:key="@string/pref_video_codec_h264_key"/> + android:key="@string/pref_video_codec_mpeg4_key"/> @@ -208,18 +184,16 @@ android:key="@string/pref_prefix_key"/> + android:title="@string/pref_escape_plus" + android:key="@string/pref_escape_plus_key"/> + android:title="@string/pref_sipinfo_dtmf" + android:key="@string/pref_sipinfo_dtmf_key"/> + android:title="@string/pref_rfc2833_dtmf" + android:key="@string/pref_rfc2833_dtmf_key"/> @@ -227,69 +201,57 @@ android:title="@string/pref_network_title"> + android:key="@string/pref_wifi_only_key"/> + android:key="@string/pref_ice_enable_key"/> + android:key="@string/pref_upnp_enable_key"/> + android:key="@string/pref_transport_use_random_ports_key"/> + android:key="@string/pref_transport_key"/> + android:key="@string/pref_media_encryption_key"/> + android:key="@string/pref_push_notification_key"/> + android:key="@string/pref_ipv6_key"/> @@ -297,58 +259,48 @@ android:title="@string/pref_advanced"> + android:key="@string/pref_debug_key"/> + android:key="@string/pref_background_mode_key"/> + android:key="@string/pref_animation_enable_key"/> + android:key="@string/pref_autostart_key"/> + android:key="@string/pref_image_sharing_server_key"/> + android:key="@string/pref_remote_provisioning_key"/> @@ -358,18 +310,17 @@ android:layout="@layout/hidden"> + android:title="@string/pref_audio_hacks_use_routing_api_title" + android:key="@string/pref_audio_hacks_use_routing_api_key"/> + android:title="@string/pref_audio_hacks_use_galaxys_hack_title" + android:key="@string/pref_audio_hacks_use_galaxys_hack_key"/> @@ -383,10 +334,9 @@ android:key="@string/pref_linphone_friend_key"> + android:key="@string/pref_auto_accept_friends_key" + android:summary="@string/pref_auto_accept_friends_desc"/> diff --git a/res/xml/settings.xml b/res/xml/settings.xml deleted file mode 100644 index 899a62c96..000000000 --- a/res/xml/settings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - diff --git a/src/org/linphone/AccountPreferencesFragment.java b/src/org/linphone/AccountPreferencesFragment.java index 1da113e2a..60ad82da9 100644 --- a/src/org/linphone/AccountPreferencesFragment.java +++ b/src/org/linphone/AccountPreferencesFragment.java @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import org.linphone.compatibility.Compatibility; import org.linphone.ui.PreferencesListFragment; -import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.Preference; @@ -36,7 +35,6 @@ import android.text.InputType; */ public class AccountPreferencesFragment extends PreferencesListFragment { private int n; - private String key; public AccountPreferencesFragment() { super(R.xml.account_preferences); @@ -48,122 +46,116 @@ public class AccountPreferencesFragment extends PreferencesListFragment { PreferenceScreen screen = getPreferenceScreen(); n = getArguments().getInt("Account", 0); - key = getAccountNumber(n); manageAccountPreferencesFields(screen); } - OnPreferenceChangeListener preferenceChangedListener = new OnPreferenceChangeListener() { + OnPreferenceChangeListener usernameChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - preference.setSummary(newValue.toString()); + LinphonePreferences.instance().setAccountUsername(n, newValue.toString()); + return true; + } + }; + OnPreferenceChangeListener useridChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountUserId(n, newValue.toString()); + return true; + } + }; + OnPreferenceChangeListener passwordChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountPassword(n, newValue.toString()); + return true; + } + }; + OnPreferenceChangeListener domainChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountDomain(n, newValue.toString()); + return true; + } + }; + OnPreferenceChangeListener proxyChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountProxy(n, newValue.toString()); + return true; + } + }; + OnPreferenceChangeListener outboundProxyChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountOutboundProxyEnabled(n, (Boolean)newValue); + return true; + } + }; + OnPreferenceChangeListener disableChangedListener = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LinphonePreferences.instance().setAccountEnabled(n, (Boolean)newValue); return true; } }; private void manageAccountPreferencesFields(PreferenceScreen parent) { - final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); - PreferenceCategory account = (PreferenceCategory) getPreferenceScreen().getPreference(0); EditTextPreference username = (EditTextPreference) account.getPreference(0); - username.setText(prefs.getString(getString(R.string.pref_username_key) + key, "")); + username.setText(LinphonePreferences.instance().getAccountUsername(n)); username.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - username.setKey(getString(R.string.pref_username_key) + key); - username.setOnPreferenceChangeListener(preferenceChangedListener); + username.setOnPreferenceChangeListener(usernameChangedListener); username.setSummary(username.getText()); EditTextPreference userid = (EditTextPreference) account.getPreference(1); - userid.setText(prefs.getString(getString(R.string.pref_auth_userid_key) + key, "")); + userid.setText(LinphonePreferences.instance().getAccountUserId(n)); userid.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - userid.setKey(getString(R.string.pref_auth_userid_key) + key); - userid.setOnPreferenceChangeListener(preferenceChangedListener); + userid.setOnPreferenceChangeListener(useridChangedListener); userid.setSummary(userid.getText()); EditTextPreference password = (EditTextPreference) account.getPreference(2); - password.setText(prefs.getString(getString(R.string.pref_passwd_key) + key, "")); + password.setText(LinphonePreferences.instance().getAccountPassword(n)); password.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - password.setKey(getString(R.string.pref_passwd_key) + key); + password.setOnPreferenceChangeListener(passwordChangedListener); EditTextPreference domain = (EditTextPreference) account.getPreference(3); - domain.setText(prefs.getString(getString(R.string.pref_domain_key) + key, "")); + domain.setText(LinphonePreferences.instance().getAccountDomain(n)); domain.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - domain.setKey(getString(R.string.pref_domain_key) + key); - domain.setOnPreferenceChangeListener(preferenceChangedListener); + domain.setOnPreferenceChangeListener(domainChangedListener); domain.setSummary(domain.getText()); PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen().getPreference(1); EditTextPreference proxy = (EditTextPreference) advanced.getPreference(0); - proxy.setText(prefs.getString(getString(R.string.pref_proxy_key) + key, "")); + proxy.setText(LinphonePreferences.instance().getAccountProxy(n)); proxy.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - proxy.setKey(getString(R.string.pref_proxy_key) + key); - proxy.setOnPreferenceChangeListener(preferenceChangedListener); + proxy.setOnPreferenceChangeListener(proxyChangedListener); proxy.setSummary("".equals(proxy.getText()) || (proxy.getText() == null) ? getString(R.string.pref_help_proxy) : proxy.getText()); Preference outboundProxy = advanced.getPreference(1); - Compatibility.setPreferenceChecked(outboundProxy, prefs.getBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false)); - outboundProxy.setKey(getString(R.string.pref_enable_outbound_proxy_key) + key); - + Compatibility.setPreferenceChecked(outboundProxy, LinphonePreferences.instance().isAccountOutboundProxySet(n)); + outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); + final Preference disable = advanced.getPreference(2); disable.setEnabled(true); - Compatibility.setPreferenceChecked(disable, prefs.getBoolean(getString(R.string.pref_disable_account_key) + key, false)); - disable.setKey(getString(R.string.pref_disable_account_key) + key); + Compatibility.setPreferenceChecked(disable, !LinphonePreferences.instance().isAccountEnabled(n)); final Preference delete = advanced.getPreference(4); delete.setEnabled(true); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { - int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 1); - SharedPreferences.Editor editor = prefs.edit(); - - for (int i = n; i < nbAccounts - 1; i++) { - editor.putString(getString(R.string.pref_username_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_username_key) + getAccountNumber(i+1), null)); - editor.putString(getString(R.string.pref_auth_userid_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_auth_userid_key) + getAccountNumber(i+1), null)); - editor.putString(getString(R.string.pref_passwd_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_passwd_key) + getAccountNumber(i+1), null)); - editor.putString(getString(R.string.pref_domain_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_domain_key) + getAccountNumber(i+1), null)); - editor.putString(getString(R.string.pref_proxy_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_proxy_key) + getAccountNumber(i+1), null)); - editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(i), prefs.getBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(i+1), false)); - editor.putBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(i), prefs.getBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(i+1), false)); - } - - if (n != 0) { - int lastAccount = nbAccounts - 1; - editor.putString(getString(R.string.pref_username_key) + getAccountNumber(lastAccount), null); - editor.putString(getString(R.string.pref_passwd_key) + getAccountNumber(lastAccount), null); - editor.putString(getString(R.string.pref_domain_key) + getAccountNumber(lastAccount), null); - editor.putString(getString(R.string.pref_proxy_key) + getAccountNumber(lastAccount), null); - editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(lastAccount), false); - editor.putBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(lastAccount), false); - - int defaultAccount = prefs.getInt(getString(R.string.pref_default_account_key), 0); - if (defaultAccount > n) { - editor.putInt(getString(R.string.pref_default_account_key), defaultAccount - 1); - } - editor.putInt(getString(R.string.pref_extra_accounts), nbAccounts - 1); - } else if (n == 0 && nbAccounts <= 1) { - editor.putString(getString(R.string.pref_username_key), ""); - editor.putString(getString(R.string.pref_passwd_key), ""); - editor.putString(getString(R.string.pref_domain_key), ""); - } else { - editor.putInt(getString(R.string.pref_extra_accounts), nbAccounts - 1); - } - - editor.commit(); - + LinphonePreferences.instance().deleteAccount(n); LinphoneActivity.instance().displaySettings(); - return true; } }); Preference mainAccount = advanced.getPreference(3); - Compatibility.setPreferenceChecked(mainAccount, prefs.getInt(getString(R.string.pref_default_account_key), 0) == n); + Compatibility.setPreferenceChecked(mainAccount, LinphonePreferences.instance().getDefaultAccountIndex() == n); mainAccount.setEnabled(!Compatibility.isPreferenceChecked(mainAccount)); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { - - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(getString(R.string.pref_default_account_key), n); - editor.commit(); + LinphonePreferences.instance().setDefaultAccount(n); disable.setEnabled(false); Compatibility.setPreferenceChecked(disable, false); preference.setEnabled(false); @@ -172,30 +164,14 @@ public class AccountPreferencesFragment extends PreferencesListFragment { }); } - private String getAccountNumber(int n) { - if (n > 0) - return Integer.toString(n); - else - return ""; - } - @Override public void onPause() { super.onPause(); - SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); - int n = prefs.getInt(getString(R.string.pref_extra_accounts), 1); - String keyUsername = getString(R.string.pref_username_key) + getAccountNumber(n-1); - - if (prefs.getString(keyUsername, "").equals("")) { + int n = LinphonePreferences.instance().getAccountCount(); + if (LinphonePreferences.instance().getAccountUsername(n).equals("")) { //If not, we suppress it to not display a blank field - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(getString(R.string.pref_extra_accounts), n-1); - editor.commit(); - } - - if (LinphoneActivity.isInstanciated()) { - LinphoneActivity.instance().applyConfigChangesIfNeeded(); + LinphonePreferences.instance().setAccountCount(n-1); } } } diff --git a/src/org/linphone/BootReceiver.java b/src/org/linphone/BootReceiver.java index 836e62d12..6acb5a4e0 100644 --- a/src/org/linphone/BootReceiver.java +++ b/src/org/linphone/BootReceiver.java @@ -21,14 +21,13 @@ package org.linphone; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.preference.PreferenceManager; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.pref_autostart_key), false)) { + if (LinphonePreferences.instance().shouldStartAtStartup()) { Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN); lLinphoneServiceIntent.setClass(context, LinphoneService.class); context.startService(lLinphoneServiceIntent);; diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 9112c9e5b..0324a78b6 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -48,7 +48,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; @@ -61,7 +60,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Parcelable; -import android.preference.PreferenceManager; import android.provider.MediaStore; import android.support.v4.app.Fragment; import android.support.v4.content.CursorLoader; @@ -194,8 +192,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } displayChat(displayName, pictureUri); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance()); - uploadServerUri = prefs.getString(getString(R.string.pref_image_sharing_server_key), getString(R.string.pref_image_sharing_server_default)); + uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl(); textWatcher = new TextWatcher() { public void afterTextChanged(Editable arg0) { diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index d419f3288..bb018a2f7 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -37,7 +37,6 @@ import org.linphone.ui.Numpad; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.net.Uri; @@ -45,7 +44,6 @@ import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.os.SystemClock; -import android.preference.PreferenceManager; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; @@ -127,8 +125,7 @@ public class InCallActivity extends FragmentActivity implements isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers); showCallListInVideo = getApplicationContext().getResources().getBoolean(R.bool.show_current_calls_above_video); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - isAnimationDisabled = getApplicationContext().getResources().getBoolean(R.bool.disable_animations) || !prefs.getBoolean(getString(R.string.pref_animation_enable_key), false); + isAnimationDisabled = getApplicationContext().getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled(); cameraNumber = AndroidCameraConfiguration.retrieveCameras().length; if (findViewById(R.id.fragmentContainer) != null) { @@ -273,7 +270,7 @@ public class InCallActivity extends FragmentActivity implements mHandler.post(new Runnable() { @Override public void run() { - if (!isVideoActivatedInSettings()) { + if (!LinphonePreferences.instance().isVideoEnabled()) { video.setEnabled(false); } else { if (isVideoEnabled) { @@ -355,12 +352,6 @@ public class InCallActivity extends FragmentActivity implements public void updateStatusFragment(StatusFragment statusFragment) { status = statusFragment; } - - private boolean isVideoActivatedInSettings() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean settingsVideoEnabled = prefs.getBoolean(getString(R.string.pref_video_enable_key), false); - return settingsVideoEnabled; - } @Override public void onClick(View v) { @@ -1087,7 +1078,7 @@ public class InCallActivity extends FragmentActivity implements if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call - boolean isVideoEnabled = LinphoneManager.getInstance().isVideoEnabled(); + boolean isVideoEnabled = LinphonePreferences.instance().isVideoEnabled(); if (!isVideoEnabled) { acceptCallUpdate(false); return; @@ -1095,7 +1086,7 @@ public class InCallActivity extends FragmentActivity implements boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); - boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera(); + boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests(); if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { mHandler.post(new Runnable() { public void run() { diff --git a/src/org/linphone/IncomingCallActivity.java b/src/org/linphone/IncomingCallActivity.java index 362e05fc1..7e296604d 100644 --- a/src/org/linphone/IncomingCallActivity.java +++ b/src/org/linphone/IncomingCallActivity.java @@ -156,7 +156,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat private void answer() { LinphoneCallParams params = LinphoneManager.getLc().createDefaultCallParameters(); - if (mCall != null && mCall.getRemoteParams() != null && mCall.getRemoteParams().getVideoEnabled() && LinphoneManager.isInstanciated() && LinphoneManager.getInstance().isAutoAcceptCamera()) { + if (mCall != null && mCall.getRemoteParams() != null && mCall.getRemoteParams().getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) { params.setVideoEnabled(true); } else { params.setVideoEnabled(false); @@ -176,7 +176,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat return; } final LinphoneCallParams remoteParams = mCall.getRemoteParams(); - if (remoteParams != null && remoteParams.getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) { + if (remoteParams != null && remoteParams.getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) { LinphoneActivity.instance().startVideoActivity(mCall); } else { LinphoneActivity.instance().startIncallActivity(mCall); diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index b31ae29ab..ff0387eeb 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -27,7 +27,6 @@ import java.util.Collection; import java.util.List; import org.linphone.LinphoneManager.AddressType; -import org.linphone.LinphoneManager.LinphoneConfigException; import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener; import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; @@ -53,14 +52,12 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.Fragment.SavedState; @@ -139,10 +136,9 @@ public class LinphoneActivity extends FragmentActivity implements } boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_wizard_at_first_start); - SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); - if (useFirstLoginActivity && !pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) { - if (pref.getInt(getString(R.string.pref_extra_accounts), -1) > -1) { - pref.edit().putBoolean(getString(R.string.first_launch_suceeded_once_key), true); + if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) { + if (LinphonePreferences.instance().getAccountCount() > 0) { + LinphonePreferences.instance().firstLaunchSuccessful(); } else { startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY); } @@ -320,8 +316,7 @@ public class LinphoneActivity extends FragmentActivity implements } private void updateAnimationsState() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !prefs.getBoolean(getString(R.string.pref_animation_enable_key), false); + isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled(); isContactPresenceDisabled = !getResources().getBoolean(R.bool.enable_linphone_friends); } @@ -674,30 +669,13 @@ public class LinphoneActivity extends FragmentActivity implements public void applyConfigChangesIfNeeded() { if (nextFragment != FragmentsAvailable.SETTINGS && nextFragment != FragmentsAvailable.ACCOUNT_SETTINGS) { - reloadConfig(); updateAnimationsState(); } } + @Deprecated private void reloadConfig() { - LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); - - if (lc != null && (lc.isInComingInvitePending() || lc.isIncall())) { - Log.w("Call in progress => settings not applied"); - return; - } - - try { - LinphoneManager.getInstance().initFromConf(); - lc.setVideoPolicy(LinphoneManager.getInstance().isAutoInitiateVideoCalls(), LinphoneManager.getInstance().isAutoAcceptCamera()); - } catch (LinphoneException e) { - if (!(e instanceof LinphoneConfigException)) { - Log.e(e, "Cannot update config"); - return; - } - - LinphoneActivity.instance().showPreferenceErrorDialog(e.getMessage()); - } + // Nothing to do here anymore } public void displayAccountSettings(int accountNumber) { @@ -996,8 +974,7 @@ public class LinphoneActivity extends FragmentActivity implements } sipUri = sipUri.replace("<", "").replace(">", ""); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (prefs.getBoolean(getString(R.string.pref_auto_accept_friends_key), false)) { + if (LinphonePreferences.instance().shouldAutomaticallyAcceptFriendsRequests()) { Contact contact = findContactWithSipAddress(sipUri); if (contact != null) { friend.enableSubscribes(true); @@ -1364,7 +1341,7 @@ public class LinphoneActivity extends FragmentActivity implements public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (currentFragment == FragmentsAvailable.DIALER) { - boolean isBackgroundModeActive = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_background_mode_key), getResources().getBoolean(R.bool.pref_background_mode_default)); + boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled(); if (!isBackgroundModeActive) { stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); finish(); diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 5886b941f..b519605fc 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -21,12 +21,6 @@ package org.linphone; import static android.media.AudioManager.MODE_RINGTONE; import static android.media.AudioManager.STREAM_RING; import static android.media.AudioManager.STREAM_VOICE_CALL; -import static org.linphone.R.string.pref_codec_amr_key; -import static org.linphone.R.string.pref_codec_amrwb_key; -import static org.linphone.R.string.pref_codec_ilbc_key; -import static org.linphone.R.string.pref_codec_speex16_key; -import static org.linphone.R.string.pref_codec_speex32_key; -import static org.linphone.R.string.pref_video_enable_key; import static org.linphone.core.LinphoneCall.State.CallEnd; import static org.linphone.core.LinphoneCall.State.Error; import static org.linphone.core.LinphoneCall.State.IncomingReceived; @@ -51,7 +45,6 @@ import org.linphone.LinphoneSimpleListener.LinphoneServiceListener; import org.linphone.compatibility.Compatibility; import org.linphone.core.CallDirection; import org.linphone.core.LinphoneAddress; -import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCallParams; @@ -61,11 +54,8 @@ import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneContent; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.EcCalibratorStatus; -import org.linphone.core.LinphoneCore.FirewallPolicy; import org.linphone.core.LinphoneCore.GlobalState; -import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCore.RegistrationState; -import org.linphone.core.LinphoneCore.Transports; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreListener; @@ -95,8 +85,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.hardware.Sensor; @@ -111,7 +99,6 @@ import android.os.Build; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.Vibrator; -import android.preference.PreferenceManager; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.telephony.TelephonyManager; @@ -142,16 +129,12 @@ public class LinphoneManager implements LinphoneCoreListener { private Context mServiceContext; private AudioManager mAudioManager; private PowerManager mPowerManager; - private ConnectivityManager mConnectivityManager; - private SharedPreferences mPref; private Resources mR; + private LinphonePreferences mPrefs; private LinphoneCore mLc; - private static Transports initialTransports; - private static LinphonePreferenceManager sLPref; private String lastLcStatusMessage; private String basePath; private static boolean sExited; - private String contactParams; private boolean mAudioFocused; private boolean isNetworkReachable; @@ -189,12 +172,9 @@ public class LinphoneManager implements LinphoneCoreListener { mPauseSoundFile = basePath + "/toy_mono.wav"; mChatDatabaseFile = basePath + "/linphone-history.db"; - sLPref = LinphonePreferenceManager.getInstance(c); mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE)); mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE); - mPref = PreferenceManager.getDefaultSharedPreferences(c); mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE); - mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); mR = c.getResources(); } @@ -210,7 +190,7 @@ public class LinphoneManager implements LinphoneCoreListener { private final String mPauseSoundFile; private final String mChatDatabaseFile; - private Timer mTimer = new Timer("Linphone scheduler"); + private Timer mTimer; private BroadcastReceiver mKeepAliveReceiver = new KeepAliveReceiver(); @@ -414,9 +394,8 @@ public class LinphoneManager implements LinphoneCoreListener { if (mLc.isNetworkReachable()) { try { if (Version.isVideoCapable()) { - boolean prefVideoEnable = isVideoEnabled(); - int key = R.string.pref_video_initiate_call_with_video_key; - boolean prefInitiateWithVideo = getPrefBoolean(key, false); + boolean prefVideoEnable = mPrefs.isVideoEnabled(); + boolean prefInitiateWithVideo = mPrefs.shouldInitiateVideoCall(); CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo, isLowBandwidthConnection); } else { CallManager.getInstance().inviteAddress(lAddress, false, isLowBandwidthConnection); @@ -435,7 +414,7 @@ public class LinphoneManager implements LinphoneCoreListener { } private void resetCameraFromPreferences() { - boolean useFrontCam = getPrefBoolean(R.string.pref_video_use_front_camera_key, mR.getBoolean(R.bool.pref_video_use_front_camera_default)); + boolean useFrontCam = mPrefs.useFrontCam(); int camId = 0; AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras(); @@ -469,6 +448,7 @@ public class LinphoneManager implements LinphoneCoreListener { } return false; } + public void enableCamera(LinphoneCall call, boolean enable) { if (call != null) { call.enableCamera(enable); @@ -507,7 +487,7 @@ public class LinphoneManager implements LinphoneCoreListener { return false; } - String pref = getPrefString(R.string.pref_tunnel_mode_key, R.string.default_tunnel_mode_entry_value); + String pref = mPrefs.getTunnelMode(); if (getString(R.string.tunnel_mode_entry_value_always).equals(pref)) { return true; @@ -532,7 +512,7 @@ public class LinphoneManager implements LinphoneCoreListener { mLc.tunnelEnable(true); } else { Log.i("Tunnel should not be used"); - String pref = getPrefString(R.string.pref_tunnel_mode_key, R.string.default_tunnel_mode_entry_value); + String pref = mPrefs.getTunnelMode(); mLc.tunnelEnable(false); if (getString(R.string.tunnel_mode_entry_value_auto).equals(pref)) { mLc.tunnelAutoDetect(); @@ -549,53 +529,18 @@ public class LinphoneManager implements LinphoneCoreListener { LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name)); // Try to get remote provisioning - String remote_provisioning = (getPrefString(R.string.pref_remote_provisioning_key, mR.getString(R.string.pref_remote_provisioning_default))); + String remote_provisioning = mPrefs.getRemoteProvisioningUrl(); if(remote_provisioning != null && remote_provisioning.length() > 0 && RemoteProvisioning.isAvailable()) { RemoteProvisioning.download(remote_provisioning, mLinphoneConfigFile); } - mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null); - mLc.getConfig().setInt("sip", "store_auth_info", 0); - mLc.setContext(c); - try { - String versionName = c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName; - if (versionName == null) { - versionName = String.valueOf(c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionCode); - } - mLc.setUserAgent("LinphoneAndroid", versionName); - } catch (NameNotFoundException e) { - Log.e(e, "cannot get version name"); - } - - mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets"); - - mLc.setRing(null); - mLc.setRootCA(mLinphoneRootCaFile); - mLc.setPlayFile(mPauseSoundFile); - mLc.setChatDatabasePath(mChatDatabaseFile); - - int availableCores = Runtime.getRuntime().availableProcessors(); - Log.w("MediaStreamer : " + availableCores + " cores detected and configured"); - mLc.setCpuCount(availableCores); - - try { - initFromConf(); - } catch (LinphoneException e) { - Log.w("no config ready yet"); - } - - TimerTask lTask = new TimerTask() { - @Override - public void run() { - mLc.iterate(); - } - }; - /*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/ - mTimer.schedule(lTask, 0, 20); + initLiblinphone(c); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); lFilter.addAction(Intent.ACTION_SCREEN_OFF); mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter); + + updateNetworkReachability(); startBluetooth(); resetCameraFromPreferences(); @@ -604,6 +549,44 @@ public class LinphoneManager implements LinphoneCoreListener { Log.e(e, "Cannot start linphone"); } } + + public synchronized void initLiblinphone(Context c) throws LinphoneCoreException { + boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && mPrefs.isDebugEnabled(); + LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name)); + + mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null); + mLc.setContext(c); + try { + String versionName = c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName; + if (versionName == null) { + versionName = String.valueOf(c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionCode); + } + mLc.setUserAgent("LinphoneAndroid", versionName); + } catch (NameNotFoundException e) { + Log.e(e, "cannot get version name"); + } + + mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets"); + + mLc.setRing(null); + mLc.setRootCA(mLinphoneRootCaFile); + mLc.setPlayFile(mPauseSoundFile); + mLc.setChatDatabasePath(mChatDatabaseFile); + + int availableCores = Runtime.getRuntime().availableProcessors(); + Log.w("MediaStreamer : " + availableCores + " cores detected and configured"); + mLc.setCpuCount(availableCores); + + TimerTask lTask = new TimerTask() { + @Override + public void run() { + mLc.iterate(); + } + }; + /*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/ + mTimer = new Timer("Linphone scheduler"); + mTimer.schedule(lTask, 0, 20); + } private void copyAssetsFromPackage() throws IOException { copyIfNotExist(R.raw.oldphone_mono,mRingSoundFile); @@ -613,12 +596,14 @@ public class LinphoneManager implements LinphoneCoreListener { copyIfNotExist(R.raw.lpconfig, new File(mLPConfigXsd).getName()); copyIfNotExist(R.raw.rootca, new File(mLinphoneRootCaFile).getName()); } + private void copyIfNotExist(int ressourceId,String target) throws IOException { File lFileToCopy = new File(target); if (!lFileToCopy.exists()) { copyFromPackage(ressourceId,lFileToCopy.getName()); } } + private void copyFromPackage(int ressourceId,String target) throws IOException{ FileOutputStream lOutputStream = mServiceContext.openFileOutput (target, 0); InputStream lInputStream = mR.openRawResource(ressourceId); @@ -645,188 +630,6 @@ public class LinphoneManager implements LinphoneCoreListener { } return false; } - - private void initFromConfTunnel(){ - if (!mLc.isTunnelAvailable()) - return; - - NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); - mLc.tunnelCleanServers(); - String host = getString(R.string.tunnel_host); - if (host == null || host.length() == 0) - host = mPref.getString(getString(R.string.pref_tunnel_host_key), ""); - int port = Integer.parseInt(getPrefString(R.string.pref_tunnel_port_key, "443")); - mLc.tunnelAddServerAndMirror(host, port, 12345,500); - manageTunnelServer(info); - } - - public void initAccounts() throws LinphoneCoreException { - mLc.clearAuthInfos(); - mLc.clearProxyConfigs(); - - for (int i = 0; i < getPrefExtraAccountsNumber(); i++) { - String key = i == 0 ? "" : String.valueOf(i); - if (!getPrefBoolean(getString(R.string.pref_disable_account_key) + key, false)) { - initAccount(key, i == getPrefInt(R.string.pref_default_account_key, 0)); - } - } - - LinphoneProxyConfig lDefaultProxyConfig = mLc.getDefaultProxyConfig(); - if (lDefaultProxyConfig != null) { - //prefix - String lPrefix = getPrefString(R.string.pref_prefix_key, null); - if (lPrefix != null) { - lDefaultProxyConfig.setDialPrefix(lPrefix); - } - //escape + - lDefaultProxyConfig.setDialEscapePlus(getPrefBoolean(R.string.pref_escape_plus_key, false)); - } else if (LinphoneService.isReady()) { - LinphoneService.instance().onRegistrationStateChanged(RegistrationState.RegistrationNone, null); - } - } - - private void initAccount(String key, boolean defaultAccount) throws LinphoneCoreException { - String username = getPrefString(getString(R.string.pref_username_key) + key, null); - String userid = getPrefString(getString(R.string.pref_auth_userid_key) + key, null); - String password = getPrefString(getString(R.string.pref_passwd_key) + key, null); - String domain = getPrefString(getString(R.string.pref_domain_key) + key, null); - if (username != null && username.length() > 0 && password != null) { - LinphoneAuthInfo lAuthInfo = LinphoneCoreFactory.instance().createAuthInfo(username - , userid - , password - , null - ,null); - mLc.addAuthInfo(lAuthInfo); - - if (domain != null && domain.length() > 0) { - String identity = "sip:" + username +"@" + domain; - String proxy = getPrefString(getString(R.string.pref_proxy_key) + key, null); - if (proxy == null || proxy.length() == 0) { - proxy = "sip:" + domain; - } - if (!proxy.startsWith("sip:")) { - proxy = "sip:" + proxy; - } - - LinphoneProxyConfig proxycon = LinphoneCoreFactory.instance().createProxyConfig(identity, proxy, null, true); - String defaultExpire = getString(R.string.pref_expire_default); - proxycon.setExpires(tryToParseIntValue(getPrefString(R.string.pref_expire_key, defaultExpire), defaultExpire)); - - // Add parameters for push notifications - if (mR.getBoolean(R.bool.enable_push_id)) { - String regId = getPrefString(R.string.push_reg_id_key, null); - String appId = getString(R.string.push_sender_id); - if (regId != null && getPrefBoolean(R.string.pref_push_notification_key, mR.getBoolean(R.bool.pref_push_notification_default))) { - String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId + ";pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-call-snd=ring.caf;pn-msg-snd=msg.caf"; - proxycon.setContactParameters(contactInfos); - } - } else if (contactParams != null) { - proxycon.setContactParameters(contactParams); - } - mLc.addProxyConfig(proxycon); - - //outbound proxy - if (getPrefBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false)) { - proxycon.setRoute(proxy); - } else { - proxycon.setRoute(null); - } - proxycon.done(); - - if (defaultAccount) { - mLc.setDefaultProxyConfig(proxycon); - } - } - } - } - - private void readAndSetAudioAndVideoPorts() throws NumberFormatException { - int aPortStart, aPortEnd, vPortStart, vPortEnd; - int defaultAudioPort, defaultVideoPort; - defaultAudioPort = Integer.parseInt(getString(R.string.default_audio_port)); - defaultVideoPort = Integer.parseInt(getString(R.string.default_video_port)); - aPortStart = aPortEnd = defaultAudioPort; - vPortStart = vPortEnd = defaultVideoPort; - - String audioPort = getPrefString(R.string.pref_audio_port_key, String.valueOf(aPortStart)); - String videoPort = getPrefString(R.string.pref_video_port_key, String.valueOf(vPortStart)); - - if (audioPort.contains("-")) { - // Port range - aPortStart = Integer.parseInt(audioPort.split("-")[0]); - aPortEnd = Integer.parseInt(audioPort.split("-")[1]); - } else { - try { - aPortStart = aPortEnd = Integer.parseInt(audioPort); - } catch (NumberFormatException nfe) { - aPortStart = aPortEnd = defaultAudioPort; - } - } - - if (videoPort.contains("-")) { - // Port range - vPortStart = Integer.parseInt(videoPort.split("-")[0]); - vPortEnd = Integer.parseInt(videoPort.split("-")[1]); - } else { - try { - vPortStart = vPortEnd = Integer.parseInt(videoPort); - } catch (NumberFormatException nfe) { - vPortStart = vPortEnd = defaultVideoPort; - } - } - - if (aPortStart >= aPortEnd) { - mLc.setAudioPort(aPortStart); - } else { - mLc.setAudioPortRange(aPortStart, aPortEnd); - } - - if (vPortStart >= vPortEnd) { - mLc.setVideoPort(vPortStart); - } else { - mLc.setVideoPortRange(vPortStart, vPortEnd); - } - } - - private int tryToParseIntValue(String valueToParse, String defaultValue) { - return tryToParseIntValue(valueToParse, Integer.parseInt(defaultValue)); - } - - private int tryToParseIntValue(String valueToParse, int defaultValue) { - try { - int returned = Integer.parseInt(valueToParse); - return returned; - } catch (NumberFormatException nfe) { - - } - return defaultValue; - } - - public void setContactParams(String params) { - contactParams = params; - } - - public void initFromConf() throws LinphoneConfigException { - boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && getPrefBoolean(R.string.pref_debug_key, mR.getBoolean(R.bool.pref_debug_default)); - LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name)); - initFromConfTunnel(); - - if (initialTransports == null) - initialTransports = mLc.getSignalingTransportPorts(); - - setSignalingTransportsFromConfiguration(initialTransports); - setPreferredVideoSizeFromConfiguration(); - - //accounts - try { - initAccounts(); - - //init network state - updateNetworkReachability(); - } catch (LinphoneCoreException e) { - throw new LinphoneConfigException(getString(R.string.wrong_settings),e); - } - } public void updateNetworkReachability() { ConnectivityManager cm = (ConnectivityManager) mServiceContext.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -840,8 +643,7 @@ public class LinphoneManager implements LinphoneCoreListener { } } else if (eventInfo.getState() == NetworkInfo.State.CONNECTED){ manageTunnelServer(eventInfo); - SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mServiceContext); - boolean wifiOnly = pref.getBoolean(getString(R.string.pref_wifi_only_key), mR.getBoolean(R.bool.pref_wifi_only_default)); + boolean wifiOnly = LinphonePreferences.instance().shouldOnlyRegisterOnWifiNetwork(); if ((eventInfo.getTypeName().equals("WIFI")) || (!eventInfo.getTypeName().equals("WIFI") && !wifiOnly)) { if (!isNetworkReachable) { isNetworkReachable = true; @@ -857,96 +659,6 @@ public class LinphoneManager implements LinphoneCoreListener { } } } - - private void setSignalingTransportsFromConfiguration(Transports t) { - Transports ports = new Transports(t); - boolean useRandomPort = getPrefBoolean(R.string.pref_transport_use_random_ports_key, mR.getBoolean(R.bool.pref_transport_use_random_ports_default)); - int lPreviousPort = tryToParseIntValue(getPrefString(R.string.pref_sip_port_key, getString(R.string.pref_sip_port_default)), 5060); - if (lPreviousPort>0xFFFF || useRandomPort) { - lPreviousPort=(int)(Math.random() * (0xFFFF - 1024)) + 1024; - Log.w("Using random port " + lPreviousPort); - } - - String transport = getPrefString(R.string.pref_transport_key, getString(R.string.pref_transport_udp_key)); - if (transport.equals(getString(R.string.pref_transport_tcp_key))) - { - ports.udp = 0; - ports.tls = 0; - ports.tcp = lPreviousPort; - } else if (transport.equals(getString(R.string.pref_transport_udp_key))) - { - ports.tcp = 0; - ports.tls = 0; - ports.udp = lPreviousPort; - } else if (transport.equals(getString(R.string.pref_transport_tls_key))) - { - ports.udp = 0; - ports.tcp = 0; - ports.tls = lPreviousPort; - } - - mLc.setSignalingTransportPorts(ports); - } - - private void enableDisableAudioCodec(String codec, int rate, int channels, int key) throws LinphoneCoreException { - PayloadType pt = mLc.findPayloadType(codec, rate, channels); - if (pt !=null) { - boolean enable= getPrefBoolean(key,false); - mLc.enablePayloadType(pt, enable); - } - } - private void enableDisableAudioCodec(String codec, int rate, int channels, boolean enable) throws LinphoneCoreException { - PayloadType pt = mLc.findPayloadType(codec, rate, channels); - if (pt !=null) { - mLc.enablePayloadType(pt, enable); - } - } - - private void enableDisableVideoCodecs(PayloadType videoCodec) throws LinphoneCoreException { - String mime = videoCodec.getMime(); - int key; - int defaultValueKey; - - if ("MP4V-ES".equals(mime)) { - key = R.string.pref_video_codec_mpeg4_key; - defaultValueKey = R.bool.pref_video_codec_mpeg4_default; - } else if ("H264".equals(mime)) { - key = R.string.pref_video_codec_h264_key; - defaultValueKey = R.bool.pref_video_codec_h264_default; - } else if ("H263-1998".equals(mime)) { - key = R.string.pref_video_codec_h263_key; - defaultValueKey = R.bool.pref_video_codec_h263_default; - } else if ("VP8".equals(mime)) { - key = R.string.pref_video_codec_vp8_key; - defaultValueKey = R.bool.pref_video_codec_vp8_default; - } else { - Log.e("Unhandled video codec ", mime); - mLc.enablePayloadType(videoCodec, false); - return; - } - - boolean enable = getPrefBoolean(key, mR.getBoolean(defaultValueKey)); - mLc.enablePayloadType(videoCodec, enable); - } - - private void setPreferredVideoSizeFromConfiguration() { - String preferredVideoSize = getPrefString(R.string.pref_preferred_video_size_key, getString(R.string.pref_preferred_video_size_vga_key)); - int bandwidth = 512 + 60; - if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_hd_key))) { - preferredVideoSize = "uxga"; - bandwidth = 1024 + 60; - } else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_vga_key))) { - preferredVideoSize = "vga"; - bandwidth = 512 + 60; - } else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_qvga_key))) { - preferredVideoSize = "qvga"; - bandwidth = 380 + 60; - } - - mLc.setPreferredVideoSizeByName(preferredVideoSize); - mLc.setUploadBandwidth(bandwidth); - mLc.setDownloadBandwidth(bandwidth); - } @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void doDestroy() { @@ -984,28 +696,6 @@ public class LinphoneManager implements LinphoneCoreListener { private String getString(int key) { return mR.getString(key); } - private boolean getPrefBoolean(int key, boolean value) { - return mPref.getBoolean(mR.getString(key), value); - } - private boolean getPrefBoolean(String key, boolean value) { - return mPref.getBoolean(key, value); - } - private String getPrefString(int key, String value) { - return mPref.getString(mR.getString(key), value); - } - private int getPrefInt(int key, int value) { - return mPref.getInt(mR.getString(key), value); - } - private String getPrefString(int key, int value) { - return mPref.getString(mR.getString(key), mR.getString(value)); - } - private String getPrefString(String key, String value) { - return mPref.getString(key, value); - } - private int getPrefExtraAccountsNumber() { - return mPref.getInt(getString(R.string.pref_extra_accounts), 1); - } - /* Simple implementation as Android way seems very complicate: For example: with wifi and mobile actives; when pulling mobile down: @@ -1205,7 +895,7 @@ public class LinphoneManager implements LinphoneCoreListener { Compatibility.setAudioManagerInCallMode(mAudioManager); } - if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) { + if (Hacks.needSoftvolume() || LinphonePreferences.instance().shouldUseSoftvolume()) { adjustVolume(0); // Synchronize } } @@ -1372,55 +1062,6 @@ public class LinphoneManager implements LinphoneCoreListener { return CallManager.getInstance().reinviteWithVideo(); } - public boolean isVideoEnabled() { - return getPrefBoolean(R.string.pref_video_enable_key, false); - } - - public boolean isAutoAcceptCamera() { - return isVideoEnabled() && getPrefBoolean(R.string.pref_video_automatically_accept_video_key, false); - } - - public boolean isAutoInitiateVideoCalls() { - return isVideoEnabled() && getPrefBoolean(R.string.pref_video_initiate_call_with_video_key, false); - } - - // Called on first launch only - public void initializePayloads() { - Log.i("Initializing supported payloads"); - Editor e = mPref.edit(); - boolean fastCpu = Version.hasFastCpu(); - - e.putBoolean(getString(R.string.pref_codec_gsm_key), true); - e.putBoolean(getString(R.string.pref_codec_pcma_key), true); - e.putBoolean(getString(R.string.pref_codec_pcmu_key), true); - e.putBoolean(getString(R.string.pref_codec_speex8_key), true); - e.putBoolean(getString(R.string.pref_codec_g722_key), false); - e.putBoolean(getString(pref_codec_speex16_key), fastCpu); - e.putBoolean(getString(pref_codec_speex32_key), fastCpu); - - boolean ilbc = LinphoneService.isReady() && LinphoneManager.getLc() - .findPayloadType("iLBC", 8000, 1)!=null; - e.putBoolean(getString(pref_codec_ilbc_key), ilbc); - - boolean amr = LinphoneService.isReady() && LinphoneManager.getLc() - .findPayloadType("AMR", 8000, 1)!=null; - e.putBoolean(getString(pref_codec_amr_key), amr); - - boolean amrwb = LinphoneService.isReady() && LinphoneManager.getLc() - .findPayloadType("AMR-WB", 16000, 1)!=null; - e.putBoolean(getString(pref_codec_amrwb_key), amrwb); - - boolean g729 = LinphoneService.isReady() && LinphoneManager.getLc() - .findPayloadType("G729", 8000, 1)!=null; - e.putBoolean(getString(R.string.pref_codec_g729_key), g729); - - if (Version.sdkStrictlyBelow(5) || !Version.hasNeon() || !Hacks.hasCamera()) { - e.putBoolean(getString(pref_video_enable_key), false); - } - - e.commit(); - } - /** * * @return false if already in video call. diff --git a/src/org/linphone/LinphonePreferenceManager.java b/src/org/linphone/LinphonePreferenceManager.java deleted file mode 100644 index a9906fa44..000000000 --- a/src/org/linphone/LinphonePreferenceManager.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -PreferenceManager.java -Copyright (C) 2011 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package org.linphone; - -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; - -public class LinphonePreferenceManager { - - private static LinphonePreferenceManager instance; - private Context c; - private SharedPreferences p; - - public LinphonePreferenceManager(Context context) { - c = context.getApplicationContext(); - p = PreferenceManager.getDefaultSharedPreferences(c); - } - - private String getString(int key) { - return c.getString(key); - } - - public boolean useSoftvolume() { - return p.getBoolean( - getString(R.string.pref_audio_soft_volume_key), false); - } - - public boolean useAudioRoutingAPIHack() { - return p.getBoolean( - getString(R.string.pref_audio_hacks_use_routing_api_key), false); - } - - public boolean useGalaxySHack() { - return p.getBoolean( - getString(R.string.pref_audio_hacks_use_galaxys_hack_key), false); - } - - public int useSpecificAudioModeHack() { - return Integer.parseInt(p.getString(getString(R.string.pref_audio_use_specific_mode_key), "0")); - } - - public static final synchronized LinphonePreferenceManager getInstance(Context c) { - if (instance == null) { - instance = new LinphonePreferenceManager(c.getApplicationContext()); - } - return instance; - } - -} diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index 6d0afc9c8..41af8096d 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -17,97 +17,182 @@ You should have received a copy of the GNU General Public License 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.util.HashMap; -import java.util.Map; - -import org.linphone.core.LinphoneCoreFactory; -import org.linphone.core.LpConfig; -import org.linphone.mediastream.Log; - -import android.content.res.Resources; /** * @author Sylvain Berfini */ public class LinphonePreferences { private static LinphonePreferences instance; - private Map dict, changesDict; - private LpConfig config; - public static final synchronized LinphonePreferences getInstance() { + public static final synchronized LinphonePreferences instance() { if (instance == null) { instance = new LinphonePreferences(); - instance.load(); } return instance; } private LinphonePreferences() { - dict = new HashMap(); - changesDict = new HashMap(); - if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() == null) { - config = LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile); - } else { - config = LinphoneManager.getLc().getConfig(); - } + } - public String get(String key) { - if (dict.containsKey(key)) { - return dict.get(key); - } + public boolean isFirstLaunch() { + return false; + } + + public void firstLaunchSuccessful() { + } + + public boolean isDebugEnabled() { + return false; + } + + public String getRemoteProvisioningUrl() { return null; } - - public String getNew(String key) { - if (changesDict.containsKey(key)) { - return changesDict.get(key); - } else if (dict.containsKey(key)) { - return dict.get(key); - } + + public String getTunnelMode() { return null; } - - public void set(String key, String value) { - if (dict.containsKey(key)) { - if (dict.get(key) != value || value.length() == 0) { - changesDict.put(key, value); - } - } else { - changesDict.put(key, value); - } + + public boolean useFrontCam() { + return false; + } + + public boolean isVideoEnabled() { + return false; + } + + public boolean shouldInitiateVideoCall() { + return false; + } + + public boolean shouldAutomaticallyAcceptVideoRequests() { + return false; + } + + public void setPushNotificationRegistrationID(String regId) { + + } + + public String getPushNotificationRegistrationID() { + return null; + } + + public boolean shouldStartAtStartup() { + return false; + } + + public String getSharingPictureServerUrl() { + return null; + } + + public boolean shouldUseLinphoneToStoreChatHistory() { + return false; + } + + public boolean areAnimationsEnabled() { + return false; + } + + public boolean shouldAutomaticallyAcceptFriendsRequests() { + return false; + } + + public boolean isBackgroundModeEnabled() { + return false; + } + + public boolean shouldOnlyRegisterOnWifiNetwork() { + return false; + } + + public boolean shouldUseSoftvolume() { + return false; + } + + public String getRingtone(String defaultRingtone) { + return defaultRingtone; } - public boolean hasValueChanged(String key) { - return changesDict.containsKey(key); + public void setRingtone(String ringtone) { + + } + + // Accounts + public void setAccountUsername(int n, String string) { + + } + + public String getAccountUsername(int i) { + return null; + } + + public void setAccountUserId(int n, String string) { + + } + + public String getAccountUserId(int n) { + return null; + } + + public void setAccountPassword(int n, String string) { + + } + + public String getAccountPassword(int n) { + return null; + } + + public void setAccountDomain(int n, String string) { + + } + + public String getAccountDomain(int i) { + return null; + } + + public void setAccountProxy(int n, String string) { + + } + + public String getAccountProxy(int n) { + return null; + } + + public void setAccountOutboundProxyEnabled(int n, Boolean newValue) { + + } + + public boolean isAccountOutboundProxySet(int n) { + return false; + } + + public void setAccountEnabled(int n, Boolean newValue) { + } - public void load() { - loadSection("sip", R.array.lpconfig_sip_keys); + public void setDefaultAccount(int accountIndex) { + } - - private void loadSection(String section, int resourcesID) { - Log.w("Preferences loading for section " + section); - for (String key : LinphoneService.instance().getResources().getStringArray(resourcesID)) { - String value = config.getString("sip", key, ""); - if (value != null && value.length() > 0) { - Log.w("Value read for key " + key + " : " + value); - dict.put(key, value); - } else { - Log.w("Value not found for key " + key); - } - } + + public int getDefaultAccountIndex() { + return 0; } - - public void save() { - Log.w("Preferences saving..."); - Resources res = LinphoneService.instance().getResources(); - for (String key : res.getStringArray(R.array.lpconfig_sip_keys)) { - if (hasValueChanged(key)) { - Log.w("Saving changed preference : " + getNew(key)); - config.setString("sip", key, getNew(key)); - } - } - config.sync(); + + public void setAccountCount(int i) { + } + + public int getAccountCount() { + return 0; + } + + public boolean isAccountEnabled(int n) { + return false; + } + + public void deleteAccount(int n) { + + } + // End of Accounts } diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 310e283dc..07c682aa4 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -47,7 +47,6 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; @@ -60,7 +59,6 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.SystemClock; -import android.preference.PreferenceManager; import android.provider.MediaStore; /** @@ -137,8 +135,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis super.onCreate(); // In case restart after a crash. Main in LinphoneActivity - LinphonePreferenceManager.getInstance(this); - mNotificationTitle = getString(R.string.app_name); // Dump some debugging information to the logs @@ -576,7 +572,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis // If the correspondent proposes video while audio call boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); - boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera(); + boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests(); if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { try { LinphoneManager.getLc().deferCallUpdate(call); @@ -616,14 +612,11 @@ public final class LinphoneService extends Service implements LinphoneServiceLis } public void changeRingtone(String ringtone) { - SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); - editor.putString(getString(R.string.pref_audio_ringtone), ringtone); - editor.commit(); + LinphonePreferences.instance().setRingtone(ringtone); } public void onRingerPlayerCreated(MediaPlayer mRingerPlayer) { - String uriString = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_audio_ringtone), - android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()); + String uriString = LinphonePreferences.instance().getRingtone(android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()); try { if (uriString.startsWith("content://")) { mRingerPlayer.setDataSource(this, Uri.parse(uriString)); diff --git a/src/org/linphone/PreferencesFragment.java b/src/org/linphone/PreferencesFragment.java index 5a4a767ee..0a179db54 100644 --- a/src/org/linphone/PreferencesFragment.java +++ b/src/org/linphone/PreferencesFragment.java @@ -50,7 +50,6 @@ import org.linphone.ui.PreferencesListFragment; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.preference.CheckBoxPreference; @@ -160,9 +159,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa initializePreferredVideoSizePreferences(); - if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) { - doOnFirstLaunch(); - } if (Hacks.hasBuiltInEchoCanceller()) { uncheckDisableAndHideCheckbox(R.string.pref_echo_cancellation_key); findPreference(R.string.pref_echo_canceller_calibration_key).setLayoutResource(R.layout.hidden); @@ -275,9 +271,8 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa addAccount.setTitle(getString(R.string.pref_add_account)); addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { - SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); - nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0); - prefs.edit().putInt(getString(R.string.pref_extra_accounts), nbAccounts+1).commit(); + nbAccounts = LinphonePreferences.instance().getAccountCount(); + LinphonePreferences.instance().setAccountCount(nbAccounts + 1); addExtraAccountPreferencesButton(accounts, nbAccounts, true); LinphoneActivity.instance().displayAccountSettings(nbAccounts); @@ -293,10 +288,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa p.setLayoutResource(R.layout.hidden); } - private void doOnFirstLaunch() { - prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH, false).commit(); - } - private synchronized void startEcCalibration() { try { LinphoneManager.getInstance().startEcCalibration(this); @@ -341,18 +332,9 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa Preference box = findPreference(key); box.setEnabled(enabled); Compatibility.setPreferenceChecked(box, value); - writeBoolean(key, value); if (hidden) box.setLayoutResource(R.layout.hidden); } - private void writeBoolean(int key, boolean value) { - prefs().edit().putBoolean(getString(key), value).commit(); - } - - private SharedPreferences prefs() { - return getPreferenceManager().getSharedPreferences(); - } - private void detectAudioCodec(int id, String mime, int rate, int channels, boolean hide) { Log.w("Payload type for codec " + mime + " = " + LinphoneManager.getLc().findPayloadType(mime, rate, channels)); boolean enable = LinphoneService.isReady() && LinphoneManager.getLc().findPayloadType(mime, rate, channels)!=null; @@ -372,8 +354,7 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa accounts.removeAll(); // Get already configured extra accounts - SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); - nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0); + nbAccounts = LinphonePreferences.instance().getAccountCount(); for (int i = 0; i < nbAccounts; i++) { // For each, add menus to configure it addExtraAccountPreferencesButton(accounts, i, false); @@ -385,30 +366,20 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa } private void addExtraAccountPreferencesButton(PreferenceCategory parent, final int n, boolean isNewAccount) { - SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); if (isNewAccount) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(getString(R.string.pref_extra_accounts), n+1); - editor.commit(); + LinphonePreferences.instance().setAccountCount(n+1); } - final LedPreference me = new LedPreference(mContext); - String keyUsername = getString(R.string.pref_username_key); - String keyDomain = getString(R.string.pref_domain_key); - if (n > 0) { - keyUsername += n + ""; - keyDomain += n + ""; - } - - String username = prefs.getString(keyUsername, ""); - String domain = prefs.getString(keyDomain, ""); + final LedPreference led = new LedPreference(mContext); + String username = LinphonePreferences.instance().getAccountUsername(n); + String domain = LinphonePreferences.instance().getAccountDomain(n); if (username == null) { - me.setTitle(getString(R.string.pref_sipaccount)); + led.setTitle(getString(R.string.pref_sipaccount)); } else { - me.setTitle(username + "@" + domain); + led.setTitle(username + "@" + domain); } - me.setOnPreferenceClickListener(new OnPreferenceClickListener() + led.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { LinphoneActivity.instance().displayAccountSettings(n); @@ -416,8 +387,8 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa } }); - updateAccountLed(me, username, domain); - parent.addPreference(me); + updateAccountLed(led, username, domain); + parent.addPreference(led); } private void updateAccountLed(final LedPreference me, final String username, final String domain) { diff --git a/src/org/linphone/SettingsFragment.java b/src/org/linphone/SettingsFragment.java index 1a7e9b05e..92f87b22c 100644 --- a/src/org/linphone/SettingsFragment.java +++ b/src/org/linphone/SettingsFragment.java @@ -7,71 +7,54 @@ import org.linphone.LinphoneManager.EcCalibrationListener; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.EcCalibratorStatus; import org.linphone.core.LinphoneCore.MediaEncryption; -import org.linphone.mediastream.Log; import org.linphone.ui.PreferencesListFragment; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.PreferenceScreen; +import android.preference.Preference.OnPreferenceClickListener; public class SettingsFragment extends PreferencesListFragment implements EcCalibrationListener { - private LinphonePreferences mPrefs; - - @Override - public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) { - - } - public SettingsFragment() { - super(R.xml.settings); + super(R.xml.preferences); } @Override public void onCreate(Bundle 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); + // Init the settings page interface + initSettings(); + hideSettings(); + setListeners(); } - private void setListenerForPreference(Preference pref) { - // FIXME: first display doesn't match the linphonerc values + // Inits the values or the listener on some settings + private void initSettings() { + initMediaEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_media_encryption_key))); + initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key))); - if (pref.hasKey()) { - pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - Log.w("New value for preference key " + preference.getKey() + ":" + newValue.toString()); - mPrefs.set(preference.getKey(), newValue.toString()); + // Add action on About button + findPreference(getString(R.string.menu_about_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + if (LinphoneActivity.isInstanciated()) { + LinphoneActivity.instance().displayAbout(); return true; } - }); - } else { - if (pref instanceof PreferenceCategory) { - 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) { - PreferenceScreen screen = (PreferenceScreen) pref; - int count = screen.getPreferenceCount(); - for (int i = 0; i < count; i++) { - Preference p = screen.getPreference(i); - setListenerForPreference(p); - } + return false; } + }); + + // Disable sip port choice if port is random + findPreference(getString(R.string.pref_sip_port_key)).setEnabled(!((CheckBoxPreference)findPreference(getString(R.string.pref_transport_use_random_ports_key))).isChecked()); + } + + // Read the values set in resources and hides the settings accordingly + private void hideSettings() { + if (!getResources().getBoolean(R.bool.display_about_in_settings)) { + findPreference(getString(R.string.menu_about_key)).setLayoutResource(R.layout.hidden); } } @@ -81,18 +64,13 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); } catch (Exception e) {} - List mencEntries=new ArrayList(); - List mencEntryValues=new ArrayList(); + List mencEntries = new ArrayList(); + List mencEntryValues = new ArrayList(); 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); + setListPreferenceValues(pref, mencEntries, mencEntryValues); return; } @@ -109,18 +87,49 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib 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); + setListPreferenceValues(pref, mencEntries, mencEntryValues); } } + private void initializeTransportPreferences(ListPreference pref) { + List mencEntries = new ArrayList(); + List mencEntryValues = new ArrayList(); + mencEntries.add(getString(R.string.pref_transport_udp)); + mencEntryValues.add(getString(R.string.pref_transport_udp_key)); + mencEntries.add(getString(R.string.pref_transport_tcp)); + mencEntryValues.add(getString(R.string.pref_transport_tcp_key)); + + if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) { + mencEntries.add(getString(R.string.pref_transport_tls)); + mencEntryValues.add(getString(R.string.pref_transport_tls_key)); + } + setListPreferenceValues(pref, mencEntries, mencEntryValues); + } + + private static void setListPreferenceValues(ListPreference pref, List entries, List values) { + CharSequence[] contents = new CharSequence[entries.size()]; + entries.toArray(contents); + pref.setEntries(contents); + contents = new CharSequence[values.size()]; + values.toArray(contents); + pref.setEntryValues(contents); + } + + private void setListeners() { + + } + @Override - public void onDestroy() { - LinphonePreferences.getInstance().save(); - super.onDestroy(); + public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) { + + } + + @Override + public void onResume() { + super.onResume(); + + if (LinphoneActivity.isInstanciated()) { + LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS); + } } } diff --git a/src/org/linphone/StatusFragment.java b/src/org/linphone/StatusFragment.java index e06c7abef..10f2c93c3 100644 --- a/src/org/linphone/StatusFragment.java +++ b/src/org/linphone/StatusFragment.java @@ -38,10 +38,8 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -485,13 +483,9 @@ public class StatusFragment extends Fragment { } class AccountsListAdapter extends BaseAdapter { - private SharedPreferences prefs; private List checkboxes; AccountsListAdapter() { - if (LinphoneActivity.isInstanciated()) { - prefs = PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance()); - } checkboxes = new ArrayList(); } @@ -501,23 +495,16 @@ public class StatusFragment extends Fragment { public void onClick(View v) { CheckBox checkBox = (CheckBox) v; if (checkBox.isChecked()) { - SharedPreferences.Editor editor = prefs.edit(); String tag = (String) checkBox.getTag(); String sipAddress = tag.split(":")[0]; int accountPosition = Integer.parseInt(tag.split(":")[1]); - int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0); + int nbAccounts = LinphonePreferences.instance().getAccountCount(); int accountIndex = 0; for (int i = 0; i < nbAccounts; i++) { - String keyUsername = getString(R.string.pref_username_key); - String keyDomain = getString(R.string.pref_domain_key); - if (i > 0) { - keyUsername += i + ""; - keyDomain += i + ""; - } - String username = prefs.getString(keyUsername, ""); - String domain = prefs.getString(keyDomain, ""); + String username = LinphonePreferences.instance().getAccountUsername(i); + String domain = LinphonePreferences.instance().getAccountDomain(i); String identity = username + "@" + domain; if (identity.equals(sipAddress)) { accountIndex = i; @@ -525,8 +512,7 @@ public class StatusFragment extends Fragment { } } - editor.putInt(getString(R.string.pref_default_account_key), accountIndex); - editor.commit(); + LinphonePreferences.instance().setDefaultAccount(accountIndex); for (CheckBox cb : checkboxes) { cb.setChecked(false); @@ -590,32 +576,22 @@ public class StatusFragment extends Fragment { isDefault.setChecked(false); isDefault.setEnabled(true); - if (prefs != null) { - int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0); - int accountIndex = 0; - for (int i = 0; i < nbAccounts; i++) - { - String keyUsername = getString(R.string.pref_username_key); - String keyDomain = getString(R.string.pref_domain_key); - if (i > 0) { - keyUsername += i + ""; - keyDomain += i + ""; - } - String username = prefs.getString(keyUsername, ""); - String domain = prefs.getString(keyDomain, ""); - String id = username + "@" + domain; - if (id.equals(sipAddress)) { - accountIndex = i; - break; - } - } - if (prefs.getInt(getString(R.string.pref_default_account_key), 0) == accountIndex) { - isDefault.setChecked(true); - isDefault.setEnabled(false); - status.setImageResource(getStatusIconResource(lpc.getState(), true)); - } else { - status.setImageResource(getStatusIconResource(lpc.getState(), false)); + int nbAccounts = LinphonePreferences.instance().getAccountCount(); + int accountIndex = 0; + for (int i = 0; i < nbAccounts; i++) + { + String username = LinphonePreferences.instance().getAccountUsername(i); + String domain = LinphonePreferences.instance().getAccountDomain(i); + String id = username + "@" + domain; + if (id.equals(sipAddress)) { + accountIndex = i; + break; } + } + if (LinphonePreferences.instance().getDefaultAccountIndex() == accountIndex) { + isDefault.setChecked(true); + isDefault.setEnabled(false); + status.setImageResource(getStatusIconResource(lpc.getState(), true)); } else { status.setImageResource(getStatusIconResource(lpc.getState(), false)); } diff --git a/src/org/linphone/compatibility/ApiEightPlus.java b/src/org/linphone/compatibility/ApiEightPlus.java index fb9cc1f63..01c88dabd 100644 --- a/src/org/linphone/compatibility/ApiEightPlus.java +++ b/src/org/linphone/compatibility/ApiEightPlus.java @@ -1,12 +1,11 @@ package org.linphone.compatibility; +import org.linphone.LinphonePreferences; import org.linphone.R; import org.linphone.mediastream.Log; import android.annotation.TargetApi; import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.view.Display; import com.google.android.gcm.GCMRegistrar; @@ -40,28 +39,21 @@ public class ApiEightPlus { } public static void initPushNotificationService(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - try { // Starting the push notification service GCMRegistrar.checkDevice(context); GCMRegistrar.checkManifest(context); final String regId = GCMRegistrar.getRegistrationId(context); String newPushSenderID = context.getString(R.string.push_sender_id); - String currentPushSenderID = prefs.getString(context.getString(R.string.push_sender_id_key), null); + String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID(); if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) { GCMRegistrar.register(context, newPushSenderID); Log.d("Push Notification : storing current sender id = " + newPushSenderID); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(context.getString(R.string.push_sender_id_key), newPushSenderID); - - editor.commit(); + LinphonePreferences.instance().setPushNotificationRegistrationID(newPushSenderID); } else { Log.d("Push Notification : already registered with id = " + regId); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(context.getString(R.string.push_reg_id_key), regId); - editor.commit(); + LinphonePreferences.instance().setPushNotificationRegistrationID(regId); } } catch (java.lang.UnsupportedOperationException e) { Log.i("Push Notification not activated"); diff --git a/src/org/linphone/gcm/GCMService.java b/src/org/linphone/gcm/GCMService.java index 5ca6d11be..6172a321b 100644 --- a/src/org/linphone/gcm/GCMService.java +++ b/src/org/linphone/gcm/GCMService.java @@ -19,14 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import org.linphone.LinphoneManager; +import org.linphone.LinphonePreferences; import org.linphone.R; -import org.linphone.core.LinphoneCoreException; import org.linphone.mediastream.Log; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import com.google.android.gcm.GCMBaseIntentService; @@ -57,27 +55,13 @@ public class GCMService extends GCMBaseIntentService { @Override protected void onRegistered(Context context, String regId) { Log.d("Registered push notification : " + regId); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(context.getString(R.string.push_reg_id_key), regId); - editor.commit(); - - if (LinphoneManager.isInstanciated()) { - try { - LinphoneManager.getInstance().initAccounts(); - } catch (LinphoneCoreException e) { - e.printStackTrace(); - } - } + LinphonePreferences.instance().setPushNotificationRegistrationID(regId); } @Override protected void onUnregistered(Context context, String regId) { Log.w("Unregistered push notification : " + regId); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(context.getString(R.string.push_reg_id_key), null); - editor.commit(); + LinphonePreferences.instance().setPushNotificationRegistrationID(null); } protected String[] getSenderIds(Context context) { diff --git a/src/org/linphone/setup/SetupActivity.java b/src/org/linphone/setup/SetupActivity.java index 150188603..2c8219a3a 100644 --- a/src/org/linphone/setup/SetupActivity.java +++ b/src/org/linphone/setup/SetupActivity.java @@ -18,10 +18,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import org.linphone.LinphoneManager; +import org.linphone.LinphonePreferences; import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; import org.linphone.R; import org.linphone.core.LinphoneCore.RegistrationState; -import org.linphone.mediastream.Log; import android.app.Activity; import android.content.Context; @@ -115,6 +115,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { setResult(Activity.RESULT_CANCELED); finish(); } + LinphonePreferences.instance().firstLaunchSuccessful(); } else if (id == R.id.setup_next) { if (firstFragment == SetupFragmentsEnum.LINPHONE_LOGIN) { LinphoneLoginFragment linphoneFragment = (LinphoneLoginFragment) fragment; @@ -145,6 +146,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { setResult(Activity.RESULT_CANCELED); finish(); } + LinphonePreferences.instance().firstLaunchSuccessful(); } if (currentFragment == SetupFragmentsEnum.MENU) { WelcomeFragment fragment = new WelcomeFragment(); @@ -184,14 +186,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { } saveCreatedAccount(username, password, domain); - LinphoneManager.getInstance().initializePayloads(); - - try { - LinphoneManager.getInstance().initFromConf(); - } catch (Throwable e) { - Log.e(e, "Error while initializing from config in first login activity"); - Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show(); - } if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { launchEchoCancellerCalibration(sendEcCalibrationResult); @@ -227,17 +221,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { LinphoneManager.addListener(registrationListener); saveCreatedAccount(username, password, domain); - LinphoneManager.getInstance().initializePayloads(); - - try { - LinphoneManager.getInstance().initFromConf(); - } catch (Throwable e) { - LinphoneManager.removeListener(registrationListener); - deleteCreatedAccount(); - - Log.e(e, "Error while initializing from config in first login activity"); - Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show(); - } } public void linphoneLogIn(String username, String password, boolean validate) { @@ -375,16 +358,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { public void isAccountVerified() { Toast.makeText(this, getString(R.string.setup_account_validated), Toast.LENGTH_LONG).show(); - - LinphoneManager.getInstance().initializePayloads(); - - try { - LinphoneManager.getInstance().initFromConf(); - } catch (Throwable e) { - Log.e(e, "Error while initializing from config in first login activity"); - Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show(); - } - launchEchoCancellerCalibration(true); } diff --git a/submodules/linphone b/submodules/linphone index b8453d1bc..13442d397 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit b8453d1bc16ab5bac06255bc8467bed0c60bcc3a +Subproject commit 13442d397b8a8e5c8c95bb525fa0491d0ad1599b