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

Commit 634cecb8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add signature permission to allow access to shortcuts for sysui

Bug 34715012
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest1 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest2 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest3 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest4 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest5 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest6 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest7 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest8 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest9 -w com.android.frameworks.servicestests
Test: adb shell am instrument -w -e class com.android.server.pm.ShortcutManagerTest10 -w com.android.frameworks.servicestests
Test: cts-tradefed run cts-dev --skip-device-info --skip-preconditions --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker -a armeabi-v7a -l INFO -m CtsShortcutManagerTestCases
Test: cts-tradefed run cts-dev --skip-device-info --skip-preconditions --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker -a armeabi-v7a -l INFO -m CtsShortcutHostTestCases

Change-Id: I922f9fb872e27b25d1016b3894165a0e63faa9b5
parent fac6655c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10511,6 +10511,7 @@ package android.content.pm {
    method public android.content.pm.LauncherApps.ShortcutQuery setQueryFlags(int);
    method public android.content.pm.LauncherApps.ShortcutQuery setShortcutIds(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_ALL_PINNED = 1024; // 0x400
    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
+19 −3
Original line number Diff line number Diff line
@@ -282,12 +282,27 @@ public class LauncherApps {
        public static final int FLAG_GET_MANIFEST = FLAG_MATCH_MANIFEST;

        /**
         * Does not retrieve CHOOSER only shortcuts.
         * TODO: Add another flag for MATCH_ALL_PINNED
         * @hide include all pinned shortcuts by any launchers, not just by the caller,
         * in the result.
         * If the caller doesn't havve the {@link android.Manifest.permission#ACCESS_SHORTCUTS}
         * permission, this flag will be ignored.
         */
        @TestApi
        public static final int FLAG_MATCH_ALL_PINNED = 1 << 10;

        /**
         * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST
         * @hide
         */
        public static final int FLAG_MATCH_ALL_KINDS =
                FLAG_GET_DYNAMIC | FLAG_GET_PINNED | FLAG_GET_MANIFEST;
                FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST;

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

        /** @hide kept for unit tests */
        @Deprecated
@@ -319,6 +334,7 @@ public class LauncherApps {
                        FLAG_MATCH_PINNED,
                        FLAG_MATCH_MANIFEST,
                        FLAG_GET_KEY_FIELDS_ONLY,
                        FLAG_MATCH_MANIFEST,
                })
        @Retention(RetentionPolicy.SOURCE)
        public @interface QueryFlags {}
+4 −3
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public abstract class ShortcutServiceInternal {
            @NonNull String callingPackage, long changedSince,
            @Nullable String packageName, @Nullable List<String> shortcutIds,
            @Nullable ComponentName componentName, @ShortcutQuery.QueryFlags int flags,
            int userId);
            int userId, int callingPid, int callingUid);

    public abstract boolean
            isPinnedByCaller(int launcherUserId, @NonNull String callingPackage,
@@ -58,7 +58,8 @@ public abstract class ShortcutServiceInternal {

    public abstract Intent[] createShortcutIntents(
            int launcherUserId, @NonNull String callingPackage,
            @NonNull String packageName, @NonNull String shortcutId, int userId);
            @NonNull String packageName, @NonNull String shortcutId, int userId,
            int callingPid, int callingUid);

    public abstract void addListener(@NonNull ShortcutChangeListener listener);

@@ -70,7 +71,7 @@ public abstract class ShortcutServiceInternal {
            @NonNull String packageName, @NonNull String shortcutId, int userId);

    public abstract boolean hasShortcutHostPermission(int launcherUserId,
            @NonNull String callingPackage);
            @NonNull String callingPackage, int callingPid, int callingUid);

    public abstract boolean requestPinAppWidget(@NonNull String callingPackage,
            @NonNull AppWidgetProviderInfo appWidget, @Nullable Bundle extras,
+4 −0
Original line number Diff line number Diff line
@@ -3587,6 +3587,10 @@
    <permission android:name="android.permission.INSTANT_APP_FOREGROUND_SERVICE"
        android:protectionLevel="signature|development|instant|appop" />

    <!-- @hide Allows system components to access all app shortcuts. -->
    <permission android:name="android.permission.ACCESS_SHORTCUTS"
        android:protectionLevel="signature" />

    <application android:process="system"
                 android:persistent="true"
                 android:hasCode="false"
+21 −12
Original line number Diff line number Diff line
@@ -30,12 +30,10 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ILauncherApps;
import android.content.pm.IOnAppsChangedListener;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
@@ -64,7 +62,6 @@ import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.SystemService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@@ -89,10 +86,14 @@ public class LauncherAppsService extends SystemService {
    static class BroadcastCookie {
        public final UserHandle user;
        public final String packageName;
        public final int callingUid;
        public final int callingPid;

        BroadcastCookie(UserHandle userHandle, String packageName) {
        BroadcastCookie(UserHandle userHandle, String packageName, int callingPid, int callingUid) {
            this.user = userHandle;
            this.packageName = packageName;
            this.callingUid = callingUid;
            this.callingPid = callingPid;
        }
    }

@@ -127,6 +128,11 @@ public class LauncherAppsService extends SystemService {
            return getCallingUid();
        }

        @VisibleForTesting
        int injectBinderCallingPid() {
            return getCallingPid();
        }

        final int injectCallingUserId() {
            return UserHandle.getUserId(injectBinderCallingUid());
        }
@@ -166,7 +172,7 @@ public class LauncherAppsService extends SystemService {
                }
                mListeners.unregister(listener);
                mListeners.register(listener, new BroadcastCookie(UserHandle.of(getCallingUserId()),
                        callingPackage));
                        callingPackage, injectBinderCallingPid(), injectBinderCallingUid()));
            }
        }

