oldShortcut.ensureUpdatableWith(newShortcut);
wasPinned = oldShortcut.isPinned();
- if (!oldShortcut.isEnabled()) {
- newShortcut.addFlags(ShortcutInfo.FLAG_DISABLED);
- }
}
- // TODO Check max dynamic count.
- // mShortcutUser.mService.enforceMaxDynamicShortcuts(newDynamicCount);
-
// If it was originally pinned, the new one should be pinned too.
if (wasPinned) {
newShortcut.addFlags(ShortcutInfo.FLAG_PINNED);
// Verify each shortcut's status.
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
final ShortcutInfo si = mShortcuts.valueAt(i);
- if (!(si.isManifestShortcut() || si.isDynamic() || si.isPinned())) {
+ if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned())) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
+ " is not manifest, dynamic or pinned.");
}
- if (si.isManifestShortcut() && si.isDynamic()) {
+ if (si.isDeclaredInManifest() && si.isDynamic()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
+ " is both dynamic and manifest at the same time.");
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
assertNotNull(launchShortcutAndGetIntent_withShortcutInfo(packageName, shortcutId, userId));
}
- // TODO Fix all tests using it.
protected void assertShortcutNotLaunchable(@NonNull String packageName,
@NonNull String shortcutId, int userId) {
+ reset(mServiceContext);
try {
mLauncherApps.startShortcut(packageName, shortcutId, null, null,
UserHandle.of(userId));
} catch (SecurityException expected) {
- // security exception is okay too.
+ // security exception is okay.
+ return;
}
+ // This shouldn't have been called.
+ verify(mServiceContext, times(0)).startActivityAsUser(
+ any(Intent.class),
+ any(Bundle.class),
+ any(UserHandle.class));
}
protected void assertBitmapDirectories(int userId, String... expectedDirectories) {
/**
* This is similar to the above test, except it used "disable" instead of "remove". It also
* does "enable".
- *
- * TODO Fix the commented out tests.
*/
public void testDisableAndEnableShortcuts() {
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
"s2");
-// assertFalse(mLauncherApps.startShortcut(
-// CALLING_PACKAGE_1, "s2", null, null, HANDLE_USER_0));
+ assertShortcutNotLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2,
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))),
"s3", "s4");
-// assertFalse(mLauncherApps.startShortcut(
-// CALLING_PACKAGE_2, "s3", null, null, HANDLE_USER_0));
-// assertTrue(mLauncherApps.startShortcut(
-// CALLING_PACKAGE_2, "s4", null, null, HANDLE_USER_0));
+ assertShortcutNotLaunchable(CALLING_PACKAGE_2, "s3", USER_0);
+ assertShortcutLaunchable(CALLING_PACKAGE_2, "s4", USER_0);
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_3,
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
"s2");
-// assertTrue(mLauncherApps.startShortcut(
-// CALLING_PACKAGE_1, "s2", null, null, HANDLE_USER_0));
+ assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
+ });
+ }
+
+ public void testDisableShortcuts_thenRepublish() {
+ runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+
+ runWithCaller(LAUNCHER_1, USER_0, () -> {
+ mLauncherApps.pinShortcuts(
+ CALLING_PACKAGE_1, list("s1", "s2", "s3"), HANDLE_USER_0);
+ });
+
+ mManager.disableShortcuts(list("s1", "s2", "s3"));
+
+ assertWith(getCallerShortcuts())
+ .haveIds("s1", "s2", "s3")
+ .areAllNotDynamic()
+ .areAllPinned()
+ .areAllDisabled();
+
+ // Make sure updateShortcuts() will not re-enable them.
+ assertTrue(mManager.updateShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+
+ assertWith(getCallerShortcuts())
+ .haveIds("s1", "s2", "s3")
+ .areAllNotDynamic()
+ .areAllPinned()
+ .areAllDisabled();
+
+ // Re-publish s1 with setDynamicShortcuts.
+ mInjectedCurrentTimeMillis += INTERVAL; // reset throttling
+
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"))));
+
+ assertWith(getCallerShortcuts())
+ .haveIds("s1", "s2", "s3")
+
+ .selectByIds("s1")
+ .areAllDynamic()
+ .areAllPinned()
+ .areAllEnabled()
+
+ .revertToOriginalList()
+ .selectByIds("s2", "s3")
+ .areAllNotDynamic()
+ .areAllPinned()
+ .areAllDisabled();
+
+ // Re-publish s2 with addDynamicShortcuts.
+ mInjectedCurrentTimeMillis += INTERVAL; // reset throttling
+
+ assertTrue(mManager.addDynamicShortcuts(list(
+ makeShortcut("s2"))));
+
+ assertWith(getCallerShortcuts())
+ .haveIds("s1", "s2", "s3")
+
+ .selectByIds("s1", "s2")
+ .areAllDynamic()
+ .areAllPinned()
+ .areAllEnabled()
+
+ .revertToOriginalList()
+ .selectByIds("s3")
+ .areAllNotDynamic()
+ .areAllPinned()
+ .areAllDisabled();
});
}
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.test.MoreAsserts;
-import android.util.ArraySet;
import android.util.Log;
import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;