use of android.util.SparseArray in project android_frameworks_base by DirtyUnicorns.
the class TaskPersister method writeTaskIdsFiles.
private void writeTaskIdsFiles() {
SparseArray<SparseBooleanArray> changedTaskIdsPerUser = new SparseArray<>();
synchronized (mService) {
for (int userId : mRecentTasks.usersWithRecentsLoadedLocked()) {
SparseBooleanArray taskIdsToSave = mRecentTasks.mPersistedTaskIds.get(userId);
SparseBooleanArray persistedIdsInFile = mTaskIdsInFile.get(userId);
if (persistedIdsInFile != null && persistedIdsInFile.equals(taskIdsToSave)) {
continue;
} else {
SparseBooleanArray taskIdsToSaveCopy = taskIdsToSave.clone();
mTaskIdsInFile.put(userId, taskIdsToSaveCopy);
changedTaskIdsPerUser.put(userId, taskIdsToSaveCopy);
}
}
}
for (int i = 0; i < changedTaskIdsPerUser.size(); i++) {
writePersistedTaskIdsForUser(changedTaskIdsPerUser.valueAt(i), changedTaskIdsPerUser.keyAt(i));
}
}
use of android.util.SparseArray in project android_frameworks_base by DirtyUnicorns.
the class ProcessStatsService method readLocked.
boolean readLocked(ProcessStats stats, AtomicFile file) {
try {
FileInputStream stream = file.openRead();
stats.read(stream);
stream.close();
if (stats.mReadError != null) {
Slog.w(TAG, "Ignoring existing stats; " + stats.mReadError);
if (DEBUG) {
ArrayMap<String, SparseArray<ProcessState>> procMap = stats.mProcesses.getMap();
final int NPROC = procMap.size();
for (int ip = 0; ip < NPROC; ip++) {
Slog.w(TAG, "Process: " + procMap.keyAt(ip));
SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid " + uids.keyAt(iu) + ": " + uids.valueAt(iu));
}
}
ArrayMap<String, SparseArray<SparseArray<ProcessStats.PackageState>>> pkgMap = stats.mPackages.getMap();
final int NPKG = pkgMap.size();
for (int ip = 0; ip < NPKG; ip++) {
Slog.w(TAG, "Package: " + pkgMap.keyAt(ip));
SparseArray<SparseArray<ProcessStats.PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid: " + uids.keyAt(iu));
SparseArray<ProcessStats.PackageState> vers = uids.valueAt(iu);
final int NVERS = vers.size();
for (int iv = 0; iv < NVERS; iv++) {
Slog.w(TAG, " Vers: " + vers.keyAt(iv));
ProcessStats.PackageState pkgState = vers.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
Slog.w(TAG, " Process " + pkgState.mProcesses.keyAt(iproc) + ": " + pkgState.mProcesses.valueAt(iproc));
}
final int NSRVS = pkgState.mServices.size();
for (int isvc = 0; isvc < NSRVS; isvc++) {
Slog.w(TAG, " Service " + pkgState.mServices.keyAt(isvc) + ": " + pkgState.mServices.valueAt(isvc));
}
}
}
}
}
return false;
}
} catch (Throwable e) {
stats.mReadError = "caught exception: " + e;
Slog.e(TAG, "Error reading process statistics", e);
return false;
}
return true;
}
use of android.util.SparseArray in project android_frameworks_base by DirtyUnicorns.
the class IpConfigStore method readIpAndProxyConfigurations.
public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
int version = in.readInt();
if (version != 2 && version != 1) {
loge("Bad version on IP configuration file, ignore read");
return null;
}
while (true) {
int id = -1;
// Default is DHCP with no proxy
IpAssignment ipAssignment = IpAssignment.DHCP;
ProxySettings proxySettings = ProxySettings.NONE;
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
String proxyHost = null;
String pacFileUrl = null;
int proxyPort = -1;
String exclusionList = null;
String key;
do {
key = in.readUTF();
try {
if (key.equals(ID_KEY)) {
id = in.readInt();
} else if (key.equals(IP_ASSIGNMENT_KEY)) {
ipAssignment = IpAssignment.valueOf(in.readUTF());
} else if (key.equals(LINK_ADDRESS_KEY)) {
LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
staticIpConfiguration.ipAddress = linkAddr;
} else {
loge("Non-IPv4 or duplicate address: " + linkAddr);
}
} else if (key.equals(GATEWAY_KEY)) {
LinkAddress dest = null;
InetAddress gateway = null;
if (version == 1) {
// only supported default gateways - leave the dest/prefix empty
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
if (staticIpConfiguration.gateway == null) {
staticIpConfiguration.gateway = gateway;
} else {
loge("Duplicate gateway: " + gateway.getHostAddress());
}
} else {
if (in.readInt() == 1) {
dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
}
if (in.readInt() == 1) {
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
}
RouteInfo route = new RouteInfo(dest, gateway);
if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
staticIpConfiguration.gateway = gateway;
} else {
loge("Non-IPv4 default or duplicate route: " + route);
}
}
} else if (key.equals(DNS_KEY)) {
staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
} else if (key.equals(PROXY_SETTINGS_KEY)) {
proxySettings = ProxySettings.valueOf(in.readUTF());
} else if (key.equals(PROXY_HOST_KEY)) {
proxyHost = in.readUTF();
} else if (key.equals(PROXY_PORT_KEY)) {
proxyPort = in.readInt();
} else if (key.equals(PROXY_PAC_FILE)) {
pacFileUrl = in.readUTF();
} else if (key.equals(EXCLUSION_LIST_KEY)) {
exclusionList = in.readUTF();
} else if (key.equals(EOS)) {
break;
} else {
loge("Ignore unknown key " + key + "while reading");
}
} catch (IllegalArgumentException e) {
loge("Ignore invalid address while reading" + e);
}
} while (true);
if (id != -1) {
IpConfiguration config = new IpConfiguration();
networks.put(id, config);
switch(ipAssignment) {
case STATIC:
config.staticIpConfiguration = staticIpConfiguration;
config.ipAssignment = ipAssignment;
break;
case DHCP:
config.ipAssignment = ipAssignment;
break;
case UNASSIGNED:
loge("BUG: Found UNASSIGNED IP on file, use DHCP");
config.ipAssignment = IpAssignment.DHCP;
break;
default:
loge("Ignore invalid ip assignment while reading.");
config.ipAssignment = IpAssignment.UNASSIGNED;
break;
}
switch(proxySettings) {
case STATIC:
ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
config.proxySettings = proxySettings;
config.httpProxy = proxyInfo;
break;
case PAC:
ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
config.proxySettings = proxySettings;
config.httpProxy = proxyPacProperties;
break;
case NONE:
config.proxySettings = proxySettings;
break;
case UNASSIGNED:
loge("BUG: Found UNASSIGNED proxy on file, use NONE");
config.proxySettings = ProxySettings.NONE;
break;
default:
loge("Ignore invalid proxy settings while reading");
config.proxySettings = ProxySettings.UNASSIGNED;
break;
}
} else {
if (DBG)
log("Missing id while parsing configuration");
}
}
} catch (EOFException ignore) {
} catch (IOException e) {
loge("Error parsing configuration: " + e);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
return networks;
}
use of android.util.SparseArray in project android_frameworks_base by DirtyUnicorns.
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.SparseArray in project android_frameworks_base by DirtyUnicorns.
the class ActivityManagerService method findProcessLocked.
private ProcessRecord findProcessLocked(String process, int userId, String callName) {
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, callName, null);
ProcessRecord proc = null;
try {
int pid = Integer.parseInt(process);
synchronized (mPidsSelfLocked) {
proc = mPidsSelfLocked.get(pid);
}
} catch (NumberFormatException e) {
}
if (proc == null) {
ArrayMap<String, SparseArray<ProcessRecord>> all = mProcessNames.getMap();
SparseArray<ProcessRecord> procs = all.get(process);
if (procs != null && procs.size() > 0) {
proc = procs.valueAt(0);
if (userId != UserHandle.USER_ALL && proc.userId != userId) {
for (int i = 1; i < procs.size(); i++) {
ProcessRecord thisProc = procs.valueAt(i);
if (thisProc.userId == userId) {
proc = thisProc;
break;
}
}
}
}
}
return proc;
}
Aggregations