diff --git a/app/build.gradle b/app/build.gradle index b958ac83..e2007252 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { minSdkVersion 14 targetSdkVersion 22 - versionCode 93 - versionName "1.0.3" + versionCode 94 + versionName "1.0.4" buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" } diff --git a/app/src/main/java/at/bitfire/davdroid/model/ServiceDB.java b/app/src/main/java/at/bitfire/davdroid/model/ServiceDB.java index b33505fe..2ac5b5f1 100644 --- a/app/src/main/java/at/bitfire/davdroid/model/ServiceDB.java +++ b/app/src/main/java/at/bitfire/davdroid/model/ServiceDB.java @@ -72,15 +72,21 @@ public class ServiceDB { public OpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) + setWriteAheadLoggingEnabled(true); } @Override public void onOpen(SQLiteDatabase db) { - db.enableWriteAheadLogging(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) db.setForeignKeyConstraintsEnabled(true); - else + else { + if (!db.enableWriteAheadLogging()) + App.log.warning("Couldn't enable write-ahead logging"); + db.execSQL("PRAGMA foreign_keys=ON;"); + } } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java index bbe8ff68..5028ba1d 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -8,18 +8,14 @@ package at.bitfire.davdroid.syncadapter; import android.accounts.Account; -import android.app.Service; -import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.ContentValues; import android.content.Context; -import android.content.Intent; import android.content.SyncResult; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; -import android.os.IBinder; import android.provider.CalendarContract; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -32,7 +28,6 @@ import at.bitfire.davdroid.App; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB.Collections; -import at.bitfire.davdroid.model.ServiceDB.OpenHelper; import at.bitfire.davdroid.model.ServiceDB.Services; import at.bitfire.davdroid.resource.LocalCalendar; import at.bitfire.ical4android.CalendarStorageException; @@ -43,14 +38,14 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { super.onCreate(); - syncAdapter = new SyncAdapter(this, dbHelper); + syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase()); } private static class SyncAdapter extends SyncAdapterService.SyncAdapter { - public SyncAdapter(Context context, OpenHelper dbHelper) { - super(context, dbHelper); + public SyncAdapter(Context context, SQLiteDatabase db) { + super(context, db); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java index ce59c21c..f02ec32d 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java @@ -8,31 +8,24 @@ package at.bitfire.davdroid.syncadapter; import android.accounts.Account; -import android.app.Service; -import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.ContentValues; import android.content.Context; -import android.content.Intent; import android.content.SyncResult; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; -import android.os.IBinder; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import java.util.List; import java.util.logging.Level; -import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB; import at.bitfire.davdroid.model.ServiceDB.Collections; -import at.bitfire.davdroid.model.ServiceDB.OpenHelper; import lombok.Cleanup; public class ContactsSyncAdapterService extends SyncAdapterService { @@ -40,14 +33,14 @@ public class ContactsSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { super.onCreate(); - syncAdapter = new ContactsSyncAdapter(this, dbHelper); + syncAdapter = new ContactsSyncAdapter(this, dbHelper.getReadableDatabase()); } private static class ContactsSyncAdapter extends SyncAdapter { - public ContactsSyncAdapter(Context context, OpenHelper dbHelper) { - super(context, dbHelper); + public ContactsSyncAdapter(Context context, SQLiteDatabase db) { + super(context, db); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java index 370401ec..6da750eb 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncAdapterService.java @@ -50,11 +50,12 @@ public abstract class SyncAdapterService extends Service { public static abstract class SyncAdapter extends AbstractThreadedSyncAdapter { - protected final SQLiteDatabase db; - public SyncAdapter(Context context, ServiceDB.OpenHelper dbHelper) { + protected final SQLiteDatabase db; // will be closed in SyncAdapterService::onDestroy(), don't close manually! + + public SyncAdapter(Context context, SQLiteDatabase db) { super(context, false); - db = dbHelper.getReadableDatabase(); + this.db = db; } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java index 426d0974..3a15e7b6 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncAdapterService.java @@ -8,18 +8,14 @@ package at.bitfire.davdroid.syncadapter; import android.accounts.Account; -import android.app.Service; -import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.ContentValues; import android.content.Context; -import android.content.Intent; import android.content.SyncResult; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; -import android.os.IBinder; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -31,7 +27,6 @@ import at.bitfire.davdroid.App; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB.Collections; -import at.bitfire.davdroid.model.ServiceDB.OpenHelper; import at.bitfire.davdroid.model.ServiceDB.Services; import at.bitfire.davdroid.resource.LocalTaskList; import at.bitfire.ical4android.CalendarStorageException; @@ -43,14 +38,14 @@ public class TasksSyncAdapterService extends SyncAdapterService { @Override public void onCreate() { super.onCreate(); - syncAdapter = new SyncAdapter(this, dbHelper); + syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase()); } private static class SyncAdapter extends SyncAdapterService.SyncAdapter { - public SyncAdapter(Context context, OpenHelper dbHelper) { - super(context, dbHelper); + public SyncAdapter(Context context, SQLiteDatabase db) { + super(context, db); } @Override @@ -73,8 +68,6 @@ public class TasksSyncAdapterService extends SyncAdapterService { App.log.log(Level.SEVERE, "Couldn't enumerate local task lists", e); } catch (InvalidAccountException e) { App.log.log(Level.SEVERE, "Couldn't get account settings", e); - } finally { - db.close(); } App.log.info("Task sync complete");