From 1bb1124b806ef61a36133c6ca6e1fd80a4d8e1be Mon Sep 17 00:00:00 2001 From: Fabian Bender <91562175+Fabtron@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:29:39 +0200 Subject: [PATCH] Fix unhandeld SQLiteException (#214) --- CHANGELOG.md | 1 + core/src/main/java/io/snabble/sdk/ProductDatabase.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a095fe315..1fba349e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Fixed * ui: subject dialog for external billing now works in dark mode * ui: external billing icon works with dark mode now +* core: prevent SQLiteLockedException and recover from it on product database update ## [0.75.7] ### Added diff --git a/core/src/main/java/io/snabble/sdk/ProductDatabase.java b/core/src/main/java/io/snabble/sdk/ProductDatabase.java index 60c346df3..c6721741b 100644 --- a/core/src/main/java/io/snabble/sdk/ProductDatabase.java +++ b/core/src/main/java/io/snabble/sdk/ProductDatabase.java @@ -6,7 +6,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.database.Cursor; -import android.database.sqlite.SQLiteCantOpenDatabaseException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.os.CancellationSignal; @@ -336,9 +335,12 @@ synchronized void applyDeltaUpdate(InputStream inputStream) throws IOException { } final SQLiteDatabase tempDb; + if (!tempDbFile.canRead() || !tempDbFile.canWrite()) + throw new IOException("TempDbFile cannot be read and/or written."); + try { tempDb = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null); - } catch (SQLiteCantOpenDatabaseException e) { + } catch (SQLiteException e) { project.logErrorEvent("Could not open or create db: %s", e.getMessage()); throw new IOException("Could not open or create db", e); }