Search in sources :

Example 96 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by crdroidandroid.

the class KeySetManagerServiceTest method testAddDefinedKSToPackageOrthoUpgrAliasSame.

/* upgrd defined keyset ortho but reuse alias (make sure old is removed and
     * alias points to new keyset)
     */
public void testAddDefinedKSToPackageOrthoUpgrAliasSame() throws ReflectiveOperationException {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    /* now upgrade to different set w/same alias as before */
    keys = new ArraySet<PublicKey>();
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    keys.add(keyB);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
    assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    ArraySet<Long> mapping = ksMapping.get(2);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(2)));
    assertNotNull(ps.keySetData.getAliases().get("aliasA"));
    assertEquals(new Long(2), ps.keySetData.getAliases().get("aliasA"));
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 97 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by crdroidandroid.

the class KeySetManagerServiceTest method testAddUpgradeKSToPackageDisappear.

/* upgrade from defined keysets w/upgrade to different defined keysets and
     * make sure the previously specified upgrade keyset has been removed. */
public void testAddUpgradeKSToPackageDisappear() {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    ArraySet<String> upgradeKS = new ArraySet<String>();
    upgradeKS.add("aliasA");
    mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
    keys = new ArraySet<PublicKey>();
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    keys.add(keyB);
    definedKS.remove("aliasA");
    definedKS.put("aliasB", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    assertNull(ps.keySetData.getUpgradeKeySets());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 98 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by crdroidandroid.

the class KeySetManagerServiceTest method testAddDefinedKSToPackageOrthoUpgr.

/* upgrd defined keyset ortho (make sure previous is removed for pkg) */
public void testAddDefinedKSToPackageOrthoUpgr() throws ReflectiveOperationException {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    /* now upgrade to different defined key-set */
    keys = new ArraySet<PublicKey>();
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    keys.add(keyB);
    definedKS.remove("aliasA");
    definedKS.put("aliasB", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
    assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    ArraySet<Long> mapping = ksMapping.get(2);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(2)));
    assertNull(ps.keySetData.getAliases().get("aliasA"));
    assertNotNull(ps.keySetData.getAliases().get("aliasB"));
    assertEquals(new Long(2), ps.keySetData.getAliases().get("aliasB"));
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 99 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by crdroidandroid.

the class KeySetManagerServiceTest method testRemoveAppKSDataDefined.

/* remove package which used defined and upgrade keysets and ensure  removed */
public void testRemoveAppKSDataDefined() throws ReflectiveOperationException {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    /* removal requires signing keyset to be specified (since all apps are
         * assumed to have it).  We skipped this in the defined tests, but can't
         * here. */
    mKsms.addSigningKeySetToPackageLPw(ps, keys);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    ArraySet<String> upgradeKS = new ArraySet<String>();
    upgradeKS.add("aliasA");
    mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
    mKsms.removeAppKeySetDataLPw(ps.name);
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(0, ksMapping.size());
    assertEquals(PackageKeySetData.KEYSET_UNASSIGNED, ps.keySetData.getProperSigningKeySet());
    assertEquals(0, ps.keySetData.getAliases().size());
    assertNull(ps.keySetData.getUpgradeKeySets());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 100 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by crdroidandroid.

the class KeySetManagerServiceTest method testEncodePublicKey.

public void testEncodePublicKey() throws IOException {
    ArrayMap<String, PackageSetting> packagesMap = new ArrayMap<String, PackageSetting>();
    KeySetManagerService ksms = new KeySetManagerService(packagesMap);
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
    assertEquals(ksms.encodePublicKey(keyA), KeySetStrings.ctsKeySetPublicKeyA);
    assertEquals(ksms.encodePublicKey(keyB), KeySetStrings.ctsKeySetPublicKeyB);
    assertEquals(ksms.encodePublicKey(keyC), KeySetStrings.ctsKeySetPublicKeyC);
}
Also used : PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Aggregations

ArrayMap (android.util.ArrayMap)365 ArraySet (android.util.ArraySet)77 ArrayList (java.util.ArrayList)75 PublicKey (java.security.PublicKey)49 HashMap (java.util.HashMap)32 Preference (android.support.v7.preference.Preference)30 IOException (java.io.IOException)30 Map (java.util.Map)29 HashSet (java.util.HashSet)28 Intent (android.content.Intent)24 Test (org.junit.Test)24 ComponentName (android.content.ComponentName)22 RemoteException (android.os.RemoteException)22 Field (java.lang.reflect.Field)21 Activity (android.app.Activity)20 SparseArray (android.util.SparseArray)18 List (java.util.List)18 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 Point (android.graphics.Point)17 Method (java.lang.reflect.Method)17