Search in sources :

Example 76 with Nullable

use of android.annotation.Nullable in project android_frameworks_base by AOSPA.

the class ContentResolver method insert.

/**
     * Inserts a row into a table at the given URL.
     *
     * If the content provider supports transactions the insertion will be atomic.
     *
     * @param url The URL of the table to insert into.
     * @param values The initial values for the newly inserted row. The key is the column name for
     *               the field. Passing an empty ContentValues will create an empty row.
     * @return the URL of the newly created row.
     */
@Nullable
public final Uri insert(@RequiresPermission.Write @NonNull Uri url, @Nullable ContentValues values) {
    android.util.SeempLog.record_uri(37, url);
    Preconditions.checkNotNull(url, "url");
    IContentProvider provider = acquireProvider(url);
    if (provider == null) {
        throw new IllegalArgumentException("Unknown URL " + url);
    }
    try {
        long startTime = SystemClock.uptimeMillis();
        Uri createdRow = provider.insert(mPackageName, url, values);
        long durationMillis = SystemClock.uptimeMillis() - startTime;
        maybeLogUpdateToEventLog(durationMillis, url, "insert", null);
        return createdRow;
    } catch (RemoteException e) {
        // Manager will kill this process shortly anyway.
        return null;
    } finally {
        releaseProvider(provider);
    }
}
Also used : RemoteException(android.os.RemoteException) Uri(android.net.Uri) Nullable(android.annotation.Nullable)

Example 77 with Nullable

use of android.annotation.Nullable in project android_frameworks_base by AOSPA.

the class PackageUtils method computeSha256Digest.

/**
     * Computes the SHA256 digest of some data.
     * @param data The data.
     * @return The digest or null if an error occurs.
     */
@Nullable
public static String computeSha256Digest(@NonNull byte[] data) {
    MessageDigest messageDigest;
    try {
        messageDigest = MessageDigest.getInstance("SHA256");
    } catch (NoSuchAlgorithmException e) {
        /* can't happen */
        return null;
    }
    messageDigest.update(data);
    final byte[] digest = messageDigest.digest();
    final int digestLength = digest.length;
    final int charCount = 2 * digestLength;
    final char[] chars = new char[charCount];
    for (int i = 0; i < digestLength; i++) {
        final int byteHex = digest[i] & 0xFF;
        chars[i * 2] = HEX_ARRAY[byteHex >>> 4];
        chars[i * 2 + 1] = HEX_ARRAY[byteHex & 0x0F];
    }
    return new String(chars);
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) Nullable(android.annotation.Nullable)

Example 78 with Nullable

use of android.annotation.Nullable in project android_frameworks_base by AOSPA.

the class ProgressBar method getTintTarget.

/**
     * Returns the drawable to which a tint or tint mode should be applied.
     *
     * @param layerId id of the layer to modify
     * @param shouldFallback whether the base drawable should be returned
     *                       if the id does not exist
     * @return the drawable to modify
     */
