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

Commit 897759cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Increases the shortcut limit to 15 per activity" into rvc-dev am: df2f706d

Change-Id: Id2acf5bcc248508ffa014aa3ab7db5638830fa2d
parents 9481bbbf df2f706d
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -169,7 +169,7 @@ public class ShortcutService extends IShortcutService.Stub {
    static final int DEFAULT_MAX_UPDATES_PER_INTERVAL = 10;
    static final int DEFAULT_MAX_UPDATES_PER_INTERVAL = 10;


    @VisibleForTesting
    @VisibleForTesting
    static final int DEFAULT_MAX_SHORTCUTS_PER_APP = 10;
    static final int DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY = 15;


    @VisibleForTesting
    @VisibleForTesting
    static final int DEFAULT_MAX_ICON_DIMENSION_DP = 96;
    static final int DEFAULT_MAX_ICON_DIMENSION_DP = 96;
@@ -730,7 +730,7 @@ public class ShortcutService extends IShortcutService.Stub {
                ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
                ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));


        mMaxShortcuts = Math.max(0, (int) parser.getLong(
        mMaxShortcuts = Math.max(0, (int) parser.getLong(
                ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_APP));
                ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY));


        final int iconDimensionDp = Math.max(1, injectIsLowRamDevice()
        final int iconDimensionDp = Math.max(1, injectIsLowRamDevice()
                ? (int) parser.getLong(
                ? (int) parser.getLong(
+2 −0
Original line number Original line Diff line number Diff line
@@ -720,6 +720,8 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {


    protected static final long INTERVAL = 10000;
    protected static final long INTERVAL = 10000;


    // This doesn't need to match the max shortcuts limit in the framework, and tests should either
    // use this or set their own limit for testing, without assuming any particular max value.
    protected static final int MAX_SHORTCUTS = 10;
    protected static final int MAX_SHORTCUTS = 10;


    protected static final int MAX_UPDATES_PER_INTERVAL = 3;
    protected static final int MAX_UPDATES_PER_INTERVAL = 3;
+37 −38
Original line number Original line Diff line number Diff line
@@ -234,7 +234,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
        assertEquals(ShortcutService.DEFAULT_RESET_INTERVAL_SEC * 1000,
        assertEquals(ShortcutService.DEFAULT_RESET_INTERVAL_SEC * 1000,
                mService.getResetIntervalForTest());
                mService.getResetIntervalForTest());


        assertEquals(ShortcutService.DEFAULT_MAX_SHORTCUTS_PER_APP,
        assertEquals(ShortcutService.DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY,
                mService.getMaxShortcutsForTest());
                mService.getMaxShortcutsForTest());


        assertEquals(ShortcutService.DEFAULT_MAX_UPDATES_PER_INTERVAL,
        assertEquals(ShortcutService.DEFAULT_MAX_UPDATES_PER_INTERVAL,
@@ -393,6 +393,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
    }
    }


    public void testPushDynamicShortcut() {
    public void testPushDynamicShortcut() {
        // Change the max number of shortcuts.
        mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=5");


        setCaller(CALLING_PACKAGE_1, USER_0);
        setCaller(CALLING_PACKAGE_1, USER_0);


@@ -400,12 +402,11 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
        final ShortcutInfo s2 = makeShortcut("s2");
        final ShortcutInfo s2 = makeShortcut("s2");
        final ShortcutInfo s3 = makeShortcut("s3");
        final ShortcutInfo s3 = makeShortcut("s3");
        final ShortcutInfo s4 = makeShortcut("s4");
        final ShortcutInfo s4 = makeShortcut("s4");

        final ShortcutInfo s5 = makeShortcut("s5");
        final ShortcutInfo s10 = makeShortcut("s10");
        final ShortcutInfo s6 = makeShortcut("s6");
        final ShortcutInfo s11 = makeShortcut("s11");
        final ShortcutInfo s7 = makeShortcut("s7");
        final ShortcutInfo s12 = makeShortcut("s12");
        final ShortcutInfo s8 = makeShortcut("s8");
        final ShortcutInfo s13 = makeShortcut("s13");
        final ShortcutInfo s9 = makeShortcut("s9");
        final ShortcutInfo s14 = makeShortcut("s14");


        // Test push as first shortcut
        // Test push as first shortcut
        mManager.pushDynamicShortcut(s1);
        mManager.pushDynamicShortcut(s1);
@@ -440,63 +441,61 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
        mInjectedCurrentTimeMillis += INTERVAL; // reset
        mInjectedCurrentTimeMillis += INTERVAL; // reset


        // Test push as last
        // Test push as last
        assertTrue(mManager.addDynamicShortcuts(makeShortcuts("s5", "s6", "s7", "s8", "s9")));
        mManager.pushDynamicShortcut(s5);
        mManager.pushDynamicShortcut(s10);
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
                "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10");
                "s1", "s2", "s3", "s4", "s5");
        assertEquals(0, getCallerShortcut("s10").getRank());
        assertEquals(0, getCallerShortcut("s5").getRank());
        assertEquals(1, getCallerShortcut("s5").getRank());
        assertEquals(1, getCallerShortcut("s3").getRank());
        assertEquals(6, getCallerShortcut("s3").getRank());
        assertEquals(2, getCallerShortcut("s1").getRank());
        assertEquals(7, getCallerShortcut("s1").getRank());
        assertEquals(3, getCallerShortcut("s2").getRank());
        assertEquals(8, getCallerShortcut("s2").getRank());
        assertEquals(4, getCallerShortcut("s4").getRank());
        assertEquals(9, getCallerShortcut("s4").getRank());


        // Push when max has already reached
        // Push when max has already reached
        mManager.pushDynamicShortcut(s11);
        mManager.pushDynamicShortcut(s6);
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
                "s1", "s2", "s3", "s5", "s6", "s7", "s8", "s9", "s10", "s11");
                "s1", "s2", "s3", "s5", "s6");
        assertEquals(0, getCallerShortcut("s11").getRank());
        assertEquals(0, getCallerShortcut("s6").getRank());
        assertEquals(1, getCallerShortcut("s10").getRank());
        assertEquals(1, getCallerShortcut("s5").getRank());
        assertEquals(9, getCallerShortcut("s2").getRank());
        assertEquals(4, getCallerShortcut("s2").getRank());


        mInjectedCurrentTimeMillis += INTERVAL; // reset
        mInjectedCurrentTimeMillis += INTERVAL; // reset


        // Push with different activity
        // Push with different activity
        s12.setActivity(makeComponent(ShortcutActivity2.class));
        s7.setActivity(makeComponent(ShortcutActivity2.class));
        mManager.pushDynamicShortcut(s12);
        mManager.pushDynamicShortcut(s7);
        assertEquals(makeComponent(ShortcutActivity2.class),
        assertEquals(makeComponent(ShortcutActivity2.class),
                getCallerShortcut("s12").getActivity());
                getCallerShortcut("s7").getActivity());
        assertEquals(0, getCallerShortcut("s12").getRank());
        assertEquals(0, getCallerShortcut("s7").getRank());


        // Push to update shortcut with different activity
        // Push to update shortcut with different activity
        final ShortcutInfo s1_2 = makeShortcut("s1");
        final ShortcutInfo s1_2 = makeShortcut("s1");
        s1_2.setActivity(makeComponent(ShortcutActivity2.class));
        s1_2.setActivity(makeComponent(ShortcutActivity2.class));
        s1_2.setRank(1);
        s1_2.setRank(1);
        mManager.pushDynamicShortcut(s1_2);
        mManager.pushDynamicShortcut(s1_2);
        assertEquals(0, getCallerShortcut("s12").getRank());
        assertEquals(0, getCallerShortcut("s7").getRank());
        assertEquals(1, getCallerShortcut("s1").getRank());
        assertEquals(1, getCallerShortcut("s1").getRank());
        assertEquals(0, getCallerShortcut("s11").getRank());
        assertEquals(0, getCallerShortcut("s6").getRank());
        assertEquals(1, getCallerShortcut("s10").getRank());
        assertEquals(1, getCallerShortcut("s5").getRank());
        assertEquals(7, getCallerShortcut("s3").getRank());
        assertEquals(2, getCallerShortcut("s3").getRank());
        assertEquals(8, getCallerShortcut("s2").getRank());
        assertEquals(3, getCallerShortcut("s2").getRank());


        mInjectedCurrentTimeMillis += INTERVAL; // reset
        mInjectedCurrentTimeMillis += INTERVAL; // reset


        // Test push when dropped shortcut is cached
        // Test push when dropped shortcut is cached
        s13.setLongLived();
        s8.setLongLived();
        s13.setRank(100);
        s8.setRank(100);
        mManager.pushDynamicShortcut(s13);
        mManager.pushDynamicShortcut(s8);
        assertEquals(9, getCallerShortcut("s13").getRank());
        assertEquals(4, getCallerShortcut("s8").getRank());
        runWithCaller(LAUNCHER_1, USER_0, () -> {
        runWithCaller(LAUNCHER_1, USER_0, () -> {
            mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s13"), HANDLE_USER_0);
            mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s8"), HANDLE_USER_0);
        });
        });


        mManager.pushDynamicShortcut(s14);
        mManager.pushDynamicShortcut(s9);
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
        assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
                "s1", "s2", "s3", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s14");
                "s1", "s2", "s3", "s5", "s6", "s7", "s9");
        // Verify s13 stayed as cached
        // Verify s13 stayed as cached
        assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
        assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
                "s13");
                "s8");
    }
    }


    public void testUnlimitedCalls() {
    public void testUnlimitedCalls() {
+25 −17
Original line number Original line Diff line number Diff line
@@ -30,6 +30,8 @@ import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutInfo;
import android.os.test.TestLooper;
import android.os.test.TestLooper;


import com.android.server.pm.ShortcutService.ConfigConstants;

import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentCaptor;


import java.util.List;
import java.util.List;
@@ -372,9 +374,11 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
    }
    }


    public void testShortcutChangeCallback_pushDynamicShortcut_existingId() {
    public void testShortcutChangeCallback_pushDynamicShortcut_existingId() {
        // Change the max number of shortcuts.
        mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3");

        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2", "s3", "s4", "s5",
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2", "s3"))));
                    "s6", "s7", "s8", "s9", "s10"))));
        });
        });


        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
