1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.quickstep 17 18 import android.content.Context 19 import android.util.Log 20 import com.android.launcher3.LauncherAppState 21 import com.android.launcher3.LauncherPrefs 22 import com.android.launcher3.isBootAwareStartupDataEnabled 23 import com.android.launcher3.util.LockedUserState 24 25 /** 26 * Loads expensive objects in memory before the user is unlocked. This decreases experienced latency 27 * when starting the launcher for the first time after a reboot. 28 */ 29 object BootAwarePreloader { 30 private const val TAG = "BootAwarePreloader" 31 32 @JvmStatic startnull33 fun start(context: Context) { 34 val lp = LauncherPrefs.get(context) 35 when { 36 LockedUserState.get(context).isUserUnlocked || !isBootAwareStartupDataEnabled -> { 37 /* No-Op */ 38 } 39 lp.isStartupDataMigrated -> { 40 Log.d(TAG, "preloading start up data") 41 LauncherAppState.INSTANCE.get(context) 42 } 43 else -> { 44 Log.d(TAG, "queuing start up data migration to boot aware prefs") 45 LockedUserState.get(context).runOnUserUnlocked { 46 lp.migrateStartupDataToDeviceProtectedStorage() 47 } 48 } 49 } 50 } 51 } 52