Search in sources :

Example 91 with Nullable

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

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 92 with Nullable

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

the class PrintDocument method getData.

/**
     * Gets the data associated with this document.
     * <p>
     * <strong>Note: </strong> It is a responsibility of the client to open a
     * stream to the returned file descriptor, fully read the data, and close
     * the file descriptor.
     * </p>
     *
     * @return A file descriptor for reading the data.
     */
@Nullable
public ParcelFileDescriptor getData() {
    PrintService.throwIfNotCalledOnMainThread();
    ParcelFileDescriptor source = null;
    ParcelFileDescriptor sink = null;
    try {
        ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
        source = fds[0];
        sink = fds[1];
        mPrintServiceClient.writePrintJobData(sink, mPrintJobId);
        return source;
    } catch (IOException ioe) {
        Log.e(LOG_TAG, "Error calling getting print job data!", ioe);
    } catch (RemoteException re) {
        Log.e(LOG_TAG, "Error calling getting print job data!", re);
    } finally {
        if (sink != null) {
            try {
                sink.close();
            } catch (IOException ioe) {
            /* ignore */
            }
        }
    }
    return null;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) RemoteException(android.os.RemoteException) Nullable(android.annotation.Nullable)

Example 93 with Nullable

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

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

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

the class CryptoHelper method decryptBundle.

@Nullable
/* default */
Bundle decryptBundle(@NonNull Bundle bundle) throws GeneralSecurityException {
    Preconditions.checkNotNull(bundle, "Cannot decrypt null bundle.");
    byte[] iv = bundle.getByteArray(KEY_IV);
    byte[] encryptedBytes = bundle.getByteArray(KEY_CIPHER);
    byte[] mac = bundle.getByteArray(KEY_MAC);
    if (!verifyMac(encryptedBytes, iv, mac)) {
        Log.w(TAG, "Escrow mac mismatched!");
        return null;
    }
    IvParameterSpec ivSpec = new IvParameterSpec(iv);
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, mEncryptionKey, ivSpec);
    byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
    Parcel decryptedParcel = Parcel.obtain();
    decryptedParcel.unmarshall(decryptedBytes, 0, decryptedBytes.length);
    decryptedParcel.setDataPosition(0);
    Bundle decryptedBundle = new Bundle();
    decryptedBundle.readFromParcel(decryptedParcel);
    decryptedParcel.recycle();
    return decryptedBundle;
}
Also used : Parcel(android.os.Parcel) Bundle(android.os.Bundle) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) Nullable(android.annotation.Nullable)

Example 95 with Nullable

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

the class UserState method getPrintServices.

@Nullable
public List<PrintServiceInfo> getPrintServices(int selectionFlags) {
    synchronized (mLock) {
        List<PrintServiceInfo> selectedServices = null;
        final int installedServiceCount = mInstalledServices.size();
        for (int i = 0; i < installedServiceCount; i++) {
            PrintServiceInfo installedService = mInstalledServices.get(i);
            ComponentName componentName = new ComponentName(installedService.getResolveInfo().serviceInfo.packageName, installedService.getResolveInfo().serviceInfo.name);
            // Update isEnabled under the same lock the final returned list is created
            installedService.setIsEnabled(mActiveServices.containsKey(componentName));
            if (installedService.isEnabled()) {
                if ((selectionFlags & PrintManager.ENABLED_SERVICES) == 0) {
                    continue;
                }
            } else {
                if ((selectionFlags & PrintManager.DISABLED_SERVICES) == 0) {
                    continue;
                }
            }
            if (selectedServices == null) {
                selectedServices = new ArrayList<>();
            }
            selectedServices.add(installedService);
        }
        return selectedServices;
    }
}
Also used : PrintServiceInfo(android.printservice.PrintServiceInfo) ComponentName(android.content.ComponentName) 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