Search in sources :

Example 46 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_forBackup_resId.

public void testShortcutInfoSaveAndLoad_forBackup_resId() {
    setCaller(CALLING_PACKAGE_1, USER_0);
    final Icon res32x32 = Icon.createWithResource(mClientContext, R.drawable.black_32x32);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIcon(res32x32).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
    ShortcutInfo sorig2 = new ShortcutInfo.Builder(mClientContext).setId("id2").setTitle("x").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(456).build();
    mManager.addDynamicShortcuts(list(sorig, sorig2));
    // Dynamic shortcuts won't be backed up, so we need to pin it.
    setCaller(LAUNCHER_1, USER_0);
    mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("id", "id2"), HANDLE_USER_0);
    // Do backup & restore.
    backupAndRestore();
    // Load user-0.
    mService.handleUnlockUser(USER_0);
    ShortcutInfo si;
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_0);
    assertEquals(CALLING_PACKAGE_1, si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(0, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
    // No icon.
    assertNull(si.getBitmapPath());
    assertEquals(0, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    // Note when restored from backup, it's no longer dynamic, so shouldn't have a rank.
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_0);
    assertEquals(0, si.getRank());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 47 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class ShortcutManagerTest2 method testShortcutInfoClone_resId.

public void testShortcutInfoClone_resId() {
    setCaller(CALLING_PACKAGE_1, USER_11);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
    sorig.addFlags(ShortcutInfo.FLAG_PINNED);
    sorig.setBitmapPath("abc");
    sorig.setIconResourceId(456);
    lookupAndFillInResourceNames(sorig);
    ShortcutInfo si = sorig.clone(/* clone flags*/
    0);
    assertEquals(USER_11, si.getUserId());
    assertEquals(HANDLE_USER_11, si.getUserHandle());
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(123, si.getIcon().getResId());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals("abc", si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals("string/r456", si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(null, si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(0, si.getRank());
    assertEquals(null, si.getExtras());
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_KEY_FIELDS_ONLY, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 48 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class ShortcutManagerTest2 method testShortcutInfoClone_minimum.

public void testShortcutInfoClone_minimum() {
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(getTestContext()).setId("id").setTitle("title").setIntent(makeIntent("action", ShortcutActivity.class)).build();
    ShortcutInfo si = sorig.clone(/* clone flags*/
    0);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals(null, si.getIntent());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(null, si.getTitle());
    assertEquals(null, si.getIntent());
    assertEquals(null, si.getCategories());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo)

Example 49 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_forBackup.

public void testShortcutInfoSaveAndLoad_forBackup() {
    setCaller(CALLING_PACKAGE_1, USER_0);
    final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource(getTestContext().getResources(), R.drawable.black_32x32));
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIcon(bmp32x32).setTitle("title").setText("text").setDisabledMessage("dismes").setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
    ShortcutInfo sorig2 = new ShortcutInfo.Builder(mClientContext).setId("id2").setTitle("x").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(456).build();
    mManager.addDynamicShortcuts(list(sorig, sorig2));
    // Dynamic shortcuts won't be backed up, so we need to pin it.
    setCaller(LAUNCHER_1, USER_0);
    mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("id", "id2"), HANDLE_USER_0);
    // Do backup & restore.
    backupAndRestore();
    // Load user-0.
    mService.handleUnlockUser(USER_0);
    ShortcutInfo si;
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_0);
    assertEquals(CALLING_PACKAGE_1, si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName());
    assertEquals(null, si.getIcon());
    assertEquals("title", si.getTitle());
    assertEquals("text", si.getText());
    assertEquals("dismes", si.getDisabledMessage());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(0, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
    // No icon.
    assertNull(si.getBitmapPath());
    assertEquals(0, si.getIconResourceId());
    // Note when restored from backup, it's no longer dynamic, so shouldn't have a rank.
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_0);
    assertEquals(0, si.getRank());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 50 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class ShortcutManagerTest2 method testShortcutInfoParcel.

public void testShortcutInfoParcel() {
    setCaller(CALLING_PACKAGE_1, USER_10);
    ShortcutInfo si = parceled(new ShortcutInfo.Builder(mClientContext).setId("id").setTitle("title").setIntent(makeIntent("action", ShortcutActivity.class)).build());
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals(USER_10, si.getUserId());
    assertEquals(HANDLE_USER_10, si.getUserHandle());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    si = new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitle("title").setText("text").setDisabledMessage("dismes").setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setRank(123).setExtras(pb).build();
    si.addFlags(ShortcutInfo.FLAG_PINNED);
    si.setBitmapPath("abc");
    si.setIconResourceId(456);
    si = parceled(si);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(123, si.getIcon().getResId());
    assertEquals("title", si.getTitle());
    assertEquals("text", si.getText());
    assertEquals("dismes", si.getDisabledMessage());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals("abc", si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Aggregations

PersistableBundle (android.os.PersistableBundle)321 CarrierConfigManager (android.telephony.CarrierConfigManager)87 ComponentName (android.content.ComponentName)67 Intent (android.content.Intent)63 ShortcutInfo (android.content.pm.ShortcutInfo)48 Test (org.junit.Test)35 Bundle (android.os.Bundle)28 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)25 IOException (java.io.IOException)21 Icon (android.graphics.drawable.Icon)17 JobInfo (android.app.job.JobInfo)15 IntentFilter (android.content.IntentFilter)15 Account (android.accounts.Account)14 Activity (android.app.Activity)12 TelephonyManager (android.telephony.TelephonyManager)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 XmlPullParser (org.xmlpull.v1.XmlPullParser)12 Before (org.junit.Before)11 PendingIntent (android.app.PendingIntent)9 PackageManager (android.content.pm.PackageManager)9