Search in sources :

Example 1 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 2 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 3 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 4 with Nullable

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

the class ResourceHelper method getInternalComplexColor.

/**
     * Returns a {@link ComplexColor} from the given {@link ResourceValue}
     *
     * @param resValue the value containing a color value or a file path to a complex color
     * definition
     * @param context the current context
     * @param theme the theme to use when resolving the complex color
     * @param allowGradients when false, only {@link ColorStateList} will be returned. If a {@link
     * GradientColor} is found, null will be returned.
     */
@Nullable
private static ComplexColor getInternalComplexColor(@NonNull ResourceValue resValue, @NonNull BridgeContext context, @Nullable Theme theme, boolean allowGradients) {
    String value = resValue.getValue();
    if (value == null || RenderResources.REFERENCE_NULL.equals(value)) {
        return null;
    }
    XmlPullParser parser = null;
    // first check if the value is a file (xml most likely)
    Boolean psiParserSupport = context.getLayoutlibCallback().getFlag(RenderParamsFlags.FLAG_KEY_XML_FILE_PARSER_SUPPORT);
    if (psiParserSupport != null && psiParserSupport) {
        parser = context.getLayoutlibCallback().getXmlFileParser(value);
    }
    if (parser == null) {
        File f = new File(value);
        if (f.isFile()) {
            // providing an XmlPullParser
            try {
                parser = ParserFactory.create(f);
            } catch (XmlPullParserException | FileNotFoundException e) {
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + value, e, null);
            }
        }
    }
    if (parser != null) {
        try {
            BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, context, resValue.isFramework());
            try {
                // Advance the parser to the first element so we can detect if it's a
                // color list or a gradient color
                int type;
                //noinspection StatementWithEmptyBody
                while ((type = blockParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Seek parser to start tag.
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException("No start tag found");
                }
                final String name = blockParser.getName();
                if (allowGradients && "gradient".equals(name)) {
                    return ComplexColor_Accessor.createGradientColorFromXmlInner(context.getResources(), blockParser, blockParser, theme);
                } else if ("selector".equals(name)) {
                    return ComplexColor_Accessor.createColorStateListFromXmlInner(context.getResources(), blockParser, blockParser, theme);
                }
            } finally {
                blockParser.ensurePopped();
            }
        } catch (XmlPullParserException e) {
            Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + value, e, null);
        // we'll return null below.
        } catch (Exception e) {
            // this is an error and not warning since the file existence is
            // checked before attempting to parse it.
            Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + value, e, null);
            return null;
        }
    } else {
        // try to load the color state list from an int
        try {
            int color = getColor(value);
            return ColorStateList.valueOf(color);
        } catch (NumberFormatException e) {
            Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, "Failed to convert " + value + " into a ColorStateList", e, null);
        }
    }
    return null;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Nullable(android.annotation.Nullable)

Example 5 with Nullable

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

the class Main method renderAndVerify.

/**
     * Create a new rendering session and test that rendering the given layout doesn't throw any
     * exceptions and matches the provided image.
     * <p>
     * If frameTimeNanos is >= 0 a frame will be executed during the rendering. The time indicates
     * how far in the future is.
     */
@Nullable
private RenderResult renderAndVerify(SessionParams params, String goldenFileName, long frameTimeNanos) throws ClassNotFoundException {
    // TODO: Set up action bar handler properly to test menu rendering.
    // Create session params.
    RenderSession session = sBridge.createSession(params);
    if (frameTimeNanos != -1) {
        session.setElapsedFrameTimeNanos(frameTimeNanos);
    }
    if (!session.getResult().isSuccess()) {
        getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
    }
    // Render the session with a timeout of 50s.
    Result renderResult = session.render(50000);
    if (!renderResult.isSuccess()) {
        getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage());
    }
    try {
        String goldenImagePath = APP_TEST_DIR + "/golden/" + goldenFileName;
        ImageUtils.requireSimilar(goldenImagePath, session.getImage());
        return RenderResult.getFromSession(session);
    } catch (IOException e) {
        getLogger().error(e, e.getMessage());
    } finally {
        session.dispose();
    }
    return null;
}
Also used : RenderSession(com.android.ide.common.rendering.api.RenderSession) IOException(java.io.IOException) Result(com.android.ide.common.rendering.api.Result) 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