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.publisher2; 17 18 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith; 19 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list; 20 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makePersistableBundle; 21 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.set; 22 23 import android.content.Intent; 24 import android.content.pm.ShortcutInfo; 25 import android.content.pm.cts.shortcut.device.common.ShortcutManagerDeviceTestBase; 26 import android.graphics.BitmapFactory; 27 import android.graphics.drawable.Icon; 28 import android.test.suitebuilder.annotation.SmallTest; 29 30 @SmallTest 31 public class ShortcutManagerPreBackupTest extends ShortcutManagerDeviceTestBase { 32 public void testPreBackup() { 33 final Icon icon1 = Icon.createWithBitmap(BitmapFactory.decodeResource( 34 getContext().getResources(), R.drawable.black_16x64)); 35 final Icon icon3 = Icon.createWithResource(getContext(), R.drawable.black_64x16); 36 37 final ShortcutInfo s1 = new ShortcutInfo.Builder(getContext(), "s1") 38 .setShortLabel("shortlabel1") 39 .setLongLabel("longlabel1") 40 .setIcon(icon1) 41 .setActivity(getActivity("MainActivity2")) 42 .setDisabledMessage("disabledmessage1") 43 .setIntents(new Intent[]{new Intent("view").putExtra("k1", "v1")}) 44 .setExtras(makePersistableBundle("ek1", "ev1")) 45 .setCategories(set("cat1")) 46 .build(); 47 48 final ShortcutInfo s2 = new ShortcutInfo.Builder(getContext(), "s2") 49 .setShortLabel("shortlabel2") 50 .setActivity(getActivity("MainActivity2")) 51 .setIntents(new Intent[]{new Intent("main")}) 52 .build(); 53 54 final ShortcutInfo s3 = new ShortcutInfo.Builder(getContext(), "s3") 55 .setShortLabel("shortlabel2") 56 .setIcon(icon3) 57 .setActivity(getActivity("MainActivity2")) 58 .setIntents(new Intent[]{new Intent("main")}) 59 .build(); 60 61 assertTrue(getManager().setDynamicShortcuts(list(s1, s2, s3))); 62 63 assertWith(getManager().getDynamicShortcuts()) 64 .haveIds("s1", "s2", "s3") 65 .areAllNotPinned(); 66 67 assertWith(getManager().getManifestShortcuts()) 68 .haveIds("ms1", "ms2") 69 .areAllNotPinned() 70 // Note MainActivity2 have manifest shortcuts too, but because of the ID overlap, 71 // they're ignored at this point. 72 .areAllWithActivity(getActivity("MainActivity")); 73 } 74 } 75