1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

Clear journal cache on account deletion (fix account re-add issue)

Clearing the cache is a good idea regardless, though because of the
unique constraints in the cache on the journal name, this was causing
issues when deleting an account and then adding it back.
This commit is contained in:
Tom Hacohen 2017-03-23 22:24:38 +00:00
parent f984b76ec6
commit 415d5d5447

View File

@ -13,6 +13,7 @@ import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Binder;
@ -20,6 +21,10 @@ import android.os.IBinder;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.etesync.syncadapter.model.JournalEntity;
import com.etesync.syncadapter.model.ServiceDB.OpenHelper;
import com.etesync.syncadapter.model.ServiceDB.Services;
import java.lang.ref.WeakReference;
import java.util.HashSet;
import java.util.Iterator;
@ -27,8 +32,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import com.etesync.syncadapter.model.ServiceDB.OpenHelper;
import com.etesync.syncadapter.model.ServiceDB.Services;
import io.requery.Persistable;
import io.requery.sql.EntityDataStore;
public class AccountUpdateService extends Service {
@ -109,10 +114,20 @@ public class AccountUpdateService extends Service {
for (Account account : am.getAccountsByType(Constants.ACCOUNT_TYPE))
sqlAccountNames.add(DatabaseUtils.sqlEscapeString(account.name));
if (sqlAccountNames.isEmpty())
EntityDataStore<Persistable> data = ((App) getApplication()).getData();
if (sqlAccountNames.isEmpty()) {
data.delete(JournalEntity.class).get().value();
db.delete(Services._TABLE, null, null);
else
} else {
Cursor cur = db.query(Services._TABLE, new String[]{Services.ID}, Services.ACCOUNT_NAME + " NOT IN (" + TextUtils.join(",", sqlAccountNames) + ")", null, null, null, null);
cur.moveToFirst();
while(!cur.isAfterLast()) {
data.delete(JournalEntity.class).where(JournalEntity.SERVICE.eq(cur.getLong(0))).get().value();
cur.moveToNext();
}
db.delete(Services._TABLE, Services.ACCOUNT_NAME + " NOT IN (" + TextUtils.join(",", sqlAccountNames) + ")", null);
}
} finally {
dbHelper.close();
}