Home | History | Annotate | Download | only in launcher4
      1 /*
      2  * Copyright (C) 2017 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.launcher4;
     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 testRestoredOnOldVersion() {
     32         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
     33                 .haveIds("ms1", "ms2", "s1", "s2")
     34                 .areAllPinned()
     35 
     36                 .selectByIds("ms1", "ms2")
     37                 .areAllEnabled()
     38                 .areAllManifest()
     39 
     40                 // s1 is re-published, so it's enabled and dynamic.
     41                 .revertToOriginalList()
     42                 .selectByIds("s1")
     43                 .areAllEnabled()
     44                 .areAllDynamic()
     45                 .forAllShortcuts(si -> {
     46                     assertEquals("shortlabel1_new_one", si.getShortLabel());
     47 
     48                     // The app re-published the shortcut, not updated, so the fields that existed
     49                     // in the original shortcut is gone now.
     50                     assertNull(si.getExtras());
     51                 })
     52 
     53                 .revertToOriginalList()
     54                 .selectByIds("s2")
     55                 .areAllDisabled()
     56                 .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_VERSION_LOWER)
     57                 .forAllShortcuts(si -> {
     58                     // Note the label shouldn't be updated with the updateShortcuts() call.
     59                     assertEquals("shortlabel2", si.getShortLabel());
     60                 })
     61                 .areAllNotDynamic();
     62     }
     63 
     64     public void testRestoredOnNewVersion() {
     65         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
     66                 .haveIds("ms1", "ms2", "s1", "s2")
     67                 .areAllPinned()
     68 
     69                 .selectByIds("ms1", "ms2")
     70                 .areAllEnabled()
     71                 .areAllManifest()
     72 
     73                 // s1 is re-published, so it's enabled and dynamic.
     74                 .revertToOriginalList()
     75                 .selectByIds("s1", "s2")
     76                 .areAllEnabled()
     77 
     78                 .revertToOriginalList()
     79                 .selectByIds("s1")
     80                 .areAllDynamic()
     81                 .forAllShortcuts(si -> {
     82                     assertEquals("shortlabel1_new_one", si.getShortLabel());
     83 
     84                     // The app re-published the shortcut, not updated, so the fields that existed
     85                     // in the original shortcut is gone now.
     86                     assertNull(si.getExtras());
     87                 })
     88 
     89                 .revertToOriginalList()
     90                 .selectByIds("s2")
     91                 .areAllNotDynamic()
     92                 .forAllShortcuts(si -> {
     93                     assertEquals("shortlabel2_updated", si.getShortLabel());
     94                 })
     95                 ;
     96     }
     97 
     98 
     99     public void testRestoreWrongKey() {
    100         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
    101                 .haveIds("ms1", "ms2", "s1", "s2")
    102                 .areAllPinned()
    103 
    104                 .selectByIds("ms1", "ms2")
    105                 .areAllEnabled()
    106                 .areAllManifest()
    107 
    108                 // s1 is re-published, so it's enabled and dynamic.
    109                 .revertToOriginalList()
    110                 .selectByIds("s1")
    111                 .areAllEnabled()
    112                 .areAllDynamic()
    113                 .forAllShortcuts(si -> {
    114                     assertEquals("shortlabel1_new_one", si.getShortLabel());
    115 
    116                     // The app re-published the shortcut, not updated, so the fields that existed
    117                     // in the original shortcut is gone now.
    118                     assertNull(si.getExtras());
    119                 })
    120 
    121 
    122                 // updateShortcuts() shouldn't work on it, so it keeps the original label.
    123                 .revertToOriginalList()
    124                 .selectByIds("s2")
    125                 .areAllNotDynamic()
    126                 .forAllShortcuts(si -> {
    127                     assertEquals("shortlabel2", si.getShortLabel());
    128                 })
    129         ;
    130     }
    131 
    132     public void testRestoreNoManifestOnOldVersion() {
    133         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
    134                 .haveIds("ms1", "ms2", "s1", "s2")
    135                 .areAllPinned()
    136 
    137                 .selectByIds("s1", "ms1")
    138                 .areAllEnabled()
    139                 .areAllDynamic()
    140                 .areAllMutable()
    141 
    142                 .revertToOriginalList()
    143                 .selectByIds("s2", "ms2")
    144                 .areAllDisabled();
    145     }
    146 
    147     public void testRestoreNoManifestOnNewVersion() {
    148         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
    149                 .haveIds("ms1", "ms2", "s1", "s2")
    150                 .areAllPinned()
    151 
    152                 .selectByIds("ms1", "ms2")
    153                 .areAllDisabled()
    154                 .areAllImmutable()
    155                 .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_APP_CHANGED)
    156 
    157                 .revertToOriginalList()
    158                 .selectByIds("s1", "s2")
    159                 .areAllEnabled()
    160                 .areAllMutable();
    161     }
    162 
    163     public void testInvisibleIgnored() {
    164         assertWith(getPackageShortcuts(ShortcutManagerPreBackupTest.PUBLISHER4_PKG))
    165                 .haveIds("ms1", "ms2", "s1", "s2")
    166 
    167                 .selectByIds("ms1", "s1", "s2")
    168                 .areAllPinned()
    169                 .areAllDisabled()
    170                 .areAllWithDisabledReason(ShortcutInfo.DISABLED_REASON_VERSION_LOWER)
    171                 .areAllNotDynamic()
    172                 .areAllNotManifest()
    173 
    174                 .revertToOriginalList()
    175                 .selectByIds("ms2")
    176                 .areAllEnabled()
    177                 .areAllPinned()
    178                 .areAllNotDynamic()
    179                 .areAllNotManifest();
    180     }
    181 }
    182