Permanently provide functionality for LauncherPref items that don't need
to be migrated, but are boot aware.
Bug: 251502424
Test: Tested that Migration works as expected, as well as shared
preference information that doesn't need to be migrated. Also sanity
tested phone in general.
Change-Id: Ie8460e360856cbe20a7770b1747f75c7154759ab
diff --git a/quickstep/src/com/android/quickstep/BootAwarePreloader.kt b/quickstep/src/com/android/quickstep/BootAwarePreloader.kt
index 35404a9..2fc4d04 100644
--- a/quickstep/src/com/android/quickstep/BootAwarePreloader.kt
+++ b/quickstep/src/com/android/quickstep/BootAwarePreloader.kt
@@ -19,7 +19,7 @@
import android.util.Log
import com.android.launcher3.LauncherAppState
import com.android.launcher3.LauncherPrefs
-import com.android.launcher3.isBootAwareStartupDataEnabled
+import com.android.launcher3.moveStartupDataToDeviceProtectedStorageIsEnabled
import com.android.launcher3.util.LockedUserState
/**
@@ -33,7 +33,8 @@
fun start(context: Context) {
val lp = LauncherPrefs.get(context)
when {
- LockedUserState.get(context).isUserUnlocked || !isBootAwareStartupDataEnabled -> {
+ LockedUserState.get(context).isUserUnlocked ||
+ !moveStartupDataToDeviceProtectedStorageIsEnabled -> {
/* No-Op */
}
lp.isStartupDataMigrated -> {
diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt
index bdd92eb..4db2fca 100644
--- a/src/com/android/launcher3/LauncherPrefs.kt
+++ b/src/com/android/launcher3/LauncherPrefs.kt
@@ -60,11 +60,11 @@
IS_STARTUP_DATA_MIGRATED.defaultValue
)
- // TODO: Remove `item == TASKBAR_PINNING` once isBootAwareStartupDataEnabled is always true
private fun chooseSharedPreferences(item: Item): SharedPreferences =
if (
- (isBootAwareStartupDataEnabled && item.isBootAware && isStartupDataMigrated) ||
- item == TASKBAR_PINNING
+ (moveStartupDataToDeviceProtectedStorageIsEnabled &&
+ item.encryptionType == EncryptionType.MOVE_TO_DEVICE_PROTECTED &&
+ isStartupDataMigrated) || item.encryptionType == EncryptionType.DEVICE_PROTECTED
)
bootAwarePrefs
else item.encryptedPrefs
@@ -139,13 +139,20 @@
private fun prepareToPutValues(
updates: Array<out Pair<Item, Any>>
): List<SharedPreferences.Editor> {
- val updatesPerPrefFile = updates.groupBy { it.first.encryptedPrefs }.toMutableMap()
+ val updatesPerPrefFile =
+ updates
+ .filter { it.first.encryptionType != EncryptionType.DEVICE_PROTECTED }
+ .groupBy { it.first.encryptedPrefs }
+ .toMutableMap()
- if (isBootAwareStartupDataEnabled) {
- val bootAwareUpdates = updates.filter { it.first.isBootAware }
- if (bootAwareUpdates.isNotEmpty()) {
- updatesPerPrefFile[bootAwarePrefs] = bootAwareUpdates
+ val bootAwareUpdates =
+ updates.filter {
+ (it.first.encryptionType == EncryptionType.MOVE_TO_DEVICE_PROTECTED &&
+ moveStartupDataToDeviceProtectedStorageIsEnabled) ||
+ it.first.encryptionType == EncryptionType.DEVICE_PROTECTED
}
+ if (bootAwareUpdates.isNotEmpty()) {
+ updatesPerPrefFile[bootAwarePrefs] = bootAwareUpdates
}
return updatesPerPrefFile.map { prefToItemValueList ->
@@ -238,13 +245,20 @@
* .apply() or .commit()
*/
private fun prepareToRemove(items: Array<out Item>): List<SharedPreferences.Editor> {
- val itemsPerFile = items.groupBy { it.encryptedPrefs }.toMutableMap()
+ val itemsPerFile =
+ items
+ .filter { it.encryptionType != EncryptionType.DEVICE_PROTECTED }
+ .groupBy { it.encryptedPrefs }
+ .toMutableMap()
- if (isBootAwareStartupDataEnabled) {
- val bootAwareUpdates = items.filter { it.isBootAware }
- if (bootAwareUpdates.isNotEmpty()) {
- itemsPerFile[bootAwarePrefs] = bootAwareUpdates
+ val bootAwareUpdates =
+ items.filter {
+ (it.encryptionType == EncryptionType.MOVE_TO_DEVICE_PROTECTED &&
+ moveStartupDataToDeviceProtectedStorageIsEnabled) ||
+ it.encryptionType == EncryptionType.DEVICE_PROTECTED
}
+ if (bootAwareUpdates.isNotEmpty()) {
+ itemsPerFile[bootAwarePrefs] = bootAwareUpdates
}
return itemsPerFile.map { (prefs, items) ->
@@ -255,7 +269,7 @@
}
fun migrateStartupDataToDeviceProtectedStorage() {
- if (!isBootAwareStartupDataEnabled) return
+ if (!moveStartupDataToDeviceProtectedStorageIsEnabled) return
Log.d(
TAG,
@@ -264,7 +278,7 @@
)
with(bootAwarePrefs.edit()) {
- BOOT_AWARE_ITEMS.forEach { putValue(it, get(it)) }
+ ITEMS_TO_MOVE_TO_DEVICE_PROTECTED_STORAGE.forEach { putValue(it, get(it)) }
putBoolean(IS_STARTUP_DATA_MIGRATED.sharedPrefKey, true)
apply()
}
@@ -280,30 +294,66 @@
const val TASKBAR_PINNING_KEY = "TASKBAR_PINNING_KEY"
const val SHOULD_SHOW_SMARTSPACE_KEY = "SHOULD_SHOW_SMARTSPACE_KEY"
- @JvmField val ICON_STATE = nonRestorableItem(LauncherAppState.KEY_ICON_STATE, "", true)
+ @JvmField
+ val ICON_STATE =
+ nonRestorableItem(
+ LauncherAppState.KEY_ICON_STATE,
+ "",
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
@JvmField
val ALL_APPS_OVERVIEW_THRESHOLD =
- nonRestorableItem(LauncherAppState.KEY_ALL_APPS_OVERVIEW_THRESHOLD, 180, true)
- @JvmField val THEMED_ICONS = backedUpItem(Themes.KEY_THEMED_ICONS, false, true)
+ nonRestorableItem(
+ LauncherAppState.KEY_ALL_APPS_OVERVIEW_THRESHOLD,
+ 180,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val THEMED_ICONS =
+ backedUpItem(Themes.KEY_THEMED_ICONS, false, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
@JvmField val PROMISE_ICON_IDS = backedUpItem(InstallSessionHelper.PROMISE_ICON_IDS, "")
@JvmField val WORK_EDU_STEP = backedUpItem(WorkProfileManager.KEY_WORK_EDU_STEP, 0)
- @JvmField val WORKSPACE_SIZE = backedUpItem(DeviceGridState.KEY_WORKSPACE_SIZE, "", true)
- @JvmField val HOTSEAT_COUNT = backedUpItem(DeviceGridState.KEY_HOTSEAT_COUNT, -1, true)
- @JvmField val TASKBAR_PINNING = backedUpItem(TASKBAR_PINNING_KEY, false, true)
+ @JvmField
+ val WORKSPACE_SIZE =
+ backedUpItem(
+ DeviceGridState.KEY_WORKSPACE_SIZE,
+ "",
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val HOTSEAT_COUNT =
+ backedUpItem(
+ DeviceGridState.KEY_HOTSEAT_COUNT,
+ -1,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val TASKBAR_PINNING =
+ backedUpItem(TASKBAR_PINNING_KEY, false, EncryptionType.DEVICE_PROTECTED)
@JvmField
val DEVICE_TYPE =
- backedUpItem(DeviceGridState.KEY_DEVICE_TYPE, InvariantDeviceProfile.TYPE_PHONE, true)
+ backedUpItem(
+ DeviceGridState.KEY_DEVICE_TYPE,
+ InvariantDeviceProfile.TYPE_PHONE,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val DB_FILE =
+ backedUpItem(DeviceGridState.KEY_DB_FILE, "", EncryptionType.MOVE_TO_DEVICE_PROTECTED)
@JvmField
val SHOULD_SHOW_SMARTSPACE =
- backedUpItem("SHOULD_SHOW_SMARTSPACE_KEY", WIDGET_ON_FIRST_SCREEN, true)
- @JvmField val DB_FILE = backedUpItem(DeviceGridState.KEY_DB_FILE, "", true)
+ backedUpItem(
+ SHOULD_SHOW_SMARTSPACE_KEY,
+ WIDGET_ON_FIRST_SCREEN,
+ EncryptionType.DEVICE_PROTECTED
+ )
@JvmField
val RESTORE_DEVICE =
backedUpItem(
RestoreDbTask.RESTORED_DEVICE_TYPE,
InvariantDeviceProfile.TYPE_PHONE,
- true
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField val APP_WIDGET_IDS = backedUpItem(RestoreDbTask.APPWIDGET_IDS, "")
@JvmField val OLD_APP_WIDGET_IDS = backedUpItem(RestoreDbTask.APPWIDGET_OLD_IDS, "")
@@ -313,7 +363,7 @@
"idp_grid_name",
isBackedUp = true,
defaultValue = null,
- isBootAware = true,
+ encryptionType = EncryptionType.MOVE_TO_DEVICE_PROTECTED,
type = String::class.java
)
@JvmField
@@ -327,7 +377,7 @@
"is_startup_data_boot_aware",
isBackedUp = false,
defaultValue = false,
- isBootAware = true
+ encryptionType = EncryptionType.DEVICE_PROTECTED
)
@VisibleForTesting
@@ -335,22 +385,22 @@
fun <T> backedUpItem(
sharedPrefKey: String,
defaultValue: T,
- isBootAware: Boolean = false
+ encryptionType: EncryptionType = EncryptionType.ENCRYPTED
): ConstantItem<T> =
- ConstantItem(sharedPrefKey, isBackedUp = true, defaultValue, isBootAware)
+ ConstantItem(sharedPrefKey, isBackedUp = true, defaultValue, encryptionType)
@JvmStatic
fun <T> backedUpItem(
sharedPrefKey: String,
type: Class<out T>,
- isBootAware: Boolean = false,
+ encryptionType: EncryptionType = EncryptionType.ENCRYPTED,
defaultValueFromContext: (c: Context) -> T
): ContextualItem<T> =
ContextualItem(
sharedPrefKey,
isBackedUp = true,
defaultValueFromContext,
- isBootAware,
+ encryptionType,
type
)
@@ -359,9 +409,9 @@
fun <T> nonRestorableItem(
sharedPrefKey: String,
defaultValue: T,
- isBootAware: Boolean = false
+ encryptionType: EncryptionType = EncryptionType.ENCRYPTED
): ConstantItem<T> =
- ConstantItem(sharedPrefKey, isBackedUp = false, defaultValue, isBootAware)
+ ConstantItem(sharedPrefKey, isBackedUp = false, defaultValue, encryptionType)
@Deprecated("Don't use shared preferences directly. Use other LauncherPref methods.")
@JvmStatic
@@ -386,17 +436,16 @@
}
// It is a var because the unit tests are setting this to true so they can run.
-@VisibleForTesting
-var isBootAwareStartupDataEnabled: Boolean =
- com.android.launcher3.config.FeatureFlags.ENABLE_BOOT_AWARE_STARTUP_DATA.get()
+var moveStartupDataToDeviceProtectedStorageIsEnabled: Boolean =
+ com.android.launcher3.config.FeatureFlags.MOVE_STARTUP_DATA_TO_DEVICE_PROTECTED_STORAGE.get()
-private val BOOT_AWARE_ITEMS: MutableSet<ConstantItem<*>> = mutableSetOf()
+private val ITEMS_TO_MOVE_TO_DEVICE_PROTECTED_STORAGE: MutableSet<ConstantItem<*>> = mutableSetOf()
abstract class Item {
abstract val sharedPrefKey: String
abstract val isBackedUp: Boolean
abstract val type: Class<*>
- abstract val isBootAware: Boolean
+ abstract val encryptionType: EncryptionType
val sharedPrefFile: String
get() = if (isBackedUp) SHARED_PREFERENCES_KEY else DEVICE_PREFERENCES_KEY
@@ -407,13 +456,16 @@
override val sharedPrefKey: String,
override val isBackedUp: Boolean,
val defaultValue: T,
- override val isBootAware: Boolean,
+ override val encryptionType: EncryptionType,
// The default value can be null. If so, the type needs to be explicitly stated, or else NPE
override val type: Class<out T> = defaultValue!!::class.java
) : Item() {
init {
- if (isBootAware && isBootAwareStartupDataEnabled) {
- BOOT_AWARE_ITEMS.add(this)
+ if (
+ encryptionType == EncryptionType.MOVE_TO_DEVICE_PROTECTED &&
+ moveStartupDataToDeviceProtectedStorageIsEnabled
+ ) {
+ ITEMS_TO_MOVE_TO_DEVICE_PROTECTED_STORAGE.add(this)
}
}
}
@@ -422,7 +474,7 @@
override val sharedPrefKey: String,
override val isBackedUp: Boolean,
private val defaultSupplier: (c: Context) -> T,
- override val isBootAware: Boolean,
+ override val encryptionType: EncryptionType,
override val type: Class<out T>
) : Item() {
private var default: T? = null
@@ -434,3 +486,9 @@
return default!!
}
}
+
+enum class EncryptionType {
+ ENCRYPTED,
+ DEVICE_PROTECTED,
+ MOVE_TO_DEVICE_PROTECTED
+}
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 92d7a3c..94124bd 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -260,10 +260,11 @@
"Enables taskbar pinning to allow user to switch between transient and persistent "
+ "taskbar flavors");
- public static final BooleanFlag ENABLE_BOOT_AWARE_STARTUP_DATA = getDebugFlag(251502424,
- "ENABLE_BOOT_AWARE_STARTUP_DATA", DISABLED, "Marks LauncherPref data as (and allows it "
- + "to) available while the device is locked. Enabling this causes a 1-time "
- + "migration of certain SharedPreferences data. Improves startup latency.");
+ public static final BooleanFlag MOVE_STARTUP_DATA_TO_DEVICE_PROTECTED_STORAGE = getDebugFlag(
+ 251502424, "ENABLE_BOOT_AWARE_STARTUP_DATA", DISABLED,
+ "Marks LauncherPref data as (and allows it to) available while the device is"
+ + " locked. Enabling this causes a 1-time movement of certain SharedPreferences"
+ + " data. Improves startup latency.");
// TODO(Block 18): Clean up flags
public static final BooleanFlag ENABLE_APP_PAIRS = getDebugFlag(274189428,
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 8059600..15666cf 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -17,6 +17,7 @@
package com.android.launcher3.model;
import static com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN;
+import static com.android.launcher3.LauncherPrefs.SHOULD_SHOW_SMARTSPACE;
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.config.FeatureFlags.SMARTSPACE_AS_A_WIDGET;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
@@ -299,28 +300,17 @@
logASplit("bindWidgets");
verifyNotStopped();
- if (SMARTSPACE_AS_A_WIDGET.get() && LauncherPrefs.get(mApp.getContext())
- .get(LauncherPrefs.SHOULD_SHOW_SMARTSPACE)) {
+ LauncherPrefs prefs = LauncherPrefs.get(mApp.getContext());
+ if (SMARTSPACE_AS_A_WIDGET.get() && prefs.get(SHOULD_SHOW_SMARTSPACE)) {
mLauncherBinder.bindSmartspaceWidget();
// Turn off pref.
- LauncherPrefs.get(mApp.getContext()).putSync(
- LauncherPrefs.backedUpItem(
- LauncherPrefs.SHOULD_SHOW_SMARTSPACE_KEY,
- WIDGET_ON_FIRST_SCREEN,
- true)
- .to(false));
+ prefs.putSync(SHOULD_SHOW_SMARTSPACE.to(false));
logASplit("bindSmartspaceWidget");
verifyNotStopped();
} else if (!SMARTSPACE_AS_A_WIDGET.get() && WIDGET_ON_FIRST_SCREEN
- && !LauncherPrefs.get(mApp.getContext())
- .get(LauncherPrefs.SHOULD_SHOW_SMARTSPACE)) {
+ && !prefs.get(LauncherPrefs.SHOULD_SHOW_SMARTSPACE)) {
// Turn on pref.
- LauncherPrefs.get(mApp.getContext()).putSync(
- LauncherPrefs.backedUpItem(
- LauncherPrefs.SHOULD_SHOW_SMARTSPACE_KEY,
- WIDGET_ON_FIRST_SCREEN,
- true)
- .to(true));
+ prefs.putSync(SHOULD_SHOW_SMARTSPACE.to(true));
}
if (FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
diff --git a/src/com/android/launcher3/model/ModelDbController.java b/src/com/android/launcher3/model/ModelDbController.java
index e10e72d..139efc3 100644
--- a/src/com/android/launcher3/model/ModelDbController.java
+++ b/src/com/android/launcher3/model/ModelDbController.java
@@ -54,6 +54,7 @@
import com.android.launcher3.AutoInstallsLayout.SourceResources;
import com.android.launcher3.ConstantItem;
import com.android.launcher3.DefaultLayoutParser;
+import com.android.launcher3.EncryptionType;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherFiles;
@@ -499,11 +500,11 @@
private ConstantItem<Boolean> getEmptyDbCreatedKey(String dbName) {
if (mContext instanceof SandboxContext) {
return LauncherPrefs.nonRestorableItem(EMPTY_DATABASE_CREATED,
- false /* default value */, false /* boot aware */);
+ false /* default value */, EncryptionType.ENCRYPTED);
}
String key = TextUtils.equals(dbName, LauncherFiles.LAUNCHER_DB)
? EMPTY_DATABASE_CREATED : EMPTY_DATABASE_CREATED + "@" + dbName;
- return LauncherPrefs.backedUpItem(key, false /* default value */, false /* boot aware */);
+ return LauncherPrefs.backedUpItem(key, false /* default value */, EncryptionType.ENCRYPTED);
}
/**
diff --git a/tests/src/com/android/launcher3/LauncherPrefsTest.kt b/tests/src/com/android/launcher3/LauncherPrefsTest.kt
index d59e02a..88a430b 100644
--- a/tests/src/com/android/launcher3/LauncherPrefsTest.kt
+++ b/tests/src/com/android/launcher3/LauncherPrefsTest.kt
@@ -33,7 +33,8 @@
private val TEST_BOOLEAN_ITEM = LauncherPrefs.nonRestorableItem("1", false)
private val TEST_STRING_ITEM = LauncherPrefs.nonRestorableItem("2", "( ͡❛ ͜ʖ ͡❛)")
private val TEST_INT_ITEM = LauncherPrefs.nonRestorableItem("3", -1)
-private val TEST_CONTEXTUAL_ITEM = ContextualItem("4", true, { true }, false, Boolean::class.java)
+private val TEST_CONTEXTUAL_ITEM =
+ ContextualItem("4", true, { true }, EncryptionType.ENCRYPTED, Boolean::class.java)
private const val TEST_DEFAULT_VALUE = "default"
private const val TEST_PREF_KEY = "test_pref_key"
@@ -51,13 +52,13 @@
@BeforeClass
@JvmStatic
fun setup() {
- isBootAwareStartupDataEnabled = true
+ moveStartupDataToDeviceProtectedStorageIsEnabled = true
}
@AfterClass
@JvmStatic
fun teardown() {
- isBootAwareStartupDataEnabled = false
+ moveStartupDataToDeviceProtectedStorageIsEnabled = false
}
}
@@ -203,7 +204,11 @@
@Test
fun put_bootAwareItem_updatesDeviceProtectedStorage() {
val bootAwareItem =
- LauncherPrefs.backedUpItem(TEST_PREF_KEY, TEST_DEFAULT_VALUE, isBootAware = true)
+ LauncherPrefs.backedUpItem(
+ TEST_PREF_KEY,
+ TEST_DEFAULT_VALUE,
+ EncryptionType.DEVICE_PROTECTED
+ )
val bootAwarePrefs: SharedPreferences =
context
@@ -220,7 +225,11 @@
@Test
fun put_bootAwareItem_updatesEncryptedStorage() {
val bootAwareItem =
- LauncherPrefs.backedUpItem(TEST_PREF_KEY, TEST_DEFAULT_VALUE, isBootAware = true)
+ LauncherPrefs.backedUpItem(
+ TEST_PREF_KEY,
+ TEST_DEFAULT_VALUE,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
val encryptedPrefs: SharedPreferences =
context.getSharedPreferences(bootAwareItem.sharedPrefFile, Context.MODE_PRIVATE)
@@ -235,7 +244,11 @@
@Test
fun remove_bootAwareItem_removesFromDeviceProtectedStorage() {
val bootAwareItem =
- LauncherPrefs.backedUpItem(TEST_PREF_KEY, TEST_DEFAULT_VALUE, isBootAware = true)
+ LauncherPrefs.backedUpItem(
+ TEST_PREF_KEY,
+ TEST_DEFAULT_VALUE,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
val bootAwarePrefs: SharedPreferences =
context
@@ -254,7 +267,11 @@
@Test
fun remove_bootAwareItem_removesFromEncryptedStorage() {
val bootAwareItem =
- LauncherPrefs.backedUpItem(TEST_PREF_KEY, TEST_DEFAULT_VALUE, isBootAware = true)
+ LauncherPrefs.backedUpItem(
+ TEST_PREF_KEY,
+ TEST_DEFAULT_VALUE,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
val encryptedPrefs: SharedPreferences =
context.getSharedPreferences(bootAwareItem.sharedPrefFile, Context.MODE_PRIVATE)
@@ -271,7 +288,11 @@
@Test
fun migrate_bootAwareItemsToDeviceProtectedStorage_worksAsIntended() {
val bootAwareItem =
- LauncherPrefs.backedUpItem(TEST_PREF_KEY, TEST_DEFAULT_VALUE, isBootAware = true)
+ LauncherPrefs.backedUpItem(
+ TEST_PREF_KEY,
+ TEST_DEFAULT_VALUE,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
launcherPrefs.removeSync(bootAwareItem)
val bootAwarePrefs: SharedPreferences =
@@ -303,7 +324,7 @@
LauncherPrefs.backedUpItem(
TEST_PREF_KEY + "_",
TEST_DEFAULT_VALUE + "_",
- isBootAware = false
+ EncryptionType.ENCRYPTED
)
val bootAwarePrefs: SharedPreferences =