mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Merge "Adding support for customizing shortcut pinning logic" into tm-qpr-dev
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#909090"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
||||
@@ -1947,7 +1947,7 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
|
||||
setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: processShortcutFromDrop");
|
||||
if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
|
||||
if (!info.getActivityInfo(this).startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
|
||||
handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import android.content.ComponentName;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -29,13 +29,20 @@ import java.util.Optional;
|
||||
* Meta data that is used for deferred binding. e.g., this object is used to pass information on
|
||||
* draggable targets when they are dropped onto the workspace from another container.
|
||||
*/
|
||||
public class PendingAddItemInfo extends ItemInfo {
|
||||
public class PendingAddItemInfo extends ItemInfoWithIcon {
|
||||
|
||||
/**
|
||||
* The component that will be created.
|
||||
*/
|
||||
public ComponentName componentName;
|
||||
|
||||
public PendingAddItemInfo() { }
|
||||
|
||||
public PendingAddItemInfo(PendingAddItemInfo info) {
|
||||
super(info);
|
||||
componentName = info.componentName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String dumpProperties() {
|
||||
return super.dumpProperties() + " componentName=" + componentName;
|
||||
@@ -46,13 +53,18 @@ public class PendingAddItemInfo extends ItemInfo {
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public ItemInfo makeShallowCopy() {
|
||||
public PendingAddItemInfo makeShallowCopy() {
|
||||
PendingAddItemInfo itemInfo = new PendingAddItemInfo();
|
||||
itemInfo.copyFrom(this);
|
||||
itemInfo.componentName = this.componentName;
|
||||
return itemInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingAddItemInfo clone() {
|
||||
return makeShallowCopy();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ComponentName getTargetComponent() {
|
||||
|
||||
@@ -557,6 +557,12 @@ public final class Utilities {
|
||||
int width, int height, Object[] outObj) {
|
||||
ActivityContext activity = ActivityContext.lookupContext(context);
|
||||
LauncherAppState appState = LauncherAppState.getInstance(context);
|
||||
if (info instanceof PendingAddShortcutInfo) {
|
||||
ShortcutConfigActivityInfo activityInfo =
|
||||
((PendingAddShortcutInfo) info).getActivityInfo(context);
|
||||
outObj[0] = activityInfo;
|
||||
return activityInfo.getFullResIcon(appState.getIconCache());
|
||||
}
|
||||
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
|
||||
LauncherActivityInfo activityInfo = context.getSystemService(LauncherApps.class)
|
||||
.resolveActivity(info.getIntent(), info.user);
|
||||
@@ -565,12 +571,6 @@ public final class Utilities {
|
||||
.getIconProvider().getIcon(
|
||||
activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
|
||||
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
||||
if (info instanceof PendingAddShortcutInfo) {
|
||||
ShortcutConfigActivityInfo activityInfo =
|
||||
((PendingAddShortcutInfo) info).activityInfo;
|
||||
outObj[0] = activityInfo;
|
||||
return activityInfo.getFullResIcon(appState.getIconCache());
|
||||
}
|
||||
List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info)
|
||||
.buildRequest(context)
|
||||
.query(ShortcutRequest.ALL);
|
||||
|
||||
@@ -2690,7 +2690,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
|
||||
if (d.dragInfo instanceof PendingAddShortcutInfo) {
|
||||
WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo)
|
||||
.activityInfo.createWorkspaceItemInfo();
|
||||
.getActivityInfo(mLauncher).createWorkspaceItemInfo();
|
||||
if (si != null) {
|
||||
d.dragInfo = si;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ import androidx.dynamicanimation.animation.FloatPropertyCompat;
|
||||
import androidx.dynamicanimation.animation.SpringAnimation;
|
||||
import androidx.dynamicanimation.animation.SpringForce;
|
||||
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
@@ -218,12 +217,6 @@ public abstract class DragView<T extends Context & ActivityContext> extends Fram
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public void setItemInfo(final ItemInfo info) {
|
||||
if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
|
||||
&& info.itemType != LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION
|
||||
&& info.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
|
||||
&& info.itemType != LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
|
||||
return;
|
||||
}
|
||||
// Load the adaptive icon on a background thread and add the view in ui thread.
|
||||
MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
|
||||
Object[] outObj = new Object[1];
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.android.launcher3.pm.ShortcutConfigActivityInfo;
|
||||
* request.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo {
|
||||
public class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo {
|
||||
|
||||
// Class name used in the target component, such that it will never represent an
|
||||
// actual existing class.
|
||||
|
||||
@@ -1263,7 +1263,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo
|
||||
? (PendingAddShortcutInfo) d.dragInfo : null;
|
||||
WorkspaceItemInfo pasiSi =
|
||||
pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
|
||||
pasi != null ? pasi.getActivityInfo(launcher).createWorkspaceItemInfo() : null;
|
||||
if (pasi != null && pasiSi == null) {
|
||||
// There is no WorkspaceItemInfo, so we have to go through a configuration activity.
|
||||
pasi.container = mInfo.id;
|
||||
|
||||
@@ -60,6 +60,7 @@ import com.android.launcher3.model.data.IconRequestInfo;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.pm.InstallSessionHelper;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.util.InstantAppResolver;
|
||||
@@ -81,6 +82,11 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class IconCache extends BaseIconCache {
|
||||
|
||||
// Shortcut extra which can point to a packageName and can be used to indicate an alternate
|
||||
// badge info. Launcher only reads this if the shortcut comes from a system app.
|
||||
public static final String EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE =
|
||||
"extra_shortcut_badge_override_package";
|
||||
|
||||
private static final String TAG = "Launcher.IconCache";
|
||||
|
||||
private final Predicate<ItemInfoWithIcon> mIsUsingFallbackOrNonDefaultIconCheck = w ->
|
||||
@@ -260,8 +266,15 @@ public class IconCache extends BaseIconCache {
|
||||
getTitleAndIcon(appInfo, false);
|
||||
return appInfo.bitmap;
|
||||
} else {
|
||||
PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(),
|
||||
shortcutInfo.getUserHandle());
|
||||
String pkg = shortcutInfo.getPackage();
|
||||
String override = shortcutInfo.getExtras() == null ? null
|
||||
: shortcutInfo.getExtras().getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE);
|
||||
if (!TextUtils.isEmpty(override)
|
||||
&& InstallSessionHelper.INSTANCE.get(mContext)
|
||||
.isTrustedPackage(pkg, shortcutInfo.getUserHandle())) {
|
||||
pkg = override;
|
||||
}
|
||||
PackageItemInfo pkgInfo = new PackageItemInfo(pkg, shortcutInfo.getUserHandle());
|
||||
getTitleAndIconForApp(pkgInfo, false);
|
||||
return pkgInfo.bitmap;
|
||||
}
|
||||
|
||||
@@ -171,15 +171,22 @@ public class InstallSessionHelper {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
String pkg = sessionInfo.getInstallerPackageName();
|
||||
return isTrustedPackage(sessionInfo.getInstallerPackageName(), getUserHandle(sessionInfo))
|
||||
? sessionInfo : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the provided packageName can be trusted for user configurations
|
||||
*/
|
||||
public boolean isTrustedPackage(String pkg, UserHandle user) {
|
||||
synchronized (mSessionVerifiedMap) {
|
||||
if (!mSessionVerifiedMap.containsKey(pkg)) {
|
||||
boolean hasSystemFlag = new PackageManagerHelper(mAppContext).getApplicationInfo(
|
||||
pkg, getUserHandle(sessionInfo), ApplicationInfo.FLAG_SYSTEM) != null;
|
||||
pkg, user, ApplicationInfo.FLAG_SYSTEM) != null;
|
||||
mSessionVerifiedMap.put(pkg, DEBUG || hasSystemFlag);
|
||||
}
|
||||
}
|
||||
return mSessionVerifiedMap.get(pkg) ? sessionInfo : null;
|
||||
return mSessionVerifiedMap.get(pkg);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.LauncherActivityInfo;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -112,26 +111,6 @@ public abstract class ShortcutConfigActivityInfo implements ComponentWithLabelAn
|
||||
return true;
|
||||
}
|
||||
|
||||
static class ShortcutConfigActivityInfoVL extends ShortcutConfigActivityInfo {
|
||||
|
||||
private final ActivityInfo mInfo;
|
||||
|
||||
ShortcutConfigActivityInfoVL(ActivityInfo info) {
|
||||
super(new ComponentName(info.packageName, info.name), Process.myUserHandle());
|
||||
mInfo = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getLabel(PackageManager pm) {
|
||||
return mInfo.loadLabel(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getFullResIcon(IconCache cache) {
|
||||
return cache.getFullResIcon(mInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(26)
|
||||
public static class ShortcutConfigActivityInfoVO extends ShortcutConfigActivityInfo {
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.android.launcher3.widget;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.launcher3.PendingAddItemInfo;
|
||||
import com.android.launcher3.pm.ShortcutConfigActivityInfo;
|
||||
|
||||
@@ -27,13 +29,28 @@ import com.android.launcher3.pm.ShortcutConfigActivityInfo;
|
||||
*/
|
||||
public class PendingAddShortcutInfo extends PendingAddItemInfo {
|
||||
|
||||
public ShortcutConfigActivityInfo activityInfo;
|
||||
// TODO: Make it @NonNull
|
||||
protected ShortcutConfigActivityInfo mActivityInfo;
|
||||
|
||||
public PendingAddShortcutInfo(ShortcutConfigActivityInfo activityInfo) {
|
||||
this.activityInfo = activityInfo;
|
||||
this.mActivityInfo = activityInfo;
|
||||
componentName = activityInfo.getComponent();
|
||||
user = activityInfo.getUser();
|
||||
itemType = activityInfo.getItemType();
|
||||
this.container = CONTAINER_WIDGETS_TRAY;
|
||||
}
|
||||
|
||||
public PendingAddShortcutInfo(PendingAddShortcutInfo info) {
|
||||
super(info);
|
||||
mActivityInfo = info.mActivityInfo;
|
||||
}
|
||||
|
||||
public PendingAddShortcutInfo() { }
|
||||
|
||||
/**
|
||||
* Returns the info used for creating the shortcut
|
||||
*/
|
||||
public ShortcutConfigActivityInfo getActivityInfo(Context context) {
|
||||
return mActivityInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,8 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_WIDGET);
|
||||
} else {
|
||||
PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo;
|
||||
Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache());
|
||||
Drawable icon = createShortcutInfo.getActivityInfo(launcher)
|
||||
.getFullResIcon(app.getIconCache());
|
||||
LauncherIcons li = LauncherIcons.obtain(launcher);
|
||||
preview = new FastBitmapDrawable(
|
||||
li.createScaledBitmap(icon, BaseIconFactory.MODE_DEFAULT));
|
||||
|
||||
Reference in New Issue
Block a user