Search in sources :

Example 6 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

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 7 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class ContentProvider method openPipeHelper.

/**
     * A helper function for implementing {@link #openTypedAssetFile}, for
     * creating a data pipe and background thread allowing you to stream
     * generated data back to the client.  This function returns a new
     * ParcelFileDescriptor that should be returned to the caller (the caller
     * is responsible for closing it).
     *
     * @param uri The URI whose data is to be written.
     * @param mimeType The desired type of data to be written.
     * @param opts Options supplied by caller.
     * @param args Your own custom arguments.
     * @param func Interface implementing the function that will actually
     * stream the data.
     * @return Returns a new ParcelFileDescriptor holding the read side of
     * the pipe.  This should be returned to the caller for reading; the caller
     * is responsible for closing it when done.
     */
@NonNull
public <T> ParcelFileDescriptor openPipeHelper(@NonNull final Uri uri, @NonNull final String mimeType, @Nullable final Bundle opts, @Nullable final T args, @NonNull final PipeDataWriter<T> func) throws FileNotFoundException {
    try {
        final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
        AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>() {

            @Override
            protected Object doInBackground(Object... params) {
                func.writeDataToPipe(fds[1], uri, mimeType, opts, args);
                try {
                    fds[1].close();
                } catch (IOException e) {
                    Log.w(TAG, "Failure closing pipe", e);
                }
                return null;
            }
        };
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) null);
        return fds[0];
    } catch (IOException e) {
        throw new FileNotFoundException("failure making pipe");
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) AsyncTask(android.os.AsyncTask) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Example 8 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class KeyChain method toCertificate.

/** @hide */
@NonNull
public static X509Certificate toCertificate(@NonNull byte[] bytes) {
    if (bytes == null) {
        throw new IllegalArgumentException("bytes == null");
    }
    try {
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
        return (X509Certificate) cert;
    } catch (CertificateException e) {
        throw new AssertionError(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) NonNull(android.annotation.NonNull)

Example 9 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

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 10 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class TaskPersister method loadPersistedTaskIdsForUser.

@NonNull
SparseBooleanArray loadPersistedTaskIdsForUser(int userId) {
    if (mTaskIdsInFile.get(userId) != null) {
        return mTaskIdsInFile.get(userId).clone();
    }
    final SparseBooleanArray persistedTaskIds = new SparseBooleanArray();
    synchronized (mIoLock) {
        BufferedReader reader = null;
        String line;
        try {
            reader = new BufferedReader(new FileReader(getUserPersistedTaskIdsFile(userId)));
            while ((line = reader.readLine()) != null) {
                for (String taskIdString : line.split("\\s+")) {
                    int id = Integer.parseInt(taskIdString);
                    persistedTaskIds.put(id, true);
                }
            }
        } catch (FileNotFoundException e) {
        // File doesn't exist. Ignore.
        } catch (Exception e) {
            Slog.e(TAG, "Error while reading taskIds file for user " + userId, e);
        } finally {
            IoUtils.closeQuietly(reader);
        }
    }
    mTaskIdsInFile.put(userId, persistedTaskIds);
    return persistedTaskIds.clone();
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) 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