Search in sources :

Example 1 with ArrayMap

use of android.util.ArrayMap in project buck by facebook.

the class ResourcesLoader method getActiveResourcesFromResourcesManager.

private static Collection<WeakReference<Resources>> getActiveResourcesFromResourcesManager() {
    try {
        Class resourcesManagerClass;
        try {
            resourcesManagerClass = Class.forName("android.app.ResourcesManager");
        } catch (ClassNotFoundException e) {
            return null;
        }
        Method getResourcesManager = resourcesManagerClass.getDeclaredMethod("getInstance");
        getResourcesManager.setAccessible(true);
        Object resourcesManager = getResourcesManager.invoke(null);
        try {
            return ((ArrayMap<?, WeakReference<Resources>>) Reflect.getField(resourcesManager, resourcesManagerClass, "mActiveResources")).values();
        } catch (NoSuchFieldException e) {
            return (Collection<WeakReference<Resources>>) Reflect.getField(resourcesManager, resourcesManagerClass, "mResourceReferences");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) ArrayMap(android.util.ArrayMap) Method(java.lang.reflect.Method) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 2 with ArrayMap

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

the class ApkSignatureSchemeV2Verifier method verify.

/**
     * Verifies the contents of the provided APK file against the provided APK Signature Scheme v2
     * Block.
     *
     * @param signatureInfo APK Signature Scheme v2 Block and information relevant for verifying it
     *        against the APK file.
     */
private static X509Certificate[][] verify(FileDescriptor apkFileDescriptor, SignatureInfo signatureInfo) throws SecurityException {
    int signerCount = 0;
    Map<Integer, byte[]> contentDigests = new ArrayMap<>();
    List<X509Certificate[]> signerCerts = new ArrayList<>();
    CertificateFactory certFactory;
    try {
        certFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("Failed to obtain X.509 CertificateFactory", e);
    }
    ByteBuffer signers;
    try {
        signers = getLengthPrefixedSlice(signatureInfo.signatureBlock);
    } catch (IOException e) {
        throw new SecurityException("Failed to read list of signers", e);
    }
    while (signers.hasRemaining()) {
        signerCount++;
        try {
            ByteBuffer signer = getLengthPrefixedSlice(signers);
            X509Certificate[] certs = verifySigner(signer, contentDigests, certFactory);
            signerCerts.add(certs);
        } catch (IOException | BufferUnderflowException | SecurityException e) {
            throw new SecurityException("Failed to parse/verify signer #" + signerCount + " block", e);
        }
    }
    if (signerCount < 1) {
        throw new SecurityException("No signers found");
    }
    if (contentDigests.isEmpty()) {
        throw new SecurityException("No content digests found");
    }
    verifyIntegrity(contentDigests, apkFileDescriptor, signatureInfo.apkSigningBlockOffset, signatureInfo.centralDirOffset, signatureInfo.eocdOffset, signatureInfo.eocd);
    return signerCerts.toArray(new X509Certificate[signerCerts.size()][]);
}
Also used : ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) DirectByteBuffer(java.nio.DirectByteBuffer) ByteBuffer(java.nio.ByteBuffer) X509Certificate(java.security.cert.X509Certificate) BigInteger(java.math.BigInteger) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 3 with ArrayMap

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

the class CaptivePortalLoginActivity method setWebViewProxy.

// Find WebView's proxy BroadcastReceiver and prompt it to read proxy system properties.
private void setWebViewProxy() {
    LoadedApk loadedApk = getApplication().mLoadedApk;
    try {
        Field receiversField = LoadedApk.class.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(rec, getApplicationContext(), intent);
                    Log.v(TAG, "Prompting WebView proxy reload.");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception while setting WebView proxy: " + e);
    }
}
Also used : Field(java.lang.reflect.Field) LoadedApk(android.app.LoadedApk) ArrayMap(android.util.ArrayMap) Intent(android.content.Intent) Method(java.lang.reflect.Method) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InterruptedException(java.lang.InterruptedException)

Example 4 with ArrayMap

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

the class KeySetManagerServiceTest method testAddDefinedKSToPackageThree.

/* add defined keyset, remove it, add again and make sure diff id. */
public void testAddDefinedKSToPackageThree() 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> keys1 = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys1.add(keyA);
    definedKS.put("aliasA", keys1);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    /* now upgrade to different set */
    ArraySet<PublicKey> keys2 = new ArraySet<PublicKey>();
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    keys2.add(keyB);
    definedKS.remove("aliasA");
    definedKS.put("aliasB", keys2);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    /* upgrade back to original */
    definedKS.remove("aliasB");
    definedKS.put("aliasA", keys1);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 2));
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 3));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 2));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 3));
    assertEquals(keyA, KeySetUtils.getPubKey(mKsms, 3));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    ArraySet<Long> mapping = ksMapping.get(3);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(3)));
    assertEquals(new Long(3), ps.keySetData.getAliases().get("aliasA"));
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 5 with ArrayMap

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

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)

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