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

Commit 7009b3e1 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh Committed by Android (Google) Code Review
Browse files

Merge "Persist the Persons field in ShortcutInfo"

parents fbea7f7c ebb4b607
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2273,7 +2273,8 @@ public final class ShortcutInfo implements Parcelable {
            CharSequence disabledMessage, int disabledMessageResId, String disabledMessageResName,
            Set<String> categories, Intent[] intentsWithExtras, int rank, PersistableBundle extras,
            long lastChangedTimestamp,
            int flags, int iconResId, String iconResName, String bitmapPath, int disabledReason) {
            int flags, int iconResId, String iconResName, String bitmapPath, int disabledReason,
            Person[] persons) {
        mUserId = userId;
        mId = id;
        mPackageName = packageName;
@@ -2299,5 +2300,6 @@ public final class ShortcutInfo implements Parcelable {
        mIconResName = iconResName;
        mBitmapPath = bitmapPath;
        mDisabledReason = disabledReason;
        mPersons = persons;
    }
}
+45 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.pm;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.Person;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
@@ -33,6 +34,7 @@ import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
import com.android.server.pm.ShortcutService.DumpFilter;
@@ -71,6 +73,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    private static final String TAG_EXTRAS = "extras";
    private static final String TAG_SHORTCUT = "shortcut";
    private static final String TAG_CATEGORIES = "categories";
    private static final String TAG_PERSON = "person";

    private static final String ATTR_NAME = "name";
    private static final String ATTR_CALL_COUNT = "call-count";
@@ -96,6 +99,12 @@ class ShortcutPackage extends ShortcutPackageItem {
    private static final String ATTR_ICON_RES_NAME = "icon-resname";
    private static final String ATTR_BITMAP_PATH = "bitmap-path";

    private static final String ATTR_PERSON_NAME = "name";
    private static final String ATTR_PERSON_URI = "uri";
    private static final String ATTR_PERSON_KEY = "key";
    private static final String ATTR_PERSON_IS_BOT = "is-bot";
    private static final String ATTR_PERSON_IS_IMPORTANT = "is-important";

    private static final String NAME_CATEGORIES = "categories";

    private static final String TAG_STRING_ARRAY_XMLUTILS = "string-array";
@@ -1499,6 +1508,22 @@ class ShortcutPackage extends ShortcutPackageItem {
                    out.endTag(null, TAG_CATEGORIES);
                }
            }
            if (!forBackup) {  // Don't backup the persons field.
                final Person[] persons = si.getPersons();
                if (!ArrayUtils.isEmpty(persons)) {
                    for (int i = 0; i < persons.length; i++) {
                        final Person p = persons[i];

                        out.startTag(null, TAG_PERSON);
                        ShortcutService.writeAttr(out, ATTR_PERSON_NAME, p.getName());
                        ShortcutService.writeAttr(out, ATTR_PERSON_URI, p.getUri());
                        ShortcutService.writeAttr(out, ATTR_PERSON_KEY, p.getKey());
                        ShortcutService.writeAttr(out, ATTR_PERSON_IS_BOT, p.isBot());
                        ShortcutService.writeAttr(out, ATTR_PERSON_IS_IMPORTANT, p.isImportant());
                        out.endTag(null, TAG_PERSON);
                    }
                }
            }
            final Intent[] intentsNoExtras = si.getIntentsNoExtras();
            final PersistableBundle[] intentsExtras = si.getIntentPersistableExtrases();
            final int numIntents = intentsNoExtras.length;
