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

Commit 0c1814a1 authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

Merge \"Don\'t allow shortcuts with non-main activities\" into nyc-mr1-dev

am: e5b46f3b

Change-Id: I1b2e721e0bb44c35c49d8d983bc6b5a3e7a73d3d
parents 42ec9b86 e5b46f3b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1444,6 +1444,10 @@ public class ShortcutService extends IShortcutService.Stub {
                    shortcut.getPackage().equals(shortcut.getActivity().getPackageName()),
                    "Cannot publish shortcut: activity " + shortcut.getActivity() + " does not"
                    + " belong to package " + shortcut.getPackage());
            Preconditions.checkState(
                    injectIsMainActivity(shortcut.getActivity(), shortcut.getUserId()),
                    "Cannot publish shortcut: activity " + shortcut.getActivity() + " is not"
                            + " main activity");
        }

        if (!forUpdate) {
+28 −2
Original line number Diff line number Diff line
@@ -130,7 +130,6 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
        assertExpectException(NullPointerException.class, "action must be set",
                () -> new ShortcutInfo.Builder(getTestContext(), "id").setIntent(new Intent()));

        // same for add.
        assertExpectException(
                IllegalArgumentException.class, "Short label must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
@@ -139,6 +138,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
            assertTrue(getManager().setDynamicShortcuts(list(si)));
        });

        // same for add.
        assertExpectException(
                IllegalArgumentException.class, "Short label must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
@@ -147,7 +147,6 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
            assertTrue(getManager().addDynamicShortcuts(list(si)));
        });

        // same for add.
        assertExpectException(NullPointerException.class, "Intent must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
                    .setActivity(new ComponentName(getTestContext().getPackageName(), "s"))
@@ -181,6 +180,33 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
                    .build();
            assertTrue(getManager().addDynamicShortcuts(list(si)));
        });

        // Now all activities are not main.
        mMainActivityChecker = (component, userId) -> false;

        assertExpectException(
                IllegalStateException.class, "is not main", () -> {
                    ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
                            .setActivity(new ComponentName(getTestContext(), "s"))
                            .build();
                    assertTrue(getManager().setDynamicShortcuts(list(si)));
                });
        // For add
        assertExpectException(
                IllegalStateException.class, "is not main", () -> {
                    ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
                            .setActivity(new ComponentName(getTestContext(), "s"))
                            .build();
                    assertTrue(getManager().addDynamicShortcuts(list(si)));
                });
        // For update
        assertExpectException(
                IllegalStateException.class, "is not main", () -> {
                    ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id")
                            .setActivity(new ComponentName(getTestContext(), "s"))
                            .build();
                    assertTrue(getManager().updateShortcuts(list(si)));
                });
    }

    public void testShortcutInfoParcel() {