diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index c1376cca6..8a80e1f18 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -146,65 +146,125 @@ public class LinphonePreferences { private void saveAuthInfo(LinphoneAuthInfo authInfo) { getLc().addAuthInfo(authInfo); } - - private String tempUsername; - private String tempUserId; - private String tempPassword; - private String tempDomain; - private String tempProxy; - private boolean tempOutboundProxy; - private String tempContactsParams; - private String tempExpire; - private TransportType tempTransport; - - /** - * Creates a new account using values previously set using setNew* functions - * @throws LinphoneCoreException - */ - public void saveNewAccount() throws LinphoneCoreException { - String identity = "sip:" + tempUsername + "@" + tempDomain; - String proxy = "sip:"; - proxy += tempProxy == null ? tempDomain : tempProxy; - LinphoneAddress proxyAddr = LinphoneCoreFactory.instance().createLinphoneAddress(proxy); - - if (tempTransport == null) { - tempTransport = TransportType.LinphoneTransportUdp; + + public static class AccountBuilder { + private LinphoneCore lc; + public AccountBuilder(LinphoneCore lc) { + this.lc = lc; } - proxyAddr.setTransport(tempTransport); - - String route = tempOutboundProxy ? proxyAddr.asStringUriOnly() : null; - - LinphoneProxyConfig prxCfg = LinphoneCoreFactory.instance().createProxyConfig(identity, proxyAddr.asStringUriOnly(), route, true); - if (tempContactsParams != null) - prxCfg.setContactUriParameters(tempContactsParams); - if (tempExpire != null) { - try { - prxCfg.setExpires(Integer.parseInt(tempExpire)); - } catch (NumberFormatException nfe) { } + private String tempUsername; + private String tempUserId; + private String tempPassword; + private String tempDomain; + private String tempProxy; + private boolean tempOutboundProxy; + private String tempContactsParams; + private String tempExpire; + private TransportType tempTransport; + private boolean tempEnabled = true; + private boolean tempNoDefault = false; + + public AccountBuilder setTransport(TransportType transport) { + tempTransport = transport; + return this; + } + public AccountBuilder setUsername(String username) { + tempUsername = username; + return this; + } + + public AccountBuilder setPassword(String password) { + tempPassword = password; + return this; + } + + public AccountBuilder setDomain(String domain) { + tempDomain = domain; + return this; + } + + public AccountBuilder setProxy(String proxy) { + tempProxy = proxy; + return this; + } + public AccountBuilder setOutboundProxyEnabled(boolean enabled) { + tempOutboundProxy = enabled; + return this; + } + + public AccountBuilder setContactParameters(String contactParams) { + tempContactsParams = contactParams; + return this; } - LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null, tempDomain); - - getLc().addProxyConfig(prxCfg); - getLc().addAuthInfo(authInfo); - - if (getAccountCount() == 1) - getLc().setDefaultProxyConfig(prxCfg); - - tempUsername = null; - tempUserId = null; - tempPassword = null; - tempDomain = null; - tempProxy = null; - tempOutboundProxy = false; - tempContactsParams = null; - tempExpire = null; - tempTransport = null; + public AccountBuilder setExpires(String expire) { + tempExpire = expire; + return this; + } + + public AccountBuilder setUserId(String userId) { + tempUserId = userId; + return this; + } + + public AccountBuilder setEnabled(boolean enable) { + tempEnabled = enable; + return this; + } + + public AccountBuilder setNoDefault(boolean yesno) { + tempNoDefault = yesno; + return this; + } + + /** + * Creates a new account + * @throws LinphoneCoreException + */ + public void saveNewAccount() throws LinphoneCoreException { + String identity = "sip:" + tempUsername + "@" + tempDomain; + String proxy = "sip:"; + if (tempProxy == null) { + proxy += tempDomain; + } else { + if (!tempProxy.startsWith("sip:") && !tempProxy.startsWith(" 0 && password != null) { - mNewPrefs.setNewAccountUsername(username); - mNewPrefs.setNewAccountUserId(userid); - mNewPrefs.setNewAccountDomain(domain); - mNewPrefs.setNewAccountPassword(password); - String proxy = getPrefString(getString(R.string.pref_proxy_key) + key, null); - mNewPrefs.setNewAccountProxy(proxy); String expire = getPrefString(R.string.pref_expire_key, null); - mNewPrefs.setNewAccountExpires(expire); + + AccountBuilder builder = new AccountBuilder(LinphoneManager.getLc()) + .setUsername(username) + .setUserId(userid) + .setDomain(domain) + .setPassword(password) + .setProxy(proxy) + .setExpires(expire); if (getPrefBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false)) { - mNewPrefs.setNewAccountOutboundProxyEnabled(true); + builder.setOutboundProxyEnabled(true); } if (mResources.getBoolean(R.bool.enable_push_id)) { String regId = mNewPrefs.getPushNotificationRegistrationID(); String appId = getString(R.string.push_sender_id); if (regId != null && mNewPrefs.isPushNotificationEnabled()) { String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId; - mNewPrefs.setNewAccountContactParameters(contactInfos); + builder.setContactParameters(contactInfos); } } try { - mNewPrefs.saveNewAccount(); + builder.saveNewAccount(); } catch (LinphoneCoreException e) { e.printStackTrace(); } diff --git a/src/org/linphone/setup/SetupActivity.java b/src/org/linphone/setup/SetupActivity.java index 9fe6c2ee3..981431aef 100644 --- a/src/org/linphone/setup/SetupActivity.java +++ b/src/org/linphone/setup/SetupActivity.java @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import org.linphone.LinphoneManager; import org.linphone.LinphonePreferences; +import org.linphone.LinphonePreferences.AccountBuilder; import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; import org.linphone.R; import org.linphone.core.LinphoneAddress.TransportType; @@ -285,30 +286,31 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { boolean isMainAccountLinphoneDotOrg = domain.equals(getString(R.string.default_domain)); boolean useLinphoneDotOrgCustomPorts = getResources().getBoolean(R.bool.use_linphone_server_ports); - mPrefs.setNewAccountUsername(username); - mPrefs.setNewAccountDomain(domain); - mPrefs.setNewAccountPassword(password); + AccountBuilder builder = new AccountBuilder(LinphoneManager.getLc()) + .setUsername(username) + .setDomain(domain) + .setPassword(password); if (isMainAccountLinphoneDotOrg && useLinphoneDotOrgCustomPorts) { if (getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) { - mPrefs.setNewAccountProxy(domain + ":5228"); - mPrefs.setNewAccountTransport(TransportType.LinphoneTransportTcp); + builder.setProxy(domain + ":5228") + .setTransport(TransportType.LinphoneTransportTcp); } else { - mPrefs.setNewAccountProxy(domain + ":5223"); - mPrefs.setNewAccountTransport(TransportType.LinphoneTransportTls); + builder.setProxy(domain + ":5223") + .setTransport(TransportType.LinphoneTransportTls); } - mPrefs.setNewAccountExpires("604800"); - mPrefs.setNewAccountOutboundProxyEnabled(true); + builder.setExpires("604800") + .setOutboundProxyEnabled(true); mPrefs.setStunServer(getString(R.string.default_stun)); mPrefs.setIceEnabled(true); mPrefs.setPushNotificationEnabled(true); } else { String forcedProxy = getResources().getString(R.string.setup_forced_proxy); if (!TextUtils.isEmpty(forcedProxy)) { - mPrefs.setNewAccountProxy(forcedProxy); - mPrefs.setNewAccountOutboundProxyEnabled(true); + builder.setProxy(forcedProxy) + .setOutboundProxyEnabled(true); } } @@ -317,12 +319,12 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { String appId = getString(R.string.push_sender_id); if (regId != null && mPrefs.isPushNotificationEnabled()) { String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId; - mPrefs.setNewAccountContactParameters(contactInfos); + builder.setContactParameters(contactInfos); } } try { - mPrefs.saveNewAccount(); + builder.saveNewAccount(); accountCreated = true; } catch (LinphoneCoreException e) { e.printStackTrace(); diff --git a/submodules/belle-sip b/submodules/belle-sip index dbb21ad93..55b0f5439 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit dbb21ad93461aa3cdf9663f1ba2cdb7dfb568ce4 +Subproject commit 55b0f5439ad07c9829f6dd88ae1a9dbfdaca851d diff --git a/submodules/linphone b/submodules/linphone index aad2df16d..a45d28a32 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit aad2df16d1945abd71bef720d079515383cf88d4 +Subproject commit a45d28a328be70f037995c48dd4742fbb1eb9519