@@ -1588,6 +1613,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        String bitmapPath;
        int backupVersionCode;
        ArraySet<String> categories = null;
        ArrayList<Person> persons = new ArrayList<>();

        id = ShortcutService.parseStringAttribute(parser, ATTR_ID);
        activityComponent = ShortcutService.parseComponentNameAttribute(parser,
@@ -1638,6 +1664,9 @@ class ShortcutPackage extends ShortcutPackageItem {
                case TAG_CATEGORIES:
                    // This just contains string-array.
                    continue;
                case TAG_PERSON:
                    persons.add(parsePerson(parser));
                    continue;
                case TAG_STRING_ARRAY_XMLUTILS:
                    if (NAME_CATEGORIES.equals(ShortcutService.parseStringAttribute(parser,
                            ATTR_NAME_XMLUTILS))) {
@@ -1680,7 +1709,8 @@ class ShortcutPackage extends ShortcutPackageItem {
                categories,
                intents.toArray(new Intent[intents.size()]),
                rank, extras, lastChangedTimestamp, flags,
                iconResId, iconResName, bitmapPath, disabledReason);
                iconResId, iconResName, bitmapPath, disabledReason,
                persons.toArray(new Person[persons.size()]));
    }

    private static Intent parseIntent(XmlPullParser parser)
@@ -1713,6 +1743,20 @@ class ShortcutPackage extends ShortcutPackageItem {
        return intent;
    }

    private static Person parsePerson(XmlPullParser parser)
            throws IOException, XmlPullParserException {
        CharSequence name = ShortcutService.parseStringAttribute(parser, ATTR_PERSON_NAME);
        String uri = ShortcutService.parseStringAttribute(parser, ATTR_PERSON_URI);
        String key = ShortcutService.parseStringAttribute(parser, ATTR_PERSON_KEY);
        boolean isBot = ShortcutService.parseBooleanAttribute(parser, ATTR_PERSON_IS_BOT);
        boolean isImportant = ShortcutService.parseBooleanAttribute(parser,
                ATTR_PERSON_IS_IMPORTANT);

        Person.Builder builder = new Person.Builder();
        builder.setName(name).setUri(uri).setKey(key).setBot(isBot).setImportant(isImportant);
        return builder.build();
    }

    @VisibleForTesting
    List<ShortcutInfo> getAllShortcutsForTest() {
        return new ArrayList<>(mShortcuts.values());
+2 −1
Original line number Diff line number Diff line
@@ -449,7 +449,8 @@ public class ShortcutParser {
                iconResId,
                null, // icon res name
                null, // bitmap path
                disabledReason);
                disabledReason,
                null /* persons */);
    }

    private static String parseCategory(ShortcutService service, AttributeSet attrs) {
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.verify;

import android.Manifest.permission;
import android.app.ActivityManager;
import android.app.Person;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
@@ -890,6 +891,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                .setText("text")
                .setDisabledMessage("dismes")
                .setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"))
                .setPerson(makePerson("person", "personKey", "personUri"))
                .setIntent(makeIntent("action", ShortcutActivity.class, "key", "val"))
                .setRank(123)
                .setExtras(pb)
@@ -901,6 +903,8 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                .setTitle("x")
                .setActivity(new ComponentName(mClientContext, ShortcutActivity2.class))
                .setIntent(makeIntent("action", ShortcutActivity.class, "key", "val"))
                .setPersons(list(makePerson("person1", "personKey1", "personUri1"),
                        makePerson("person2", "personKey2", "personUri2")).toArray(new Person[2]))
                .setRank(456)
                .build();
        sorig2.setTimestamp(mInjectedCurrentTimeMillis);
@@ -936,6 +940,10 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
        assertEquals("action", si.getIntent().getAction());
        assertEquals("val", si.getIntent().getStringExtra("key"));
        assertEquals(1, si.getPersons().length);
        assertEquals("person", si.getPersons()[0].getName());
        assertEquals("personKey", si.getPersons()[0].getKey());
        assertEquals("personUri", si.getPersons()[0].getUri());
        assertEquals(0, si.getRank());
        assertEquals(1, si.getExtras().getInt("k"));

@@ -949,6 +957,8 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        // to test it.
        si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_10);
        assertEquals(1, si.getRank());
        assertEquals(2, si.getPersons().length);
        assertEquals("personUri2", si.getPersons()[1].getUri());

        dumpUserFile(USER_10);
    }
@@ -1114,6 +1124,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                .setDisabledMessage("dismes")
                .setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"))
                .setIntent(makeIntent("action", ShortcutActivity.class, "key", "val"))
                .setPerson(makePerson("person", "personKey", "personUri"))
                .setRank(123)
                .setExtras(pb)
                .build();
@@ -1150,6 +1161,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
        assertEquals("action", si.getIntent().getAction());
        assertEquals("val", si.getIntent().getStringExtra("key"));
        assertEquals(0, si.getPersons().length); // Don't backup the persons field
        assertEquals(0, si.getRank());
        assertEquals(1, si.getExtras().getInt("k"));