From 127baee746f167e40ecb6e48228595242b9d83ce Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 4 Sep 2021 20:44:05 +0200 Subject: [PATCH] Added fail-safe --- app/src/main/java/eu/faircode/email/DB.java | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index cc3094d59d..3734db8792 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -401,18 +401,22 @@ public abstract class DB extends RoomDatabase { Log.i("Get PRAGMA " + pragma + "=" + (cursor.moveToNext() ? cursor.getString(0) : "?")); } - ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - int class_mb = am.getMemoryClass(); - int cache_size = class_mb * 1024 * 100 / DB_CACHE_PERCENTAGE; - - // https://www.sqlite.org/pragma.html#pragma_cache_size - Log.i("Set PRAGMA cache_size=" + cache_size); - try (Cursor cursor = db.query("PRAGMA cache_size=" + cache_size + ";", null)) { - cursor.moveToNext(); // required - } + try { + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + int class_mb = am.getMemoryClass(); + int cache_size = class_mb * 1024 * 100 / DB_CACHE_PERCENTAGE; + + // https://www.sqlite.org/pragma.html#pragma_cache_size + Log.i("Set PRAGMA cache_size=" + cache_size); + try (Cursor cursor = db.query("PRAGMA cache_size=" + cache_size + ";", null)) { + cursor.moveToNext(); // required + } - try (Cursor cursor = db.query("PRAGMA cache_size;")) { - Log.i("Get PRAGMA cache_size=" + (cursor.moveToNext() ? cursor.getInt(0) : "?")); + try (Cursor cursor = db.query("PRAGMA cache_size;")) { + Log.i("Get PRAGMA cache_size=" + (cursor.moveToNext() ? cursor.getInt(0) : "?")); + } + } catch (Throwable ex) { + Log.e(ex); } Log.i("Set PRAGMA cache_spill=0");