Rework proxy config uses

Add realm in linphone account on wizzard
This commit is contained in:
Margaux Clerc 2014-08-28 17:38:09 +02:00
parent 78b89a930f
commit 43d09414ff
7 changed files with 71 additions and 74 deletions

View file

@ -33,7 +33,9 @@ import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedLis
import org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
import org.linphone.core.CallDirection; import org.linphone.core.CallDirection;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallLog; import org.linphone.core.LinphoneCallLog;
import org.linphone.core.LinphoneCallLog.CallStatus; import org.linphone.core.LinphoneCallLog.CallStatus;
@ -768,15 +770,25 @@ public class LinphoneActivity extends FragmentActivity implements
getChatStorage().updateMessageStatus(to, id, newState); getChatStorage().updateMessageStatus(to, id, newState);
} }
@Override public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) {
public void onRegistrationStateChanged(RegistrationState state) {
if (statusFragment != null) {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null && lc.getDefaultProxyConfig() != null) if (statusFragment != null) {
if (lc != null)
if(lc.getDefaultProxyConfig() == null)
statusFragment.registrationStateChanged(proxy.getState());
else
statusFragment.registrationStateChanged(lc.getDefaultProxyConfig().getState()); statusFragment.registrationStateChanged(lc.getDefaultProxyConfig().getState());
else else
statusFragment.registrationStateChanged(RegistrationState.RegistrationNone); 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) { private void displayMissedCalls(final int missedCallsCount) {

View file

@ -795,9 +795,9 @@ public class LinphoneManager implements LinphoneCoreListener {
mListenerDispatcher.onGlobalStateChanged(state, message); 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+"]"); Log.i("new state ["+state+"]");
mListenerDispatcher.onRegistrationStateChanged(state, message); mListenerDispatcher.onRegistrationStateChanged(proxy, state, message);
} }
private int savedMaxCallWhileGsmIncall; private int savedMaxCallWhileGsmIncall;
@ -1285,11 +1285,11 @@ public class LinphoneManager implements LinphoneCoreListener {
if (serviceListener != null) serviceListener.onGlobalStateChanged( state, message); if (serviceListener != null) serviceListener.onGlobalStateChanged( state, message);
} }
public void onRegistrationStateChanged(RegistrationState state, public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state,
String message) { String message) {
if (serviceListener != null) serviceListener.onRegistrationStateChanged(state, message); if (serviceListener != null) serviceListener.onRegistrationStateChanged(proxy, state, message);
for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneOnRegistrationStateChangedListener.class)) { for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneOnRegistrationStateChangedListener.class)) {
listener.onRegistrationStateChanged(state); listener.onRegistrationStateChanged(proxy, state, message);
} }
} }

View file

@ -168,6 +168,7 @@ public class LinphonePreferences {
private String tempPassword; private String tempPassword;
private String tempDomain; private String tempDomain;
private String tempProxy; private String tempProxy;
private String tempRealm;
private boolean tempOutboundProxy; private boolean tempOutboundProxy;
private String tempContactsParams; private String tempContactsParams;
private String tempExpire; private String tempExpire;
@ -245,6 +246,11 @@ public class LinphonePreferences {
return this; return this;
} }
public AccountBuilder setRealm(String realm) {
tempRealm = realm;
return this;
}
public AccountBuilder setQualityReportingCollector(String collector) { public AccountBuilder setQualityReportingCollector(String collector) {
tempQualityReportingCollector = collector; tempQualityReportingCollector = collector;
return this; return this;
@ -300,7 +306,7 @@ public class LinphonePreferences {
String route = tempOutboundProxy ? proxyAddr.asStringUriOnly() : null; 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) if (tempContactsParams != null)
prxCfg.setContactUriParameters(tempContactsParams); prxCfg.setContactUriParameters(tempContactsParams);
@ -315,7 +321,9 @@ public class LinphonePreferences {
prxCfg.enableQualityReporting(tempQualityReportingEnabled); prxCfg.enableQualityReporting(tempQualityReportingEnabled);
prxCfg.setQualityReportingCollector(tempQualityReportingCollector); prxCfg.setQualityReportingCollector(tempQualityReportingCollector);
prxCfg.setQualityReportingInterval(tempQualityReportingInterval); 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); 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) { public void setAccountTransport(int n, String transport) {
LinphoneProxyConfig proxyConfig = getProxyConfig(n); LinphoneProxyConfig proxyConfig = getProxyConfig(n);
@ -675,36 +678,17 @@ public class LinphonePreferences {
} }
public void deleteAccount(int n) { public void deleteAccount(int n) {
final LinphoneAuthInfo authInfo = getAuthInfo(n);
final LinphoneProxyConfig proxyCfg = getProxyConfig(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) if (proxyCfg != null)
getLc().removeProxyConfig(proxyCfg); getLc().removeProxyConfig(proxyCfg);
if (getLc().getProxyConfigList().length == 0) { 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); LinphoneActivity.instance().getStatusFragment().registrationStateChanged(RegistrationState.RegistrationNone);
} else { } else {
resetDefaultProxyConfig(); resetDefaultProxyConfig();
getLc().refreshRegisters(); getLc().refreshRegisters();
} }
} }
}).start();
}
// End of accounts settings // End of accounts settings
// Audio settings // Audio settings

