Merge \"Make sure re-published dynamic shortcuts are always enabled\" into nyc-mr1-dev
am: 7df9ce075f
Change-Id: I91802afbc807abbd07d75b0aa26adda240ba4082
This commit is contained in:
@@ -255,9 +255,6 @@ class ShortcutPackage extends ShortcutPackageItem {
|
|||||||
oldShortcut.ensureUpdatableWith(newShortcut);
|
oldShortcut.ensureUpdatableWith(newShortcut);
|
||||||
|
|
||||||
wasPinned = oldShortcut.isPinned();
|
wasPinned = oldShortcut.isPinned();
|
||||||
if (!oldShortcut.isEnabled()) {
|
|
||||||
newShortcut.addFlags(ShortcutInfo.FLAG_DISABLED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it was originally pinned, the new one should be pinned too.
|
// If it was originally pinned, the new one should be pinned too.
|
||||||
@@ -1422,12 +1419,12 @@ class ShortcutPackage extends ShortcutPackageItem {
|
|||||||
// Verify each shortcut's status.
|
// Verify each shortcut's status.
|
||||||
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
|
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
|
||||||
final ShortcutInfo si = mShortcuts.valueAt(i);
|
final ShortcutInfo si = mShortcuts.valueAt(i);
|
||||||
if (!(si.isManifestShortcut() || si.isDynamic() || si.isPinned())) {
|
if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned())) {
|
||||||
failed = true;
|
failed = true;
|
||||||
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
|
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
|
||||||
+ " is not manifest, dynamic or pinned.");
|
+ " is not manifest, dynamic or pinned.");
|
||||||
}
|
}
|
||||||
if (si.isManifestShortcut() && si.isDynamic()) {
|
if (si.isDeclaredInManifest() && si.isDynamic()) {
|
||||||
failed = true;
|
failed = true;
|
||||||
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
|
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId()
|
||||||
+ " is both dynamic and manifest at the same time.");
|
+ " is both dynamic and manifest at the same time.");
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.doAnswer;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -1381,15 +1382,21 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
|
|||||||
assertNotNull(launchShortcutAndGetIntent_withShortcutInfo(packageName, shortcutId, userId));
|
assertNotNull(launchShortcutAndGetIntent_withShortcutInfo(packageName, shortcutId, userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Fix all tests using it.
|
|
||||||
protected void assertShortcutNotLaunchable(@NonNull String packageName,
|
protected void assertShortcutNotLaunchable(@NonNull String packageName,
|
||||||
@NonNull String shortcutId, int userId) {
|
@NonNull String shortcutId, int userId) {
|
||||||
|
reset(mServiceContext);
|
||||||
try {
|
try {
|
||||||
mLauncherApps.startShortcut(packageName, shortcutId, null, null,
|
mLauncherApps.startShortcut(packageName, shortcutId, null, null,
|
||||||
UserHandle.of(userId));
|
UserHandle.of(userId));
|
||||||
} catch (SecurityException expected) {
|
} 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) {
|
protected void assertBitmapDirectories(int userId, String... expectedDirectories) {
|
||||||
|
|||||||
@@ -1602,8 +1602,6 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
|||||||
/**
|
/**
|
||||||
* This is similar to the above test, except it used "disable" instead of "remove". It also
|
* This is similar to the above test, except it used "disable" instead of "remove". It also
|
||||||
* does "enable".
|
* does "enable".
|
||||||
*
|
|
||||||
* TODO Fix the commented out tests.
|
|
||||||
*/
|
*/
|
||||||
public void testDisableAndEnableShortcuts() {
|
public void testDisableAndEnableShortcuts() {
|
||||||
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
|
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
|
||||||
@@ -1677,17 +1675,14 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
|||||||
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
|
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
|
||||||
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
|
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
|
||||||
"s2");
|
"s2");
|
||||||
// assertFalse(mLauncherApps.startShortcut(
|
assertShortcutNotLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
|
||||||
// CALLING_PACKAGE_1, "s2", null, null, HANDLE_USER_0));
|
|
||||||
|
|
||||||
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(
|
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(
|
||||||
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2,
|
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_2,
|
||||||
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))),
|
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser()))),
|
||||||
"s3", "s4");
|
"s3", "s4");
|
||||||
// assertFalse(mLauncherApps.startShortcut(
|
assertShortcutNotLaunchable(CALLING_PACKAGE_2, "s3", USER_0);
|
||||||
// CALLING_PACKAGE_2, "s3", null, null, HANDLE_USER_0));
|
assertShortcutLaunchable(CALLING_PACKAGE_2, "s4", USER_0);
|
||||||
// assertTrue(mLauncherApps.startShortcut(
|
|
||||||
// CALLING_PACKAGE_2, "s4", null, null, HANDLE_USER_0));
|
|
||||||
|
|
||||||
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(
|
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(
|
||||||
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_3,
|
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_3,
|
||||||
@@ -1707,8 +1702,77 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
|||||||
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
|
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
|
||||||
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
|
/* activity =*/ null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))),
|
||||||
"s2");
|
"s2");
|
||||||
// assertTrue(mLauncherApps.startShortcut(
|
assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
|
||||||
// CALLING_PACKAGE_1, "s2", null, null, HANDLE_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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,11 @@ package com.android.server.pm.shortcutmanagertest;
|
|||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static junit.framework.Assert.assertNotNull;
|
||||||
import static junit.framework.Assert.assertNotSame;
|
|
||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Matchers.anyList;
|
import static org.mockito.Matchers.anyList;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
@@ -50,11 +48,9 @@ import android.os.ParcelFileDescriptor;
|
|||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.test.MoreAsserts;
|
import android.test.MoreAsserts;
|
||||||
import android.util.ArraySet;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
import org.hamcrest.BaseMatcher;
|
import org.hamcrest.BaseMatcher;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
|
|||||||
Reference in New Issue
Block a user