@@ -384,7 +388,7 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
        });
        });


        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            mManager.pushDynamicShortcut(makeShortcut("s5"));
            mManager.pushDynamicShortcut(makeShortcut("s2"));
        });
        });


        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
@@ -396,13 +400,15 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {


        assertWith(shortcuts.getValue())
        assertWith(shortcuts.getValue())
                .areAllWithKeyFieldsOnly()
                .areAllWithKeyFieldsOnly()
                .haveIds("s5");
                .haveIds("s2");
    }
    }


    public void testShortcutChangeCallback_pushDynamicShortcut_causeDeletion() {
    public void testShortcutChangeCallback_pushDynamicShortcut_causeDeletion() {
        // Change the max number of shortcuts.
        mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3");

        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2", "s3", "s4", "s5",
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2", "s3"))));
                    "s6", "s7", "s8", "s9", "s10"))));
        });
        });


        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
@@ -412,7 +418,7 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
        });
        });


        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            mManager.pushDynamicShortcut(makeShortcut("s11"));
            mManager.pushDynamicShortcut(makeShortcut("s4"));
        });
        });


        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
@@ -427,31 +433,33 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {


        assertWith(changedShortcuts.getValue())
        assertWith(changedShortcuts.getValue())
                .areAllWithKeyFieldsOnly()
                .areAllWithKeyFieldsOnly()
                .haveIds("s11");
                .haveIds("s4");


        assertWith(removedShortcuts.getValue())
        assertWith(removedShortcuts.getValue())
                .areAllWithKeyFieldsOnly()
                .areAllWithKeyFieldsOnly()
                .haveIds("s10");
                .haveIds("s3");
    }
    }


    public void testShortcutChangeCallback_pushDynamicShortcut_causeDeletionButCached() {
    public void testShortcutChangeCallback_pushDynamicShortcut_causeDeletionButCached() {
        // Change the max number of shortcuts.
        mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3");

        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2", "s3", "s4", "s5",
            assertTrue(mManager.setDynamicShortcuts((makeShortcuts("s1", "s2"))));
                    "s6", "s7", "s8", "s9"))));
            ShortcutInfo s3 = makeLongLivedShortcut("s3");
            ShortcutInfo s10 = makeLongLivedShortcut("s10");
            s3.setRank(3);
            s10.setRank(10);
            mManager.pushDynamicShortcut(s3);  // Add a long lived shortcut to the end of the list.
            mManager.pushDynamicShortcut(s10);  // Add a long lived shortcut to the end of the list.
        });
        });


        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
        ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
        runWithCaller(LAUNCHER_1, USER_0, () -> {
        runWithCaller(LAUNCHER_1, USER_0, () -> {
            mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s10"), HANDLE_USER_0);
            mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
            mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
            mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
                    mTestLooper.getNewExecutor());
                    mTestLooper.getNewExecutor());
        });
        });


        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
            mManager.pushDynamicShortcut(makeShortcut("s11"));
            mManager.pushDynamicShortcut(makeShortcut("s4"));
        });
        });


        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
@@ -463,7 +471,7 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {


        assertWith(shortcuts.getValue())
        assertWith(shortcuts.getValue())
                .areAllWithKeyFieldsOnly()
                .areAllWithKeyFieldsOnly()
                .haveIds("s10", "s11");
                .haveIds("s3", "s4");
    }
    }


    public void testShortcutChangeCallback_disableShortcuts() {
    public void testShortcutChangeCallback_disableShortcuts() {