summaryrefslogtreecommitdiff
path: root/src/com/android/launcher3/LauncherPrefs.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherPrefs.kt')
-rw-r--r--src/com/android/launcher3/LauncherPrefs.kt232
1 files changed, 187 insertions, 45 deletions
diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt
index 427eaa3bab..78056e625b 100644
--- a/src/com/android/launcher3/LauncherPrefs.kt
+++ b/src/com/android/launcher3/LauncherPrefs.kt
@@ -21,9 +21,16 @@ import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.util.Log
import androidx.annotation.VisibleForTesting
+import com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN
import com.android.launcher3.LauncherFiles.DEVICE_PREFERENCES_KEY
import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY
-import com.android.launcher3.allapps.WorkProfileManager
+import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_DELAY
+import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_END_SCALE_PERCENT
+import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_ITERATIONS
+import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_SCALE_EXPONENT
+import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_START_SCALE_PERCENT
+import com.android.launcher3.config.FeatureFlags.LPNH_SLOP_PERCENTAGE
+import com.android.launcher3.config.FeatureFlags.LPNH_TIMEOUT_MS
import com.android.launcher3.model.DeviceGridState
import com.android.launcher3.pm.InstallSessionHelper
import com.android.launcher3.provider.RestoreDbTask
@@ -60,7 +67,11 @@ class LauncherPrefs(private val encryptedContext: Context) {
)
private fun chooseSharedPreferences(item: Item): SharedPreferences =
- if (isBootAwareStartupDataEnabled && item.isBootAware && isStartupDataMigrated)
+ if (
+ (moveStartupDataToDeviceProtectedStorageIsEnabled &&
+ item.encryptionType == EncryptionType.MOVE_TO_DEVICE_PROTECTED &&
+ isStartupDataMigrated) || item.encryptionType == EncryptionType.DEVICE_PROTECTED
+ )
bootAwarePrefs
else item.encryptedPrefs
@@ -134,13 +145,20 @@ class LauncherPrefs(private val encryptedContext: Context) {
private fun prepareToPutValues(
updates: Array<out Pair<Item, Any>>
): List<SharedPreferences.Editor> {
- val updatesPerPrefFile = updates.groupBy { it.first.encryptedPrefs }.toMutableMap()
-
- if (isBootAwareStartupDataEnabled) {
- val bootAwareUpdates = updates.filter { it.first.isBootAware }
- if (bootAwareUpdates.isNotEmpty()) {
- updatesPerPrefFile[bootAwarePrefs] = bootAwareUpdates
+ val updatesPerPrefFile =
+ updates
+ .filter { it.first.encryptionType != EncryptionType.DEVICE_PROTECTED }
+ .groupBy { it.first.encryptedPrefs }
+ .toMutableMap()
+
+ 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 ->
@@ -233,13 +251,20 @@ class LauncherPrefs(private val encryptedContext: Context) {
* .apply() or .commit()
*/
private fun prepareToRemove(items: Array<out Item>): List<SharedPreferences.Editor> {
- val itemsPerFile = items.groupBy { it.encryptedPrefs }.toMutableMap()
-
- if (isBootAwareStartupDataEnabled) {
- val bootAwareUpdates = items.filter { it.isBootAware }
- if (bootAwareUpdates.isNotEmpty()) {
- itemsPerFile[bootAwarePrefs] = bootAwareUpdates
+ val itemsPerFile =
+ items
+ .filter { it.encryptionType != EncryptionType.DEVICE_PROTECTED }
+ .groupBy { it.encryptedPrefs }
+ .toMutableMap()
+
+ 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) ->
@@ -250,7 +275,7 @@ class LauncherPrefs(private val encryptedContext: Context) {
}
fun migrateStartupDataToDeviceProtectedStorage() {
- if (!isBootAwareStartupDataEnabled) return
+ if (!moveStartupDataToDeviceProtectedStorageIsEnabled) return
Log.d(
TAG,
@@ -259,7 +284,7 @@ class LauncherPrefs(private val encryptedContext: Context) {
)
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()
}
@@ -274,27 +299,123 @@ class LauncherPrefs(private val encryptedContext: Context) {
@JvmStatic fun get(context: Context): LauncherPrefs = INSTANCE.get(context)
const val TASKBAR_PINNING_KEY = "TASKBAR_PINNING_KEY"
- @JvmField val ICON_STATE = nonRestorableItem(LauncherAppState.KEY_ICON_STATE, "", true)
+ const val SHOULD_SHOW_SMARTSPACE_KEY = "SHOULD_SHOW_SMARTSPACE_KEY"
+ @JvmField
+ val ICON_STATE =
+ nonRestorableItem(
+ "pref_icon_shape_path",
+ "",
+ 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(
+ "pref_all_apps_overview_threshold",
+ 180,
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_slop_percentage",
+ LPNH_SLOP_PERCENTAGE.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_TIMEOUT_MS =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_timeout_ms",
+ LPNH_TIMEOUT_MS.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_haptic_hint_start_scale_percent",
+ LPNH_HAPTIC_HINT_START_SCALE_PERCENT.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_haptic_hint_end_scale_percent",
+ LPNH_HAPTIC_HINT_END_SCALE_PERCENT.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_haptic_hint_scale_exponent",
+ LPNH_HAPTIC_HINT_SCALE_EXPONENT.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_haptic_hint_iterations",
+ LPNH_HAPTIC_HINT_ITERATIONS.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY =
+ nonRestorableItem(
+ "pref_long_press_nav_handle_haptic_hint_delay",
+ LPNH_HAPTIC_HINT_DELAY.get(),
+ EncryptionType.MOVE_TO_DEVICE_PROTECTED
+ )
+ @JvmField
+ val PRIVATE_SPACE_APPS =
+ nonRestorableItem(
+ "pref_private_space_apps",
+ 0,
+ 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)
+ @JvmField val WORK_EDU_STEP = backedUpItem("showed_work_profile_edu", 0)
+ @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)
- @JvmField val DB_FILE = backedUpItem(DeviceGridState.KEY_DB_FILE, "", 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,
+ 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, "")
@@ -304,7 +425,7 @@ class LauncherPrefs(private val encryptedContext: Context) {
"idp_grid_name",
isBackedUp = true,
defaultValue = null,
- isBootAware = true,
+ encryptionType = EncryptionType.MOVE_TO_DEVICE_PROTECTED,
type = String::class.java
)
@JvmField
@@ -318,41 +439,49 @@ class LauncherPrefs(private val encryptedContext: Context) {
"is_startup_data_boot_aware",
isBackedUp = false,
defaultValue = false,
- isBootAware = true
+ encryptionType = EncryptionType.DEVICE_PROTECTED
)
- @VisibleForTesting
+ // Preferences for widget configurations
+ @JvmField
+ val RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =
+ backedUpItem("launcher.reconfigurable_widget_education_tip_seen", false)
+ @JvmField
+ val WIDGETS_EDUCATION_DIALOG_SEEN =
+ backedUpItem("launcher.widgets_education_dialog_seen", false)
+ @JvmField
+ val WIDGETS_EDUCATION_TIP_SEEN = backedUpItem("launcher.widgets_education_tip_seen", false)
+
@JvmStatic
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
)
- @VisibleForTesting
@JvmStatic
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
@@ -376,17 +505,17 @@ class LauncherPrefs(private val encryptedContext: Context) {
}
}
-// This is hard-coded to false for now until it is time to release this optimization. It is only
-// a var because the unit tests are setting this to true so they can run.
-@VisibleForTesting var isBootAwareStartupDataEnabled: Boolean = false
+// It is a var because the unit tests are setting this to true so they can run.
+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
@@ -397,22 +526,27 @@ data class ConstantItem<T>(
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)
}
}
+
+ fun get(c: Context): T = LauncherPrefs.get(c).get(this)
}
data class ContextualItem<T>(
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
@@ -423,4 +557,12 @@ data class ContextualItem<T>(
}
return default!!
}
+
+ fun get(c: Context): T = LauncherPrefs.get(c).get(this)
+}
+
+enum class EncryptionType {
+ ENCRYPTED,
+ DEVICE_PROTECTED,
+ MOVE_TO_DEVICE_PROTECTED
}