Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 505fb760 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh
Browse files

Adds CACHED shortcuts and methods to retrieve and remove

Adds a new flag to ShortcutInfo to mark it as cached. Also adds new
APIs in ShortcutManager to remove or retrieve a cached shortcut.

Bug: 148084870
Test: atest com.android.server.pm.ShortcutManagerTest1 \
            com.android.server.pm.ShortcutManagerTest2 \
            com.android.server.pm.ShortcutManagerTest3 \
            com.android.server.pm.ShortcutManagerTest4 \
            com.android.server.pm.ShortcutManagerTest5 \
            com.android.server.pm.ShortcutManagerTest6 \
            com.android.server.pm.ShortcutManagerTest7 \
            com.android.server.pm.ShortcutManagerTest8 \
            com.android.server.pm.ShortcutManagerTest9 \
            com.android.server.pm.ShortcutManagerTest10
Change-Id: I859b416ccd4228eec10a436550ff98866a62af66
parent 879bc4ae
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -11672,6 +11672,7 @@ package android.content.pm {
    method public android.content.pm.LauncherApps.ShortcutQuery setQueryFlags(int);
    method public android.content.pm.LauncherApps.ShortcutQuery setShortcutIds(@Nullable java.util.List<java.lang.String>);
    field public static final int FLAG_GET_KEY_FIELDS_ONLY = 4; // 0x4
    field public static final int FLAG_MATCH_CACHED = 16; // 0x10
    field public static final int FLAG_MATCH_DYNAMIC = 1; // 0x1
    field public static final int FLAG_MATCH_MANIFEST = 8; // 0x8
    field public static final int FLAG_MATCH_PINNED = 2; // 0x2
@@ -12365,6 +12366,7 @@ package android.content.pm {
    method @Nullable public CharSequence getShortLabel();
    method public android.os.UserHandle getUserHandle();
    method public boolean hasKeyFieldsOnly();
    method public boolean isCached();
    method public boolean isDeclaredInManifest();
    method public boolean isDynamic();
    method public boolean isEnabled();
@@ -12414,14 +12416,20 @@ package android.content.pm {
    method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getManifestShortcuts();
    method public int getMaxShortcutCountPerActivity();
    method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getPinnedShortcuts();
    method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getShortcuts(int);
    method public boolean isRateLimitingActive();
    method public boolean isRequestPinShortcutSupported();
    method public void removeAllDynamicShortcuts();
    method public void removeDynamicShortcuts(@NonNull java.util.List<java.lang.String>);
    method public void removeLongLivedShortcuts(@NonNull java.util.List<java.lang.String>);
    method public void reportShortcutUsed(String);
    method public boolean requestPinShortcut(@NonNull android.content.pm.ShortcutInfo, @Nullable android.content.IntentSender);
    method public boolean setDynamicShortcuts(@NonNull java.util.List<android.content.pm.ShortcutInfo>);
    method public boolean updateShortcuts(@NonNull java.util.List<android.content.pm.ShortcutInfo>);
    field public static final int FLAG_MATCH_CACHED = 8; // 0x8
    field public static final int FLAG_MATCH_DYNAMIC = 2; // 0x2
    field public static final int FLAG_MATCH_MANIFEST = 1; // 0x1
    field public static final int FLAG_MATCH_PINNED = 4; // 0x4
  }
  public class Signature implements android.os.Parcelable {
+4 −0
Original line number Diff line number Diff line
@@ -78,4 +78,8 @@ interface IShortcutService {
    ParceledListSlice getShareTargets(String packageName, in IntentFilter filter, int userId);

    boolean hasShareTargets(String packageName, String packageToCheck, int userId);

    void removeLongLivedShortcuts(String packageName, in List shortcutIds, int userId);

    ParceledListSlice getShortcuts(String packageName, int matchFlags, int userId);
}
 No newline at end of file
+9 −3
Original line number Diff line number Diff line
@@ -324,6 +324,11 @@ public class LauncherApps {
         */
        public static final int FLAG_MATCH_MANIFEST = 1 << 3;

        /**
         * Include cached shortcuts in the result.
         */
        public static final int FLAG_MATCH_CACHED = 1 << 4;

        /** @hide kept for unit tests */
        @Deprecated
        public static final int FLAG_GET_MANIFEST = FLAG_MATCH_MANIFEST;
@@ -345,11 +350,11 @@ public class LauncherApps {
        public static final int FLAG_MATCH_PINNED_BY_ANY_LAUNCHER = 1 << 10;

        /**
         * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST
         * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_CACHED
         * @hide
         */
        public static final int FLAG_MATCH_ALL_KINDS =
                FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST;
                FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_CACHED;

        /**
         * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_ALL_PINNED
@@ -386,8 +391,8 @@ public class LauncherApps {
                FLAG_MATCH_DYNAMIC,
                FLAG_MATCH_PINNED,
                FLAG_MATCH_MANIFEST,
                FLAG_MATCH_CACHED,
                FLAG_GET_KEY_FIELDS_ONLY,
                FLAG_MATCH_MANIFEST,
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface QueryFlags {}
@@ -454,6 +459,7 @@ public class LauncherApps {
         *     <li>{@link #FLAG_MATCH_DYNAMIC}
         *     <li>{@link #FLAG_MATCH_PINNED}
         *     <li>{@link #FLAG_MATCH_MANIFEST}
         *     <li>{@link #FLAG_MATCH_CACHED}
         *     <li>{@link #FLAG_GET_KEY_FIELDS_ONLY}
         * </ul>
         */
+16 −1
Original line number Diff line number Diff line
@@ -119,6 +119,9 @@ public final class ShortcutInfo implements Parcelable {
    /** @hide */
    public static final int FLAG_LONG_LIVED = 1 << 13;

    /** @hide */
    public static final int FLAG_CACHED = 1 << 14;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
            FLAG_DYNAMIC,
@@ -135,6 +138,7 @@ public final class ShortcutInfo implements Parcelable {
            FLAG_ICON_FILE_PENDING_SAVE,
            FLAG_SHADOW,
            FLAG_LONG_LIVED,
            FLAG_CACHED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ShortcutFlags {}
@@ -1681,6 +1685,16 @@ public final class ShortcutInfo implements Parcelable {
        addFlags(FLAG_LONG_LIVED);
    }

    /** @hide */
    public void setCached() {
        addFlags(FLAG_CACHED);
    }

    /** Return whether a shortcut is cached. */
    public boolean isCached() {
        return hasFlags(FLAG_CACHED);
    }

    /** Return whether a shortcut is dynamic. */
    public boolean isDynamic() {
        return hasFlags(FLAG_DYNAMIC);
@@ -1765,7 +1779,8 @@ public final class ShortcutInfo implements Parcelable {

    /** @hide */
    public boolean isAlive() {
        return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST);
        return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST)
                || hasFlags(FLAG_CACHED);
    }

    /** @hide */
+88 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.content.pm;

import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -40,6 +41,8 @@ import android.os.ServiceManager;

import com.android.internal.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
@@ -62,6 +65,44 @@ import java.util.List;
public class ShortcutManager {
    private static final String TAG = "ShortcutManager";

    /**
     * Include manifest shortcuts in the result.
     *
     * @see #getShortcuts(int)
     */
    public static final int FLAG_MATCH_MANIFEST = 1 << 0;

    /**
     * Include dynamic shortcuts in the result.
     *
     * @see #getShortcuts(int)
     */
    public static final int FLAG_MATCH_DYNAMIC = 1 << 1;

    /**
     * Include pinned shortcuts in the result.
     *
     * @see #getShortcuts(int)
     */
    public static final int FLAG_MATCH_PINNED = 1 << 2;

    /**
     * Include cached shortcuts in the result.
     *
     * @see #getShortcuts(int)
     */
    public static final int FLAG_MATCH_CACHED = 1 << 3;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_MATCH_" }, value = {
            FLAG_MATCH_MANIFEST,
            FLAG_MATCH_DYNAMIC,
            FLAG_MATCH_PINNED,
            FLAG_MATCH_CACHED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ShortcutMatchFlags {}

    private final Context mContext;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private final IShortcutService mService;
@@ -118,8 +159,8 @@ public class ShortcutManager {
    @NonNull
    public List<ShortcutInfo> getDynamicShortcuts() {
        try {
            return mService.getDynamicShortcuts(mContext.getPackageName(), injectMyUserId())
                    .getList();
            return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_DYNAMIC,
                    injectMyUserId()).getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -137,7 +178,35 @@ public class ShortcutManager {
    @NonNull
    public List<ShortcutInfo> getManifestShortcuts() {
        try {
            return mService.getManifestShortcuts(mContext.getPackageName(), injectMyUserId())
            return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_MANIFEST,
                    injectMyUserId()).getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns {@link ShortcutInfo}s that match {@code matchFlags}.
     *
     * @param matchFlags result includes shortcuts matching this flags. Any combination of:
     * <ul>
     *     <li>{@link #FLAG_MATCH_MANIFEST}
     *     <li>{@link #FLAG_MATCH_DYNAMIC}
     *     <li>{@link #FLAG_MATCH_PINNED}
     *     <li>{@link #FLAG_MATCH_CACHED}
     * </ul>

     * @return list of {@link ShortcutInfo}s that match the flag.
     *
     * <p>At least one of the {@code MATCH} flags should be set. Otherwise no shortcuts will be
     * returned.
     *
     * @throws IllegalStateException when the user is locked.
     */
    @NonNull
    public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) {
        try {
            return mService.getShortcuts(mContext.getPackageName(), matchFlags, injectMyUserId())
                    .getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -193,6 +262,20 @@ public class ShortcutManager {
        }
    }

    /**
     * Delete long lived shortcuts by ID.
     *
     * @throws IllegalStateException when the user is locked.
     */
    public void removeLongLivedShortcuts(@NonNull List<String> shortcutIds) {
        try {
            mService.removeLongLivedShortcuts(mContext.getPackageName(), shortcutIds,
                    injectMyUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Return all pinned shortcuts from the caller app.
     *
@@ -205,8 +288,8 @@ public class ShortcutManager {
    @NonNull
    public List<ShortcutInfo> getPinnedShortcuts() {
        try {
            return mService.getPinnedShortcuts(mContext.getPackageName(), injectMyUserId())
                    .getList();
            return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED,
                    injectMyUserId()).getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
Loading