Search in sources :

Example 21 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by DirtyUnicorns.

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 22 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by DirtyUnicorns.

the class ShortcutManagerTest2 method testShortcutInfoCopyNonNullFieldsFrom_resId.

public void testShortcutInfoCopyNonNullFieldsFrom_resId() throws InterruptedException {
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(getTestContext()).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);
    ShortcutInfo si;
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("x", "y")).build());
    assertEquals(11, si.getTextResId());
    assertEquals(new ComponentName("x", "y"), si.getActivity());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIcon(Icon.createWithResource(mClientContext, 456)).build());
    assertEquals(11, si.getTextResId());
    assertEquals(456, si.getIcon().getResId());
    assertEquals(0, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    assertEquals(null, si.getBitmapPath());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTitle("xyz").build());
    assertEquals(11, si.getTextResId());
    assertEquals("xyz", si.getTitle());
    assertEquals(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTitleResId(123).build());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTitle());
    assertEquals(123, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setText("xxx").build());
    assertEquals(123, si.getRank());
    assertEquals("xxx", si.getText());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTextResId(1111).build());
    assertEquals(123, si.getRank());
    assertEquals(null, si.getText());
    assertEquals(1111, si.getTextResId());
    assertEquals(null, si.getTextResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setDisabledMessage("xxx").build());
    assertEquals(123, si.getRank());
    assertEquals("xxx", si.getDisabledMessage());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setDisabledMessageResId(11111).build());
    assertEquals(123, si.getRank());
    assertEquals(null, si.getDisabledMessage());
    assertEquals(11111, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setCategories(set()).build());
    assertEquals(11, si.getTextResId());
    assertEquals(set(), si.getCategories());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setCategories(set("x")).build());
    assertEquals(11, si.getTextResId());
    assertEquals(set("x"), si.getCategories());
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIntent(makeIntent("action2", ShortcutActivity.class)).build());
    assertEquals(11, si.getTextResId());
    assertEquals("action2", si.getIntent().getAction());
    assertEquals(null, si.getIntent().getStringExtra("key"));
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIntent(makeIntent("action3", ShortcutActivity.class, "key", "x")).build());
    assertEquals(11, si.getTextResId());
    assertEquals("action3", si.getIntent().getAction());
    assertEquals("x", si.getIntent().getStringExtra("key"));
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setRank(999).build());
    assertEquals(11, si.getTextResId());
    assertEquals(999, si.getRank());
    PersistableBundle pb2 = new PersistableBundle();
    pb2.putInt("x", 99);
    si = sorig.clone(/* flags=*/
    0);
    si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setExtras(pb2).build());
    assertEquals(11, si.getTextResId());
    assertEquals(99, si.getExtras().getInt("x"));
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 23 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by DirtyUnicorns.

the class ShortcutManagerTestUtils method makePersistableBundle.

public static PersistableBundle makePersistableBundle(Object... keysAndValues) {
    assertTrue((keysAndValues.length % 2) == 0);
    if (keysAndValues.length == 0) {
        return null;
    }
    final PersistableBundle ret = new PersistableBundle();
    for (int i = keysAndValues.length - 2; i >= 0; i -= 2) {
        final String key = keysAndValues[i].toString();
        final Object value = keysAndValues[i + 1];
        if (value == null) {
            ret.putString(key, null);
        } else if (value instanceof Integer) {
            ret.putInt(key, (Integer) value);
        } else if (value instanceof String) {
            ret.putString(key, (String) value);
        } else if (value instanceof PersistableBundle) {
            ret.putPersistableBundle(key, (PersistableBundle) value);
        } else {
            fail("Type not supported yet: " + value.getClass().getName());
        }
    }
    return ret;
}
Also used : PersistableBundle(android.os.PersistableBundle) JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString)

Example 24 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by DirtyUnicorns.

the class SyncOperationTest method testConversionFromExtras.

@SmallTest
public void testConversionFromExtras() {
    PersistableBundle extras = new PersistableBundle();
    SyncOperation op = SyncOperation.maybeCreateFromJobExtras(extras);
    assertTrue("Non sync operation bundle falsely converted to SyncOperation.", op == null);
}
Also used : PersistableBundle(android.os.PersistableBundle) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 25 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by DirtyUnicorns.

the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_resId.

public void testShortcutInfoSaveAndLoad_resId() throws InterruptedException {
    mRunningUsers.put(USER_10, true);
    setCaller(CALLING_PACKAGE_1, USER_10);
    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();
    sorig.setTimestamp(mInjectedCurrentTimeMillis);
    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();
    sorig2.setTimestamp(mInjectedCurrentTimeMillis);
    mManager.addDynamicShortcuts(list(sorig, sorig2));
    mInjectedCurrentTimeMillis += 1;
    final long now = mInjectedCurrentTimeMillis;
    mInjectedCurrentTimeMillis += 1;
    // Save and load.
    mService.saveDirtyInfo();
    initService();
    mService.handleUnlockUser(USER_10);
    ShortcutInfo si;
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_10);
    assertEquals(USER_10, si.getUserId());
    assertEquals(HANDLE_USER_10, si.getUserHandle());
    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_DYNAMIC | ShortcutInfo.FLAG_HAS_ICON_RES | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
    assertNull(si.getBitmapPath());
    assertEquals(R.drawable.black_32x32, si.getIconResourceId());
    assertTrue(si.getLastChangedTimestamp() < now);
    // Make sure ranks are saved too.  Because of the auto-adjusting, we need two shortcuts
    // to test it.
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_10);
    assertEquals(1, si.getRank());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

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