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

Commit c6096027 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh
Browse files

Clone Persons field in ShortcutInfo only for app prediction

Persons field in ShortcutInfo should only be accessible when caller
has the MANAGE_APP_PREDICTIONS permission.

Bug: 123959894
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: I1908496dfbf9b11624b0746154bb5ea6f2d30c38
parent ece7a57a
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -152,15 +152,22 @@ public final class ShortcutInfo implements Parcelable {
    /** @hide */
    public static final int CLONE_REMOVE_RES_NAMES = 1 << 3;

    /** @hide */
    public static final int CLONE_REMOVE_PERSON = 1 << 4;

    /** @hide */
    public static final int CLONE_REMOVE_FOR_CREATOR = CLONE_REMOVE_ICON | CLONE_REMOVE_RES_NAMES;

    /** @hide */
    public static final int CLONE_REMOVE_FOR_LAUNCHER = CLONE_REMOVE_ICON | CLONE_REMOVE_INTENT
            | CLONE_REMOVE_RES_NAMES;
            | CLONE_REMOVE_RES_NAMES | CLONE_REMOVE_PERSON;

    /** @hide */
    public static final int CLONE_REMOVE_FOR_LAUNCHER_APPROVAL = CLONE_REMOVE_INTENT
            | CLONE_REMOVE_RES_NAMES | CLONE_REMOVE_PERSON;

    /** @hide */
    public static final int CLONE_REMOVE_FOR_APP_PREDICTION = CLONE_REMOVE_ICON
            | CLONE_REMOVE_RES_NAMES;

    /** @hide */
@@ -169,8 +176,11 @@ public final class ShortcutInfo implements Parcelable {
            CLONE_REMOVE_INTENT,
            CLONE_REMOVE_NON_KEY_INFO,
            CLONE_REMOVE_RES_NAMES,
            CLONE_REMOVE_PERSON,
            CLONE_REMOVE_FOR_CREATOR,
            CLONE_REMOVE_FOR_LAUNCHER
            CLONE_REMOVE_FOR_LAUNCHER,
            CLONE_REMOVE_FOR_LAUNCHER_APPROVAL,
            CLONE_REMOVE_FOR_APP_PREDICTION
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface CloneFlags {}
@@ -548,7 +558,9 @@ public final class ShortcutInfo implements Parcelable {
            mDisabledMessage = source.mDisabledMessage;
            mDisabledMessageResId = source.mDisabledMessageResId;
            mCategories = cloneCategories(source.mCategories);
            if ((cloneFlags & CLONE_REMOVE_PERSON) == 0) {
                mPersons = clonePersons(source.mPersons);
            }
            if ((cloneFlags & CLONE_REMOVE_INTENT) == 0) {
                mIntents = cloneIntents(source.mIntents);
                mIntentPersistableExtrases =
+3 −2
Original line number Diff line number Diff line
@@ -674,9 +674,10 @@ class ShortcutPackage extends ShortcutPackageItem {
            return new ArrayList<>();
        }

        // Get the list of all dynamic shortcuts in this package
        // Get the list of all dynamic shortcuts in this package.
        final ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
        findAll(shortcuts, ShortcutInfo::isDynamicVisible, ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
        findAll(shortcuts, ShortcutInfo::isDynamicVisible,
                ShortcutInfo.CLONE_REMOVE_FOR_APP_PREDICTION);

        final List<ShortcutManager.ShareShortcutInfo> result = new ArrayList<>();
        for (int i = 0; i < shortcuts.size(); i++) {
+25 −3
Original line number Diff line number Diff line
@@ -423,9 +423,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
        assertEquals(null, si.getIntent());
        assertEquals(123, si.getRank());
        assertEquals("person", si.getPersons()[0].getName());
        assertEquals("personKey", si.getPersons()[0].getKey());
        assertEquals("personUri", si.getPersons()[0].getUri());
        assertEquals(null, si.getPersons());
        assertEquals(1, si.getExtras().getInt("k"));

        assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_LONG_LIVED, si.getFlags());
@@ -455,6 +453,30 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {

        assertEquals(456, si.getIconResourceId());
        assertEquals(null, si.getIconResName());

        si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_APP_PREDICTION);

        assertEquals(mClientContext.getPackageName(), si.getPackage());
        assertEquals("id", si.getId());
        assertEquals(new ComponentName("a", "b"), si.getActivity());
        assertEquals(null, si.getIcon());
        assertEquals("title", si.getTitle());
        assertEquals("text", si.getText());
        assertEquals("dismes", si.getDisabledMessage());
        assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
        assertEquals("action", si.getIntent().getAction());
        assertEquals("val", si.getIntent().getStringExtra("key"));
        assertEquals(123, si.getRank());
        assertEquals("person", si.getPersons()[0].getName());
        assertEquals("personKey", si.getPersons()[0].getKey());
        assertEquals("personUri", si.getPersons()[0].getUri());
        assertEquals(1, si.getExtras().getInt("k"));

        assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_LONG_LIVED, si.getFlags());
        assertEquals(null, si.getBitmapPath());

        assertEquals(456, si.getIconResourceId());
        assertEquals(null, si.getIconResName());
    }

    public void testShortcutInfoClone_resId() {