From 2632377083b34e1ff6ae5ed42948b4443e6b43ea Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Wed, 3 Jun 2020 13:59:32 +0800 Subject: [PATCH] Speed up the cache building of app info data Trigger the background thread to cache the app icon and label description. It could reduce data loading times in UI thread to avoid the scrolling janky. Test: manual and robotests Fixes: 156527207 Change-Id: If171a450b51c7fd8c4ae19d8d149c944a17cf0e9 --- .../settingslib/applications/ApplicationsState.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index 1d4cfdc88ad5e..a89cf37e2d068 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -60,6 +60,7 @@ import androidx.lifecycle.OnLifecycleEvent; import com.android.internal.R; import com.android.internal.util.ArrayUtils; import com.android.settingslib.Utils; +import com.android.settingslib.utils.ThreadUtils; import java.io.File; import java.io.IOException; @@ -1588,6 +1589,15 @@ public class ApplicationsState { this.size = SIZE_UNKNOWN; this.sizeStale = true; ensureLabel(context); + // Speed up the cache of the icon and label description if they haven't been created. + ThreadUtils.postOnBackgroundThread(() -> { + if (this.icon == null) { + this.ensureIconLocked(context); + } + if (this.labelDescription == null) { + this.ensureLabelDescriptionLocked(context); + } + }); } public void ensureLabel(Context context) {