use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.
the class UserManagerService method getUsers.
@Override
@NonNull
public List<UserInfo> getUsers(boolean excludeDying) {
checkManageOrCreateUsersPermission("query users");
synchronized (mUsersLock) {
ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size());
final int userSize = mUsers.size();
for (int i = 0; i < userSize; i++) {
UserInfo ui = mUsers.valueAt(i).info;
if (ui.partial) {
continue;
}
if (!excludeDying || !mRemovingUserIds.get(ui.id)) {
users.add(userWithName(ui));
}
}
return users;
}
}
use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.
the class MediaMetadata method getDescription.
/**
* Returns a simple description of this metadata for display purposes.
*
* @return A simple description of this metadata.
*/
@NonNull
public MediaDescription getDescription() {
if (mDescription != null) {
return mDescription;
}
String mediaId = getString(METADATA_KEY_MEDIA_ID);
CharSequence[] text = new CharSequence[3];
Bitmap icon = null;
Uri iconUri = null;
// First handle the case where display data is set already
CharSequence displayText = getText(METADATA_KEY_DISPLAY_TITLE);
if (!TextUtils.isEmpty(displayText)) {
// If they have a display title use only display data, otherwise use
// our best bets
text[0] = displayText;
text[1] = getText(METADATA_KEY_DISPLAY_SUBTITLE);
text[2] = getText(METADATA_KEY_DISPLAY_DESCRIPTION);
} else {
// Use whatever fields we can
int textIndex = 0;
int keyIndex = 0;
while (textIndex < text.length && keyIndex < PREFERRED_DESCRIPTION_ORDER.length) {
CharSequence next = getText(PREFERRED_DESCRIPTION_ORDER[keyIndex++]);
if (!TextUtils.isEmpty(next)) {
// Fill in the next empty bit of text
text[textIndex++] = next;
}
}
}
// Get the best art bitmap we can find
for (int i = 0; i < PREFERRED_BITMAP_ORDER.length; i++) {
Bitmap next = getBitmap(PREFERRED_BITMAP_ORDER[i]);
if (next != null) {
icon = next;
break;
}
}
// Get the best Uri we can find
for (int i = 0; i < PREFERRED_URI_ORDER.length; i++) {
String next = getString(PREFERRED_URI_ORDER[i]);
if (!TextUtils.isEmpty(next)) {
iconUri = Uri.parse(next);
break;
}
}
MediaDescription.Builder bob = new MediaDescription.Builder();
bob.setMediaId(mediaId);
bob.setTitle(text[0]);
bob.setSubtitle(text[1]);
bob.setDescription(text[2]);
bob.setIconBitmap(icon);
bob.setIconUri(iconUri);
mDescription = bob.build();
return mDescription;
}
use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.
the class VendorConfig method readVendorConfigs.
/**
* Read the vendor configuration file.
*
* @param context The content issuing the read
*
* @return An map pointing from vendor name to config
*
* @throws IOException
* @throws XmlPullParserException
*/
@NonNull
private static ArrayMap<String, VendorConfig> readVendorConfigs(@NonNull final Context context) throws IOException, XmlPullParserException {
try (XmlResourceParser parser = context.getResources().getXml(R.xml.vendorconfigs)) {
// Skip header
int parsingEvent;
do {
parsingEvent = parser.next();
} while (parsingEvent != XmlResourceParser.START_TAG);
ArrayList<VendorConfig> configs = readTagList(parser, VENDORS_TAG, VENDOR_TAG, new TagReader<VendorConfig>() {
public VendorConfig readTag(XmlPullParser parser, String tagName) throws XmlPullParserException, IOException {
return readVendorConfig(context, parser, tagName);
}
});
ArrayMap<String, VendorConfig> configMap = new ArrayMap<>(configs.size());
final int numConfigs = configs.size();
for (int i = 0; i < numConfigs; i++) {
VendorConfig config = configs.get(i);
configMap.put(config.name, config);
}
return configMap;
}
}
use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.
the class PackageItemInfo method loadSafeLabel.
/**
* Same as {@link #loadLabel(PackageManager)} with the addition that
* the returned label is safe for being presented in the UI since it
* will not contain new lines and the length will be limited to a
* reasonable amount. This prevents a malicious party to influence UI
* layout via the app label misleading the user into performing a
* detrimental for them action. If the label is too long it will be
* truncated and ellipsized at the end.
*
* @param pm A PackageManager from which the label can be loaded; usually
* the PackageManager from which you originally retrieved this item
* @return Returns a CharSequence containing the item's label. If the
* item does not have a label, its name is returned.
*
* @hide
*/
@SystemApi
@NonNull
public CharSequence loadSafeLabel(@NonNull PackageManager pm) {
// loadLabel() always returns non-null
String label = loadLabel(pm).toString();
// strip HTML tags to avoid <br> and other tags overwriting original message
String labelStr = Html.fromHtml(label).toString();
// If the label contains new line characters it may push the UI
// down to hide a part of it. Labels shouldn't have new line
// characters, so just truncate at the first time one is seen.
final int labelLength = labelStr.length();
int offset = 0;
while (offset < labelLength) {
final int codePoint = labelStr.codePointAt(offset);
final int type = Character.getType(codePoint);
if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
labelStr = labelStr.substring(0, offset);
break;
}
// replace all non-break space to " " in order to be trimmed
if (type == Character.SPACE_SEPARATOR) {
labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset + Character.charCount(codePoint));
}
offset += Character.charCount(codePoint);
}
labelStr = labelStr.trim();
if (labelStr.isEmpty()) {
return packageName;
}
TextPaint paint = new TextPaint();
paint.setTextSize(42);
return TextUtils.ellipsize(labelStr, paint, MAX_LABEL_SIZE_PX, TextUtils.TruncateAt.END);
}
use of android.annotation.NonNull in project android_frameworks_base by ResurrectionRemix.
the class ApplicationPackageManager method getPrimaryStorageCandidateVolumes.
@Override
@NonNull
public List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
final StorageManager storage = mContext.getSystemService(StorageManager.class);
final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
final List<VolumeInfo> vols = storage.getVolumes();
final List<VolumeInfo> candidates = new ArrayList<>();
if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, storage.getPrimaryStorageUuid()) && currentVol != null) {
// TODO: support moving primary physical to emulated volume
candidates.add(currentVol);
} else {
for (VolumeInfo vol : vols) {
if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
candidates.add(vol);
}
}
}
return candidates;
}
Aggregations