Loading core/java/android/content/pm/ShortcutInfo.java +2 −2 Original line number Diff line number Diff line Loading @@ -254,9 +254,9 @@ public final class ShortcutInfo implements Parcelable { */ public void enforceMandatoryFields() { Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided"); Preconditions.checkNotNull(mActivity, "activity must be provided"); Preconditions.checkNotNull(mActivity, "Activity must be provided"); if (mTitle == null && mTitleResId == 0) { throw new IllegalArgumentException("Shortcut title must be provided"); throw new IllegalArgumentException("Short label must be provided"); } Preconditions.checkNotNull(mIntent, "Shortcut Intent must be provided"); } Loading services/core/java/com/android/server/pm/ShortcutPackage.java +1 −1 Original line number Diff line number Diff line Loading @@ -908,7 +908,7 @@ class ShortcutPackage extends ShortcutPackageItem { if (operation != ShortcutService.OPERATION_UPDATE) { // This method may be called before validating shortcuts, so this may happen, // and is a caller side error. throw new NullPointerException("activity must be provided"); throw new NullPointerException("Activity must be provided"); } continue; // Activity can be null for update. } Loading services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -697,6 +697,10 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { return getInstrumentation().getContext(); } protected ShortcutManager getManager() { return mManager; } protected void deleteAllSavedFiles() { // Empty the data directory. if (mInjectedFilePathRoot.exists()) { Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java +64 −21 Original line number Diff line number Diff line Loading @@ -56,35 +56,78 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { // ShortcutInfo tests public void testShortcutInfoMissingMandatoryFields() { // Disable throttling. mService.updateConfigurationLocked( ShortcutService.ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=99999999," + ShortcutService.ConfigConstants.KEY_MAX_SHORTCUTS + "=99999999" ); assertExpectException( IllegalArgumentException.class, "ID must be provided", () -> new ShortcutInfo.Builder(getTestContext()).build()); assertExpectException( NullPointerException.class, "Intent action must be set", assertExpectException(NullPointerException.class, "Intent action must be set", () -> new ShortcutInfo.Builder(getTestContext()).setIntent(new Intent())); assertExpectException(NullPointerException.class, "Activity must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()).setId("id").build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( NullPointerException.class, "activity must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id").build() .enforceMandatoryFields()); IllegalArgumentException.class, "Short label must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( IllegalArgumentException.class, "title must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id") .setActivity( new ComponentName(getTestContext().getPackageName(), "s")) .build() .enforceMandatoryFields()); IllegalArgumentException.class, "Short label must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); assertExpectException(NullPointerException.class, "Intent must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .setShortLabel("x") .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException(NullPointerException.class, "Intent must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .setShortLabel("x") .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); assertExpectException( NullPointerException.class, "Intent must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id") .setActivity( new ComponentName(getTestContext().getPackageName(), "s")) .setTitle("x").build() .enforceMandatoryFields()); IllegalStateException.class, "package name mismatch", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName("xxx", "s")) .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( IllegalStateException.class, "package name mismatch", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName("xxx", "s")) .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); } public void testShortcutInfoParcel() { Loading services/tests/shortcutmanagerutils/src/com/android/server/pm/shortcutmanagertest/ShortcutManagerTestUtils.java +3 −2 Original line number Diff line number Diff line Loading @@ -289,8 +289,6 @@ public class ShortcutManagerTestUtils { String expectedExceptionMessageRegex, Runnable r) { try { r.run(); Assert.fail("Expected exception type " + expectedExceptionType.getName() + " was not thrown (message=" + message + ")"); } catch (Throwable e) { Assert.assertTrue( "Expected exception type was " + expectedExceptionType.getName() Loading @@ -299,7 +297,10 @@ public class ShortcutManagerTestUtils { if (expectedExceptionMessageRegex != null) { MoreAsserts.assertContainsRegex(expectedExceptionMessageRegex, e.getMessage()); } return; // Pass } Assert.fail("Expected exception type " + expectedExceptionType.getName() + " was not thrown"); } public static List<ShortcutInfo> assertShortcutIds(List<ShortcutInfo> actualShortcuts, Loading Loading
core/java/android/content/pm/ShortcutInfo.java +2 −2 Original line number Diff line number Diff line Loading @@ -254,9 +254,9 @@ public final class ShortcutInfo implements Parcelable { */ public void enforceMandatoryFields() { Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided"); Preconditions.checkNotNull(mActivity, "activity must be provided"); Preconditions.checkNotNull(mActivity, "Activity must be provided"); if (mTitle == null && mTitleResId == 0) { throw new IllegalArgumentException("Shortcut title must be provided"); throw new IllegalArgumentException("Short label must be provided"); } Preconditions.checkNotNull(mIntent, "Shortcut Intent must be provided"); } Loading
services/core/java/com/android/server/pm/ShortcutPackage.java +1 −1 Original line number Diff line number Diff line Loading @@ -908,7 +908,7 @@ class ShortcutPackage extends ShortcutPackageItem { if (operation != ShortcutService.OPERATION_UPDATE) { // This method may be called before validating shortcuts, so this may happen, // and is a caller side error. throw new NullPointerException("activity must be provided"); throw new NullPointerException("Activity must be provided"); } continue; // Activity can be null for update. } Loading
services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -697,6 +697,10 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { return getInstrumentation().getContext(); } protected ShortcutManager getManager() { return mManager; } protected void deleteAllSavedFiles() { // Empty the data directory. if (mInjectedFilePathRoot.exists()) { Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java +64 −21 Original line number Diff line number Diff line Loading @@ -56,35 +56,78 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { // ShortcutInfo tests public void testShortcutInfoMissingMandatoryFields() { // Disable throttling. mService.updateConfigurationLocked( ShortcutService.ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=99999999," + ShortcutService.ConfigConstants.KEY_MAX_SHORTCUTS + "=99999999" ); assertExpectException( IllegalArgumentException.class, "ID must be provided", () -> new ShortcutInfo.Builder(getTestContext()).build()); assertExpectException( NullPointerException.class, "Intent action must be set", assertExpectException(NullPointerException.class, "Intent action must be set", () -> new ShortcutInfo.Builder(getTestContext()).setIntent(new Intent())); assertExpectException(NullPointerException.class, "Activity must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()).setId("id").build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( NullPointerException.class, "activity must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id").build() .enforceMandatoryFields()); IllegalArgumentException.class, "Short label must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( IllegalArgumentException.class, "title must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id") .setActivity( new ComponentName(getTestContext().getPackageName(), "s")) .build() .enforceMandatoryFields()); IllegalArgumentException.class, "Short label must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); assertExpectException(NullPointerException.class, "Intent must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .setShortLabel("x") .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException(NullPointerException.class, "Intent must be provided", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName(getTestContext().getPackageName(), "s")) .setShortLabel("x") .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); assertExpectException( NullPointerException.class, "Intent must be provided", () -> new ShortcutInfo.Builder(getTestContext()).setId("id") .setActivity( new ComponentName(getTestContext().getPackageName(), "s")) .setTitle("x").build() .enforceMandatoryFields()); IllegalStateException.class, "package name mismatch", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName("xxx", "s")) .build(); assertTrue(getManager().setDynamicShortcuts(list(si))); }); assertExpectException( IllegalStateException.class, "package name mismatch", () -> { ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()) .setId("id") .setActivity(new ComponentName("xxx", "s")) .build(); assertTrue(getManager().addDynamicShortcuts(list(si))); }); } public void testShortcutInfoParcel() { Loading
services/tests/shortcutmanagerutils/src/com/android/server/pm/shortcutmanagertest/ShortcutManagerTestUtils.java +3 −2 Original line number Diff line number Diff line Loading @@ -289,8 +289,6 @@ public class ShortcutManagerTestUtils { String expectedExceptionMessageRegex, Runnable r) { try { r.run(); Assert.fail("Expected exception type " + expectedExceptionType.getName() + " was not thrown (message=" + message + ")"); } catch (Throwable e) { Assert.assertTrue( "Expected exception type was " + expectedExceptionType.getName() Loading @@ -299,7 +297,10 @@ public class ShortcutManagerTestUtils { if (expectedExceptionMessageRegex != null) { MoreAsserts.assertContainsRegex(expectedExceptionMessageRegex, e.getMessage()); } return; // Pass } Assert.fail("Expected exception type " + expectedExceptionType.getName() + " was not thrown"); } public static List<ShortcutInfo> assertShortcutIds(List<ShortcutInfo> actualShortcuts, Loading