ammargitham / WallFlow

Wallpaper app for Android using Jetpack Compose
GNU General Public License v3.0
325 stars 18 forks source link

App crashing when trying to perform a backup #80

Closed Lucki closed 5 months ago

Lucki commented 5 months ago

The (normal version v2.4.1) app is crashing when trying to perform a backup.

Sorry, it seems I'm somehow good at finding these bugs… I have never backed up before. I want to test the plus version and bring settings, favorites, … over.

Repro:

  1. Navigate to "More" → "Backup and Restore" → "Backup"
  2. Select all checkmarks to backup everything. Important one seems to be "Favorites".
  3. Select a location, go with the default name. I chose the download (and later home) folder.
  4. The app crashes. The resulting backup file is 0 Bytes in size.
FATAL EXCEPTION: main
Process: com.ammar.wallflow, PID: 1074
android.database.sqlite.SQLiteException: too many SQL variables (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM wallhaven_wallpapers WHERE wallhaven_id in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,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,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:652)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1545)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1520)
    at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.query(SourceFile:1)
    at androidx.room.RoomDatabase.query(Unknown Source:34)
    at okio.Okio.query(SourceFile:12)
    at com.ammar.wallflow.data.db.dao.wallpaper.WallhavenWallpapersDao_Impl$getByWallhavenId$2.call(SourceFile:56)
    at com.ammar.wallflow.data.db.dao.wallpaper.WallhavenWallpapersDao_Impl$getByWallhavenId$2.call(SourceFile:19)
    at androidx.room.CoroutinesRoom$Companion$execute$4$job$1.invokeSuspend(SourceFile:10)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
    at kotlinx.coroutines.DispatchedTask.run(Unknown Source:96)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@c5a8e49, Dispatchers.Main.immediate]
ammargitham commented 5 months ago

It seems you have a lot of Favorites (around 4k) which is causing the SQL statement to fail.

ammargitham commented 5 months ago

@Lucki Do you really have so many Favorites? I need confirmation before I look into resolving this. Or else the bug might be something else.

Lucki commented 5 months ago

Hm, it certainly sounds like alot. I marked quite a bunch of darker wallpapers in the beginning, so it seems possible? I sometimes use the favorites to get a pool of dark-ish wallpaper. The light/dark button is more recent than those favorites.

Maybe I indeed shouldn't import them into plus version… My hope is that there's a model for the automatic thing that can decide if a wallpaper has a brighter appearance, throw that away and search for another one, which is hopefully darker. Or that the newish light/dark can somehow decide by itself, I have to explore that function further.

Anyway, it's possible that the amount is the culprit. If it isn't possible to fix, then I'm absolutely not disappointed, but the limitation should be stated somehow somewhere.

ammargitham commented 5 months ago

Even then 4k seems like a lot to me. Is your phone by any chance rooted? That would help in debugging this further.

My hope is that there's a model for the automatic thing that can decide if a wallpaper has a brighter appearance, throw that away and search for another one, which is hopefully darker. Or that the newish light/dark can somehow decide by itself, I have to explore that function further.

The model in the Plus version currently is only for cropping wallpapers. It doesn't detect light/dark wallpapers

Lucki commented 5 months ago

Ah, damn. I haven't looked into the model thing too deeply yet. Maybe I'll craft a feature request out of it if it bothers me too much :smile:

My phone is actually rooted, yes.

ammargitham commented 5 months ago

Awesome. Go into /data/data/com.ammar.wallflow/databases and send me the app, app-shm, app-wal files. The app does not gather any personal info, so you can send these without worries. You could attach them here, or you can send me the files via email (ammar.githam@outlook.com). This will allow me to run SQL queries directly on your db.

Lucki commented 5 months ago

The app db has indeed 3789 records in the favorites table. The max id is 3915, so it seems I also removed quite a bunch. I don't remember setting this many 'favorites'.

ammargitham commented 5 months ago

Do you have auto 'mark as favorite' enabled in Auto wallpaper preferences?

Lucki commented 5 months ago

No, all manual. I never had that setting active.

ammargitham commented 5 months ago

I see. 4k seems like a very big number to be manual. Have you ever previously done a backup/restore before?

Lucki commented 5 months ago

No, I haven't. As I said, I can imagine marking quite a bunch because I used it less for 'favorite' and more for 'these are a pool of darker wallpapers'.

ammargitham commented 5 months ago

Is it possible for you to share the db?

Otherwise can you check if the following query returns anything:

SELECT source_id FROM favorites WHERE source_id IN
  (SELECT source_id FROM favorites GROUP BY source_id HAVING COUNT(*) > 1);

Ideally it should not return anything.

Lucki commented 5 months ago

I thought I did, but apparently I forgot to click on send while looking into the DB myself.

ammargitham commented 5 months ago

Thanks. I'll look into it. Btw, the crash is a SQLite limitation which Google's AndroidX Room library should've handled. But the issue is still open (https://issuetracker.google.com/issues/73634057).

ammargitham commented 5 months ago

Fixed in v2.4.2

Lucki commented 5 months ago

I'm sorry this required so much code changes :(