Search in sources :

Example 51 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class CryptoHelper method createMac.

@NonNull
private byte[] createMac(@NonNull byte[] cipher, @NonNull byte[] iv) throws GeneralSecurityException {
    Mac mac = Mac.getInstance(MAC_ALGORITHM);
    mac.init(mMacKey);
    mac.update(cipher);
    mac.update(iv);
    return mac.doFinal();
}
Also used : Mac(javax.crypto.Mac) NonNull(android.annotation.NonNull)

Example 52 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class AndroidKeyStoreProvider method getAndroidKeyStorePublicKey.

@NonNull
public static AndroidKeyStorePublicKey getAndroidKeyStorePublicKey(@NonNull String alias, int uid, @NonNull @KeyProperties.KeyAlgorithmEnum String keyAlgorithm, @NonNull byte[] x509EncodedForm) {
    PublicKey publicKey;
    try {
        KeyFactory keyFactory = KeyFactory.getInstance(keyAlgorithm);
        publicKey = keyFactory.generatePublic(new X509EncodedKeySpec(x509EncodedForm));
    } catch (NoSuchAlgorithmException e) {
        throw new ProviderException("Failed to obtain " + keyAlgorithm + " KeyFactory", e);
    } catch (InvalidKeySpecException e) {
        throw new ProviderException("Invalid X.509 encoding of public key", e);
    }
    if (KeyProperties.KEY_ALGORITHM_EC.equalsIgnoreCase(keyAlgorithm)) {
        return new AndroidKeyStoreECPublicKey(alias, uid, (ECPublicKey) publicKey);
    } else if (KeyProperties.KEY_ALGORITHM_RSA.equalsIgnoreCase(keyAlgorithm)) {
        return new AndroidKeyStoreRSAPublicKey(alias, uid, (RSAPublicKey) publicKey);
    } else {
        throw new ProviderException("Unsupported Android Keystore public key algorithm: " + keyAlgorithm);
    }
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) ProviderException(java.security.ProviderException) NoSuchProviderException(java.security.NoSuchProviderException) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKey(java.security.PublicKey) ECPublicKey(java.security.interfaces.ECPublicKey) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory) NonNull(android.annotation.NonNull)

Example 53 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class ConditionProviders method loadComponentNamesFromSetting.

@Override
@NonNull
protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName, int userId) {
    final ContentResolver cr = mContext.getContentResolver();
    String settingValue = Settings.Secure.getStringForUser(cr, settingName, userId);
    if (TextUtils.isEmpty(settingValue))
        return new ArraySet<>();
    String[] packages = settingValue.split(ENABLED_SERVICES_SEPARATOR);
    ArraySet<ComponentName> result = new ArraySet<>(packages.length);
    for (int i = 0; i < packages.length; i++) {
        if (!TextUtils.isEmpty(packages[i])) {
            final ComponentName component = ComponentName.unflattenFromString(packages[i]);
            if (component != null) {
                result.addAll(queryPackageForServices(component.getPackageName(), userId));
            } else {
                result.addAll(queryPackageForServices(packages[i], userId));
            }
        }
    }
    return result;
}
Also used : ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName) ContentResolver(android.content.ContentResolver) NonNull(android.annotation.NonNull)

Example 54 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class ManagedServices method loadComponentNamesFromSetting.

@NonNull
protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName, int userId) {
    final ContentResolver cr = mContext.getContentResolver();
    String settingValue = Settings.Secure.getStringForUser(cr, settingName, userId);
    if (TextUtils.isEmpty(settingValue))
        return new ArraySet<>();
    String[] restored = settingValue.split(ENABLED_SERVICES_SEPARATOR);
    ArraySet<ComponentName> result = new ArraySet<>(restored.length);
    for (int i = 0; i < restored.length; i++) {
        ComponentName value = ComponentName.unflattenFromString(restored[i]);
        if (null != value) {
            result.add(value);
        }
    }
    return result;
}
Also used : ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName) ContentResolver(android.content.ContentResolver) NonNull(android.annotation.NonNull)

Example 55 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.

the class DefaultPermissionGrantPolicy method readDefaultPermissionExceptionsLPw.

@NonNull
private ArrayMap<String, List<DefaultPermissionGrant>> readDefaultPermissionExceptionsLPw() {
    File dir = new File(Environment.getRootDirectory(), "etc/default-permissions");
    if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
        return new ArrayMap<>(0);
    }
    File[] files = dir.listFiles();
    if (files == null) {
        return new ArrayMap<>(0);
    }
    ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>();
    // Iterate over the files in the directory and scan .xml files
    for (File file : files) {
        if (!file.getPath().endsWith(".xml")) {
            Slog.i(TAG, "Non-xml file " + file + " in " + dir + " directory, ignoring");
            continue;
        }
        if (!file.canRead()) {
            Slog.w(TAG, "Default permissions file " + file + " cannot be read");
            continue;
        }
        try (InputStream str = new BufferedInputStream(new FileInputStream(file))) {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(str, null);
            parse(parser, grantExceptions);
        } catch (XmlPullParserException | IOException e) {
            Slog.w(TAG, "Error reading default permissions file " + file, e);
        }
    }
    return grantExceptions;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayMap(android.util.ArrayMap) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) ArrayList(java.util.ArrayList) List(java.util.List) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)322 ArrayList (java.util.ArrayList)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)35 ComponentName (android.content.ComponentName)25 File (java.io.File)22 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 FileNotFoundException (java.io.FileNotFoundException)15 Paint (android.graphics.Paint)14 PackageParser (android.content.pm.PackageParser)12 ContentResolver (android.content.ContentResolver)10 UserInfo (android.content.pm.UserInfo)10 StorageManager (android.os.storage.StorageManager)10 VolumeInfo (android.os.storage.VolumeInfo)10 KeyCharacteristics (android.security.keymaster.KeyCharacteristics)10