Merge \"Make sure re-published dynamic shortcuts are always enabled\" into nyc-mr1-dev

am: 7df9ce075f

Change-Id: I91802afbc807abbd07d75b0aa26adda240ba4082
This commit is contained in:
Makoto Onuki
2016-07-01 16:50:59 +00:00
committed by android-build-merger
4 changed files with 85 additions and 21 deletions

View File

@@ -255,9 +255,6 @@ class ShortcutPackage extends ShortcutPackageItem {
oldShortcut.ensureUpdatableWith(newShortcut);
wasPinned = oldShortcut.isPinned();
if (!oldShortcut.isEnabled()) {
newShortcut.addFlags(ShortcutInfo.FLAG_DISABLED);
}
}
// 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.
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.");

View File

@@ -29,6 +29,7 @@ import static org.mockito.Mockito.doAnswer;
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;
@@ -1381,15 +1382,21 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
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) {

View File

@@ -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
* does "enable".
*
* TODO Fix the commented out tests.
*/
public void testDisableAndEnableShortcuts() {
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
@@ -1677,17 +1675,14 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
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,
@@ -1707,8 +1702,77 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
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();
});
}

View File

@@ -18,13 +18,11 @@ package com.android.server.pm.shortcutmanagertest;
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;
@@ -50,11 +48,9 @@ import android.os.ParcelFileDescriptor;
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;