1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.content.pm.cts.shortcut.backup.launcher1; 17 18 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith; 19 20 import android.content.pm.ShortcutInfo; 21 import android.content.pm.cts.shortcut.device.common.ShortcutManagerDeviceTestBase; 22 23 public class ShortcutManagerPostBackupTest extends ShortcutManagerDeviceTestBase { 24 @Override 25 protected void setUp() throws Exception { 26 super.setUp(); 27 28 setAsDefaultLauncher(MainActivity.class); 29 } 30 31 public void testWithUninstall_beforeAppRestore() { 32 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER1_PKG)).isEmpty(); 33 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER2_PKG)).isEmpty(); 34 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER3_PKG)).isEmpty(); 35 } 36 37 public void testWithUninstall_afterAppRestore() { 38 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER1_PKG)) 39 .haveIds("ms1", "ms2", "s1") 40 .areAllEnabled() 41 42 .selectByIds("s1", "ms1") 43 .areAllPinned() 44 45 .revertToOriginalList() 46 .selectByIds("ms2") 47 .areAllNotPinned(); 48 49 // Note s3 and ms2 were disabled before backup, so they were not backed up. 50 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER2_PKG)) 51 .haveIds("ms1", "ms2", "s1", "s2") 52 .areAllEnabled() 53 54 .selectByIds("s1", "s2") 55 .areAllPinned() 56 57 .revertToOriginalList() 58 .selectByIds("ms1") 59 .areAllNotPinned(); 60 61 // Package3 doesn't support backup&restore. 62 // However, the manifest-shortcuts will be republished anyway, so they're still pinned. 63 // The dynamic shortcuts can't be restored, but we'll still restore them as disabled 64 // shortcuts that are not visible to the publisher. 65 assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER3_PKG)) 66 .haveIds("ms1", "ms2", "s1", "s2") 67 .areAllPinned() 68 69 .selectByIds("ms1", "ms2") 70 .areAllEnabled() 71 .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_NOT_DISABLED) 72 73 .revertToOriginalList() 74 .selectByIds("s1", "s2") 75 .areAllDisabled() 76 .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED) 77 ; 78 } 79 } 80