Add unit test and fix bug related to "Migrate IDP_GRID_NAME usage to LauncherPrefs" CL.
The issue was that kotlin initializes class variables before contructor
variables, but allows constructor variables to be referenced by
the class variables before they are initialized. This led to `isBackedUp`
always being false, and then the SharedPreference store always and only
checking if values were in DEVICE_PREFERENCES rather than the standard
backed up preferences.
The fix is to make the class variable sharedPrefFile lazily retrieved.
That way, isBackedUp will have been initialized and behave correctly.
Bug: 269569568
Test: Everything works on device and manual and unit tests
verified original bug is not present.
Change-Id: I8ab4a5752886ce8f4a2988295fa61c8a2c38ec7c
diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt
index befaa64..e5a1879 100644
--- a/src/com/android/launcher3/LauncherPrefs.kt
+++ b/src/com/android/launcher3/LauncherPrefs.kt
@@ -274,7 +274,8 @@
abstract val sharedPrefKey: String
abstract val isBackedUp: Boolean
abstract val type: Class<*>
- val sharedPrefFile: String = if (isBackedUp) SHARED_PREFERENCES_KEY else DEVICE_PREFERENCES_KEY
+ val sharedPrefFile: String
+ get() = if (isBackedUp) SHARED_PREFERENCES_KEY else DEVICE_PREFERENCES_KEY
fun <T> to(value: T): Pair<Item, T> = Pair(this, value)
}