diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-09-07 14:34:58 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-09-08 22:54:18 +0200 |
commit | 8adf715f7cd259c1b27a6125720e88b2e765863f (patch) | |
tree | b7968ab440050631aa4949c7b3d4dc084e7ecf12 | |
parent | 299e4bb9ff1994fedd37cb16667f04c1bca50fd4 (diff) |
be a bit more careful when deleting and deactivating accounts
6 files changed, 48 insertions, 23 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 256720be5..99ff1a5fb 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -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() { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 0ac5633c1..e22426b9e 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1724,12 +1724,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) { @@ -1767,12 +1772,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); @@ -3328,7 +3335,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)); } diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 75450d6c4..ad6518f33 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -125,7 +125,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; @@ -202,7 +204,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)); diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index 81e553bd5..edf4481b5 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -303,12 +303,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) { diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index d1012c761..a3323951a 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1394,8 +1394,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"); } } @@ -1420,7 +1422,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) { @@ -1430,8 +1436,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(); } } } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2bb727d90..bee62ccc6 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -697,5 +697,6 @@ <string name="unread_messages">Unread messages:</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="error_file_corrupt">This file seems to be corrupt.</string> + <string name="error_file_corrupt">This file seems to be corrupt.</string> + <string name="unable_to_update_account">Unable to update account</string> </resources> |