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