2017-01-05 21:50:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3.model;
|
|
|
|
|
|
2023-05-12 23:07:25 +00:00
|
|
|
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
|
2023-09-25 11:34:56 -07:00
|
|
|
import static com.android.launcher3.config.FeatureFlags.shouldShowFirstPageWidget;
|
2023-05-12 23:07:25 +00:00
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
2017-01-05 15:22:41 -08:00
|
|
|
import android.content.pm.LauncherActivityInfo;
|
2019-10-02 16:13:34 -07:00
|
|
|
import android.content.pm.LauncherApps;
|
2017-01-05 21:50:27 -08:00
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.database.CursorWrapper;
|
|
|
|
|
import android.os.UserHandle;
|
|
|
|
|
import android.provider.BaseColumns;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.util.LongSparseArray;
|
|
|
|
|
|
2021-01-12 19:30:02 +00:00
|
|
|
import androidx.annotation.Nullable;
|
2020-03-26 01:48:24 -07:00
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
import com.android.launcher3.InvariantDeviceProfile;
|
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
2021-01-12 19:30:02 +00:00
|
|
|
import com.android.launcher3.LauncherSettings.Favorites;
|
2017-01-05 21:50:27 -08:00
|
|
|
import com.android.launcher3.Utilities;
|
|
|
|
|
import com.android.launcher3.Workspace;
|
|
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2019-10-02 16:13:34 -07:00
|
|
|
import com.android.launcher3.icons.IconCache;
|
2017-01-05 21:50:27 -08:00
|
|
|
import com.android.launcher3.logging.FileLog;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.AppInfo;
|
2021-08-18 14:53:50 -07:00
|
|
|
import com.android.launcher3.model.data.IconRequestInfo;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
|
|
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
2021-05-07 16:05:51 -07:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutKey;
|
2017-01-05 21:50:27 -08:00
|
|
|
import com.android.launcher3.util.ContentWriter;
|
|
|
|
|
import com.android.launcher3.util.GridOccupancy;
|
2018-10-04 15:11:00 -07:00
|
|
|
import com.android.launcher3.util.IntArray;
|
|
|
|
|
import com.android.launcher3.util.IntSparseArrayMap;
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2017-01-14 15:05:14 -08:00
|
|
|
import java.net.URISyntaxException;
|
2017-01-05 21:50:27 -08:00
|
|
|
import java.security.InvalidParameterException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extension of {@link Cursor} with utility methods for workspace loading.
|
|
|
|
|
*/
|
|
|
|
|
public class LoaderCursor extends CursorWrapper {
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "LoaderCursor";
|
|
|
|
|
|
2020-07-29 15:03:46 -07:00
|
|
|
private final LongSparseArray<UserHandle> allUsers;
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2023-04-14 14:08:37 -07:00
|
|
|
private final LauncherAppState mApp;
|
2017-01-05 21:50:27 -08:00
|
|
|
private final Context mContext;
|
|
|
|
|
private final IconCache mIconCache;
|
|
|
|
|
private final InvariantDeviceProfile mIDP;
|
|
|
|
|
|
2022-11-22 20:02:07 +00:00
|
|
|
private final IntArray mItemsToRemove = new IntArray();
|
|
|
|
|
private final IntArray mRestoredRows = new IntArray();
|
|
|
|
|
private final IntSparseArrayMap<GridOccupancy> mOccupied = new IntSparseArrayMap<>();
|
|
|
|
|
|
|
|
|
|
private final int mIconIndex;
|
|
|
|
|
public final int mTitleIndex;
|
|
|
|
|
|
|
|
|
|
private final int mIdIndex;
|
|
|
|
|
private final int mContainerIndex;
|
|
|
|
|
private final int mItemTypeIndex;
|
|
|
|
|
private final int mScreenIndex;
|
|
|
|
|
private final int mCellXIndex;
|
|
|
|
|
private final int mCellYIndex;
|
|
|
|
|
private final int mProfileIdIndex;
|
|
|
|
|
private final int mRestoredIndex;
|
|
|
|
|
private final int mIntentIndex;
|
|
|
|
|
|
|
|
|
|
private final int mAppWidgetIdIndex;
|
|
|
|
|
private final int mAppWidgetProviderIndex;
|
|
|
|
|
private final int mSpanXIndex;
|
|
|
|
|
private final int mSpanYIndex;
|
|
|
|
|
private final int mRankIndex;
|
|
|
|
|
private final int mOptionsIndex;
|
|
|
|
|
private final int mAppWidgetSourceIndex;
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2021-01-12 19:30:02 +00:00
|
|
|
@Nullable
|
|
|
|
|
private LauncherActivityInfo mActivityInfo;
|
|
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
// Properties loaded per iteration
|
|
|
|
|
public long serialNumber;
|
|
|
|
|
public UserHandle user;
|
2018-10-04 15:11:00 -07:00
|
|
|
public int id;
|
|
|
|
|
public int container;
|
2017-01-05 21:50:27 -08:00
|
|
|
public int itemType;
|
2017-01-11 14:33:38 -08:00
|
|
|
public int restoreFlag;
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2023-05-12 23:07:25 +00:00
|
|
|
public LoaderCursor(Cursor cursor, LauncherAppState app, UserManagerState userManagerState) {
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
super(cursor);
|
|
|
|
|
|
2023-04-14 14:08:37 -07:00
|
|
|
mApp = app;
|
2020-06-08 17:06:09 -07:00
|
|
|
allUsers = userManagerState.allUsers;
|
2017-01-05 21:50:27 -08:00
|
|
|
mContext = app.getContext();
|
|
|
|
|
mIconCache = app.getIconCache();
|
|
|
|
|
mIDP = app.getInvariantDeviceProfile();
|
|
|
|
|
|
|
|
|
|
// Init column indices
|
2022-11-22 20:02:07 +00:00
|
|
|
mIconIndex = getColumnIndexOrThrow(Favorites.ICON);
|
|
|
|
|
mTitleIndex = getColumnIndexOrThrow(Favorites.TITLE);
|
|
|
|
|
|
|
|
|
|
mIdIndex = getColumnIndexOrThrow(Favorites._ID);
|
|
|
|
|
mContainerIndex = getColumnIndexOrThrow(Favorites.CONTAINER);
|
|
|
|
|
mItemTypeIndex = getColumnIndexOrThrow(Favorites.ITEM_TYPE);
|
|
|
|
|
mScreenIndex = getColumnIndexOrThrow(Favorites.SCREEN);
|
|
|
|
|
mCellXIndex = getColumnIndexOrThrow(Favorites.CELLX);
|
|
|
|
|
mCellYIndex = getColumnIndexOrThrow(Favorites.CELLY);
|
|
|
|
|
mProfileIdIndex = getColumnIndexOrThrow(Favorites.PROFILE_ID);
|
|
|
|
|
mRestoredIndex = getColumnIndexOrThrow(Favorites.RESTORED);
|
|
|
|
|
mIntentIndex = getColumnIndexOrThrow(Favorites.INTENT);
|
|
|
|
|
|
|
|
|
|
mAppWidgetIdIndex = getColumnIndexOrThrow(Favorites.APPWIDGET_ID);
|
|
|
|
|
mAppWidgetProviderIndex = getColumnIndexOrThrow(Favorites.APPWIDGET_PROVIDER);
|
|
|
|
|
mSpanXIndex = getColumnIndexOrThrow(Favorites.SPANX);
|
|
|
|
|
mSpanYIndex = getColumnIndexOrThrow(Favorites.SPANY);
|
|
|
|
|
mRankIndex = getColumnIndexOrThrow(Favorites.RANK);
|
|
|
|
|
mOptionsIndex = getColumnIndexOrThrow(Favorites.OPTIONS);
|
|
|
|
|
mAppWidgetSourceIndex = getColumnIndexOrThrow(Favorites.APPWIDGET_SOURCE);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean moveToNext() {
|
|
|
|
|
boolean result = super.moveToNext();
|
|
|
|
|
if (result) {
|
2021-01-12 19:30:02 +00:00
|
|
|
mActivityInfo = null;
|
|
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
// Load common properties.
|
2022-11-22 20:02:07 +00:00
|
|
|
itemType = getInt(mItemTypeIndex);
|
|
|
|
|
container = getInt(mContainerIndex);
|
|
|
|
|
id = getInt(mIdIndex);
|
|
|
|
|
serialNumber = getInt(mProfileIdIndex);
|
2017-01-05 21:50:27 -08:00
|
|
|
user = allUsers.get(serialNumber);
|
2022-11-22 20:02:07 +00:00
|
|
|
restoreFlag = getInt(mRestoredIndex);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-14 15:05:14 -08:00
|
|
|
public Intent parseIntent() {
|
2022-11-22 20:02:07 +00:00
|
|
|
String intentDescription = getString(mIntentIndex);
|
2017-01-14 15:05:14 -08:00
|
|
|
try {
|
|
|
|
|
return TextUtils.isEmpty(intentDescription) ?
|
|
|
|
|
null : Intent.parseUri(intentDescription, 0);
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
Log.e(TAG, "Error parsing Intent");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 01:48:24 -07:00
|
|
|
@VisibleForTesting
|
2019-03-27 16:03:06 -07:00
|
|
|
public WorkspaceItemInfo loadSimpleWorkspaceItem() {
|
|
|
|
|
final WorkspaceItemInfo info = new WorkspaceItemInfo();
|
2020-03-26 01:48:24 -07:00
|
|
|
info.intent = new Intent();
|
2017-01-05 21:50:27 -08:00
|
|
|
// Non-app shortcuts are only supported for current user.
|
|
|
|
|
info.user = user;
|
|
|
|
|
info.itemType = itemType;
|
|
|
|
|
info.title = getTitle();
|
|
|
|
|
// the fallback icon
|
2017-12-19 16:49:24 -08:00
|
|
|
if (!loadIcon(info)) {
|
2019-10-25 13:41:28 -07:00
|
|
|
info.bitmap = mIconCache.getDefaultIcon(info.user);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: If there's an explicit component and we can't install that, delete it.
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
|
|
|
|
|
*/
|
2019-03-27 16:03:06 -07:00
|
|
|
protected boolean loadIcon(WorkspaceItemInfo info) {
|
2021-08-18 14:53:50 -07:00
|
|
|
return createIconRequestInfo(info, false).loadWorkspaceIcon(mContext);
|
|
|
|
|
}
|
2017-12-19 16:49:24 -08:00
|
|
|
|
2021-08-18 14:53:50 -07:00
|
|
|
public IconRequestInfo<WorkspaceItemInfo> createIconRequestInfo(
|
|
|
|
|
WorkspaceItemInfo wai, boolean useLowResIcon) {
|
2023-05-01 16:55:59 -07:00
|
|
|
byte[] iconBlob = itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT || restoreFlag != 0
|
2023-03-29 16:52:27 -07:00
|
|
|
? getIconBlob() : null;
|
2021-08-18 14:53:50 -07:00
|
|
|
|
2023-03-29 16:52:27 -07:00
|
|
|
return new IconRequestInfo<>(wai, mActivityInfo, iconBlob, useLowResIcon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the icon data for at the current position
|
|
|
|
|
*/
|
|
|
|
|
public byte[] getIconBlob() {
|
|
|
|
|
return getBlob(mIconIndex);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the title or empty string
|
|
|
|
|
*/
|
2023-03-29 16:52:27 -07:00
|
|
|
public String getTitle() {
|
2022-11-22 20:02:07 +00:00
|
|
|
return Utilities.trim(getString(mTitleIndex));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When loading an app widget for the workspace, returns it's app widget id
|
|
|
|
|
*/
|
|
|
|
|
public int getAppWidgetId() {
|
|
|
|
|
return getInt(mAppWidgetIdIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When loading an app widget for the workspace, returns the widget provider
|
|
|
|
|
*/
|
|
|
|
|
public String getAppWidgetProvider() {
|
|
|
|
|
return getString(mAppWidgetProviderIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the x position for the item in the cell layout's grid
|
|
|
|
|
*/
|
|
|
|
|
public int getSpanX() {
|
|
|
|
|
return getInt(mSpanXIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the y position for the item in the cell layout's grid
|
|
|
|
|
*/
|
|
|
|
|
public int getSpanY() {
|
|
|
|
|
return getInt(mSpanYIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the rank for the item
|
|
|
|
|
*/
|
|
|
|
|
public int getRank() {
|
|
|
|
|
return getInt(mRankIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the options for the item
|
|
|
|
|
*/
|
|
|
|
|
public int getOptions() {
|
|
|
|
|
return getInt(mOptionsIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When loading an app widget for the workspace, returns it's app widget source
|
|
|
|
|
*/
|
|
|
|
|
public int getAppWidgetSource() {
|
|
|
|
|
return getInt(mAppWidgetSourceIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the screen that the item is on
|
|
|
|
|
*/
|
|
|
|
|
public int getScreen() {
|
|
|
|
|
return getInt(mScreenIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the UX container that the item is in
|
|
|
|
|
*/
|
|
|
|
|
public int getContainer() {
|
|
|
|
|
return getInt(mContainerIndex);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-27 16:03:06 -07:00
|
|
|
* Make an WorkspaceItemInfo object for a restored application or shortcut item that points
|
2017-01-05 21:50:27 -08:00
|
|
|
* to a package that is not yet installed on the system.
|
|
|
|
|
*/
|
2019-03-27 16:03:06 -07:00
|
|
|
public WorkspaceItemInfo getRestoredItemInfo(Intent intent) {
|
|
|
|
|
final WorkspaceItemInfo info = new WorkspaceItemInfo();
|
2017-01-05 21:50:27 -08:00
|
|
|
info.user = user;
|
2017-01-12 16:55:36 -08:00
|
|
|
info.intent = intent;
|
2017-01-05 21:50:27 -08:00
|
|
|
|
|
|
|
|
// the fallback icon
|
2017-12-19 16:49:24 -08:00
|
|
|
if (!loadIcon(info)) {
|
2017-01-05 21:50:27 -08:00
|
|
|
mIconCache.getTitleAndIcon(info, false /* useLowResIcon */);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 16:03:06 -07:00
|
|
|
if (hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORED_ICON)) {
|
2017-01-05 21:50:27 -08:00
|
|
|
String title = getTitle();
|
|
|
|
|
if (!TextUtils.isEmpty(title)) {
|
|
|
|
|
info.title = Utilities.trim(title);
|
|
|
|
|
}
|
2019-08-19 13:32:09 -07:00
|
|
|
} else if (hasRestoreFlag(WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON)) {
|
2017-01-05 21:50:27 -08:00
|
|
|
if (TextUtils.isEmpty(info.title)) {
|
|
|
|
|
info.title = getTitle();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-01-11 14:33:38 -08:00
|
|
|
throw new InvalidParameterException("Invalid restoreType " + restoreFlag);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 16:11:34 -08:00
|
|
|
info.contentDescription = mIconCache.getUserBadgedLabel(info.title, info.user);
|
2017-01-05 21:50:27 -08:00
|
|
|
info.itemType = itemType;
|
2017-01-11 14:33:38 -08:00
|
|
|
info.status = restoreFlag;
|
2017-01-05 21:50:27 -08:00
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-12 19:30:02 +00:00
|
|
|
public LauncherActivityInfo getLauncherActivityInfo() {
|
|
|
|
|
return mActivityInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
/**
|
2019-03-27 16:03:06 -07:00
|
|
|
* Make an WorkspaceItemInfo object for a shortcut that is an application.
|
2017-01-05 21:50:27 -08:00
|
|
|
*/
|
2019-03-27 16:03:06 -07:00
|
|
|
public WorkspaceItemInfo getAppShortcutInfo(
|
2017-01-05 21:50:27 -08:00
|
|
|
Intent intent, boolean allowMissingTarget, boolean useLowResIcon) {
|
2021-08-18 14:53:50 -07:00
|
|
|
return getAppShortcutInfo(intent, allowMissingTarget, useLowResIcon, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WorkspaceItemInfo getAppShortcutInfo(
|
|
|
|
|
Intent intent, boolean allowMissingTarget, boolean useLowResIcon, boolean loadIcon) {
|
2017-01-05 21:50:27 -08:00
|
|
|
if (user == null) {
|
|
|
|
|
Log.d(TAG, "Null user found in getShortcutInfo");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentName componentName = intent.getComponent();
|
|
|
|
|
if (componentName == null) {
|
|
|
|
|
Log.d(TAG, "Missing component found in getShortcutInfo");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
|
|
|
|
|
newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
|
newIntent.setComponent(componentName);
|
2021-01-12 19:30:02 +00:00
|
|
|
mActivityInfo = mContext.getSystemService(LauncherApps.class)
|
2017-01-05 21:50:27 -08:00
|
|
|
.resolveActivity(newIntent, user);
|
2021-01-12 19:30:02 +00:00
|
|
|
if ((mActivityInfo == null) && !allowMissingTarget) {
|
2017-01-05 21:50:27 -08:00
|
|
|
Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 16:03:06 -07:00
|
|
|
final WorkspaceItemInfo info = new WorkspaceItemInfo();
|
2017-01-05 21:50:27 -08:00
|
|
|
info.user = user;
|
|
|
|
|
info.intent = newIntent;
|
|
|
|
|
|
2021-08-18 14:53:50 -07:00
|
|
|
if (loadIcon) {
|
|
|
|
|
mIconCache.getTitleAndIcon(info, mActivityInfo, useLowResIcon);
|
|
|
|
|
if (mIconCache.isDefaultIcon(info.bitmap, user)) {
|
|
|
|
|
loadIcon(info);
|
|
|
|
|
}
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-12 19:30:02 +00:00
|
|
|
if (mActivityInfo != null) {
|
|
|
|
|
AppInfo.updateRuntimeFlagsForActivityTarget(info, mActivityInfo);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// from the db
|
|
|
|
|
if (TextUtils.isEmpty(info.title)) {
|
2022-07-21 15:43:00 -07:00
|
|
|
if (loadIcon) {
|
|
|
|
|
info.title = getTitle();
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2022-07-21 15:43:00 -07:00
|
|
|
// fall back to the class name of the activity
|
|
|
|
|
if (info.title == null) {
|
|
|
|
|
info.title = componentName.getClassName();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
info.title = "";
|
|
|
|
|
}
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 16:11:34 -08:00
|
|
|
info.contentDescription = mIconCache.getUserBadgedLabel(info.title, info.user);
|
2017-01-05 21:50:27 -08:00
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a {@link ContentWriter} which can be used to update the current item.
|
|
|
|
|
*/
|
|
|
|
|
public ContentWriter updater() {
|
|
|
|
|
return new ContentWriter(mContext, new ContentWriter.CommitParams(
|
2023-05-12 23:07:25 +00:00
|
|
|
mApp.getModel().getModelDbController(),
|
2018-10-04 15:11:00 -07:00
|
|
|
BaseColumns._ID + "= ?", new String[]{Integer.toString(id)}));
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Marks the current item for removal
|
|
|
|
|
*/
|
|
|
|
|
public void markDeleted(String reason) {
|
|
|
|
|
FileLog.e(TAG, reason);
|
2022-11-22 20:02:07 +00:00
|
|
|
mItemsToRemove.add(id);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes any items marked for removal.
|
|
|
|
|
* @return true is any item was removed.
|
|
|
|
|
*/
|
|
|
|
|
public boolean commitDeleted() {
|
2022-11-22 20:02:07 +00:00
|
|
|
if (mItemsToRemove.size() > 0) {
|
2017-01-05 21:50:27 -08:00
|
|
|
// Remove dead items
|
2023-05-12 23:07:25 +00:00
|
|
|
mApp.getModel().getModelDbController().delete(TABLE_NAME,
|
|
|
|
|
Utilities.createDbSelectionQuery(Favorites._ID, mItemsToRemove), null);
|
2017-01-05 21:50:27 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Marks the current item as restored
|
|
|
|
|
*/
|
|
|
|
|
public void markRestored() {
|
2017-01-11 14:33:38 -08:00
|
|
|
if (restoreFlag != 0) {
|
2022-11-22 20:02:07 +00:00
|
|
|
mRestoredRows.add(id);
|
2017-01-11 14:33:38 -08:00
|
|
|
restoreFlag = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasRestoreFlag(int flagMask) {
|
|
|
|
|
return (restoreFlag & flagMask) != 0;
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void commitRestoredItems() {
|
2022-11-22 20:02:07 +00:00
|
|
|
if (mRestoredRows.size() > 0) {
|
2017-01-05 21:50:27 -08:00
|
|
|
// Update restored items that no longer require special handling
|
|
|
|
|
ContentValues values = new ContentValues();
|
2022-11-22 20:02:07 +00:00
|
|
|
values.put(Favorites.RESTORED, 0);
|
2023-05-12 23:07:25 +00:00
|
|
|
mApp.getModel().getModelDbController().update(TABLE_NAME, values,
|
|
|
|
|
Utilities.createDbSelectionQuery(Favorites._ID, mRestoredRows), null);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true is the item is on workspace or hotseat
|
|
|
|
|
*/
|
|
|
|
|
public boolean isOnWorkspaceOrHotseat() {
|
2022-11-22 20:02:07 +00:00
|
|
|
return container == Favorites.CONTAINER_DESKTOP || container == Favorites.CONTAINER_HOTSEAT;
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applies the following properties:
|
|
|
|
|
* {@link ItemInfo#id}
|
|
|
|
|
* {@link ItemInfo#container}
|
|
|
|
|
* {@link ItemInfo#screenId}
|
|
|
|
|
* {@link ItemInfo#cellX}
|
|
|
|
|
* {@link ItemInfo#cellY}
|
|
|
|
|
*/
|
|
|
|
|
public void applyCommonProperties(ItemInfo info) {
|
|
|
|
|
info.id = id;
|
|
|
|
|
info.container = container;
|
2022-11-22 20:02:07 +00:00
|
|
|
info.screenId = getInt(mScreenIndex);
|
|
|
|
|
info.cellX = getInt(mCellXIndex);
|
|
|
|
|
info.cellY = getInt(mCellYIndex);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
2021-11-29 12:23:40 -08:00
|
|
|
public void checkAndAddItem(ItemInfo info, BgDataModel dataModel) {
|
|
|
|
|
checkAndAddItem(info, dataModel, null);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 21:50:27 -08:00
|
|
|
/**
|
|
|
|
|
* Adds the {@param info} to {@param dataModel} if it does not overlap with any other item,
|
|
|
|
|
* otherwise marks it for deletion.
|
|
|
|
|
*/
|
2021-11-29 12:23:40 -08:00
|
|
|
public void checkAndAddItem(
|
|
|
|
|
ItemInfo info, BgDataModel dataModel, LoaderMemoryLogger logger) {
|
2022-11-22 20:02:07 +00:00
|
|
|
if (info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
2021-05-07 16:05:51 -07:00
|
|
|
// Ensure that it is a valid intent. An exception here will
|
|
|
|
|
// cause the item loading to get skipped
|
|
|
|
|
ShortcutKey.fromItemInfo(info);
|
|
|
|
|
}
|
2023-10-04 12:11:20 -07:00
|
|
|
if (checkItemPlacement(info, dataModel.isFirstPagePinnedItemEnabled)) {
|
2021-11-29 12:23:40 -08:00
|
|
|
dataModel.addItem(mContext, info, false, logger);
|
2017-01-05 21:50:27 -08:00
|
|
|
} else {
|
|
|
|
|
markDeleted("Item position overlap");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check & update map of what's occupied; used to discard overlapping/invalid items
|
|
|
|
|
*/
|
2023-10-04 12:11:20 -07:00
|
|
|
protected boolean checkItemPlacement(ItemInfo item, boolean isFirstPagePinnedItemEnabled) {
|
2018-10-04 15:11:00 -07:00
|
|
|
int containerIndex = item.screenId;
|
2022-11-22 20:02:07 +00:00
|
|
|
if (item.container == Favorites.CONTAINER_HOTSEAT) {
|
2017-01-05 21:50:27 -08:00
|
|
|
final GridOccupancy hotseatOccupancy =
|
2022-11-22 20:02:07 +00:00
|
|
|
mOccupied.get(Favorites.CONTAINER_HOTSEAT);
|
2017-01-05 21:50:27 -08:00
|
|
|
|
2021-04-07 15:02:37 -07:00
|
|
|
if (item.screenId >= mIDP.numDatabaseHotseatIcons) {
|
2017-01-05 21:50:27 -08:00
|
|
|
Log.e(TAG, "Error loading shortcut " + item
|
|
|
|
|
+ " into hotseat position " + item.screenId
|
2021-04-07 15:02:37 -07:00
|
|
|
+ ", position out of bounds: (0 to " + (mIDP.numDatabaseHotseatIcons - 1)
|
2017-01-05 21:50:27 -08:00
|
|
|
+ ")");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hotseatOccupancy != null) {
|
|
|
|
|
if (hotseatOccupancy.cells[(int) item.screenId][0]) {
|
|
|
|
|
Log.e(TAG, "Error loading shortcut into hotseat " + item
|
|
|
|
|
+ " into position (" + item.screenId + ":" + item.cellX + ","
|
|
|
|
|
+ item.cellY + ") already occupied");
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
2018-10-04 15:11:00 -07:00
|
|
|
hotseatOccupancy.cells[item.screenId][0] = true;
|
2017-01-05 21:50:27 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-04-07 15:02:37 -07:00
|
|
|
final GridOccupancy occupancy = new GridOccupancy(mIDP.numDatabaseHotseatIcons, 1);
|
2018-10-04 15:11:00 -07:00
|
|
|
occupancy.cells[item.screenId][0] = true;
|
2022-11-22 20:02:07 +00:00
|
|
|
mOccupied.put(Favorites.CONTAINER_HOTSEAT, occupancy);
|
2017-01-05 21:50:27 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
2022-11-22 20:02:07 +00:00
|
|
|
} else if (item.container != Favorites.CONTAINER_DESKTOP) {
|
2017-01-05 21:50:27 -08:00
|
|
|
// Skip further checking if it is not the hotseat or workspace container
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int countX = mIDP.numColumns;
|
|
|
|
|
final int countY = mIDP.numRows;
|
2022-11-22 20:02:07 +00:00
|
|
|
if (item.container == Favorites.CONTAINER_DESKTOP && item.cellX < 0 || item.cellY < 0
|
|
|
|
|
|| item.cellX + item.spanX > countX || item.cellY + item.spanY > countY) {
|
2017-01-05 21:50:27 -08:00
|
|
|
Log.e(TAG, "Error loading shortcut " + item
|
|
|
|
|
+ " into cell (" + containerIndex + "-" + item.screenId + ":"
|
|
|
|
|
+ item.cellX + "," + item.cellY
|
|
|
|
|
+ ") out of screen bounds ( " + countX + "x" + countY + ")");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 20:02:07 +00:00
|
|
|
if (!mOccupied.containsKey(item.screenId)) {
|
2017-01-05 21:50:27 -08:00
|
|
|
GridOccupancy screen = new GridOccupancy(countX + 1, countY + 1);
|
2023-09-25 11:34:56 -07:00
|
|
|
if (item.screenId == Workspace.FIRST_SCREEN_ID && (FeatureFlags.QSB_ON_FIRST_SCREEN
|
2023-10-04 12:11:20 -07:00
|
|
|
&& !shouldShowFirstPageWidget() && isFirstPagePinnedItemEnabled)) {
|
2022-01-10 16:13:13 +00:00
|
|
|
// Mark the first X columns (X is width of the search container) in the first row as
|
|
|
|
|
// occupied (if the feature is enabled) in order to account for the search
|
|
|
|
|
// container.
|
|
|
|
|
int spanX = mIDP.numSearchContainerColumns;
|
2022-08-02 13:36:54 -07:00
|
|
|
int spanY = 1;
|
2022-01-10 16:13:13 +00:00
|
|
|
screen.markCells(0, 0, spanX, spanY, true);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
2022-11-22 20:02:07 +00:00
|
|
|
mOccupied.put(item.screenId, screen);
|
2017-01-05 21:50:27 -08:00
|
|
|
}
|
2022-11-22 20:02:07 +00:00
|
|
|
final GridOccupancy occupancy = mOccupied.get(item.screenId);
|
2017-01-05 21:50:27 -08:00
|
|
|
|
|
|
|
|
// Check if any workspace icons overlap with each other
|
|
|
|
|
if (occupancy.isRegionVacant(item.cellX, item.cellY, item.spanX, item.spanY)) {
|
|
|
|
|
occupancy.markCells(item, true);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Error loading shortcut " + item
|
|
|
|
|
+ " into cell (" + containerIndex + "-" + item.screenId + ":"
|
|
|
|
|
+ item.cellX + "," + item.cellX + "," + item.spanX + "," + item.spanY
|
|
|
|
|
+ ") already occupied");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|