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:
- All database tables are cleared (including
ApplicationInfoGridItemEntity)
SyncDataUseCase.invoke() runs on app restart
updateEblanApplicationInfos() is called with empty oldSyncEblanApplicationInfos
- 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
- 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
Bug Description
After a destructive Room database migration, random application grid items are being inserted to the home screen, even though
firstLaunchis alreadyfalsein userData.Root Cause
When Room is destroyed via destructive migration:
ApplicationInfoGridItemEntity)SyncDataUseCase.invoke()runs on app restartupdateEblanApplicationInfos()is called with emptyoldSyncEblanApplicationInfosaddNewApplicationsToHomeScreen(), the logic compares:oldAddNewEblanApplicationInfos= EMPTY (no apps in old database)newAddNewEblanApplicationInfos= ALL non-system apps from systemaddNewEblanApplicationInfos = newAddNewEblanApplicationInfos - oldAddNewEblanApplicationInfos.toSet()→ ALL apps are treated as NEWSolution
When performing a destructive migration of Room, ensure that
addNewAppsToHomeScreenis set tofalsein 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()methoddomain/use-case/src/main/kotlin/com/eblan/launcher/domain/usecase/launcherapps/LauncherAppsUtil.kt-addNewApplicationsToHomeScreen()functiondata/room/src/main/kotlin/com/eblan/launcher/data/room/di/RoomModule.kt-.fallbackToDestructiveMigrationFrom()configuration