• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18 
19 import android.content.res.Resources
20 import com.android.quickstep.recents.data.HighResLoadingStateNotifier
21 
22 /** Determines when high res or low res thumbnails should be loaded. */
23 class HighResLoadingState : HighResLoadingStateNotifier {
24     // If the device does not support low-res thumbnails, only attempt to load high-res thumbnails
25     private val forceHighResThumbnails = !supportsLowResThumbnails()
26     var visible: Boolean = false
27         set(value) {
28             field = value
29             updateState()
30         }
31 
32     var flingingFast = false
33         set(value) {
34             field = value
35             updateState()
36         }
37 
38     var isEnabled: Boolean = false
39         private set
40 
41     private val callbacks = ArrayList<HighResLoadingStateChangedCallback>()
42 
43     interface HighResLoadingStateChangedCallback {
onHighResLoadingStateChangednull44         fun onHighResLoadingStateChanged(enabled: Boolean)
45     }
46 
47     override fun addCallback(callback: HighResLoadingStateChangedCallback) {
48         callbacks.add(callback)
49     }
50 
removeCallbacknull51     override fun removeCallback(callback: HighResLoadingStateChangedCallback) {
52         callbacks.remove(callback)
53     }
54 
updateStatenull55     private fun updateState() {
56         val prevState = isEnabled
57         isEnabled = forceHighResThumbnails || (visible && !flingingFast)
58         if (prevState != isEnabled) {
59             for (callback in callbacks.asReversed()) {
60                 callback.onHighResLoadingStateChanged(isEnabled)
61             }
62         }
63     }
64 
65     /**
66      * Returns Whether device supports low-res thumbnails. Low-res files are an optimization for
67      * faster load times of snapshots. Devices can optionally disable low-res files so that they
68      * only store snapshots at high-res scale. The actual scale can be configured in frameworks/base
69      * config overlay.
70      */
supportsLowResThumbnailsnull71     private fun supportsLowResThumbnails(): Boolean {
72         val res = Resources.getSystem()
73         val resId = res.getIdentifier("config_lowResTaskSnapshotScale", "dimen", "android")
74         if (resId != 0) {
75             return 0 < res.getFloat(resId)
76         }
77         return true
78     }
79 }
80