@@ -438,7 +444,7 @@ public class LauncherAppsService extends SystemService {
        private void ensureShortcutPermission(@NonNull String callingPackage) {
            verifyCallingPackage(callingPackage);
            if (!mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(),
                    callingPackage)) {
                    callingPackage, injectBinderCallingPid(), injectBinderCallingUid())) {
                throw new SecurityException("Caller can't access shortcut information");
            }
        }
@@ -461,7 +467,8 @@ public class LauncherAppsService extends SystemService {
            return new ParceledListSlice<>((List<ShortcutInfo>)
                    mShortcutServiceInternal.getShortcuts(getCallingUserId(),
                            callingPackage, changedSince, packageName, shortcutIds,
                            componentName, flags, targetUser.getIdentifier()));
                            componentName, flags, targetUser.getIdentifier(),
                            injectBinderCallingPid(), injectBinderCallingUid()));
        }

        @Override
@@ -514,7 +521,7 @@ public class LauncherAppsService extends SystemService {
        public boolean hasShortcutHostPermission(String callingPackage) {
            verifyCallingPackage(callingPackage);
            return mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(),
                    callingPackage);
                    callingPackage, injectBinderCallingPid(), injectBinderCallingUid());
        }

        @Override
@@ -536,7 +543,8 @@ public class LauncherAppsService extends SystemService {
            }

            final Intent[] intents = mShortcutServiceInternal.createShortcutIntents(
                    getCallingUserId(), callingPackage, packageName, shortcutId, targetUserId);
                    getCallingUserId(), callingPackage, packageName, shortcutId, targetUserId,
                    injectBinderCallingPid(), injectBinderCallingUid());
            if (intents == null || intents.length == 0) {
                return false;
            }
@@ -901,7 +909,8 @@ public class LauncherAppsService extends SystemService {

                        // Make sure the caller has the permission.
                        if (!mShortcutServiceInternal.hasShortcutHostPermission(
                                launcherUserId, cookie.packageName)) {
                                launcherUserId, cookie.packageName,
                                cookie.callingPid, cookie.callingUid)) {
                            continue;
                        }
                        // Each launcher has a different set of pinned shortcuts, so we need to do a
@@ -914,8 +923,8 @@ public class LauncherAppsService extends SystemService {
                                        /* changedSince= */ 0, packageName, /* shortcutIds=*/ null,
                                        /* component= */ null,
                                        ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY
                                        | ShortcutQuery.FLAG_GET_ALL_KINDS
                                        , userId);
                                        | ShortcutQuery.FLAG_MATCH_ALL_KINDS_WITH_ALL_PINNED
                                        , userId, cookie.callingPid, cookie.callingUid);
                        try {
                            listener.onShortcutChanged(user, packageName,
                                    new ParceledListSlice<>(list));
Loading