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

Commit e5eb0f08 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Shortcut integration with AppSearch (Part 5)

Following changes are implemented in this CL:
1. Persist shortcuts to icing whenever a shortcut is created/updated.
2. Delete shortcuts from icing only when publisher explicitly removes
the shortcut. i.e. deletion due to exceeding shortcut limit / disabling
shortcut do not lead to shortcut deletion from icing.
3. Call AppSearchSession#reportUsage when
ShortcutManger#pushDynamicShortcuts is invoked.
4. Add StrictMode warning for calling async method on mainthread.

Bug: 151359749
Test: atest ShortcutManagerTest1 ShortcutManagerTest2
ShortcutManagerTest3 ShortcutManagerTest4 ShortcutManagerTest5
ShortcutManagerTest6 ShortcutManagerTest7 ShortcutManagerTest8
ShortcutManagerTest9 ShortcutManagerTest10 ShortcutManagerTest11
Test: atest CtsShortcutManagerTestCases

Change-Id: I36f49e9546c11ddcddb9968f32169a19516d23f5
parent b0b29b24
Loading
Loading
Loading
Loading
+501 −248

File changed.

Preview size limit exceeded, changes collapsed.

+13 −0
Original line number Diff line number Diff line
@@ -1051,6 +1051,8 @@ public class ShortcutService extends IShortcutService.Stub {
        }

        final ShortcutUser user = getUserShortcutsLocked(userId);
        // Close AppSearchSession to flush pending changes.
        user.forAllPackages(ShortcutPackage::closeAppSearchSession);
        user.logSharingShortcutStats(mMetricsLogger);
    }

@@ -5080,6 +5082,17 @@ public class ShortcutService extends IShortcutService.Stub {
        }
    }

    @VisibleForTesting
    void updatePackageShortcutForTest(String packageName, String shortcutId, int userId,
            Consumer<ShortcutInfo> cb) {
        synchronized (mLock) {
            final ShortcutPackage pkg = getPackageShortcutForTest(packageName, userId);
            if (pkg == null) return;

            pkg.mutateShortcut(shortcutId, null, cb);
        }
    }

    @VisibleForTesting
    ShortcutLauncher getLauncherShortcutForTest(String packageName, int userId) {
        synchronized (mLock) {
+11 −0
Original line number Diff line number Diff line
@@ -2041,6 +2041,11 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        return mService.getPackageShortcutForTest(packageName, shortcutId, userId);
    }

    protected void updatePackageShortcut(String packageName, String shortcutId, int userId,
            Consumer<ShortcutInfo> cb) {
        mService.updatePackageShortcutForTest(packageName, shortcutId, userId, cb);
    }

    protected void assertShortcutExists(String packageName, String shortcutId, int userId) {
        assertTrue(getPackageShortcut(packageName, shortcutId, userId) != null);
    }
@@ -2236,6 +2241,10 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        return getPackageShortcut(getCallingPackage(), shortcutId, getCallingUserId());
    }

    protected void updateCallerShortcut(String shortcutId, Consumer<ShortcutInfo> cb) {
        updatePackageShortcut(getCallingPackage(), shortcutId, getCallingUserId(), cb);
    }

    protected List<ShortcutInfo> getLauncherShortcuts(String launcher, int userId, int queryFlags) {
        final List<ShortcutInfo>[] ret = new List[1];
        runWithCaller(launcher, userId, () -> {
@@ -2395,6 +2404,8 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {

        deleteAllSavedFiles();

        mMockAppSearchManager.removeShortcuts();

        initService();
        mService.applyRestore(payload, USER_0);

+7 −7
Original line number Diff line number Diff line
@@ -1702,8 +1702,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {

        // Because setDynamicShortcuts will update the timestamps when ranks are changing,
        // we explicitly set timestamps here.
        getCallerShortcut("s1").setTimestamp(5000);
        getCallerShortcut("s2").setTimestamp(1000);
        updateCallerShortcut("s1", si -> si.setTimestamp(5000));
        updateCallerShortcut("s2", si -> si.setTimestamp(1000));

        setCaller(CALLING_PACKAGE_2);
        final ShortcutInfo s2_2 = makeShortcut("s2");
@@ -1713,9 +1713,9 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
                makeComponent(ShortcutActivity.class));
        assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4)));

        getCallerShortcut("s2").setTimestamp(1500);
        getCallerShortcut("s3").setTimestamp(3000);
        getCallerShortcut("s4").setTimestamp(500);
        updateCallerShortcut("s2", si -> si.setTimestamp(1500));
        updateCallerShortcut("s3", si -> si.setTimestamp(3000));
        updateCallerShortcut("s4", si -> si.setTimestamp(500));

        setCaller(CALLING_PACKAGE_3);
        final ShortcutInfo s3_2 = makeShortcutWithLocusId("s3", makeLocusId("l2"));
@@ -1723,7 +1723,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {

        assertTrue(mManager.setDynamicShortcuts(list(s3_2)));

        getCallerShortcut("s3").setTimestamp(START_TIME + 5000);
        updateCallerShortcut("s3", si -> si.setTimestamp(START_TIME + 5000));

        setCaller(LAUNCHER_1);

@@ -7686,7 +7686,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
                        assertEquals("http://www/", si.getIntent().getData().toString());
                        assertEquals("foo/bar", si.getIntent().getType());
                        assertEquals(
                                new ComponentName("abc", ".xyz"), si.getIntent().getComponent());
                                new ComponentName("abc", "abc.xyz"), si.getIntent().getComponent());

                        assertEquals(set("cat1", "cat2"), si.getIntent().getCategories());
                        assertEquals("value1", si.getIntent().getStringExtra("key1"));