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);
}
}
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);
}
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;
}
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();
}
}
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));
}
}
Aggregations