use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class AppOpsService method readUidOps.
void readUidOps(XmlPullParser parser) throws NumberFormatException, XmlPullParserException, IOException {
final int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
String tagName = parser.getName();
if (tagName.equals("op")) {
final int code = Integer.parseInt(parser.getAttributeValue(null, "n"));
final int mode = Integer.parseInt(parser.getAttributeValue(null, "m"));
UidState uidState = getUidStateLocked(uid, true);
if (uidState.opModes == null) {
uidState.opModes = new SparseIntArray();
}
uidState.opModes.put(code, mode);
} else {
Slog.w(TAG, "Unknown element under <uid-ops>: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class GsmAlphabet method stringToGsm7BitPacked.
/**
* Converts a String into a byte array containing
* the 7-bit packed GSM Alphabet representation of the string.
*
* Byte 0 in the returned byte array is the count of septets used
* The returned byte array is the minimum size required to store
* the packed septets. The returned array cannot contain more than 255
* septets.
*
* @param data the text to convert to septets
* @param startingSeptetOffset the number of padding septets to put before
* the character data at the beginning of the array
* @param throwException If true, throws EncodeException on invalid char.
* If false, replaces unencodable char with GSM alphabet space char.
* @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
* @param languageShiftTable the 7 bit single shift language table, or 0 for the default
* GSM extension table
* @return the encoded message
*
* @throws EncodeException if String is too large to encode
*/
public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, boolean throwException, int languageTable, int languageShiftTable) throws EncodeException {
int dataLen = data.length();
int septetCount = countGsmSeptetsUsingTables(data, !throwException, languageTable, languageShiftTable);
if (septetCount == -1) {
throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char");
}
septetCount += startingSeptetOffset;
if (septetCount > 255) {
throw new EncodeException("Payload cannot exceed 255 septets");
}
int byteCount = ((septetCount * 7) + 7) / 8;
// Include space for one byte length prefix.
byte[] ret = new byte[byteCount + 1];
SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7; i < dataLen && septets < septetCount; i++, bitOffset += 7) {
char c = data.charAt(i);
int v = charToLanguageTable.get(c, -1);
if (v == -1) {
// Lookup the extended char.
v = charToShiftTable.get(c, -1);
if (v == -1) {
if (throwException) {
throw new EncodeException("stringToGsm7BitPacked(): unencodable char");
} else {
// should return ASCII space
v = charToLanguageTable.get(' ', ' ');
}
} else {
packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE);
bitOffset += 7;
septets++;
}
}
packSmsChar(ret, bitOffset, v);
septets++;
}
// Validated by check above.
ret[0] = (byte) (septetCount);
return ret;
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class GsmAlphabet method countGsmSeptetsUsingTables.
/**
* Returns the count of 7-bit GSM alphabet characters needed
* to represent this string, using the specified 7-bit language table
* and extension table (0 for GSM default tables).
* @param s the Unicode string that will be encoded
* @param use7bitOnly allow using space in place of unencodable character if true,
* otherwise, return -1 if any characters are unencodable
* @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
* @param languageShiftTable the 7 bit single shift language table, or 0 for the default
* GSM extension table
* @return the septet count for s using the specified language tables, or -1 if any
* characters are unencodable and use7bitOnly is false
*/
public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly, int languageTable, int languageShiftTable) {
int count = 0;
int sz = s.length();
SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
for (int i = 0; i < sz; i++) {
char c = s.charAt(i);
if (c == GSM_EXTENDED_ESCAPE) {
Rlog.w(TAG, "countGsmSeptets() string contains Escape character, skipping.");
continue;
}
if (charToLanguageTable.get(c, -1) != -1) {
count++;
} else if (charToShiftTable.get(c, -1) != -1) {
// escape + shift table index
count += 2;
} else if (use7bitOnly) {
// encode as space
count++;
} else {
// caller must check for this case
return -1;
}
}
return count;
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class CpuVideoTrackDecoder method findDecoderCodec.
/**
* Looks for a codec with the specified requirements.
*
* The set of codecs will be filtered down to those that meet the following requirements:
* <ol>
* <li>The codec is a decoder.</li>
* <li>The codec can decode a video of the specified format.</li>
* <li>The codec can decode to one of the specified color formats.</li>
* </ol>
* If multiple codecs are found, the one with the preferred color-format is taken. Color format
* preference is determined by the order of their appearance in the color format array.
*
* @param format The format the codec must decode.
* @param requiredColorFormats Array of target color spaces ordered by preference.
* @return A codec that meets the requirements, or null if no such codec was found.
*/
private static MediaCodec findDecoderCodec(MediaFormat format, int[] requiredColorFormats) {
TreeMap<Integer, String> candidateCodecs = new TreeMap<Integer, String>();
SparseIntArray colorPriorities = intArrayToPriorityMap(requiredColorFormats);
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
// Get next codec
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
// Check that this is a decoder
if (info.isEncoder()) {
continue;
}
// Check if this codec can decode the video in question
String requiredType = format.getString(MediaFormat.KEY_MIME);
String[] supportedTypes = info.getSupportedTypes();
Set<String> typeSet = new HashSet<String>(Arrays.asList(supportedTypes));
// Check if it can decode to one of the required color formats
if (typeSet.contains(requiredType)) {
CodecCapabilities capabilities = info.getCapabilitiesForType(requiredType);
for (int supportedColorFormat : capabilities.colorFormats) {
if (colorPriorities.indexOfKey(supportedColorFormat) >= 0) {
int priority = colorPriorities.get(supportedColorFormat);
candidateCodecs.put(priority, info.getName());
}
}
}
}
// Pick the best codec (with the highest color priority)
if (candidateCodecs.isEmpty()) {
return null;
} else {
String bestCodec = candidateCodecs.firstEntry().getValue();
try {
return MediaCodec.createByCodecName(bestCodec);
} catch (IOException e) {
throw new RuntimeException("failed to create codec for " + bestCodec, e);
}
}
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class StreamConfigurationMap method getPublicFormats.
/** Get the list of publically visible output formats; does not include IMPL_DEFINED */
private int[] getPublicFormats(boolean output) {
int[] formats = new int[getPublicFormatCount(output)];
int i = 0;
SparseIntArray map = getFormatsMap(output);
for (int j = 0; j < map.size(); j++) {
int format = map.keyAt(j);
formats[i++] = imageFormatToPublic(format);
}
if (output) {
for (int j = 0; j < mDepthOutputFormats.size(); j++) {
formats[i++] = depthFormatToPublic(mDepthOutputFormats.keyAt(j));
}
}
if (formats.length != i) {
throw new AssertionError("Too few formats " + i + ", expected " + formats.length);
}
return formats;
}
Aggregations