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; | 		return list; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void updateAccount(Account account) { | 	public boolean updateAccount(Account account) { | ||||||
| 		SQLiteDatabase db = this.getWritableDatabase(); | 		SQLiteDatabase db = this.getWritableDatabase(); | ||||||
| 		String[] args = {account.getUuid()}; | 		String[] args = {account.getUuid()}; | ||||||
| 		db.update(Account.TABLENAME, account.getContentValues(), Account.UUID | 		final int rows = db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", args); | ||||||
| 				+ "=?", args); | 		return rows == 1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void deleteAccount(Account account) { | 	public boolean deleteAccount(Account account) { | ||||||
| 		SQLiteDatabase db = this.getWritableDatabase(); | 		SQLiteDatabase db = this.getWritableDatabase(); | ||||||
| 		String[] args = {account.getUuid()}; | 		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() { | 	public boolean hasEnabledAccounts() { | ||||||
|  | |||||||
| @ -1642,12 +1642,17 @@ public class XmppConnectionService extends Service { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void updateAccount(final Account account) { | 	public boolean updateAccount(final Account account) { | ||||||
|  | 		if (databaseBackend.updateAccount(account)) { | ||||||
| 			this.statusListener.onStatusChanged(account); | 			this.statusListener.onStatusChanged(account); | ||||||
| 			databaseBackend.updateAccount(account); | 			databaseBackend.updateAccount(account); | ||||||
| 			reconnectAccountInBackground(account); | 			reconnectAccountInBackground(account); | ||||||
| 			updateAccountUi(); | 			updateAccountUi(); | ||||||
| 			getNotificationService().updateErrorNotification(); | 			getNotificationService().updateErrorNotification(); | ||||||
|  | 			return true; | ||||||
|  | 		} else { | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) { | 	public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) { | ||||||
| @ -1685,12 +1690,14 @@ public class XmppConnectionService extends Service { | |||||||
| 					public void run() { | 					public void run() { | ||||||
| 						disconnect(account, true); | 						disconnect(account, true); | ||||||
| 					} | 					} | ||||||
| 				}); | 				}).start(); | ||||||
| 			} | 			} | ||||||
| 			Runnable runnable = new Runnable() { | 			Runnable runnable = new Runnable() { | ||||||
| 				@Override | 				@Override | ||||||
| 				public void run() { | 				public void run() { | ||||||
| 					databaseBackend.deleteAccount(account); | 					if (!databaseBackend.deleteAccount(account)) { | ||||||
|  | 						Log.d(Config.LOGTAG,account.getJid().toBareJid()+": unable to delete account"); | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
| 			}; | 			}; | ||||||
| 			mDatabaseExecutor.execute(runnable); | 			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)); | 		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()) { | 			if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) { | ||||||
| 				mAccount.setOption(Account.OPTION_DISABLED, false); | 				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; | 				return; | ||||||
| 			} | 			} | ||||||
| 			final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI; | 			final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI; | ||||||
| @ -204,7 +206,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate | |||||||
| 				mPasswordConfirm.setError(null); | 				mPasswordConfirm.setError(null); | ||||||
| 				mAccount.setPassword(password); | 				mAccount.setPassword(password); | ||||||
| 				mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); | 				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 { | 			} else { | ||||||
| 				if (xmppConnectionService.findAccountByJid(jid) != null) { | 				if (xmppConnectionService.findAccountByJid(jid) != null) { | ||||||
| 					mAccountJid.setError(getString(R.string.account_already_exists)); | 					mAccountJid.setError(getString(R.string.account_already_exists)); | ||||||
|  | |||||||
| @ -318,12 +318,16 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda | |||||||
| 
 | 
 | ||||||
| 	private void disableAccount(Account account) { | 	private void disableAccount(Account account) { | ||||||
| 		account.setOption(Account.OPTION_DISABLED, true); | 		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) { | 	private void enableAccount(Account account) { | ||||||
| 		account.setOption(Account.OPTION_DISABLED, false); | 		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) { | 	private void publishOpenPGPPublicKey(Account account) { | ||||||
|  | |||||||
| @ -1381,8 +1381,10 @@ public class XmppConnection implements Runnable { | |||||||
| 			try { | 			try { | ||||||
| 				socket.close(); | 				socket.close(); | ||||||
| 			} catch (IOException e) { | 			} 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"); | 							Log.d(Config.LOGTAG, account.getJid().toBareJid()+": waiting for tag writer to finish"); | ||||||
| 							warned = true; | 							warned = true; | ||||||
| 						} | 						} | ||||||
|  | 						try { | ||||||
| 							Thread.sleep(200); | 							Thread.sleep(200); | ||||||
|  | 						} catch(InterruptedException e) { | ||||||
|  | 							Log.d(Config.LOGTAG,account.getJid().toBareJid()+": sleep interrupted"); | ||||||
|  | 						} | ||||||
| 						i++; | 						i++; | ||||||
| 					} | 					} | ||||||
| 					if (warned) { | 					if (warned) { | ||||||
| @ -1417,8 +1423,8 @@ public class XmppConnection implements Runnable { | |||||||
| 					tagWriter.writeTag(Tag.end("stream:stream")); | 					tagWriter.writeTag(Tag.end("stream:stream")); | ||||||
| 				} catch (final IOException e) { | 				} catch (final IOException e) { | ||||||
| 					Log.d(Config.LOGTAG,account.getJid().toBareJid()+": io exception during disconnect ("+e.getMessage()+")"); | 					Log.d(Config.LOGTAG,account.getJid().toBareJid()+": io exception during disconnect ("+e.getMessage()+")"); | ||||||
| 				} catch (final InterruptedException e) { | 				} finally { | ||||||
| 					Log.d(Config.LOGTAG, "interrupted"); | 					forceCloseSocket(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -681,4 +681,5 @@ | |||||||
| 	<string name="allow">Allow</string> | 	<string name="allow">Allow</string> | ||||||
| 	<string name="no_permission_to_access_x">No permission to access %s</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="remote_server_not_found">Remote server not found</string> | ||||||
|  | 	<string name="unable_to_update_account">Unable to update account</string> | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Daniel Gultsch
						Daniel Gultsch