Fix migration of account natpolicy

This commit is contained in:
Erwan Croze 2017-06-05 11:14:31 +02:00
parent 6c3c9a7025
commit 0b124e3403
8 changed files with 51 additions and 24 deletions

View file

@ -301,13 +301,8 @@ public class AccountPreferencesFragment extends PreferencesListFragment implemen
boolean value = (Boolean) newValue; boolean value = (Boolean) newValue;
if (isNewAccount) { if (isNewAccount) {
} else { } else {
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null mPrefs.setAccountIce(n, value);
&& LinphoneManager.getLc().getProxyConfigList() != null ((CheckBoxPreference)preference).setChecked(mPrefs.getAccountIce(n));
&& LinphoneManager.getLc().getProxyConfigList().length > n
&& LinphoneManager.getLc().getProxyConfigList()[n].getNatPolicy() != null)
LinphoneManager.getLc().getProxyConfigList()[n].getNatPolicy().enableIce(value);
else
return false;
} }
return true; return true;
} }
@ -319,16 +314,9 @@ public class AccountPreferencesFragment extends PreferencesListFragment implemen
String value = newValue.toString(); String value = newValue.toString();
if (isNewAccount) { if (isNewAccount) {
} else { } else {
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null mPrefs.setAccountStunServer(n, value);
&& LinphoneManager.getLc().getProxyConfigList() != null
&& LinphoneManager.getLc().getProxyConfigList().length > n
&& LinphoneManager.getLc().getProxyConfigList()[n].getNatPolicy() != null) {
LinphoneManager.getLc().getProxyConfigList()[n].getNatPolicy().setStunServer(value);
preference.setSummary(value); preference.setSummary(value);
} }
else
return false;
}
return true; return true;
} }
}; };
@ -339,7 +327,14 @@ public class AccountPreferencesFragment extends PreferencesListFragment implemen
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null && if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null &&
LinphoneManager.getLc().getProxyConfigList() != null && LinphoneManager.getLc().getProxyConfigList() != null &&
LinphoneManager.getLc().getProxyConfigList().length > n) { LinphoneManager.getLc().getProxyConfigList().length > n) {
natPolicy = LinphoneManager.getLc().getProxyConfigList()[n].getNatPolicy(); LinphoneProxyConfig proxy = LinphoneManager.getLc().getProxyConfigList()[n];
natPolicy = proxy.getNatPolicy();
if (natPolicy == null) {
natPolicy = LinphoneManager.getLc().createNatPolicy();
proxy.edit();
proxy.setNatPolicy(natPolicy);
proxy.done();
}
} }
accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc() accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc()

View file

@ -216,9 +216,9 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
@Override @Override
public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy, LinphoneCore.RegistrationState state, String smessage) { public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy, LinphoneCore.RegistrationState state, String smessage) {
LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain());
if (state.equals(RegistrationState.RegistrationCleared)) { if (state.equals(RegistrationState.RegistrationCleared)) {
if (lc != null) { if (lc != null) {
LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain());
if (authInfo != null) if (authInfo != null)
lc.removeAuthInfo(authInfo); lc.removeAuthInfo(authInfo);
} }
@ -227,7 +227,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
refreshAccounts(); refreshAccounts();
if(getResources().getBoolean(R.bool.use_phone_number_validation) if(getResources().getBoolean(R.bool.use_phone_number_validation)
&& proxy.getDomain().equals(getString(R.string.default_domain))) { && authInfo != null && authInfo.getDomain().equals(getString(R.string.default_domain))) {
if (state.equals(RegistrationState.RegistrationOk)) { if (state.equals(RegistrationState.RegistrationOk)) {
LinphoneManager.getInstance().isAccountWithAlias(); LinphoneManager.getInstance().isAccountWithAlias();
} }

View file

@ -569,6 +569,38 @@ public class LinphonePreferences {
return authInfo == null ? null : authInfo.getHa1(); return authInfo == null ? null : authInfo.getHa1();
} }
public void setAccountIce(int n, boolean ice) {
try {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.edit();
prxCfg.getNatPolicy().enableIce(ice);
prxCfg.done();
} catch (Exception e) {
Log.e(e);
}
}
public boolean getAccountIce(int n) {
if (getProxyConfig(n) == null || getProxyConfig(n).getNatPolicy() == null) return false;
return getProxyConfig(n).getNatPolicy().iceEnabled();
}
public void setAccountStunServer(int n, String stun) {
try {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.edit();
prxCfg.getNatPolicy().setStunServer(stun);
prxCfg.done();
} catch (Exception e) {
Log.e(e);
}
}
public String getAccountStunServer(int n) {
if (getProxyConfig(n) == null || getProxyConfig(n).getNatPolicy() == null) return "";
return getProxyConfig(n).getNatPolicy().getStunServer();
}
public void setAccountDomain(int n, String domain) { public void setAccountDomain(int n, String domain) {
String identity = "sip:" + getAccountUsername(n) + "@" + domain; String identity = "sip:" + getAccountUsername(n) + "@" + domain;
LinphoneAuthInfo old_info = getAuthInfo(n); LinphoneAuthInfo old_info = getAuthInfo(n);

@ -1 +1 @@
Subproject commit e534a2e9b1f2bc7009a2816c8845aa7c07812d73 Subproject commit e401c0a91f81ff2a22b713151617ba4e7994c855

@ -1 +1 @@
Subproject commit 8abfd2f68e93f69dd48a8840a654204ffe996f30 Subproject commit 5ea997060204d7eb680d94c8f258ca5bfdce1d65

@ -1 +1 @@
Subproject commit e9980c6ca74e0619215fa78f83543cb6f209f4d5 Subproject commit c03dd6f3898076e8d5721be7665dc7f0c0ada2f9

@ -1 +1 @@
Subproject commit 52025ffef5f9637426f8ed1e9f83e183e87f8be3 Subproject commit d658d212815b094e27f8d3513043c00c6e262999

@ -1 +1 @@
Subproject commit 4b0eb84c8e738a606cfd5da35d2a673853b4b13a Subproject commit bd792338c47c3849cce3661d4e693df0177873c0