Search in sources :

Example 11 with Nullable

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

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)

Example 12 with Nullable

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

the class ShortcutService method loadUserLocked.

@Nullable
private ShortcutUser loadUserLocked(@UserIdInt int userId) {
    final File path = getUserFile(userId);
    if (DEBUG) {
        Slog.d(TAG, "Loading from " + path);
    }
    final AtomicFile file = new AtomicFile(path);
    final FileInputStream in;
    try {
        in = file.openRead();
    } catch (FileNotFoundException e) {
        if (DEBUG) {
            Slog.d(TAG, "Not found " + path);
        }
        return null;
    }
    try {
        final ShortcutUser ret = loadUserInternal(userId, in, /* forBackup= */
        false);
        return ret;
    } catch (IOException | XmlPullParserException | InvalidFileFormatException e) {
        Slog.e(TAG, "Failed to read file " + file.getBaseFile(), e);
        return null;
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : AtomicFile(android.util.AtomicFile) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) AtomicFile(android.util.AtomicFile) FileInputStream(java.io.FileInputStream) Nullable(android.annotation.Nullable)

Example 13 with Nullable

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

the class MediaExtractor method getPsshInfo.

/**
     * Get the PSSH info if present.
     * @return a map of uuid-to-bytes, with the uuid specifying
     * the crypto scheme, and the bytes being the data specific to that scheme.
     * This can be {@code null} if the source does not contain PSSH info.
     */
@Nullable
public Map<UUID, byte[]> getPsshInfo() {
    Map<UUID, byte[]> psshMap = null;
    Map<String, Object> formatMap = getFileFormatNative();
    if (formatMap != null && formatMap.containsKey("pssh")) {
        ByteBuffer rawpssh = (ByteBuffer) formatMap.get("pssh");
        rawpssh.order(ByteOrder.nativeOrder());
        rawpssh.rewind();
        formatMap.remove("pssh");
        // parse the flat pssh bytebuffer into something more manageable
        psshMap = new HashMap<UUID, byte[]>();
        while (rawpssh.remaining() > 0) {
            rawpssh.order(ByteOrder.BIG_ENDIAN);
            long msb = rawpssh.getLong();
            long lsb = rawpssh.getLong();
            UUID uuid = new UUID(msb, lsb);
            rawpssh.order(ByteOrder.nativeOrder());
            int datalen = rawpssh.getInt();
            byte[] psshdata = new byte[datalen];
            rawpssh.get(psshdata);
            psshMap.put(uuid, psshdata);
        }
    }
    return psshMap;
}
Also used : UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer) Nullable(android.annotation.Nullable)

Example 14 with Nullable

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

the class CustomPrinterIconCache method getIcon.

/**
     * Get the {@link Icon} to be used as a custom icon for the printer. If not available request
     * the icon to be loaded.
     *
     * @param printerId the printer the icon belongs to
     * @return the {@link Icon} if already available or null if icon is not loaded yet
     */
@Nullable
public synchronized Icon getIcon(@NonNull PrinterId printerId) {
    Icon icon;
    File iconFile = getIconFileName(printerId);
    if (iconFile != null && iconFile.exists()) {
        try (FileInputStream is = new FileInputStream(iconFile)) {
            icon = Icon.createFromStream(is);
        } catch (IOException e) {
            icon = null;
            Log.e(LOG_TAG, "Could not read icon from " + iconFile, e);
        }
        // Touch file so that it is the not likely to be removed
        iconFile.setLastModified(System.currentTimeMillis());
    } else {
        icon = null;
    }
    return icon;
}
Also used : Icon(android.graphics.drawable.Icon) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(android.annotation.Nullable)

Example 15 with Nullable

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

the class CustomPrinterIconCache method getIconFileName.

/**
     * Return the file name to be used for the icon of a printer
     *
     * @param printerId the id of the printer
     *
     * @return The file to be used for the icon of the printer
     */
@Nullable
private File getIconFileName(@NonNull PrinterId printerId) {
    StringBuffer sb = new StringBuffer(printerId.getServiceName().getPackageName());
    sb.append("-");
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update((printerId.getServiceName().getClassName() + ":" + printerId.getLocalId()).getBytes("UTF-16"));
        sb.append(String.format("%#040x", new java.math.BigInteger(1, md.digest())));
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
        Log.e(LOG_TAG, "Could not compute custom printer icon file name", e);
        return null;
    }
    return new File(mCacheDirectory, sb.toString());
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) File(java.io.File) 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