diff --git a/CHANGELOG.md b/CHANGELOG.md index f47f1f0e4b..742189a6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. * ui: The `ProductResolver.Builder` now requires a project as constructor param, since the default value has been removed ### Removed ### Fixed +* core: Handle `SQLiteDatabaseLockedException` to fix app crash when updating the database * ui: Avoid npe caused by `isEmpty()` check on a null shopping cart * ui: Change project reference in `ProductResolver.kt` to get rid of IllegalArgumentException diff --git a/core/src/main/java/io/snabble/sdk/ProductDatabase.java b/core/src/main/java/io/snabble/sdk/ProductDatabase.java index 8ef8b8bebb..e5c5b379e2 100644 --- a/core/src/main/java/io/snabble/sdk/ProductDatabase.java +++ b/core/src/main/java/io/snabble/sdk/ProductDatabase.java @@ -6,6 +6,7 @@ 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; @@ -332,8 +333,14 @@ synchronized void applyDeltaUpdate(InputStream inputStream) throws IOException { project.logErrorEvent("Could not copy db to temp file: %s", e.getMessage()); throw e; } + final SQLiteDatabase tempDb; - SQLiteDatabase tempDb = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null); + try { + tempDb = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null); + } catch (SQLiteCantOpenDatabaseException e) { + project.logErrorEvent("Could not open or create db: %s", e.getMessage()); + throw new IOException("Could not open or create db", e); + } Scanner scanner = new Scanner(inputStream, "UTF-8"); @@ -531,9 +538,9 @@ private Cursor rawQuery(String sql, String[] args, CancellationSignal cancellati *
* While updating, the database can still be queried for data, after the update completes calls to the database * return the updated data. - * + *
* Note that database updates are usually very cheap and do not transmit data that is already on your device. - * + *
* If the database is not present or schematic changes are done that can not be resolved via a delta update * a full update is needed. */ @@ -549,9 +556,9 @@ public void update() { *
* While updating, the database can still be queried for data, after the update completes calls to the database * return the updated data. - * + *
* Note that database updates are usually very cheap and do not transmit data that is already on your device. - * + *
* If the database is not present or schematic changes are done that can not be resolved via a delta update * a full update is needed. * @@ -570,9 +577,9 @@ public void update(final UpdateCallback callback) { *
* While updating, the database can still be queried for data, after the update completes calls to the database * return the updated data. - * + *
* Note that database updates are usually very cheap and do not transmit data that is already on your device. - * + *
* If the database is not present or schematic changes are done that can not be resolved via a delta update
* a full update is needed.
*
@@ -849,7 +856,7 @@ public Product productAtCursor(Cursor cursor) {
String[] split = isPrimaryStr.split(SEPARATOR, -1);
if (split.length > 0) {
codeIsPrimaryCode = new boolean[split.length];
- for (int i=0; i