Skip to content

After destructive Room migration, random application grid items inserted to home screen #901

Description

@JackEblan

Bug Description

After a destructive Room database migration, random application grid items are being inserted to the home screen, even though firstLaunch is already false in userData.

Root Cause

When Room is destroyed via destructive migration:

  1. All database tables are cleared (including ApplicationInfoGridItemEntity)
  2. SyncDataUseCase.invoke() runs on app restart
  3. updateEblanApplicationInfos() is called with empty oldSyncEblanApplicationInfos
  4. In addNewApplicationsToHomeScreen(), the logic compares:
    • oldAddNewEblanApplicationInfos = EMPTY (no apps in old database)
    • newAddNewEblanApplicationInfos = ALL non-system apps from system
    • addNewEblanApplicationInfos = newAddNewEblanApplicationInfos - oldAddNewEblanApplicationInfos.toSet()ALL apps are treated as NEW
  5. All non-system apps get inserted as random grid items to the home screen

Solution

When performing a destructive migration of Room, ensure that addNewAppsToHomeScreen is set to false in the UserData migration so that apps are not treated as new when the database is rebuilt from scratch.

Alternatively, detect destructive migration by checking if grid items table is empty before calling addNewApplicationsToHomeScreen().

Code Location

  • domain/use-case/src/main/kotlin/com/eblan/launcher/domain/usecase/launcherapps/SyncDataUseCase.kt - updateEblanApplicationInfos() method
  • domain/use-case/src/main/kotlin/com/eblan/launcher/domain/usecase/launcherapps/LauncherAppsUtil.kt - addNewApplicationsToHomeScreen() function
  • data/room/src/main/kotlin/com/eblan/launcher/data/room/di/RoomModule.kt - .fallbackToDestructiveMigrationFrom() configuration

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions