From 6797a1e2c26d3a9b62e2e018dae7e419b8d8d14f Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Tue, 8 Jul 2014 16:26:53 +0200 Subject: [PATCH] Fix delete/disable account --- src/org/linphone/LinphonePreferences.java | 44 +++++++++++++++------- src/org/linphone/SettingsFragment.java | 46 ++++++++++++----------- src/org/linphone/StatusFragment.java | 3 +- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index b657ea4e3..4bdcf3bab 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -291,6 +291,11 @@ public class LinphonePreferences { } } + public boolean isAccountDeleted(int n){ + LinphoneProxyConfig proxyConfig = getProxyConfig(n); + return proxyConfig.getIsDeleted(); + } + public void setAccountTransport(int n, String transport) { LinphoneProxyConfig proxyConfig = getProxyConfig(n); @@ -586,6 +591,7 @@ public class LinphonePreferences { public void setAccountEnabled(int n, boolean enabled) { LinphoneProxyConfig prxCfg = getProxyConfig(n); + prxCfg.edit(); prxCfg.enableRegister(enabled); prxCfg.done(); @@ -608,19 +614,31 @@ public class LinphonePreferences { } public void deleteAccount(int n) { - LinphoneAuthInfo authInfo = getAuthInfo(n); - if (authInfo != null) - getLc().removeAuthInfo(authInfo); - LinphoneProxyConfig proxyCfg = getProxyConfig(n); - 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 { - getLc().refreshRegisters(); - } + final LinphoneAuthInfo authInfo = getAuthInfo(n); + final LinphoneProxyConfig proxyCfg = getProxyConfig(n); + + proxyCfg.edit(); + proxyCfg.enableRegister(false); + proxyCfg.done(); + + proxyCfg.setIsDeleted(true); + new Thread(new Runnable() { + + @Override + public void run() { + while(proxyCfg.getState() != RegistrationState.RegistrationCleared && proxyCfg.getState() != RegistrationState.RegistrationFailed){} + 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 { + getLc().refreshRegisters(); + } + } + }).start(); } // End of accounts settings diff --git a/src/org/linphone/SettingsFragment.java b/src/org/linphone/SettingsFragment.java index 456f02915..564a507fd 100644 --- a/src/org/linphone/SettingsFragment.java +++ b/src/org/linphone/SettingsFragment.java @@ -276,29 +276,31 @@ 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 - LedPreference account = new LedPreference(LinphoneService.instance()); - String username = mPrefs.getAccountUsername(accountId); - String domain = mPrefs.getAccountDomain(accountId); - - 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; + if(!mPrefs.isAccountDeleted(accountId)){ + 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); } - }); - updateAccountLed(account, username, domain, mPrefs.isAccountEnabled(i)); - accounts.addPreference(account); + + 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/StatusFragment.java b/src/org/linphone/StatusFragment.java index 30582ad7f..78fa8e2e0 100644 --- a/src/org/linphone/StatusFragment.java +++ b/src/org/linphone/StatusFragment.java @@ -225,7 +225,8 @@ public class StatusFragment extends Fragment { private int getStatusIconResource(LinphoneCore.RegistrationState state, boolean isDefaultAccount) { try { - boolean defaultAccountConnected = (isDefaultAccount && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getDefaultProxyConfig().isRegistered()) || !isDefaultAccount; + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + boolean defaultAccountConnected = (isDefaultAccount && lc != null && lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().isRegistered()) || !isDefaultAccount; if (state == RegistrationState.RegistrationOk && defaultAccountConnected) { return R.drawable.led_connected; } else if (state == RegistrationState.RegistrationProgress) {