@Nullable
private Drawable getTintTarget(int layerId, boolean shouldFallback) {
    Drawable layer = null;
    final Drawable d = mProgressDrawable;
    if (d != null) {
        mProgressDrawable = d.mutate();
        if (d instanceof LayerDrawable) {
            layer = ((LayerDrawable) d).findDrawableByLayerId(layerId);
        }
        if (shouldFallback && layer == null) {
            layer = d;
        }
    }
    return layer;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Nullable(android.annotation.Nullable)

Example 79 with Nullable

use of android.annotation.Nullable in project android_frameworks_base by AOSPA.

the class KeyChain method getCertificateChain.

/**
     * Returns the {@code X509Certificate} chain for the requested
     * alias, or null if there is no result.
     * <p>
     * <strong>Note:</strong> If a certificate chain was explicitly specified when the alias was
     * installed, this method will return that chain. If only the client certificate was specified
     * at the installation time, this method will try to build a certificate chain using all
     * available trust anchors (preinstalled and user-added).
     *
     * <p> This method may block while waiting for a connection to another process, and must never
     * be called from the main thread.
     * <p> As {@link Activity} and {@link Service} contexts are short-lived and can be destroyed
     * at any time from the main thread, it is safer to rely on a long-lived context such as one
     * returned from {@link Context#getApplicationContext()}.
     *
     * @param alias The alias of the desired certificate chain, typically
     * returned via {@link KeyChainAliasCallback#alias}.
     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
     * @throws IllegalStateException if called from the main thread.
     */
@Nullable
@WorkerThread
public static X509Certificate[] getCertificateChain(@NonNull Context context, @NonNull String alias) throws KeyChainException, InterruptedException {
    if (alias == null) {
        throw new NullPointerException("alias == null");
    }
    KeyChainConnection keyChainConnection = bind(context.getApplicationContext());
    try {
        IKeyChainService keyChainService = keyChainConnection.getService();
        final byte[] certificateBytes = keyChainService.getCertificate(alias);
        if (certificateBytes == null) {
            return null;
        }
        X509Certificate leafCert = toCertificate(certificateBytes);
        final byte[] certChainBytes = keyChainService.getCaCertificates(alias);
        // DevicePolicyManager.installKeyPair or CertInstaller, return that chain.
        if (certChainBytes != null && certChainBytes.length != 0) {
            Collection<X509Certificate> chain = toCertificates(certChainBytes);
            ArrayList<X509Certificate> fullChain = new ArrayList<>(chain.size() + 1);
            fullChain.add(leafCert);
            fullChain.addAll(chain);
            return fullChain.toArray(new X509Certificate[fullChain.size()]);
        } else {
            // If there isn't a certificate chain, either due to a pre-existing keypair
            // installed before N, or no chain is explicitly installed under the new logic,
            // fall back to old behavior of constructing the chain from trusted credentials.
            //
            // This logic exists to maintain old behaviour for already installed keypair, at
            // the cost of potentially returning extra certificate chain for new clients who
            // explicitly installed only the client certificate without a chain. The latter
            // case is actually no different from pre-N behaviour of getCertificateChain(),
            // in that sense this change introduces no regression. Besides the returned chain
            // is still valid so the consumer of the chain should have no problem verifying it.
            TrustedCertificateStore store = new TrustedCertificateStore();
            List<X509Certificate> chain = store.getCertificateChain(leafCert);
            return chain.toArray(new X509Certificate[chain.size()]);
        }
    } catch (CertificateException e) {
        throw new KeyChainException(e);
    } catch (RemoteException e) {
        throw new KeyChainException(e);
    } catch (RuntimeException e) {
        // only certain RuntimeExceptions can be propagated across the IKeyChainService call
        throw new KeyChainException(e);
    } finally {
        keyChainConnection.close();
    }
}
Also used : TrustedCertificateStore(com.android.org.conscrypt.TrustedCertificateStore) ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) RemoteException(android.os.RemoteException) WorkerThread(android.annotation.WorkerThread) Nullable(android.annotation.Nullable)

Example 80 with Nullable

use of android.annotation.Nullable in project android_frameworks_base by AOSPA.

the class MtpDatabase method getUnmappedDocumentsParent.

/**
     * Obtains a document that has already mapped but has unmapped children.
     * @param deviceId Device to find documents.
     * @return Identifier of found document or null.
     */
@Nullable
Identifier getUnmappedDocumentsParent(int deviceId) {
    final String fromClosure = TABLE_DOCUMENTS + " AS child INNER JOIN " + TABLE_DOCUMENTS + " AS parent ON " + "child." + COLUMN_PARENT_DOCUMENT_ID + " = " + "parent." + Document.COLUMN_DOCUMENT_ID;
    final String whereClosure = "parent." + COLUMN_DEVICE_ID + " = ? AND " + "parent." + COLUMN_ROW_STATE + " IN (?, ?) AND " + "parent." + COLUMN_DOCUMENT_TYPE + " != ? AND " + "child." + COLUMN_ROW_STATE + " = ?";
    try (final Cursor cursor = mDatabase.query(fromClosure, strings("parent." + COLUMN_DEVICE_ID, "parent." + COLUMN_STORAGE_ID, "parent." + COLUMN_OBJECT_HANDLE, "parent." + Document.COLUMN_DOCUMENT_ID, "parent." + COLUMN_DOCUMENT_TYPE), whereClosure, strings(deviceId, ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE, ROW_STATE_DISCONNECTED), null, null, null, "1")) {
        if (cursor.getCount() == 0) {
            return null;
        }
        cursor.moveToNext();
        return new Identifier(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), cursor.getString(3), cursor.getInt(4));
    }
}
Also used : Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) Nullable(android.annotation.Nullable)

Aggregations

Nullable (android.annotation.Nullable)313 RemoteException (android.os.RemoteException)40 Intent (android.content.Intent)39 DeadObjectException (android.os.DeadObjectException)35 ICancellationSignal (android.os.ICancellationSignal)35 IOException (java.io.IOException)29 File (java.io.File)26 Resources (android.content.res.Resources)25 FileNotFoundException (java.io.FileNotFoundException)24 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)24 Configuration (android.content.res.Configuration)20 ResourcesImpl (android.content.res.ResourcesImpl)20 Drawable (android.graphics.drawable.Drawable)20 ComponentName (android.content.ComponentName)15 NotFoundException (android.content.res.Resources.NotFoundException)15 Cursor (android.database.Cursor)15 ParcelFileDescriptor (android.os.ParcelFileDescriptor)15 TypedValue (android.util.TypedValue)15 ByteBuffer (java.nio.ByteBuffer)15 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)15