aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-09-07 14:34:58 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-09-07 14:34:58 +0200
commit416481bb656c5fc73d0500b09a0c4ec62590dc00 (patch)
treef41eaa6d6b17ac4fcd647e459562feaeb28c2471 /src
parente1d2c32e63d6f2276b56600945569dede3e34890 (diff)
be a bit more careful when deleting and deactivating accounts
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java11
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java26
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java8
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java14
-rw-r--r--src/main/res/values/strings.xml1
6 files changed, 47 insertions, 22 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index 9e108545..d095e2fa 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/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/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 337c0b4d..2fb33bb6 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -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));
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index fb9a14a6..c10d2741 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -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));
diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
index 2d29c521..f52ccb19 100644
--- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java
@@ -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) {
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index ddc538e5..c49477f3 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -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();
}
}
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index dbc4ab37..5a5bb6ad 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -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>