Search in sources :

Example 36 with Nullable

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

the class Resources_Delegate method getArrayResourceValue.

/**
     * Try to find the ArrayResourceValue for the given id.
     * <p/>
     * If the ResourceValue found is not of type {@link ResourceType#ARRAY}, the method logs an
     * error and return null. However, if the ResourceValue found has type {@code
     * ResourceType.ARRAY}, but the value is not an instance of {@link ArrayResourceValue}, the
     * method returns the ResourceValue. This happens on older versions of the IDE, which did not
     * parse the array resources properly.
     * <p/>
     *
     * @throws NotFoundException if no resource if found
     */
@Nullable
private static ResourceValue getArrayResourceValue(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> v = getResourceValue(resources, id, mPlatformResourceFlag);
    if (v != null) {
        ResourceValue resValue = v.getSecond();
        assert resValue != null;
        if (resValue != null) {
            final ResourceType type = resValue.getResourceType();
            if (type != ResourceType.ARRAY) {
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE, String.format("Resource with id 0x%1$X is not an array resource, but %2$s", id, type == null ? "null" : type.getDisplayName()), null);
                return null;
            }
            if (!(resValue instanceof ArrayResourceValue)) {
                Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, "Obtaining resource arrays via getTextArray, getStringArray or getIntArray is not fully supported in this version of the IDE.", null);
            }
            return resValue;
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return null;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) ResourceType(com.android.resources.ResourceType) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) Nullable(android.annotation.Nullable)

Example 37 with Nullable

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

the class Activity method getReferrer.

/**
     * Return information about who launched this activity.  If the launching Intent
     * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER},
     * that will be returned as-is; otherwise, if known, an
     * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the
     * package name that started the Intent will be returned.  This may return null if no
     * referrer can be identified -- it is neither explicitly specified, nor is it known which
     * application package was involved.
     *
     * <p>If called while inside the handling of {@link #onNewIntent}, this function will
     * return the referrer that submitted that new intent to the activity.  Otherwise, it
     * always returns the referrer of the original Intent.</p>
     *
     * <p>Note that this is <em>not</em> a security feature -- you can not trust the
     * referrer information, applications can spoof it.</p>
     */
@Nullable
public Uri getReferrer() {
    Intent intent = getIntent();
    try {
        Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
        if (referrer != null) {
            return referrer;
        }
        String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME);
        if (referrerName != null) {
            return Uri.parse(referrerName);
        }
    } catch (BadParcelableException e) {
        Log.w(TAG, "Cannot read referrer from intent;" + " intent extras contain unknown custom Parcelable objects");
    }
    if (mReferrer != null) {
        return new Uri.Builder().scheme("android-app").authority(mReferrer).build();
    }
    return null;
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) BadParcelableException(android.os.BadParcelableException) Nullable(android.annotation.Nullable)

Example 38 with Nullable

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

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 39 with Nullable

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

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)

Example 40 with Nullable

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

the class ShortcutParser method parseShortcuts.

@Nullable
public static List<ShortcutInfo> parseShortcuts(ShortcutService service, String packageName, @UserIdInt int userId) throws IOException, XmlPullParserException {
    if (ShortcutService.DEBUG) {
        Slog.d(TAG, String.format("Scanning package %s for manifest shortcuts on user %d", packageName, userId));
    }
    final List<ResolveInfo> activities = service.injectGetMainActivities(packageName, userId);
    if (activities == null || activities.size() == 0) {
        return null;
    }
    List<ShortcutInfo> result = null;
    try {
        final int size = activities.size();
        for (int i = 0; i < size; i++) {
            final ActivityInfo activityInfoNoMetadata = activities.get(i).activityInfo;
            if (activityInfoNoMetadata == null) {
                continue;
            }
            final ActivityInfo activityInfoWithMetadata = service.getActivityInfoWithMetadata(activityInfoNoMetadata.getComponentName(), userId);
            if (activityInfoWithMetadata != null) {
                result = parseShortcutsOneFile(service, activityInfoWithMetadata, packageName, userId, result);
            }
        }
    } catch (RuntimeException e) {
        // Resource ID mismatch may cause various runtime exceptions when parsing XMLs,
        // But we don't crash the device, so just swallow them.
        service.wtf("Exception caught while parsing shortcut XML for package=" + packageName, e);
        return null;
    }
    return result;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) Nullable(android.annotation.Nullable)

Aggregations

Nullable (android.annotation.Nullable)368 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 FileNotFoundException (java.io.FileNotFoundException)28 File (java.io.File)26 Resources (android.content.res.Resources)25 Implementation (org.robolectric.annotation.Implementation)25 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)24 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)24 Configuration (android.content.res.Configuration)22 ResourcesImpl (android.content.res.ResourcesImpl)20 Drawable (android.graphics.drawable.Drawable)20 TypedArray (android.content.res.TypedArray)17 ByteBuffer (java.nio.ByteBuffer)16 ComponentName (android.content.ComponentName)15 ResolveInfo (android.content.pm.ResolveInfo)15 NotFoundException (android.content.res.Resources.NotFoundException)15