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

Commit 315c6369 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Include LauncherApps#getShortcutIntents" into sc-dev am: cf4b4e4d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13960145

Change-Id: I742440854ed502a0437504145867126fe1fc2c2d
parents 88869b8a cf4b4e4d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12139,6 +12139,7 @@ package android.content.pm {
    method @Nullable public android.content.IntentSender getShortcutConfigActivityIntent(@NonNull android.content.pm.LauncherActivityInfo);
    method public java.util.List<android.content.pm.LauncherActivityInfo> getShortcutConfigActivityList(@Nullable String, @NonNull android.os.UserHandle);
    method public android.graphics.drawable.Drawable getShortcutIconDrawable(@NonNull android.content.pm.ShortcutInfo, int);
    method @Nullable public android.app.PendingIntent getShortcutIntent(@NonNull String, @NonNull String, @Nullable android.os.Bundle, @NonNull android.os.UserHandle);
    method @Nullable public java.util.List<android.content.pm.ShortcutInfo> getShortcuts(@NonNull android.content.pm.LauncherApps.ShortcutQuery, @NonNull android.os.UserHandle);
    method @Nullable public android.os.Bundle getSuspendedPackageLauncherExtras(String, android.os.UserHandle);
    method public boolean hasShortcutHostPermission();
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ interface ILauncherApps {
            String callingPackage, String packageName, in UserHandle user);
    IntentSender getShortcutConfigActivityIntent(String callingPackage, in ComponentName component,
            in UserHandle user);
    PendingIntent getShortcutIntent(String callingPackage, String packageName, String shortcutId,
            in Bundle opts, in UserHandle user);

    // Unregister is performed using package installer
    void registerPackageInstallerCallback(String callingPackage,
+24 −0
Original line number Diff line number Diff line
@@ -842,6 +842,30 @@ public class LauncherApps {
        }
    }

    /**
     * Returns PendingIntent associated with specified shortcut.
     *
     * @param packageName The packageName of the shortcut
     * @param shortcutId The id of the shortcut
     * @param opts Options to pass to the PendingIntent
     * @param user The UserHandle of the profile
     */
    @Nullable
    public PendingIntent getShortcutIntent(@NonNull final String packageName,
            @NonNull final String shortcutId, @Nullable final Bundle opts,
            @NonNull final UserHandle user) {
        logErrorForInvalidProfileAccess(user);
        if (DEBUG) {
            Log.i(TAG, "GetShortcutIntent " + packageName + "/" + shortcutId + " " + user);
        }
        try {
            return mService.getShortcutIntent(
                    mContext.getPackageName(), packageName, shortcutId, opts, user);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Retrieves a list of config activities for creating {@link ShortcutInfo}.
     *
+45 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.pm;

import static android.app.ActivityOptions.KEY_SPLASH_SCREEN_THEME;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
import static android.content.pm.LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
@@ -648,6 +649,43 @@ public class LauncherAppsService extends SystemService {
            }
        }

        /**
         * Returns the intents for a specific shortcut.
         */
        @Nullable
        @Override
        public PendingIntent getShortcutIntent(@NonNull final String callingPackage,
                @NonNull final String packageName, @NonNull final String shortcutId,
                @Nullable final Bundle opts, @NonNull final UserHandle user)
                throws RemoteException {
            Objects.requireNonNull(callingPackage);
            Objects.requireNonNull(packageName);
            Objects.requireNonNull(shortcutId);
            Objects.requireNonNull(user);

            ensureShortcutPermission(callingPackage);
            if (!canAccessProfile(user.getIdentifier(), "Cannot get shortcuts")) {
                return null;
            }

            final Intent[] intents = mShortcutServiceInternal.createShortcutIntents(
                    getCallingUserId(), callingPackage, packageName, shortcutId,
                    user.getIdentifier(), injectBinderCallingPid(), injectBinderCallingUid());
            if (intents == null || intents.length == 0) {
                return null;
            }
            final long ident = Binder.clearCallingIdentity();
            try {
                return injectCreatePendingIntent(mContext.createPackageContextAsUser(packageName,
                        0, user), 0 /* requestCode */, intents, FLAG_MUTABLE, opts, user);
            } catch (PackageManager.NameNotFoundException e) {
                Slog.e(TAG, "Cannot create pending intent from shortcut " + shortcutId, e);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
            return null;
        }

        @Override
        public boolean isPackageEnabled(String callingPackage, String packageName, UserHandle user)
                throws RemoteException {
@@ -756,6 +794,13 @@ public class LauncherAppsService extends SystemService {
                    callingPid, callingUid) == PackageManager.PERMISSION_GRANTED;
        }

        @VisibleForTesting
        PendingIntent injectCreatePendingIntent(Context context, int requestCode,
                @NonNull Intent[] intents, int flags, Bundle options, UserHandle user) {
            return PendingIntent.getActivitiesAsUser(context, requestCode, intents, flags, options,
                    user);
        }

        @Override
        public ParceledListSlice getShortcuts(@NonNull final String callingPackage,
                @NonNull final ShortcutQueryWrapper query, @NonNull final UserHandle targetUser) {
+15 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.IUidObserver;
import android.app.PendingIntent;
import android.app.Person;
import android.app.admin.DevicePolicyManager;
import android.app.appsearch.AppSearchBatchResult;
@@ -60,6 +61,7 @@ import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
@@ -197,6 +199,13 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
            return this;
        }

        @Override
        public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
                throws PackageManager.NameNotFoundException {
            // ignore.
            return this;
        }

        @Override
        public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
                IntentFilter filter, String broadcastPermission, Handler scheduler) {
@@ -620,6 +629,12 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        boolean injectHasInteractAcrossUsersFullPermission(int callingPid, int callingUid) {
            return false;
        }

        @Override
        PendingIntent injectCreatePendingIntent(Context context, int requestCode,
                @NonNull Intent[] intents, int flags, Bundle options, UserHandle user) {
            return new PendingIntent(mock(IIntentSender.class));
        }
    }

    protected class LauncherAppsTestable extends LauncherApps {
Loading