use of android.util.ArrayMap in project platform_frameworks_base by android.
the class BlobBackupHelper method readOldState.
// Internal implementation
/*
* State on-disk format:
* [Int] : overall blob version number
* [Int=N] : number of keys represented in the state blob
* N* :
* [String] key
* [Long] blob checksum, calculated after compression
*/
@SuppressWarnings("resource")
private ArrayMap<String, Long> readOldState(ParcelFileDescriptor oldStateFd) {
final ArrayMap<String, Long> state = new ArrayMap<String, Long>();
FileInputStream fis = new FileInputStream(oldStateFd.getFileDescriptor());
DataInputStream in = new DataInputStream(fis);
try {
int version = in.readInt();
if (version <= mCurrentBlobVersion) {
final int numKeys = in.readInt();
if (DEBUG) {
Log.i(TAG, " " + numKeys + " keys in state record");
}
for (int i = 0; i < numKeys; i++) {
String key = in.readUTF();
long checksum = in.readLong();
if (DEBUG) {
Log.i(TAG, " key '" + key + "' checksum is " + checksum);
}
state.put(key, checksum);
}
} else {
Log.w(TAG, "Prior state from unrecognized version " + version);
}
} catch (EOFException e) {
// is truncated we just treat it the same way.
if (DEBUG) {
Log.i(TAG, "Hit EOF reading prior state");
}
state.clear();
} catch (Exception e) {
Log.e(TAG, "Error examining prior backup state " + e.getMessage());
state.clear();
}
return state;
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class InputMethodUtils method parseInputMethodsAndSubtypesString.
/**
* Parses the setting stored input methods and subtypes string value.
*
* @param inputMethodsAndSubtypesString The input method subtypes value stored in settings.
* @return Map from input method ID to set of input method subtypes IDs.
*/
@VisibleForTesting
public static ArrayMap<String, ArraySet<String>> parseInputMethodsAndSubtypesString(@Nullable final String inputMethodsAndSubtypesString) {
final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<>();
if (TextUtils.isEmpty(inputMethodsAndSubtypesString)) {
return imeMap;
}
final SimpleStringSplitter typeSplitter = new SimpleStringSplitter(INPUT_METHOD_SEPARATOR);
final SimpleStringSplitter subtypeSplitter = new SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATOR);
List<Pair<String, ArrayList<String>>> allImeSettings = InputMethodSettings.buildInputMethodsAndSubtypeList(inputMethodsAndSubtypesString, typeSplitter, subtypeSplitter);
for (Pair<String, ArrayList<String>> ime : allImeSettings) {
ArraySet<String> subtypes = new ArraySet<>();
if (ime.second != null) {
subtypes.addAll(ime.second);
}
imeMap.put(ime.first, subtypes);
}
return imeMap;
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class ShortcutPackage method enforceShortcutCountsBeforeOperation.
/**
* Called by
* {@link android.content.pm.ShortcutManager#setDynamicShortcuts},
* {@link android.content.pm.ShortcutManager#addDynamicShortcuts}, and
* {@link android.content.pm.ShortcutManager#updateShortcuts} before actually performing
* the operation to make sure the operation wouldn't result in the target activities having
* more than the allowed number of dynamic/manifest shortcuts.
*
* @param newList shortcut list passed to set, add or updateShortcuts().
* @param operation add, set or update.
* @throws IllegalArgumentException if the operation would result in going over the max
* shortcut count for any activity.
*/
public void enforceShortcutCountsBeforeOperation(List<ShortcutInfo> newList, @ShortcutOperation int operation) {
final ShortcutService service = mShortcutUser.mService;
// Current # of dynamic / manifest shortcuts for each activity.
// (If it's for update, then don't count dynamic shortcuts, since they'll be replaced
// anyway.)
final ArrayMap<ComponentName, Integer> counts = new ArrayMap<>(4);
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
final ShortcutInfo shortcut = mShortcuts.valueAt(i);
if (shortcut.isManifestShortcut()) {
incrementCountForActivity(counts, shortcut.getActivity(), 1);
} else if (shortcut.isDynamic() && (operation != ShortcutService.OPERATION_SET)) {
incrementCountForActivity(counts, shortcut.getActivity(), 1);
}
}
for (int i = newList.size() - 1; i >= 0; i--) {
final ShortcutInfo newShortcut = newList.get(i);
final ComponentName newActivity = newShortcut.getActivity();
if (newActivity == null) {
if (operation != ShortcutService.OPERATION_UPDATE) {
service.wtf("Activity must not be null at this point");
// Just ignore this invalid case.
continue;
}
// Activity can be null for update.
continue;
}
final ShortcutInfo original = mShortcuts.get(newShortcut.getId());
if (original == null) {
if (operation == ShortcutService.OPERATION_UPDATE) {
// When updating, ignore if there's no target.
continue;
}
// Add() or set(), and there's no existing shortcut with the same ID. We're
// simply publishing (as opposed to updating) this shortcut, so just +1.
incrementCountForActivity(counts, newActivity, 1);
continue;
}
if (original.isFloating() && (operation == ShortcutService.OPERATION_UPDATE)) {
// Updating floating shortcuts doesn't affect the count, so ignore.
continue;
}
// dynamic shortcuts in the first loop.
if (operation != ShortcutService.OPERATION_SET) {
final ComponentName oldActivity = original.getActivity();
if (!original.isFloating()) {
incrementCountForActivity(counts, oldActivity, -1);
}
}
incrementCountForActivity(counts, newActivity, 1);
}
// Then make sure none of the activities have more than the max number of shortcuts.
for (int i = counts.size() - 1; i >= 0; i--) {
service.enforceMaxActivityShortcuts(counts.valueAt(i));
}
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class IpConnectivityMetrics method makeRateLimitingBuckets.
private static ArrayMap<Class<?>, TokenBucket> makeRateLimitingBuckets() {
ArrayMap<Class<?>, TokenBucket> map = new ArrayMap<>();
// one token every minute, 50 tokens max: burst of ~50 events every hour.
map.put(ApfProgramEvent.class, new TokenBucket((int) DateUtils.MINUTE_IN_MILLIS, 50));
return map;
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class KeySetManagerServiceTest method testRemoveAppKSDataDefined.
/* remove package which used defined and upgrade keysets and ensure removed */
public void testRemoveAppKSDataDefined() throws ReflectiveOperationException {
/* create PackageSetting and add to Settings mPackages */
PackageSetting ps = generateFakePackageSetting("packageA");
mPackagesMap.put(ps.name, ps);
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
/* removal requires signing keyset to be specified (since all apps are
* assumed to have it). We skipped this in the defined tests, but can't
* here. */
mKsms.addSigningKeySetToPackageLPw(ps, keys);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
ArraySet<String> upgradeKS = new ArraySet<String>();
upgradeKS.add("aliasA");
mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
mKsms.removeAppKeySetDataLPw(ps.name);
assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(0, ksMapping.size());
assertEquals(PackageKeySetData.KEYSET_UNASSIGNED, ps.keySetData.getProperSigningKeySet());
assertEquals(0, ps.keySetData.getAliases().size());
assertNull(ps.keySetData.getUpgradeKeySets());
}
Aggregations