diff options
| author | 2016-07-12 22:11:54 +0000 | |
|---|---|---|
| committer | 2016-07-12 22:11:54 +0000 | |
| commit | bc15e3ca2bf0ea00a9401c9c2cedb80a3ec175f7 (patch) | |
| tree | c6634258c6dae9280dd6572e6191ebb3c974f7c1 | |
| parent | d0c3bc327d3e90486a67dd0ef3e9e8bb5bbbab58 (diff) | |
| parent | 4885b274c1502b8e478e16d4418b7fd86ab6c865 (diff) | |
Merge \"Don\'t backup & restore disabled shortcuts.\" into nyc-mr1-dev
am: 4885b274c1
Change-Id: I23c46fa144ac1b4989a4cd93cf442b812c7d1324
3 files changed, 209 insertions, 73 deletions
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index 1a4e4e0ad80b..b94d0f0dbd1c 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -1185,8 +1185,8 @@ class ShortcutPackage extends ShortcutPackageItem { private static void saveShortcut(XmlSerializer out, ShortcutInfo si, boolean forBackup) throws IOException, XmlPullParserException { if (forBackup) { - if (!si.isPinned()) { - return; // Backup only pinned icons. + if (!(si.isPinned() && si.isEnabled())) { + return; // We only backup pinned shortcuts that are enabled. } } out.startTag(null, TAG_SHORTCUT); diff --git a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java index 3d68b591c26f..01c19d0ca12b 100644 --- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java @@ -1480,12 +1480,30 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { return new File(si.getBitmapPath()).getName(); } + /** + * @return all shortcuts stored internally for the caller. This reflects the *internal* view + * of shortcuts, which may be different from what {@link #getCallerVisibleShortcuts} would + * return, because getCallerVisibleShortcuts() will get shortcuts from the proper "front door" + * which performs some extra checks, like {@link ShortcutPackage#onRestored}. + */ protected List<ShortcutInfo> getCallerShortcuts() { final ShortcutPackage p = mService.getPackageShortcutForTest( getCallingPackage(), getCallingUserId()); return p == null ? null : p.getAllShortcutsForTest(); } + /** + * @return all shortcuts owned by caller that are actually visible via ShortcutManager. + * See also {@link #getCallerShortcuts}. + */ + protected List<ShortcutInfo> getCallerVisibleShortcuts() { + final ArrayList<ShortcutInfo> ret = new ArrayList<>(); + ret.addAll(mManager.getDynamicShortcuts()); + ret.addAll(mManager.getPinnedShortcuts()); + ret.addAll(mManager.getManifestShortcuts()); + return ret; + } + protected ShortcutInfo getCallerShortcut(String shortcutId) { return getPackageShortcut(getCallingPackage(), shortcutId, getCallingUserId()); } @@ -1696,6 +1714,8 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2", "s5"), HANDLE_USER_P0); }); + + // Note LAUNCHER_3 has allowBackup=false. runWithCaller(LAUNCHER_3, USER_0, () -> { mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0); mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s3", "s4"), HANDLE_USER_0); diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java index aa1072e14726..c7673d17424d 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -4635,8 +4635,10 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { final ShortcutUser user0 = mService.getUserShortcutsLocked(USER_0); assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_1)); assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_2)); - assertExistsAndShadow(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_1))); - assertExistsAndShadow(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_2))); + assertExistsAndShadow(user0.getAllLaunchersForTest().get( + PackageWithUser.of(USER_0, LAUNCHER_1))); + assertExistsAndShadow(user0.getAllLaunchersForTest().get( + PackageWithUser.of(USER_0, LAUNCHER_2))); assertNull(user0.getAllPackagesForTest().get(CALLING_PACKAGE_3)); assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_3))); @@ -4644,90 +4646,98 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { installPackage(USER_0, CALLING_PACKAGE_1); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertShortcutIds(assertAllPinned( - mManager.getPinnedShortcuts()), - "s1", "s2"); + assertWith(getCallerVisibleShortcuts()) + .selectDynamic() + .isEmpty() + + .revertToOriginalList() + .selectPinned() + .haveIds("s1", "s2"); }); installPackage(USER_0, LAUNCHER_1); runWithCaller(LAUNCHER_1, USER_0, () -> { - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), - "s1"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) - /* empty, not restored */ ); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) - /* empty, not restored */ ); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s1"); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); - assertEquals(0, mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0).size()); + assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) + .isEmpty(); }); installPackage(USER_0, CALLING_PACKAGE_2); runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertShortcutIds(assertAllPinned( - mManager.getPinnedShortcuts()), - "s1", "s2", "s3"); + assertWith(getCallerVisibleShortcuts()) + .selectDynamic() + .isEmpty() + + .revertToOriginalList() + .selectPinned() + .haveIds("s1", "s2", "s3"); }); runWithCaller(LAUNCHER_1, USER_0, () -> { - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), - "s1"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)), - "s1", "s2"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) - /* empty, not restored */ ); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s1"); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s1", "s2"); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); - assertEquals(0, mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0).size()); + assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) + .isEmpty(); }); // 3 shouldn't be backed up, so no pinned shortcuts. installPackage(USER_0, CALLING_PACKAGE_3); runWithCaller(CALLING_PACKAGE_3, USER_0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertEquals(0, mManager.getPinnedShortcuts().size()); + assertWith(getCallerVisibleShortcuts()) + .isEmpty(); }); // Launcher on a different profile shouldn't be restored. runWithCaller(LAUNCHER_1, USER_P0, () -> { - assertEquals(0, - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0) - .size()); - assertEquals(0, - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0) - .size()); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) - /* wasn't restored, so still empty */ ); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .isEmpty(); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .isEmpty(); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); }); // Package on a different profile, no restore. installPackage(USER_P0, CALLING_PACKAGE_1); runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertEquals(0, mManager.getPinnedShortcuts().size()); + assertWith(getCallerVisibleShortcuts()) + .isEmpty(); }); // Restore launcher 2 on user 0. installPackage(USER_0, LAUNCHER_2); runWithCaller(LAUNCHER_2, USER_0, () -> { - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), - "s2"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)), - "s2", "s3"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) - /* wasn't restored, so still empty */ ); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s2"); - assertEquals(0, mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0).size()); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s2", "s3"); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) + .isEmpty(); }); @@ -4735,33 +4745,33 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { // make sure they still have the same result. installPackage(USER_0, CALLING_PACKAGE_1); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertShortcutIds(assertAllPinned( - mManager.getPinnedShortcuts()), - "s1", "s2"); + assertWith(getCallerVisibleShortcuts()) + .areAllPinned() + .haveIds("s1", "s2"); }); installPackage(USER_0, LAUNCHER_1); runWithCaller(LAUNCHER_1, USER_0, () -> { - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)), - "s1"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)), - "s1", "s2"); - assertShortcutIds(assertAllPinned( - mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) - /* wasn't restored, so still empty */ ); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s1"); - assertEquals(0, mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0).size()); + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .areAllPinned() + .haveIds("s1", "s2"); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) + .isEmpty(); }); installPackage(USER_0, CALLING_PACKAGE_2); runWithCaller(CALLING_PACKAGE_2, USER_0, () -> { - assertEquals(0, mManager.getDynamicShortcuts().size()); - assertShortcutIds(assertAllPinned( - mManager.getPinnedShortcuts()), - "s1", "s2", "s3"); + assertWith(getCallerVisibleShortcuts()) + .areAllPinned() + .haveIds("s1", "s2", "s3"); }); } @@ -5082,6 +5092,112 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); } + public void testBackupAndRestore_disabled() { + prepareCrossProfileDataSet(); + + // Before doing backup & restore, disable s1. + runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { + mManager.disableShortcuts(list("s1")); + }); + + backupAndRestore(); + + // Below is copied from checkBackupAndRestore_success. + + // Make sure non-system user is not restored. + final ShortcutUser userP0 = mService.getUserShortcutsLocked(USER_P0); + assertEquals(0, userP0.getAllPackagesForTest().size()); + assertEquals(0, userP0.getAllLaunchersForTest().size()); + + // Make sure only "allowBackup" apps are restored, and are shadow. + final ShortcutUser user0 = mService.getUserShortcutsLocked(USER_0); + assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_1)); + assertExistsAndShadow(user0.getAllPackagesForTest().get(CALLING_PACKAGE_2)); + assertExistsAndShadow(user0.getAllLaunchersForTest().get( + PackageWithUser.of(USER_0, LAUNCHER_1))); + assertExistsAndShadow(user0.getAllLaunchersForTest().get( + PackageWithUser.of(USER_0, LAUNCHER_2))); + + assertNull(user0.getAllPackagesForTest().get(CALLING_PACKAGE_3)); + assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_0, LAUNCHER_3))); + assertNull(user0.getAllLaunchersForTest().get(PackageWithUser.of(USER_P0, LAUNCHER_1))); + + installPackage(USER_0, CALLING_PACKAGE_1); + runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { + assertWith(getCallerVisibleShortcuts()) + .areAllEnabled() // disabled shortcuts shouldn't be restored. + + .selectDynamic() + .isEmpty() + + .revertToOriginalList() + .selectPinned() + // s1 is not restored. + .haveIds("s2"); + }); + + installPackage(USER_0, LAUNCHER_1); + runWithCaller(LAUNCHER_1, USER_0, () -> { + // Note, s1 was pinned by launcher 1, but was disabled, so isn't restored. + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_1), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_2), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(buildAllQuery(CALLING_PACKAGE_3), HANDLE_USER_0)) + .isEmpty(); + + assertWith(mLauncherApps.getShortcuts(QUERY_ALL, HANDLE_USER_P0)) + .isEmpty(); + }); + } + + + public void testBackupAndRestore_manifestNotRestored() { + // Publish two manifest shortcuts. + addManifestShortcutResource( + new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), + R.xml.shortcut_2); + updatePackageVersion(CALLING_PACKAGE_1, 1); + mInternal.onPackageBroadcast( + genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); + + // Pin from launcher 1. + runWithCaller(LAUNCHER_1, USER_0, () -> { + mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms1", "ms2"), HANDLE_USER_0); + }); + + // Update and now ms2 is gone -> disabled. + addManifestShortcutResource( + new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), + R.xml.shortcut_1); + updatePackageVersion(CALLING_PACKAGE_1, 1); + mInternal.onPackageBroadcast( + genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); + + // Make sure the manifest shortcuts have been published. + runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { + assertWith(getCallerShortcuts()) + .areAllPinned() + .haveIds("ms1", "ms2") + + .selectByIds("ms1") + .areAllManifest() + .areAllEnabled() + + .revertToOriginalList() + .selectByIds("ms2") + .areAllNotManifest() + .areAllDisabled(); + }); + + // Now do the regular backup & restore test. + // The existence of the manifest shortcuts shouldn't affect the result. + prepareCrossProfileDataSet(); + backupAndRestore(); + } + public void testSaveAndLoad_crossProfile() { prepareCrossProfileDataSet(); |