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.upgrade; 17 18 import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list; 19 20 import android.content.Intent; 21 import android.content.pm.ShortcutInfo; 22 import android.content.pm.cts.shortcut.device.common.ShortcutManagerDeviceTestBase; 23 import android.graphics.drawable.Icon; 24 import android.os.PersistableBundle; 25 import android.test.suitebuilder.annotation.SmallTest; 26 import android.util.Log; 27 28 import junit.framework.AssertionFailedError; 29 30 @SmallTest 31 public class ShortcutManagerPreUpgradeTest extends ShortcutManagerDeviceTestBase { 32 public void testPreUpgrade() { 33 Log.i(Consts.TAG, "Pre: ResIDs=" + R.drawable.black_32x32 + ", " + R.drawable.black_64x64); 34 35 // Publish shortcuts with drawable icons. 36 final Icon icon1 = Icon.createWithResource(getContext(), R.drawable.black_32x32); 37 final Icon icon2 = Icon.createWithResource(getContext(), R.drawable.black_64x64); 38 39 // Store the original resource ID in the extras. 40 final PersistableBundle b1 = new PersistableBundle(); 41 b1.putInt(Consts.EXTRA_ICON_RES_ID, R.drawable.black_32x32); 42 final ShortcutInfo s1 = new ShortcutInfo.Builder(getContext(), "s1") 43 .setShortLabel("shortlabel1") 44 .setIcon(icon1) 45 .setIntents(new Intent[]{new Intent(Intent.ACTION_VIEW)}) 46 .setExtras(b1) 47 .build(); 48 49 final PersistableBundle b2 = new PersistableBundle(); 50 b2.putInt(Consts.EXTRA_ICON_RES_ID, R.drawable.black_64x64); 51 final ShortcutInfo s2 = new ShortcutInfo.Builder(getContext(), "s2") 52 .setShortLabel("shortlabel2") 53 .setIcon(icon2) 54 .setIntents(new Intent[]{new Intent(Intent.ACTION_VIEW)}) 55 .setExtras(b2) 56 .build(); 57 58 assertTrue(getManager().setDynamicShortcuts(list(s1, s2))); 59 60 // Set this package as a default launcher to access LauncherApps. 61 Launcher.setAsDefaultLauncher(getInstrumentation(), getContext()); 62 63 // Check the published icons as a launcher. 64 assertIconDimensions(getContext().getPackageName(), "s1", icon1); 65 assertIconDimensions(getContext().getPackageName(), "s2", icon2); 66 67 // Paranoid: this should fail. 68 boolean notThrown = false; 69 try { 70 assertIconDimensions(getContext().getPackageName(), "s1", icon2); 71 notThrown = true; 72 } catch (AssertionFailedError expected) { 73 // okay 74 } 75 assertFalse(notThrown); 76 } 77 } 78