1 /* 2 * Copyright (C) 2025 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 17 package com.android.quickstep.util 18 19 import android.content.Context 20 import android.content.Intent 21 import android.os.Trace 22 import android.view.Display.DEFAULT_DISPLAY 23 import com.android.launcher3.provider.RestoreDbTask 24 import com.android.launcher3.util.Executors 25 import com.android.launcher3.util.LockedUserState 26 import com.android.quickstep.OverviewComponentObserver 27 import com.android.quickstep.RecentsAnimationDeviceState 28 import com.android.systemui.shared.system.ActivityManagerWrapper 29 30 /** Utility class for preloading overview */ 31 object ActivityPreloadUtil { 32 33 @JvmStatic preloadOverviewForSUWAllSetnull34 fun preloadOverviewForSUWAllSet(ctx: Context) { 35 preloadOverview(ctx, fromInit = false, forSUWAllSet = true) 36 } 37 38 @JvmStatic preloadOverviewForTISnull39 fun preloadOverviewForTIS(ctx: Context, fromInit: Boolean) { 40 preloadOverview(ctx, fromInit = fromInit, forSUWAllSet = false) 41 } 42 preloadOverviewnull43 private fun preloadOverview(ctx: Context, fromInit: Boolean, forSUWAllSet: Boolean) { 44 Trace.beginSection("preloadOverview(fromInit=$fromInit, forSUWAllSet=$forSUWAllSet)") 45 46 try { 47 if (!LockedUserState.get(ctx).isUserUnlocked) return 48 49 val deviceState = RecentsAnimationDeviceState.INSTANCE[ctx] 50 val overviewCompObserver = OverviewComponentObserver.INSTANCE[ctx] 51 52 // Prevent the overview from being started before the real home on first boot 53 if (deviceState.isButtonNavMode && !overviewCompObserver.isHomeAndOverviewSame) return 54 55 // Preloading while a restore is pending may cause launcher to start the restore too 56 // early 57 if ((RestoreDbTask.isPending(ctx) && !forSUWAllSet) || !deviceState.isUserSetupComplete) 58 return 59 60 // The activity has been created before the initialization of overview service. It is 61 // usually happens when booting or launcher is the top activity, so we should already 62 // have the latest state. 63 if ( 64 fromInit && 65 overviewCompObserver.getContainerInterface(DEFAULT_DISPLAY).createdContainer != 66 null 67 ) 68 return 69 70 ActiveGestureProtoLogProxy.logPreloadRecentsAnimation() 71 val overviewIntent = Intent(overviewCompObserver.overviewIntentIgnoreSysUiState) 72 Executors.UI_HELPER_EXECUTOR.execute { 73 ActivityManagerWrapper.getInstance().preloadRecentsActivity(overviewIntent) 74 } 75 } finally { 76 Trace.endSection() 77 } 78 } 79 } 80