be a bit more careful when deleting and deactivating accounts
This commit is contained in:
parent
e1d2c32e63
commit
416481bb65
|
@ -607,17 +607,18 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
return list;
|
||||
}
|
||||
|
||||
public void updateAccount(Account account) {
|
||||
public boolean updateAccount(Account account) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
String[] args = {account.getUuid()};
|
||||
db.update(Account.TABLENAME, account.getContentValues(), Account.UUID
|
||||
+ "=?", args);
|
||||
final int rows = db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", args);
|
||||
return rows == 1;
|
||||
}
|
||||
|
||||
public void deleteAccount(Account account) {
|
||||
public boolean deleteAccount(Account account) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
String[] args = {account.getUuid()};
|
||||
db.delete(Account.TABLENAME, Account.UUID + "=?", args);
|
||||
final int rows = db.delete(Account.TABLENAME, Account.UUID + "=?", args);
|
||||
return rows == 1;
|
||||
}
|
||||
|
||||
public boolean hasEnabledAccounts() {
|
||||
|
|
|
@ -1642,12 +1642,17 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateAccount(final Account account) {
|
||||
this.statusListener.onStatusChanged(account);
|
||||
databaseBackend.updateAccount(account);
|
||||
reconnectAccountInBackground(account);
|
||||
updateAccountUi();
|
||||
getNotificationService().updateErrorNotification();
|
||||
public boolean updateAccount(final Account account) {
|
||||
if (databaseBackend.updateAccount(account)) {
|
||||
this.statusListener.onStatusChanged(account);
|
||||
databaseBackend.updateAccount(account);
|
||||
reconnectAccountInBackground(account);
|
||||
updateAccountUi();
|
||||
getNotificationService().updateErrorNotification();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) {
|
||||
|
@ -1685,12 +1690,14 @@ public class XmppConnectionService extends Service {
|
|||
public void run() {
|
||||
disconnect(account, true);
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
databaseBackend.deleteAccount(account);
|
||||
if (!databaseBackend.deleteAccount(account)) {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": unable to delete account");
|
||||
}
|
||||
}
|
||||
};
|
||||
mDatabaseExecutor.execute(runnable);
|
||||
|
@ -3240,7 +3247,8 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
public void sendOfflinePresence(final Account account) {
|
||||
private void sendOfflinePresence(final Account account) {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": sending offline presence");
|
||||
sendPresencePacket(account, mPresenceGenerator.sendOfflinePresence(account));
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||
}
|
||||
if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
|
||||
mAccount.setOption(Account.OPTION_DISABLED, false);
|
||||
xmppConnectionService.updateAccount(mAccount);
|
||||
if (!xmppConnectionService.updateAccount(mAccount)) {
|
||||
Toast.makeText(EditAccountActivity.this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
|
||||
|
@ -204,7 +206,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||
mPasswordConfirm.setError(null);
|
||||
mAccount.setPassword(password);
|
||||
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
||||
xmppConnectionService.updateAccount(mAccount);
|
||||
if (!xmppConnectionService.updateAccount(mAccount)) {
|
||||
Toast.makeText(EditAccountActivity.this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (xmppConnectionService.findAccountByJid(jid) != null) {
|
||||
mAccountJid.setError(getString(R.string.account_already_exists));
|
||||
|
|
|
@ -318,12 +318,16 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
|||
|
||||
private void disableAccount(Account account) {
|
||||
account.setOption(Account.OPTION_DISABLED, true);
|
||||
xmppConnectionService.updateAccount(account);
|
||||
if (!xmppConnectionService.updateAccount(account)) {
|
||||
Toast.makeText(this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void enableAccount(Account account) {
|
||||
account.setOption(Account.OPTION_DISABLED, false);
|
||||
xmppConnectionService.updateAccount(account);
|
||||
if (!xmppConnectionService.updateAccount(account)) {
|
||||
Toast.makeText(this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void publishOpenPGPPublicKey(Account account) {
|
||||
|
|
|
@ -1381,8 +1381,10 @@ public class XmppConnection implements Runnable {
|
|||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": io exception "+e.getMessage()+" during force close");
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": socket was null during force close");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1407,7 +1409,11 @@ public class XmppConnection implements Runnable {
|
|||
Log.d(Config.LOGTAG, account.getJid().toBareJid()+": waiting for tag writer to finish");
|
||||
warned = true;
|
||||
}
|
||||
Thread.sleep(200);
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch(InterruptedException e) {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": sleep interrupted");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (warned) {
|
||||
|
@ -1417,8 +1423,8 @@ public class XmppConnection implements Runnable {
|
|||
tagWriter.writeTag(Tag.end("stream:stream"));
|
||||
} catch (final IOException e) {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": io exception during disconnect ("+e.getMessage()+")");
|
||||
} catch (final InterruptedException e) {
|
||||
Log.d(Config.LOGTAG, "interrupted");
|
||||
} finally {
|
||||
forceCloseSocket();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -681,4 +681,5 @@
|
|||
<string name="allow">Allow</string>
|
||||
<string name="no_permission_to_access_x">No permission to access %s</string>
|
||||
<string name="remote_server_not_found">Remote server not found</string>
|
||||
<string name="unable_to_update_account">Unable to update account</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue