From 43d09414ff729ec1ab0a891aefa35c7194ea38e1 Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Thu, 28 Aug 2014 17:38:09 +0200 Subject: [PATCH] Rework proxy config uses Add realm in linphone account on wizzard --- src/org/linphone/LinphoneActivity.java | 22 ++++++-- src/org/linphone/LinphoneManager.java | 10 ++-- src/org/linphone/LinphonePreferences.java | 54 +++++++------------- src/org/linphone/LinphoneService.java | 4 +- src/org/linphone/LinphoneSimpleListener.java | 5 +- src/org/linphone/SettingsFragment.java | 44 ++++++++-------- src/org/linphone/setup/SetupActivity.java | 6 ++- 7 files changed, 71 insertions(+), 74 deletions(-) diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 4d7bd4157..cce21a63f 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -33,7 +33,9 @@ import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedLis 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.LinphoneProxyConfig; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCallLog; import org.linphone.core.LinphoneCallLog.CallStatus; @@ -768,15 +770,25 @@ public class LinphoneActivity extends FragmentActivity implements getChatStorage().updateMessageStatus(to, id, newState); } - @Override - public void onRegistrationStateChanged(RegistrationState state) { + public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (statusFragment != null) { - LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); - if (lc != null && lc.getDefaultProxyConfig() != null) - statusFragment.registrationStateChanged(lc.getDefaultProxyConfig().getState()); + if (lc != null) + if(lc.getDefaultProxyConfig() == null) + statusFragment.registrationStateChanged(proxy.getState()); + else + statusFragment.registrationStateChanged(lc.getDefaultProxyConfig().getState()); else statusFragment.registrationStateChanged(RegistrationState.RegistrationNone); } + + if(state.equals(RegistrationState.RegistrationCleared)){ + if(lc != null){ + LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain()); + if(authInfo != null) + lc.removeAuthInfo(authInfo); + } + } } private void displayMissedCalls(final int missedCallsCount) { diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 781b38b3a..ca93eb6dd 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -795,9 +795,9 @@ public class LinphoneManager implements LinphoneCoreListener { mListenerDispatcher.onGlobalStateChanged(state, message); } - public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig cfg,final RegistrationState state,final String message) { + public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig proxy,final RegistrationState state,final String message) { Log.i("new state ["+state+"]"); - mListenerDispatcher.onRegistrationStateChanged(state, message); + mListenerDispatcher.onRegistrationStateChanged(proxy, state, message); } private int savedMaxCallWhileGsmIncall; @@ -1285,11 +1285,11 @@ public class LinphoneManager implements LinphoneCoreListener { if (serviceListener != null) serviceListener.onGlobalStateChanged( state, message); } - public void onRegistrationStateChanged(RegistrationState state, + public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) { - if (serviceListener != null) serviceListener.onRegistrationStateChanged(state, message); + if (serviceListener != null) serviceListener.onRegistrationStateChanged(proxy, state, message); for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneOnRegistrationStateChangedListener.class)) { - listener.onRegistrationStateChanged(state); + listener.onRegistrationStateChanged(proxy, state, message); } } diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index de2133048..95138353f 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -168,6 +168,7 @@ public class LinphonePreferences { private String tempPassword; private String tempDomain; private String tempProxy; + private String tempRealm; private boolean tempOutboundProxy; private String tempContactsParams; private String tempExpire; @@ -244,6 +245,11 @@ public class LinphonePreferences { tempAvpfRRInterval = interval; return this; } + + public AccountBuilder setRealm(String realm) { + tempRealm = realm; + return this; + } public AccountBuilder setQualityReportingCollector(String collector) { tempQualityReportingCollector = collector; @@ -300,7 +306,7 @@ public class LinphonePreferences { String route = tempOutboundProxy ? proxyAddr.asStringUriOnly() : null; - LinphoneProxyConfig prxCfg = LinphoneCoreFactory.instance().createProxyConfig(identityAddr.asString(), proxyAddr.asStringUriOnly(), route, tempEnabled); + LinphoneProxyConfig prxCfg = lc.createProxyConfig(identityAddr.asString(), proxyAddr.asStringUriOnly(), route, tempEnabled); if (tempContactsParams != null) prxCfg.setContactUriParameters(tempContactsParams); @@ -315,7 +321,9 @@ public class LinphonePreferences { prxCfg.enableQualityReporting(tempQualityReportingEnabled); prxCfg.setQualityReportingCollector(tempQualityReportingCollector); prxCfg.setQualityReportingInterval(tempQualityReportingInterval); - prxCfg.setRealm("sip.linphone.org"); + + if(tempRealm != null) + prxCfg.setRealm(tempRealm); LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null, tempDomain); @@ -327,11 +335,6 @@ public class LinphonePreferences { } } - public boolean isAccountDeleted(int n){ - LinphoneProxyConfig proxyConfig = getProxyConfig(n); - return proxyConfig.getUserData() != null ? (Boolean) proxyConfig.getUserData() : false ; - } - public void setAccountTransport(int n, String transport) { LinphoneProxyConfig proxyConfig = getProxyConfig(n); @@ -675,35 +678,16 @@ public class LinphonePreferences { } public void deleteAccount(int n) { - final LinphoneAuthInfo authInfo = getAuthInfo(n); final LinphoneProxyConfig proxyCfg = getProxyConfig(n); - - proxyCfg.edit(); - proxyCfg.enableRegister(false); - proxyCfg.done(); - - proxyCfg.setUserData(true); - new Thread(new Runnable() { - - @Override - public void run() { - while(proxyCfg.getState() != RegistrationState.RegistrationCleared - && proxyCfg.getState() != RegistrationState.RegistrationFailed - && proxyCfg.getState() != RegistrationState.RegistrationNone){ - } - if (authInfo != null) - getLc().removeAuthInfo(authInfo); - if (proxyCfg != null) - getLc().removeProxyConfig(proxyCfg); - if (getLc().getProxyConfigList().length == 0) { - // TODO: remove once issue http://bugs.linphone.org/view.php?id=984 will be fixed - LinphoneActivity.instance().getStatusFragment().registrationStateChanged(RegistrationState.RegistrationNone); - } else { - resetDefaultProxyConfig(); - getLc().refreshRegisters(); - } - } - }).start(); + + if (proxyCfg != null) + getLc().removeProxyConfig(proxyCfg); + if (getLc().getProxyConfigList().length == 0) { + LinphoneActivity.instance().getStatusFragment().registrationStateChanged(RegistrationState.RegistrationNone); + } else { + resetDefaultProxyConfig(); + getLc().refreshRegisters(); + } } // End of accounts settings diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index d8c2180cf..e7432af47 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -497,7 +497,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis } } - public void onRegistrationStateChanged(final RegistrationState state, + public void onRegistrationStateChanged(final LinphoneProxyConfig proxy, final RegistrationState state, final String message) { // if (instance == null) { // Log.i("Service not ready, discarding registration state change to ",state.toString()); @@ -520,7 +520,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis mHandler.post(new Runnable() { public void run() { if (LinphoneActivity.isInstanciated()) { - LinphoneActivity.instance().onRegistrationStateChanged(state); + LinphoneActivity.instance().onRegistrationStateChanged(proxy,state,message); } } }); diff --git a/src/org/linphone/LinphoneSimpleListener.java b/src/org/linphone/LinphoneSimpleListener.java index 282f89189..218af877b 100644 --- a/src/org/linphone/LinphoneSimpleListener.java +++ b/src/org/linphone/LinphoneSimpleListener.java @@ -20,6 +20,7 @@ package org.linphone; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCall; +import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatRoom; @@ -41,8 +42,8 @@ public interface LinphoneSimpleListener { void tryingNewOutgoingCallButCannotGetCallParameters(); void tryingNewOutgoingCallButWrongDestinationAddress(); void tryingNewOutgoingCallButAlreadyInCall(); - void onRegistrationStateChanged(RegistrationState state, String message); void onDisplayStatus(String message); + void onRegistrationStateChanged(LinphoneProxyConfig proxy,RegistrationState state, String message); } @@ -68,7 +69,7 @@ public interface LinphoneSimpleListener { } public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener { - void onRegistrationStateChanged(RegistrationState state); + void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message); } public static interface ConnectivityChangedListener extends LinphoneSimpleListener { diff --git a/src/org/linphone/SettingsFragment.java b/src/org/linphone/SettingsFragment.java index 17143ee8c..b2c57e7b6 100644 --- a/src/org/linphone/SettingsFragment.java +++ b/src/org/linphone/SettingsFragment.java @@ -278,31 +278,29 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib for (int i = 0; i < nbAccounts; i++) { final int accountId = i; // For each, add menus to configure it - if(!mPrefs.isAccountDeleted(accountId)){ - String username = mPrefs.getAccountUsername(accountId); - String domain = mPrefs.getAccountDomain(accountId); - LedPreference account = new LedPreference(LinphoneService.instance()); + String username = mPrefs.getAccountUsername(accountId); + String domain = mPrefs.getAccountDomain(accountId); + LedPreference account = new LedPreference(LinphoneService.instance()); - if (username == null) { - account.setTitle(getString(R.string.pref_sipaccount)); - } else { - account.setTitle(username + "@" + domain); - } - - if (defaultAccountID == i) { - account.setSummary(R.string.default_account_flag); - } - - account.setOnPreferenceClickListener(new OnPreferenceClickListener() - { - public boolean onPreferenceClick(Preference preference) { - LinphoneActivity.instance().displayAccountSettings(accountId); - return false; - } - }); - updateAccountLed(account, username, domain, mPrefs.isAccountEnabled(i)); - accounts.addPreference(account); + if (username == null) { + account.setTitle(getString(R.string.pref_sipaccount)); + } else { + account.setTitle(username + "@" + domain); } + + if (defaultAccountID == i) { + account.setSummary(R.string.default_account_flag); + } + + account.setOnPreferenceClickListener(new OnPreferenceClickListener() + { + public boolean onPreferenceClick(Preference preference) { + LinphoneActivity.instance().displayAccountSettings(accountId); + return false; + } + }); + updateAccountLed(account, username, domain, mPrefs.isAccountEnabled(i)); + accounts.addPreference(account); } } diff --git a/src/org/linphone/setup/SetupActivity.java b/src/org/linphone/setup/SetupActivity.java index ec18e8ceb..a61d44404 100644 --- a/src/org/linphone/setup/SetupActivity.java +++ b/src/org/linphone/setup/SetupActivity.java @@ -25,6 +25,7 @@ import org.linphone.R; import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneCore.RegistrationState; import org.linphone.core.LinphoneCoreException; +import org.linphone.core.LinphoneProxyConfig; import android.app.Activity; import android.content.Context; @@ -201,7 +202,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { private LinphoneOnRegistrationStateChangedListener registrationListener = new LinphoneOnRegistrationStateChangedListener() { - public void onRegistrationStateChanged(RegistrationState state) { + public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) { if (state == RegistrationState.RegistrationOk) { LinphoneManager.removeListener(registrationListener); @@ -311,7 +312,8 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { .setAvpfRRInterval(3) .setQualityReportingCollector("sip:voip-metrics@sip.linphone.org") .setQualityReportingEnabled(true) - .setQualityReportingInterval(180); + .setQualityReportingInterval(180) + .setRealm("sip.linphone.org"); mPrefs.setStunServer(getString(R.string.default_stun));