use of android.util.ArrayMap in project platform_frameworks_base by android.
the class VpnTest method setMockedUsers.
/**
* Populate {@link #mUserManager} with a list of fake users.
*/
private void setMockedUsers(UserInfo... users) {
final Map<Integer, UserInfo> userMap = new ArrayMap<>();
for (UserInfo user : users) {
userMap.put(user.id, user);
}
/**
* @see UserManagerService#getUsers(boolean)
*/
doAnswer(invocation -> {
final boolean excludeDying = (boolean) invocation.getArguments()[0];
final ArrayList<UserInfo> result = new ArrayList<>(users.length);
for (UserInfo ui : users) {
if (!excludeDying || (ui.isEnabled() && !ui.partial)) {
result.add(ui);
}
}
return result;
}).when(mUserManager).getUsers(anyBoolean());
doAnswer(invocation -> {
final int id = (int) invocation.getArguments()[0];
return userMap.get(id);
}).when(mUserManager).getUserInfo(anyInt());
doAnswer(invocation -> {
final int id = (int) invocation.getArguments()[0];
return (userMap.get(id).flags & UserInfo.FLAG_ADMIN) != 0;
}).when(mUserManager).canHaveRestrictedProfile(anyInt());
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class ActivityManagerService method dumpAssociationsLocked.
void dumpAssociationsLocked(FileDescriptor fd, PrintWriter pw, String[] args, int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
pw.println("ACTIVITY MANAGER ASSOCIATIONS (dumpsys activity associations)");
int dumpUid = 0;
if (dumpPackage != null) {
IPackageManager pm = AppGlobals.getPackageManager();
try {
dumpUid = pm.getPackageUid(dumpPackage, MATCH_UNINSTALLED_PACKAGES, 0);
} catch (RemoteException e) {
}
}
boolean printedAnything = false;
final long now = SystemClock.uptimeMillis();
for (int i1 = 0, N1 = mAssociations.size(); i1 < N1; i1++) {
ArrayMap<ComponentName, SparseArray<ArrayMap<String, Association>>> targetComponents = mAssociations.valueAt(i1);
for (int i2 = 0, N2 = targetComponents.size(); i2 < N2; i2++) {
SparseArray<ArrayMap<String, Association>> sourceUids = targetComponents.valueAt(i2);
for (int i3 = 0, N3 = sourceUids.size(); i3 < N3; i3++) {
ArrayMap<String, Association> sourceProcesses = sourceUids.valueAt(i3);
for (int i4 = 0, N4 = sourceProcesses.size(); i4 < N4; i4++) {
Association ass = sourceProcesses.valueAt(i4);
if (dumpPackage != null) {
if (!ass.mTargetComponent.getPackageName().equals(dumpPackage) && UserHandle.getAppId(ass.mSourceUid) != dumpUid) {
continue;
}
}
printedAnything = true;
pw.print(" ");
pw.print(ass.mTargetProcess);
pw.print("/");
UserHandle.formatUid(pw, ass.mTargetUid);
pw.print(" <- ");
pw.print(ass.mSourceProcess);
pw.print("/");
UserHandle.formatUid(pw, ass.mSourceUid);
pw.println();
pw.print(" via ");
pw.print(ass.mTargetComponent.flattenToShortString());
pw.println();
pw.print(" ");
long dur = ass.mTime;
if (ass.mNesting > 0) {
dur += now - ass.mStartTime;
}
TimeUtils.formatDuration(dur, pw);
pw.print(" (");
pw.print(ass.mCount);
pw.print(" times)");
pw.print(" ");
for (int i = 0; i < ass.mStateTimes.length; i++) {
long amt = ass.mStateTimes[i];
if (ass.mLastState - ActivityManager.MIN_PROCESS_STATE == i) {
amt += now - ass.mLastStateUptime;
}
if (amt != 0) {
pw.print(" ");
pw.print(ProcessList.makeProcStateString(i + ActivityManager.MIN_PROCESS_STATE));
pw.print("=");
TimeUtils.formatDuration(amt, pw);
if (ass.mLastState - ActivityManager.MIN_PROCESS_STATE == i) {
pw.print("*");
}
}
}
pw.println();
if (ass.mNesting > 0) {
pw.print(" Currently active: ");
TimeUtils.formatDuration(now - ass.mStartTime, pw);
pw.println();
}
}
}
}
}
if (!printedAnything) {
pw.println(" (nothing)");
}
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class UserState method getPrintJobInfos.
public List<PrintJobInfo> getPrintJobInfos(int appId) {
List<PrintJobInfo> cachedPrintJobs = mPrintJobForAppCache.getPrintJobs(appId);
// Note that the print spooler is not storing print jobs that
// are in a terminal state as it is non-trivial to properly update
// the spooler state for when to forget print jobs in terminal state.
// Therefore, we fuse the cached print jobs for running apps (some
// jobs are in a terminal state) with the ones that the print
// spooler knows about (some jobs are being processed).
ArrayMap<PrintJobId, PrintJobInfo> result = new ArrayMap<PrintJobId, PrintJobInfo>();
// Add the cached print jobs for running apps.
final int cachedPrintJobCount = cachedPrintJobs.size();
for (int i = 0; i < cachedPrintJobCount; i++) {
PrintJobInfo cachedPrintJob = cachedPrintJobs.get(i);
result.put(cachedPrintJob.getId(), cachedPrintJob);
// Strip out the tag and the advanced print options.
// They are visible only to print services.
cachedPrintJob.setTag(null);
cachedPrintJob.setAdvancedOptions(null);
}
// Add everything else the spooler knows about.
List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(null, PrintJobInfo.STATE_ANY, appId);
if (printJobs != null) {
final int printJobCount = printJobs.size();
for (int i = 0; i < printJobCount; i++) {
PrintJobInfo printJob = printJobs.get(i);
result.put(printJob.getId(), printJob);
// Strip out the tag and the advanced print options.
// They are visible only to print services.
printJob.setTag(null);
printJob.setAdvancedOptions(null);
}
}
return new ArrayList<PrintJobInfo>(result.values());
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class PackageParser method parseKeySets.
private boolean parseKeySets(Package owner, Resources res, XmlResourceParser parser, String[] outError) throws XmlPullParserException, IOException {
// we've encountered the 'key-sets' tag
// all the keys and keysets that we want must be defined here
// so we're going to iterate over the parser and pull out the things we want
int outerDepth = parser.getDepth();
int currentKeySetDepth = -1;
int type;
String currentKeySet = null;
ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>();
ArraySet<String> upgradeKeySets = new ArraySet<String>();
ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>();
ArraySet<String> improperKeySets = new ArraySet<String>();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG) {
if (parser.getDepth() == currentKeySetDepth) {
currentKeySet = null;
currentKeySetDepth = -1;
}
continue;
}
String tagName = parser.getName();
if (tagName.equals("key-set")) {
if (currentKeySet != null) {
outError[0] = "Improperly nested 'key-set' tag at " + parser.getPositionDescription();
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
return false;
}
final TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestKeySet);
final String keysetName = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestKeySet_name);
definedKeySets.put(keysetName, new ArraySet<String>());
currentKeySet = keysetName;
currentKeySetDepth = parser.getDepth();
sa.recycle();
} else if (tagName.equals("public-key")) {
if (currentKeySet == null) {
outError[0] = "Improperly nested 'key-set' tag at " + parser.getPositionDescription();
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
return false;
}
final TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestPublicKey);
final String publicKeyName = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestPublicKey_name);
final String encodedKey = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestPublicKey_value);
if (encodedKey == null && publicKeys.get(publicKeyName) == null) {
outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" + " on first use at " + parser.getPositionDescription();
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
sa.recycle();
return false;
} else if (encodedKey != null) {
PublicKey currentKey = parsePublicKey(encodedKey);
if (currentKey == null) {
Slog.w(TAG, "No recognized valid key in 'public-key' tag at " + parser.getPositionDescription() + " key-set " + currentKeySet + " will not be added to the package's defined key-sets.");
sa.recycle();
improperKeySets.add(currentKeySet);
XmlUtils.skipCurrentTag(parser);
continue;
}
if (publicKeys.get(publicKeyName) == null || publicKeys.get(publicKeyName).equals(currentKey)) {
/* public-key first definition, or matches old definition */
publicKeys.put(publicKeyName, currentKey);
} else {
outError[0] = "Value of 'public-key' " + publicKeyName + " conflicts with previously defined value at " + parser.getPositionDescription();
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
sa.recycle();
return false;
}
}
definedKeySets.get(currentKeySet).add(publicKeyName);
sa.recycle();
XmlUtils.skipCurrentTag(parser);
} else if (tagName.equals("upgrade-key-set")) {
final TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestUpgradeKeySet);
String name = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name);
upgradeKeySets.add(name);
sa.recycle();
XmlUtils.skipCurrentTag(parser);
} else if (RIGID_PARSER) {
outError[0] = "Bad element under <key-sets>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription();
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
return false;
} else {
Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
XmlUtils.skipCurrentTag(parser);
continue;
}
}
Set<String> publicKeyNames = publicKeys.keySet();
if (publicKeyNames.removeAll(definedKeySets.keySet())) {
outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' and 'public-key' names must be distinct.";
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
return false;
}
owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>();
for (ArrayMap.Entry<String, ArraySet<String>> e : definedKeySets.entrySet()) {
final String keySetName = e.getKey();
if (e.getValue().size() == 0) {
Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' " + keySetName + " has no valid associated 'public-key'." + " Not including in package's defined key-sets.");
continue;
} else if (improperKeySets.contains(keySetName)) {
Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' " + keySetName + " contained improper 'public-key'" + " tags. Not including in package's defined key-sets.");
continue;
}
owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>());
for (String s : e.getValue()) {
owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s));
}
}
if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) {
owner.mUpgradeKeySets = upgradeKeySets;
} else {
outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " + "does not define all 'upgrade-key-set's .";
mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
return false;
}
return true;
}
use of android.util.ArrayMap in project platform_frameworks_base by android.
the class PackageParser method parseClusterPackageLite.
private static PackageLite parseClusterPackageLite(File packageDir, int flags) throws PackageParserException {
final File[] files = packageDir.listFiles();
if (ArrayUtils.isEmpty(files)) {
throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, "No packages found in split");
}
String packageName = null;
int versionCode = 0;
final ArrayMap<String, ApkLite> apks = new ArrayMap<>();
for (File file : files) {
if (isApkFile(file)) {
final ApkLite lite = parseApkLite(file, flags);
// consistent with the first one we encounter.
if (packageName == null) {
packageName = lite.packageName;
versionCode = lite.versionCode;
} else {
if (!packageName.equals(lite.packageName)) {
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Inconsistent package " + lite.packageName + " in " + file + "; expected " + packageName);
}
if (versionCode != lite.versionCode) {
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Inconsistent version " + lite.versionCode + " in " + file + "; expected " + versionCode);
}
}
// Assert that each split is defined only once
if (apks.put(lite.splitName, lite) != null) {
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Split name " + lite.splitName + " defined more than once; most recent was " + file);
}
}
}
final ApkLite baseApk = apks.remove(null);
if (baseApk == null) {
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Missing base APK in " + packageDir);
}
// Always apply deterministic ordering based on splitName
final int size = apks.size();
String[] splitNames = null;
String[] splitCodePaths = null;
int[] splitRevisionCodes = null;
if (size > 0) {
splitNames = new String[size];
splitCodePaths = new String[size];
splitRevisionCodes = new int[size];
splitNames = apks.keySet().toArray(splitNames);
Arrays.sort(splitNames, sSplitNameComparator);
for (int i = 0; i < size; i++) {
splitCodePaths[i] = apks.get(splitNames[i]).codePath;
splitRevisionCodes[i] = apks.get(splitNames[i]).revisionCode;
}
}
final String codePath = packageDir.getAbsolutePath();
return new PackageLite(codePath, baseApk, splitNames, splitCodePaths, splitRevisionCodes);
}
Aggregations