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

Remove redundant dbhelper calls.

These calls were made obsolete after the switch to requery. We no longer
need to get the database, because we no longer use it.
This commit is contained in:
Tom Hacohen 2017-04-19 16:07:52 +01:00
parent e15a26af9c
commit 93fb1e3c54
3 changed files with 31 additions and 44 deletions

View File

@ -58,7 +58,6 @@ public class ContactsSyncAdapterService extends SyncAdapterService {
NotificationHelper notificationManager = new NotificationHelper(getContext(), "journals-contacts", Constants.NOTIFICATION_CONTACTS_SYNC);
notificationManager.cancel();
ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(getContext());
try {
AccountSettings settings = new AccountSettings(getContext(), account);
if (!extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL) && !checkSyncConditions(settings))
@ -97,8 +96,6 @@ public class ContactsSyncAdapterService extends SyncAdapterService {
detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase);
}
notificationManager.notify(title, getContext().getString(syncPhase));
} finally {
dbHelper.close();
}
App.log.info("Address book sync complete");

View File

@ -133,7 +133,6 @@ public abstract class SyncAdapterService extends Service {
}
protected class RefreshCollections {
final private ServiceDB.OpenHelper dbHelper;
final private Account account;
final private Context context;
final private CollectionInfo.Type serviceType;
@ -142,53 +141,46 @@ public abstract class SyncAdapterService extends Service {
this.account = account;
this.serviceType = serviceType;
context = getContext();
dbHelper = new ServiceDB.OpenHelper(context);
}
void run() throws Exceptions.HttpException, Exceptions.IntegrityException, InvalidAccountException, Exceptions.GenericCryptoException {
try {
@Cleanup SQLiteDatabase db = dbHelper.getWritableDatabase();
App.log.info("Refreshing " + serviceType + " collections of service #" + serviceType.toString());
App.log.info("Refreshing " + serviceType + " collections of service #" + serviceType.toString());
OkHttpClient httpClient = HttpClient.create(context, account);
OkHttpClient httpClient = HttpClient.create(context, account);
AccountSettings settings = new AccountSettings(context, account);
JournalManager journalsManager = new JournalManager(httpClient, HttpUrl.get(settings.getUri()));
AccountSettings settings = new AccountSettings(context, account);
JournalManager journalsManager = new JournalManager(httpClient, HttpUrl.get(settings.getUri()));
List<Pair<JournalManager.Journal, CollectionInfo>> journals = new LinkedList<>();
List<Pair<JournalManager.Journal, CollectionInfo>> journals = new LinkedList<>();
for (JournalManager.Journal journal : journalsManager.getJournals()) {
Crypto.CryptoManager crypto;
if (journal.getKey() != null) {
crypto = new Crypto.CryptoManager(journal.getVersion(), settings.getKeyPair(), journal.getKey());
} else {
crypto = new Crypto.CryptoManager(journal.getVersion(), settings.password(), journal.getUid());
}
journal.verify(crypto);
CollectionInfo info = CollectionInfo.fromJson(journal.getContent(crypto));
info.updateFromJournal(journal);
if (info.type.equals(serviceType)) {
journals.add(new Pair<>(journal, info));
}
for (JournalManager.Journal journal : journalsManager.getJournals()) {
Crypto.CryptoManager crypto;
if (journal.getKey() != null) {
crypto = new Crypto.CryptoManager(journal.getVersion(), settings.getKeyPair(), journal.getKey());
} else {
crypto = new Crypto.CryptoManager(journal.getVersion(), settings.password(), journal.getUid());
}
if (journals.isEmpty()) {
CollectionInfo info = CollectionInfo.defaultForServiceType(serviceType);
info.uid = JournalManager.Journal.genUid();
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
journalsManager.putJournal(journal);
journal.verify(crypto);
CollectionInfo info = CollectionInfo.fromJson(journal.getContent(crypto));
info.updateFromJournal(journal);
if (info.type.equals(serviceType)) {
journals.add(new Pair<>(journal, info));
}
saveCollections(journals);
} finally {
dbHelper.close();
}
if (journals.isEmpty()) {
CollectionInfo info = CollectionInfo.defaultForServiceType(serviceType);
info.uid = JournalManager.Journal.genUid();
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
journalsManager.putJournal(journal);
journals.add(new Pair<>(journal, info));
}
saveCollections(journals);
}
private void saveCollections(Iterable<Pair<JournalManager.Journal, CollectionInfo>> journals) {

View File

@ -158,8 +158,6 @@ public class SetupEncryptionFragment extends DialogFragment implements LoaderMan
// add entries for account to service DB
App.log.log(Level.INFO, "Writing account configuration to database", config);
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(getContext());
SQLiteDatabase db = dbHelper.getWritableDatabase();
try {
AccountSettings settings = new AccountSettings(getContext(), account);
@ -170,7 +168,7 @@ public class SetupEncryptionFragment extends DialogFragment implements LoaderMan
if (config.cardDAV != null) {
// insert CardDAV service
insertService(db, accountName, CollectionInfo.Type.ADDRESS_BOOK, config.cardDAV);
insertService(accountName, CollectionInfo.Type.ADDRESS_BOOK, config.cardDAV);
// contact sync is automatically enabled by isAlwaysSyncable="true" in res/xml/sync_contacts.xml
settings.setSyncInterval(ContactsContract.AUTHORITY, Constants.DEFAULT_SYNC_INTERVAL);
@ -180,7 +178,7 @@ public class SetupEncryptionFragment extends DialogFragment implements LoaderMan
if (config.calDAV != null) {
// insert CalDAV service
insertService(db, accountName, CollectionInfo.Type.CALENDAR, config.calDAV);
insertService(accountName, CollectionInfo.Type.CALENDAR, config.calDAV);
// calendar sync is automatically enabled by isAlwaysSyncable="true" in res/xml/sync_contacts.xml
settings.setSyncInterval(CalendarContract.AUTHORITY, Constants.DEFAULT_SYNC_INTERVAL);
@ -202,7 +200,7 @@ public class SetupEncryptionFragment extends DialogFragment implements LoaderMan
return true;
}
protected void insertService(SQLiteDatabase db, String accountName, CollectionInfo.Type serviceType, BaseConfigurationFinder.Configuration.ServiceInfo info) {
protected void insertService(String accountName, CollectionInfo.Type serviceType, BaseConfigurationFinder.Configuration.ServiceInfo info) {
EntityDataStore<Persistable> data = ((App) getContext().getApplicationContext()).getData();
// insert service