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

Commit d4586b1e authored by Adam He's avatar Adam He
Browse files

Persists LocusId for Shortcuts.

Fixes: 128855592
Test: manual verification
Change-Id: I4219a983d04c984db50fc4c22420404947990e17
parent 90088bb8
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ class ShortcutPackage extends ShortcutPackageItem {
    private static final String ATTR_ICON_RES_ID = "icon-res";
    private static final String ATTR_ICON_RES_NAME = "icon-resname";
    private static final String ATTR_BITMAP_PATH = "bitmap-path";
    private static final String ATTR_LOCUS_ID = "locus-id";

    private static final String ATTR_PERSON_NAME = "name";
    private static final String ATTR_PERSON_URI = "uri";
@@ -1473,6 +1474,10 @@ class ShortcutPackage extends ShortcutPackageItem {
        ShortcutService.writeAttr(out, ATTR_DISABLED_REASON, si.getDisabledReason());
        ShortcutService.writeAttr(out, ATTR_TIMESTAMP,
                si.getLastChangedTimestamp());
        final LocusId locusId = si.getLocusId();
        if (locusId != null) {
            ShortcutService.writeAttr(out, ATTR_LOCUS_ID, si.getLocusId().getId());
        }
        if (forBackup) {
            // Don't write icon information.  Also drop the dynamic flag.

@@ -1612,6 +1617,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        int iconResId;
        String iconResName;
        String bitmapPath;
        final String locusIdString;
        int backupVersionCode;
        ArraySet<String> categories = null;
        ArrayList<Person> persons = new ArrayList<>();
@@ -1638,6 +1644,7 @@ class ShortcutPackage extends ShortcutPackageItem {
        iconResId = (int) ShortcutService.parseLongAttribute(parser, ATTR_ICON_RES_ID);
        iconResName = ShortcutService.parseStringAttribute(parser, ATTR_ICON_RES_NAME);
        bitmapPath = ShortcutService.parseStringAttribute(parser, ATTR_BITMAP_PATH);
        locusIdString = ShortcutService.parseStringAttribute(parser, ATTR_LOCUS_ID);

        final int outerDepth = parser.getDepth();
        int type;
@@ -1703,7 +1710,7 @@ class ShortcutPackage extends ShortcutPackageItem {
            flags |= ShortcutInfo.FLAG_SHADOW;
        }

        LocusId locusId = null; // LocusId is not  set on XML.
        final LocusId locusId = locusIdString == null ? null : new LocusId(locusIdString);

        return new ShortcutInfo(
                userId, id, packageName, activityComponent, /* icon= */ null,
+5 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.ActivityManager;
import android.app.Person;
import android.content.ComponentName;
import android.content.Intent;
import android.content.LocusId;
import android.content.pm.ShortcutInfo;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
@@ -895,6 +896,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                .setIntent(makeIntent("action", ShortcutActivity.class, "key", "val"))
                .setRank(123)
                .setExtras(pb)
                .setLocusId(new LocusId("1.2.3.4.5"))
                .build();
        sorig.setTimestamp(mInjectedCurrentTimeMillis);

@@ -906,6 +908,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                .setPersons(list(makePerson("person1", "personKey1", "personUri1"),
                        makePerson("person2", "personKey2", "personUri2")).toArray(new Person[2]))
                .setRank(456)
                .setLocusId(new LocusId("6.7.8.9"))
                .build();
        sorig2.setTimestamp(mInjectedCurrentTimeMillis);

@@ -946,6 +949,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertEquals("personUri", si.getPersons()[0].getUri());
        assertEquals(0, si.getRank());
        assertEquals(1, si.getExtras().getInt("k"));
        assertEquals("1.2.3.4.5", si.getLocusId().getId());

        assertEquals(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_HAS_ICON_FILE
                | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
@@ -959,6 +963,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertEquals(1, si.getRank());
        assertEquals(2, si.getPersons().length);
        assertEquals("personUri2", si.getPersons()[1].getUri());
        assertEquals("6.7.8.9", si.getLocusId().getId());

        dumpUserFile(USER_10);
    }