-
Notifications
You must be signed in to change notification settings - Fork 141
Refactor activity caching logic to extend CustomActivityCachingLogic … #540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * This file is part of Neo Launcher | ||
| * Copyright (c) 2022 Neo Launcher Team | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.neoapps.neolauncher.util | ||
|
|
||
| import android.content.pm.LauncherActivityInfo | ||
| import com.android.launcher3.dagger.LauncherAppSingleton | ||
| import com.android.launcher3.icons.cache.LauncherActivityCachingLogic | ||
| import com.android.launcher3.util.ComponentKey | ||
| import com.android.launcher3.util.SafeCloseable | ||
| import com.neoapps.neolauncher.preferences.NeoPrefs | ||
|
|
||
| @LauncherAppSingleton | ||
| class CustomActivityCachingLogic : LauncherActivityCachingLogic() { | ||
| private val prefs = NeoPrefs.getInstance() | ||
|
|
||
| override fun getLabel(info: LauncherActivityInfo): CharSequence? { | ||
| val key = ComponentKey(info.componentName, info.user) | ||
| val customLabel = prefs.customAppName[key] | ||
| if (!customLabel.isNullOrEmpty()) { | ||
| return customLabel | ||
| } | ||
| return super.getLabel(info) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ | |
| import com.android.launcher3.widget.WidgetSections; | ||
| import com.android.launcher3.widget.WidgetSections.WidgetSection; | ||
| import com.neoapps.neolauncher.icons.CustomIconProvider; | ||
| import com.neoapps.neolauncher.util.CustomActivityCachingLogic; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
@@ -168,7 +169,7 @@ public synchronized void updateIconsForPkg(@NonNull final String packageName, | |
| removeIconsForPkg(packageName, user); | ||
| long userSerial = mUserManager.getSerialNumberForUser(user); | ||
| for (LauncherActivityInfo app : apps) { | ||
| addIconToDBAndMemCache(app, LauncherActivityCachingLogic.INSTANCE, userSerial); | ||
| addIconToDBAndMemCache(app, new CustomActivityCachingLogic(), userSerial); | ||
| } | ||
|
Comment on lines
171
to
173
|
||
| } | ||
|
|
||
|
|
@@ -239,7 +240,7 @@ private void onIconRequestEnd() { | |
| */ | ||
| public synchronized void updateTitleAndIcon(AppInfo application) { | ||
| CacheEntry entry = cacheLocked(application.componentName, | ||
| application.user, () -> null, LauncherActivityCachingLogic.INSTANCE, | ||
| application.user, () -> null, new CustomActivityCachingLogic(), | ||
| application.getMatchingLookupFlag()); | ||
| if (entry.bitmap != null || !isDefaultIcon(entry.bitmap, application.user)) { | ||
| applyCacheEntry(entry, application); | ||
|
|
@@ -389,7 +390,7 @@ public synchronized void getTitleAndIcon( | |
| @NonNull Supplier<LauncherActivityInfo> activityInfoProvider, | ||
| @NonNull CacheLookupFlag lookupFlag) { | ||
| CacheEntry entry = cacheLocked(infoInOut.getTargetComponent(), infoInOut.user, | ||
| activityInfoProvider, LauncherActivityCachingLogic.INSTANCE, lookupFlag); | ||
| activityInfoProvider, new CustomActivityCachingLogic(), lookupFlag); | ||
| applyCacheEntry(entry, infoInOut); | ||
| } | ||
|
|
||
|
|
@@ -490,7 +491,7 @@ private <T extends ItemInfoWithIcon> void loadIconSubsection( | |
| cn, | ||
| /* user = */ sectionKey.first, | ||
| () -> duplicateIconRequests.get(0).launcherActivityInfo, | ||
| LauncherActivityCachingLogic.INSTANCE, | ||
| new CustomActivityCachingLogic(), | ||
| sectionKey.second, | ||
| c); | ||
|
|
||
|
|
@@ -539,7 +540,7 @@ private <T extends ItemInfoWithIcon> void loadIconSubsection( | |
| loadFallbackIcon( | ||
| lai, | ||
| entry, | ||
| LauncherActivityCachingLogic.INSTANCE, | ||
| new CustomActivityCachingLogic(), | ||
| DEFAULT_LOOKUP_FLAG.withUsePackageIcon(false), | ||
| /* usePackageTitle= */ loadFallbackTitle, | ||
| cn, | ||
|
|
@@ -549,7 +550,7 @@ private <T extends ItemInfoWithIcon> void loadIconSubsection( | |
| loadFallbackTitle( | ||
| lai, | ||
| entry, | ||
| LauncherActivityCachingLogic.INSTANCE, | ||
| new CustomActivityCachingLogic(), | ||
| sectionKey.first); | ||
| } | ||
|
|
||
|
|
@@ -643,7 +644,7 @@ public void updateSessionCache(PackageUserKey key, PackageInstaller.SessionInfo | |
| @VisibleForTesting | ||
| synchronized boolean isItemInDb(ComponentKey cacheKey) { | ||
| return getEntryFromDBLocked(cacheKey, new CacheEntry(), DEFAULT_LOOKUP_FLAG, | ||
| LauncherActivityCachingLogic.INSTANCE); | ||
| new CustomActivityCachingLogic()); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,6 +102,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.android.launcher3.util.UserIconInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.android.launcher3.widget.WidgetInflater; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.android.launcher3.widget.util.WidgetSizeHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.neoapps.neolauncher.util.CustomActivityCachingLogic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -254,20 +255,24 @@ private void sendFirstScreenActiveInstallsBroadcast() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean shouldAttachArchivingExtras = mIsRestoreFromBackup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && !mSettingsCache.getValue(DISABLE_INSTALLED_APPS_BROADCAST); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Utilities.ATLEAST_V) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<FirstScreenBroadcastModel> broadcastModels = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mFirstScreenBroadcastHelper.createModelsForFirstScreenBroadcast( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| firstScreenItems, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mInstallingPkgsCached, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mBgDataModel.itemsIdMap.stream().filter(WIDGET_FILTER).collect(Collectors.toList()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shouldAttachArchivingExtras | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logASplit("Sending first screen broadcast with shouldAttachArchivingExtras=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + shouldAttachArchivingExtras); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (shouldAttachArchivingExtras) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<FirstScreenBroadcastModel> broadcastModels = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mFirstScreenBroadcastHelper.createModelsForFirstScreenBroadcast( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| firstScreenItems, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mInstallingPkgsCached, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mBgDataModel.itemsIdMap.stream().filter(WIDGET_FILTER).collect(Collectors.toList()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shouldAttachArchivingExtras | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logASplit("Sending first screen broadcast with shouldAttachArchivingExtras=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + shouldAttachArchivingExtras); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| broadcastModels.forEach(bm -> bm.sentBroadcast(mContext)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logASplit("Sending first screen broadcast"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //mFirstScreenBroadcastHelper.sendBroadcasts(mContext, firstScreenItems); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+258
to
272
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (shouldAttachArchivingExtras) { | |
| List<FirstScreenBroadcastModel> broadcastModels = | |
| mFirstScreenBroadcastHelper.createModelsForFirstScreenBroadcast( | |
| firstScreenItems, | |
| mInstallingPkgsCached, | |
| mBgDataModel.itemsIdMap.stream().filter(WIDGET_FILTER).collect(Collectors.toList()), | |
| shouldAttachArchivingExtras | |
| ); | |
| logASplit("Sending first screen broadcast with shouldAttachArchivingExtras=" | |
| + shouldAttachArchivingExtras); | |
| broadcastModels.forEach(bm -> bm.sentBroadcast(mContext)); | |
| } else { | |
| logASplit("Sending first screen broadcast"); | |
| //mFirstScreenBroadcastHelper.sendBroadcasts(mContext, firstScreenItems); | |
| } | |
| List<FirstScreenBroadcastModel> broadcastModels = | |
| mFirstScreenBroadcastHelper.createModelsForFirstScreenBroadcast( | |
| firstScreenItems, | |
| mInstallingPkgsCached, | |
| mBgDataModel.itemsIdMap.stream() | |
| .filter(WIDGET_FILTER) | |
| .collect(Collectors.toList()), | |
| shouldAttachArchivingExtras | |
| ); | |
| if (shouldAttachArchivingExtras) { | |
| logASplit("Sending first screen broadcast with shouldAttachArchivingExtras=true"); | |
| } else { | |
| logASplit("Sending first screen broadcast with shouldAttachArchivingExtras=false"); | |
| } | |
| broadcastModels.forEach(bm -> bm.sentBroadcast(mContext)); |
Copilot
AI
Feb 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After switching to CustomActivityCachingLogic, this file no longer references LauncherActivityCachingLogic, so the existing import com.android.launcher3.icons.cache.LauncherActivityCachingLogic; becomes unused and will fail Java compilation. Please remove the unused import (or reintroduce a reference if still needed).
Copilot
AI
Feb 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CustomActivityCachingLogic lives under the omega flavor source set (Omega/src), but LoaderTask.java is in the main source set. This import/usage will break compilation for the aosp variant. Either move the caching-logic implementation into main, or keep main using the base LauncherActivityCachingLogic and override the behavior from the omega source set (e.g., via a flavor-specific subclass/factory/DI binding).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor changes
LauncherActivityCachingLogicfrom a Kotlinobjectto a class, which removes the singleton value that existing call sites rely on (e.g., Java.INSTANCEand Kotlin usages that passLauncherActivityCachingLogicas aCachingLogic). To avoid widespread breakage, consider keeping a singletonobject LauncherActivityCachingLogicfor the default behavior and introducing a separateopenbase class for extension (or update all call sites/tests to instantiate/pass a shared instance explicitly).