View file

@ -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) { final String message) {
// if (instance == null) { // if (instance == null) {
// Log.i("Service not ready, discarding registration state change to ",state.toString()); // 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() { mHandler.post(new Runnable() {
public void run() { public void run() {
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().onRegistrationStateChanged(state); LinphoneActivity.instance().onRegistrationStateChanged(proxy,state,message);
} }
} }
}); });

View file

@ -20,6 +20,7 @@ package org.linphone;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneChatRoom;
@ -41,8 +42,8 @@ public interface LinphoneSimpleListener {
void tryingNewOutgoingCallButCannotGetCallParameters(); void tryingNewOutgoingCallButCannotGetCallParameters();
void tryingNewOutgoingCallButWrongDestinationAddress(); void tryingNewOutgoingCallButWrongDestinationAddress();
void tryingNewOutgoingCallButAlreadyInCall(); void tryingNewOutgoingCallButAlreadyInCall();
void onRegistrationStateChanged(RegistrationState state, String message);
void onDisplayStatus(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 { public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener {
void onRegistrationStateChanged(RegistrationState state); void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message);
} }
public static interface ConnectivityChangedListener extends LinphoneSimpleListener { public static interface ConnectivityChangedListener extends LinphoneSimpleListener {

View file

@ -278,7 +278,6 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
for (int i = 0; i < nbAccounts; i++) { for (int i = 0; i < nbAccounts; i++) {
final int accountId = i; final int accountId = i;
// For each, add menus to configure it // For each, add menus to configure it
if(!mPrefs.isAccountDeleted(accountId)){
String username = mPrefs.getAccountUsername(accountId); String username = mPrefs.getAccountUsername(accountId);
String domain = mPrefs.getAccountDomain(accountId); String domain = mPrefs.getAccountDomain(accountId);
LedPreference account = new LedPreference(LinphoneService.instance()); LedPreference account = new LedPreference(LinphoneService.instance());
@ -304,7 +303,6 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
accounts.addPreference(account); accounts.addPreference(account);
} }
} }
}
private void updateAccountLed(final LedPreference me, final String username, final String domain, boolean enabled) { private void updateAccountLed(final LedPreference me, final String username, final String domain, boolean enabled) {
if (!enabled) { if (!enabled) {

View file

@ -25,6 +25,7 @@ import org.linphone.R;
import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneCore.RegistrationState; import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneProxyConfig;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -201,7 +202,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
private LinphoneOnRegistrationStateChangedListener registrationListener = new LinphoneOnRegistrationStateChangedListener() { private LinphoneOnRegistrationStateChangedListener registrationListener = new LinphoneOnRegistrationStateChangedListener() {
public void onRegistrationStateChanged(RegistrationState state) { public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) {
if (state == RegistrationState.RegistrationOk) { if (state == RegistrationState.RegistrationOk) {
LinphoneManager.removeListener(registrationListener); LinphoneManager.removeListener(registrationListener);
@ -311,7 +312,8 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
.setAvpfRRInterval(3) .setAvpfRRInterval(3)
.setQualityReportingCollector("sip:voip-metrics@sip.linphone.org") .setQualityReportingCollector("sip:voip-metrics@sip.linphone.org")
.setQualityReportingEnabled(true) .setQualityReportingEnabled(true)
.setQualityReportingInterval(180); .setQualityReportingInterval(180)
.setRealm("sip.linphone.org");
mPrefs.setStunServer(getString(R.string.default_stun)); mPrefs.setStunServer(getString(R.string.default_stun));