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