Use shared method for updating the runtime status flags for an item info
- The method AppInfo#updateRuntimeFlagsForActivityTarget should also both add and remove runtime flags to match the current state Bug: 323112914 Test: atest NexusLauncherTests Change-Id: If87acf1e2324f98cf1d96d194eac13a93fa432c1
This commit is contained in:
1 parent
8fc5e593c3
commit
21cf4439d2
5 files changed
+42
-23
No files matched your search
@@ -18,7 +18,6 @@ package com.android.launcher3.model;
|
||||
|
||||
import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR;
|
||||
import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY;
|
||||
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -33,14 +32,13 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.AppFilter;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.AlphabeticIndexCompat;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.model.BgDataModel.Callbacks;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.pm.PackageInstallInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.FlagOp;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
@@ -300,6 +298,7 @@ public class AllAppsList {
|
||||
*/
|
||||
public List<LauncherActivityInfo> updatePackage(
|
||||
Context context, String packageName, UserHandle user) {
|
||||
final UserCache userCache = UserCache.getInstance(context);
|
||||
final List<LauncherActivityInfo> matches = context.getSystemService(LauncherApps.class)
|
||||
.getActivityList(packageName, user);
|
||||
if (matches.size() > 0) {
|
||||
@@ -327,19 +326,9 @@ public class AllAppsList {
|
||||
|
||||
mIconCache.getTitleAndIcon(applicationInfo, info, false /* useLowResIcon */);
|
||||
applicationInfo.sectionName = mIndex.computeSectionName(applicationInfo.title);
|
||||
applicationInfo.setProgressLevel(
|
||||
PackageManagerHelper.getLoadingProgress(info),
|
||||
PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING);
|
||||
applicationInfo.intent = launchIntent;
|
||||
if (Flags.enableSupportForArchiving()) {
|
||||
// In case an app is archived, the respective item flag corresponding to
|
||||
// archiving should also be applied during package updates
|
||||
if (info.getActivityInfo().isArchived) {
|
||||
applicationInfo.runtimeStatusFlags |= FLAG_ARCHIVED;
|
||||
} else {
|
||||
applicationInfo.runtimeStatusFlags &= (~FLAG_ARCHIVED);
|
||||
}
|
||||
}
|
||||
AppInfo.updateRuntimeFlagsForActivityTarget(applicationInfo, info,
|
||||
userCache.getUserInfo(user));
|
||||
mDataChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ public class LoaderTask implements Runnable {
|
||||
List<IconRequestInfo<WorkspaceItemInfo>> iconRequestInfos = new ArrayList<>();
|
||||
|
||||
WorkspaceItemProcessor itemProcessor = new WorkspaceItemProcessor(c, memoryLogger,
|
||||
mUserManagerState, mLauncherApps, mPendingPackages,
|
||||
mUserCache, mUserManagerState, mLauncherApps, mPendingPackages,
|
||||
mShortcutKeyToPinnedShortcuts, mApp, mBgDataModel,
|
||||
mWidgetProvidersMap, installingPkgs, isSdCardReady,
|
||||
widgetInflater, pmHelper, iconRequestInfos, unlockedUsers,
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError
|
||||
import com.android.launcher3.config.FeatureFlags
|
||||
import com.android.launcher3.logging.FileLog
|
||||
import com.android.launcher3.model.data.AppInfo
|
||||
import com.android.launcher3.model.data.AppPairInfo
|
||||
import com.android.launcher3.model.data.FolderInfo
|
||||
import com.android.launcher3.model.data.IconRequestInfo
|
||||
@@ -41,6 +42,7 @@ import com.android.launcher3.model.data.ItemInfoWithIcon
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo
|
||||
import com.android.launcher3.pm.PackageInstallInfo
|
||||
import com.android.launcher3.pm.UserCache
|
||||
import com.android.launcher3.shortcuts.ShortcutKey
|
||||
import com.android.launcher3.util.ApiWrapper
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
@@ -60,6 +62,7 @@ import com.android.launcher3.widget.util.WidgetSizes
|
||||
class WorkspaceItemProcessor(
|
||||
private val c: LoaderCursor,
|
||||
private val memoryLogger: LoaderMemoryLogger?,
|
||||
private val userCache: UserCache,
|
||||
private val userManagerState: UserManagerState,
|
||||
private val launcherApps: LauncherApps,
|
||||
private val pendingPackages: MutableSet<PackageUserKey>,
|
||||
@@ -329,10 +332,8 @@ class WorkspaceItemProcessor(
|
||||
if (ApiWrapper.INSTANCE.get(app.context).isNonResizeableActivity(activityInfo)) {
|
||||
info.status = info.status or WorkspaceItemInfo.FLAG_NON_RESIZEABLE
|
||||
}
|
||||
info.setProgressLevel(
|
||||
PackageManagerHelper.getLoadingProgress(activityInfo),
|
||||
PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING
|
||||
)
|
||||
AppInfo.updateRuntimeFlagsForActivityTarget(info, activityInfo,
|
||||
userCache.getUserInfo(c.user))
|
||||
}
|
||||
if (
|
||||
(c.restoreFlag != 0 ||
|
||||
|
||||
@@ -175,14 +175,26 @@ public class AppInfo extends ItemInfoWithIcon implements WorkspaceItemFactory {
|
||||
return componentName;
|
||||
}
|
||||
|
||||
public static void updateRuntimeFlagsForActivityTarget(
|
||||
/**
|
||||
* Updates the runtime status flags for the given info based on the state of the specified
|
||||
* activity.
|
||||
*/
|
||||
public static boolean updateRuntimeFlagsForActivityTarget(
|
||||
ItemInfoWithIcon info, LauncherActivityInfo lai, UserIconInfo userIconInfo) {
|
||||
final int oldProgressLevel = info.getProgressLevel();
|
||||
final int oldRuntimeStatusFlags = info.runtimeStatusFlags;
|
||||
ApplicationInfo appInfo = lai.getApplicationInfo();
|
||||
if (PackageManagerHelper.isAppSuspended(appInfo)) {
|
||||
info.runtimeStatusFlags |= FLAG_DISABLED_SUSPENDED;
|
||||
} else {
|
||||
info.runtimeStatusFlags &= ~FLAG_DISABLED_SUSPENDED;
|
||||
}
|
||||
if (Flags.enableSupportForArchiving() && lai.getActivityInfo().isArchived) {
|
||||
info.runtimeStatusFlags |= FLAG_ARCHIVED;
|
||||
if (Flags.enableSupportForArchiving()) {
|
||||
if (lai.getActivityInfo().isArchived) {
|
||||
info.runtimeStatusFlags |= FLAG_ARCHIVED;
|
||||
} else {
|
||||
info.runtimeStatusFlags &= ~FLAG_ARCHIVED;
|
||||
}
|
||||
}
|
||||
info.runtimeStatusFlags |= (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0
|
||||
? FLAG_SYSTEM_NO : FLAG_SYSTEM_YES;
|
||||
@@ -190,6 +202,8 @@ public class AppInfo extends ItemInfoWithIcon implements WorkspaceItemFactory {
|
||||
if (Flags.privateSpaceRestrictAccessibilityDrag()) {
|
||||
if (userIconInfo.isPrivate()) {
|
||||
info.runtimeStatusFlags |= FLAG_NOT_PINNABLE;
|
||||
} else {
|
||||
info.runtimeStatusFlags &= ~FLAG_NOT_PINNABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +211,8 @@ public class AppInfo extends ItemInfoWithIcon implements WorkspaceItemFactory {
|
||||
info.setProgressLevel(
|
||||
PackageManagerHelper.getLoadingProgress(lai),
|
||||
PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING);
|
||||
return (oldProgressLevel != info.getProgressLevel())
|
||||
|| (oldRuntimeStatusFlags != info.runtimeStatusFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,10 +37,12 @@ import com.android.launcher3.model.data.FolderInfo
|
||||
import com.android.launcher3.model.data.IconRequestInfo
|
||||
import com.android.launcher3.model.data.ItemInfo
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo
|
||||
import com.android.launcher3.pm.UserCache
|
||||
import com.android.launcher3.shortcuts.ShortcutKey
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
import com.android.launcher3.util.PackageManagerHelper
|
||||
import com.android.launcher3.util.PackageUserKey
|
||||
import com.android.launcher3.util.UserIconInfo
|
||||
import com.android.launcher3.widget.WidgetInflater
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.google.common.truth.Truth.assertWithMessage
|
||||
@@ -68,6 +70,7 @@ class WorkspaceItemProcessorTest {
|
||||
@Mock private lateinit var mockPmHelper: PackageManagerHelper
|
||||
@Mock private lateinit var mockLauncherApps: LauncherApps
|
||||
@Mock private lateinit var mockCursor: LoaderCursor
|
||||
@Mock private lateinit var mockUserCache: UserCache
|
||||
@Mock private lateinit var mockUserManagerState: UserManagerState
|
||||
@Mock private lateinit var mockWidgetInflater: WidgetInflater
|
||||
|
||||
@@ -132,6 +135,14 @@ class WorkspaceItemProcessorTest {
|
||||
.thenReturn(mockWorkspaceInfo)
|
||||
whenever(createIconRequestInfo(any(), any())).thenReturn(mockIconRequestInfo)
|
||||
}
|
||||
mockUserCache =
|
||||
mock<UserCache>().apply {
|
||||
val userIconInfo = mock<UserIconInfo>().apply() {
|
||||
whenever(isPrivate).thenReturn(false)
|
||||
}
|
||||
whenever(getUserInfo(any())).thenReturn(userIconInfo)
|
||||
}
|
||||
|
||||
mockUserManagerState = mock<UserManagerState>()
|
||||
mockWidgetInflater = mock<WidgetInflater>()
|
||||
keyToPinnedShortcutsMap = mutableMapOf()
|
||||
@@ -147,6 +158,7 @@ class WorkspaceItemProcessorTest {
|
||||
private fun createWorkspaceItemProcessorUnderTest(
|
||||
cursor: LoaderCursor = mockCursor,
|
||||
memoryLogger: LoaderMemoryLogger? = null,
|
||||
userCache: UserCache = mockUserCache,
|
||||
userManagerState: UserManagerState = mockUserManagerState,
|
||||
launcherApps: LauncherApps = mockLauncherApps,
|
||||
shortcutKeyToPinnedShortcuts: Map<ShortcutKey, ShortcutInfo> = keyToPinnedShortcutsMap,
|
||||
@@ -165,6 +177,7 @@ class WorkspaceItemProcessorTest {
|
||||
WorkspaceItemProcessor(
|
||||
c = cursor,
|
||||
memoryLogger = memoryLogger,
|
||||
userCache = userCache,
|
||||
userManagerState = userManagerState,
|
||||
launcherApps = launcherApps,
|
||||
app = app,
|
||||
|
||||
Reference in new issue
Block a user