use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.
the class HdmiControlService method initPortInfo.
// Initialize HDMI port information. Combine the information from CEC and MHL HAL and
// keep them in one place.
@ServiceThreadOnly
private void initPortInfo() {
assertRunOnServiceThread();
HdmiPortInfo[] cecPortInfo = null;
// each port. Return empty array if CEC HAL didn't provide the info.
if (mCecController != null) {
cecPortInfo = mCecController.getPortInfos();
}
if (cecPortInfo == null) {
return;
}
SparseArray<HdmiPortInfo> portInfoMap = new SparseArray<>();
SparseIntArray portIdMap = new SparseIntArray();
SparseArray<HdmiDeviceInfo> portDeviceMap = new SparseArray<>();
for (HdmiPortInfo info : cecPortInfo) {
portIdMap.put(info.getAddress(), info.getId());
portInfoMap.put(info.getId(), info);
portDeviceMap.put(info.getId(), new HdmiDeviceInfo(info.getAddress(), info.getId()));
}
mPortIdMap = new UnmodifiableSparseIntArray(portIdMap);
mPortInfoMap = new UnmodifiableSparseArray<>(portInfoMap);
mPortDeviceMap = new UnmodifiableSparseArray<>(portDeviceMap);
HdmiPortInfo[] mhlPortInfo = mMhlController.getPortInfos();
ArraySet<Integer> mhlSupportedPorts = new ArraySet<Integer>(mhlPortInfo.length);
for (HdmiPortInfo info : mhlPortInfo) {
if (info.isMhlSupported()) {
mhlSupportedPorts.add(info.getId());
}
}
// cec port info if we do not have have port that supports MHL.
if (mhlSupportedPorts.isEmpty()) {
mPortInfo = Collections.unmodifiableList(Arrays.asList(cecPortInfo));
return;
}
ArrayList<HdmiPortInfo> result = new ArrayList<>(cecPortInfo.length);
for (HdmiPortInfo info : cecPortInfo) {
if (mhlSupportedPorts.contains(info.getId())) {
result.add(new HdmiPortInfo(info.getId(), info.getType(), info.getAddress(), info.isCecSupported(), true, info.isArcSupported()));
} else {
result.add(info);
}
}
mPortInfo = Collections.unmodifiableList(result);
}
use of android.util.SparseArray in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PowerUsageSummary method getCoalescedUsageList.
/**
* We want to coalesce some UIDs. For example, dex2oat runs under a shared gid that
* exists for all users of the same app. We detect this case and merge the power use
* for dex2oat to the device OWNER's use of the app.
* @return A sorted list of apps using power.
*/
private static List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
final SparseArray<BatterySipper> uidList = new SparseArray<>();
final ArrayList<BatterySipper> results = new ArrayList<>();
final int numSippers = sippers.size();
for (int i = 0; i < numSippers; i++) {
BatterySipper sipper = sippers.get(i);
if (sipper.getUid() > 0) {
int realUid = sipper.getUid();
// actual app UID.
if (isSharedGid(sipper.getUid())) {
realUid = UserHandle.getUid(UserHandle.USER_SYSTEM, UserHandle.getAppIdFromSharedAppGid(sipper.getUid()));
}
// Check if this UID is a system UID (mediaserver, logd, nfc, drm, etc).
if (isSystemUid(realUid) && !"mediaserver".equals(sipper.packageWithHighestDrain)) {
// Use the system UID for all UIDs running in their own sandbox that
// are not apps. We exclude mediaserver because we already are expected to
// report that as a separate item.
realUid = Process.SYSTEM_UID;
}
if (realUid != sipper.getUid()) {
// Replace the BatterySipper with a new one with the real UID set.
BatterySipper newSipper = new BatterySipper(sipper.drainType, new FakeUid(realUid), 0.0);
newSipper.add(sipper);
newSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
newSipper.mPackages = sipper.mPackages;
sipper = newSipper;
}
int index = uidList.indexOfKey(realUid);
if (index < 0) {
// New entry.
uidList.put(realUid, sipper);
} else {
// Combine BatterySippers if we already have one with this UID.
final BatterySipper existingSipper = uidList.valueAt(index);
existingSipper.add(sipper);
if (existingSipper.packageWithHighestDrain == null && sipper.packageWithHighestDrain != null) {
existingSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
}
final int existingPackageLen = existingSipper.mPackages != null ? existingSipper.mPackages.length : 0;
final int newPackageLen = sipper.mPackages != null ? sipper.mPackages.length : 0;
if (newPackageLen > 0) {
String[] newPackages = new String[existingPackageLen + newPackageLen];
if (existingPackageLen > 0) {
System.arraycopy(existingSipper.mPackages, 0, newPackages, 0, existingPackageLen);
}
System.arraycopy(sipper.mPackages, 0, newPackages, existingPackageLen, newPackageLen);
existingSipper.mPackages = newPackages;
}
}
} else {
results.add(sipper);
}
}
final int numUidSippers = uidList.size();
for (int i = 0; i < numUidSippers; i++) {
results.add(uidList.valueAt(i));
}
// The sort order must have changed, so re-sort based on total power use.
Collections.sort(results, new Comparator<BatterySipper>() {
@Override
public int compare(BatterySipper a, BatterySipper b) {
return Double.compare(b.totalPowerMah, a.totalPowerMah);
}
});
return results;
}
use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.
the class ProcessStats method writeToParcel.
/** @hide */
public void writeToParcel(Parcel out, long now, int flags) {
out.writeInt(MAGIC);
out.writeInt(PARCEL_VERSION);
out.writeInt(STATE_COUNT);
out.writeInt(ADJ_COUNT);
out.writeInt(PSS_COUNT);
out.writeInt(SYS_MEM_USAGE_COUNT);
out.writeInt(SparseMappingTable.ARRAY_SIZE);
mCommonStringToIndex = new ArrayMap<String, Integer>(mProcesses.size());
// First commit all running times.
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
final int NPROC = procMap.size();
for (int ip = 0; ip < NPROC; ip++) {
SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
uids.valueAt(iu).commitStateTime(now);
}
}
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
final int NPKG = pkgMap.size();
for (int ip = 0; ip < NPKG; ip++) {
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (proc.getCommonProcess() != proc) {
proc.commitStateTime(now);
}
}
final int NSRVS = pkgState.mServices.size();
for (int isvc = 0; isvc < NSRVS; isvc++) {
pkgState.mServices.valueAt(isvc).commitStateTime(now);
}
}
}
}
out.writeLong(mTimePeriodStartClock);
out.writeLong(mTimePeriodStartRealtime);
out.writeLong(mTimePeriodEndRealtime);
out.writeLong(mTimePeriodStartUptime);
out.writeLong(mTimePeriodEndUptime);
out.writeString(mRuntime);
out.writeInt(mHasSwappedOutPss ? 1 : 0);
out.writeInt(mFlags);
mTableData.writeToParcel(out);
if (mMemFactor != STATE_NOTHING) {
mMemFactorDurations[mMemFactor] += now - mStartTime;
mStartTime = now;
}
writeCompactedLongArray(out, mMemFactorDurations, mMemFactorDurations.length);
mSysMemUsage.writeToParcel(out);
out.writeInt(NPROC);
for (int ip = 0; ip < NPROC; ip++) {
writeCommonString(out, procMap.keyAt(ip));
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
out.writeInt(NUID);
for (int iu = 0; iu < NUID; iu++) {
out.writeInt(uids.keyAt(iu));
final ProcessState proc = uids.valueAt(iu);
writeCommonString(out, proc.getPackage());
out.writeInt(proc.getVersion());
proc.writeToParcel(out, now);
}
}
out.writeInt(NPKG);
for (int ip = 0; ip < NPKG; ip++) {
writeCommonString(out, pkgMap.keyAt(ip));
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
out.writeInt(NUID);
for (int iu = 0; iu < NUID; iu++) {
out.writeInt(uids.keyAt(iu));
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
final int NVERS = vpkgs.size();
out.writeInt(NVERS);
for (int iv = 0; iv < NVERS; iv++) {
out.writeInt(vpkgs.keyAt(iv));
final PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
out.writeInt(NPROCS);
for (int iproc = 0; iproc < NPROCS; iproc++) {
writeCommonString(out, pkgState.mProcesses.keyAt(iproc));
final ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (proc.getCommonProcess() == proc) {
// This is the same as the common process we wrote above.
out.writeInt(0);
} else {
// There is separate data for this package's process.
out.writeInt(1);
proc.writeToParcel(out, now);
}
}
final int NSRVS = pkgState.mServices.size();
out.writeInt(NSRVS);
for (int isvc = 0; isvc < NSRVS; isvc++) {
out.writeString(pkgState.mServices.keyAt(isvc));
final ServiceState svc = pkgState.mServices.valueAt(isvc);
writeCommonString(out, svc.getProcessName());
svc.writeToParcel(out, now);
}
}
}
}
// Fragmentation info (/proc/pagetypeinfo)
final int NPAGETYPES = mPageTypeLabels.size();
out.writeInt(NPAGETYPES);
for (int i = 0; i < NPAGETYPES; i++) {
out.writeInt(mPageTypeZones.get(i));
out.writeString(mPageTypeLabels.get(i));
out.writeIntArray(mPageTypeSizes.get(i));
}
mCommonStringToIndex = null;
}
use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.
the class ProcessStats method collectProcessesLocked.
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates, int[] memStates, int[] procStates, int[] sortProcStates, long now, String reqPackage, boolean activeOnly) {
final ArraySet<ProcessState> foundProcs = new ArraySet<ProcessState>();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> procs = pkgMap.valueAt(ip);
for (int iu = 0; iu < procs.size(); iu++) {
final SparseArray<PackageState> vpkgs = procs.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
final PackageState state = vpkgs.valueAt(iv);
final int NPROCS = state.mProcesses.size();
final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
for (int iproc = 0; iproc < NPROCS; iproc++) {
final ProcessState proc = state.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
continue;
}
foundProcs.add(proc.getCommonProcess());
}
}
}
}
ArrayList<ProcessState> outProcs = new ArrayList<ProcessState>(foundProcs.size());
for (int i = 0; i < foundProcs.size(); i++) {
ProcessState proc = foundProcs.valueAt(i);
if (proc.computeProcessTimeLocked(screenStates, memStates, procStates, now) > 0) {
outProcs.add(proc);
if (procStates != sortProcStates) {
proc.computeProcessTimeLocked(screenStates, memStates, sortProcStates, now);
}
}
}
Collections.sort(outProcs, ProcessState.COMPARATOR);
return outProcs;
}
use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.
the class ProcessStats method resetSafely.
public void resetSafely() {
if (DEBUG)
Slog.d(TAG, "Safely resetting state of " + mTimePeriodStartClockStr);
resetCommon();
// First initialize use count of all common processes.
final long now = SystemClock.uptimeMillis();
final ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
for (int ip = procMap.size() - 1; ip >= 0; ip--) {
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
uids.valueAt(iu).tmpNumInUse = 0;
}
}
// Next reset or prune all per-package processes, and for the ones that are reset
// track this back to the common processes.
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = pkgMap.size() - 1; ip >= 0; ip--) {
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
for (int iv = vpkgs.size() - 1; iv >= 0; iv--) {
final PackageState pkgState = vpkgs.valueAt(iv);
for (int iproc = pkgState.mProcesses.size() - 1; iproc >= 0; iproc--) {
final ProcessState ps = pkgState.mProcesses.valueAt(iproc);
if (ps.isInUse()) {
ps.resetSafely(now);
ps.getCommonProcess().tmpNumInUse++;
ps.getCommonProcess().tmpFoundSubProc = ps;
} else {
pkgState.mProcesses.valueAt(iproc).makeDead();
pkgState.mProcesses.removeAt(iproc);
}
}
for (int isvc = pkgState.mServices.size() - 1; isvc >= 0; isvc--) {
final ServiceState ss = pkgState.mServices.valueAt(isvc);
if (ss.isInUse()) {
ss.resetSafely(now);
} else {
pkgState.mServices.removeAt(isvc);
}
}
if (pkgState.mProcesses.size() <= 0 && pkgState.mServices.size() <= 0) {
vpkgs.removeAt(iv);
}
}
if (vpkgs.size() <= 0) {
uids.removeAt(iu);
}
}
if (uids.size() <= 0) {
pkgMap.removeAt(ip);
}
}
// Finally prune out any common processes that are no longer in use.
for (int ip = procMap.size() - 1; ip >= 0; ip--) {
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
ProcessState ps = uids.valueAt(iu);
if (ps.isInUse() || ps.tmpNumInUse > 0) {
// using it).
if (!ps.isActive() && ps.isMultiPackage() && ps.tmpNumInUse == 1) {
// Here we go...
ps = ps.tmpFoundSubProc;
ps.makeStandalone();
uids.setValueAt(iu, ps);
} else {
ps.resetSafely(now);
}
} else {
ps.makeDead();
uids.removeAt(iu);
}
}
if (uids.size() <= 0) {
procMap.removeAt(ip);
}
}
mStartTime = now;
if (DEBUG)
Slog.d(TAG, "State reset; now " + mTimePeriodStartClockStr);
}
Aggregations