Search in sources :

Example 96 with SparseArray

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;
}
Also used : ArraySet(android.util.ArraySet) ArrayList(java.util.ArrayList) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 97 with SparseArray

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);
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray) ServiceState(com.android.internal.app.procstats.ServiceState)

Example 98 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.

the class ProcessStats method dumpCheckinLocked.

public void dumpCheckinLocked(PrintWriter pw, String reqPackage) {
    final long now = SystemClock.uptimeMillis();
    final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
    pw.println("vers,5");
    pw.print("period,");
    pw.print(mTimePeriodStartClockStr);
    pw.print(",");
    pw.print(mTimePeriodStartRealtime);
    pw.print(",");
    pw.print(mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
    boolean partial = true;
    if ((mFlags & FLAG_SHUTDOWN) != 0) {
        pw.print(",shutdown");
        partial = false;
    }
    if ((mFlags & FLAG_SYSPROPS) != 0) {
        pw.print(",sysprops");
        partial = false;
    }
    if ((mFlags & FLAG_COMPLETE) != 0) {
        pw.print(",complete");
        partial = false;
    }
    if (partial) {
        pw.print(",partial");
    }
    if (mHasSwappedOutPss) {
        pw.print(",swapped-out-pss");
    }
    pw.println();
    pw.print("config,");
    pw.println(mRuntime);
    for (int ip = 0; ip < pkgMap.size(); ip++) {
        final String pkgName = pkgMap.keyAt(ip);
        if (reqPackage != null && !reqPackage.equals(pkgName)) {
            continue;
        }
        final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
        for (int iu = 0; iu < uids.size(); iu++) {
            final int uid = uids.keyAt(iu);
            final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
            for (int iv = 0; iv < vpkgs.size(); iv++) {
                final int vers = vpkgs.keyAt(iv);
                final PackageState pkgState = vpkgs.valueAt(iv);
                final int NPROCS = pkgState.mProcesses.size();
                final int NSRVS = pkgState.mServices.size();
                for (int iproc = 0; iproc < NPROCS; iproc++) {
                    ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                    proc.dumpPackageProcCheckin(pw, pkgName, uid, vers, pkgState.mProcesses.keyAt(iproc), now);
                }
                for (int isvc = 0; isvc < NSRVS; isvc++) {
                    final String serviceName = DumpUtils.collapseString(pkgName, pkgState.mServices.keyAt(isvc));
                    final ServiceState svc = pkgState.mServices.valueAt(isvc);
                    svc.dumpTimesCheckin(pw, pkgName, uid, vers, serviceName, now);
                }
            }
        }
    }
    ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
    for (int ip = 0; ip < procMap.size(); ip++) {
        String procName = procMap.keyAt(ip);
        SparseArray<ProcessState> uids = procMap.valueAt(ip);
        for (int iu = 0; iu < uids.size(); iu++) {
            final int uid = uids.keyAt(iu);
            final ProcessState procState = uids.valueAt(iu);
            procState.dumpProcCheckin(pw, procName, uid, now);
        }
    }
    pw.print("total");
    DumpUtils.dumpAdjTimesCheckin(pw, ",", mMemFactorDurations, mMemFactor, mStartTime, now);
    pw.println();
    final int sysMemUsageCount = mSysMemUsage.getKeyCount();
    if (sysMemUsageCount > 0) {
        pw.print("sysmemusage");
        for (int i = 0; i < sysMemUsageCount; i++) {
            final int key = mSysMemUsage.getKeyAt(i);
            final int type = SparseMappingTable.getIdFromKey(key);
            pw.print(",");
            DumpUtils.printProcStateTag(pw, type);
            for (int j = SYS_MEM_USAGE_SAMPLE_COUNT; j < SYS_MEM_USAGE_COUNT; j++) {
                if (j > SYS_MEM_USAGE_CACHED_MINIMUM) {
                    pw.print(":");
                }
                pw.print(mSysMemUsage.getValue(key, j));
            }
        }
    }
    pw.println();
    TotalMemoryUseCollection totalMem = new TotalMemoryUseCollection(ALL_SCREEN_ADJ, ALL_MEM_ADJ);
    computeTotalMemoryUse(totalMem, now);
    pw.print("weights,");
    pw.print(totalMem.totalTime);
    pw.print(",");
    pw.print(totalMem.sysMemCachedWeight);
    pw.print(":");
    pw.print(totalMem.sysMemSamples);
    pw.print(",");
    pw.print(totalMem.sysMemFreeWeight);
    pw.print(":");
    pw.print(totalMem.sysMemSamples);
    pw.print(",");
    pw.print(totalMem.sysMemZRamWeight);
    pw.print(":");
    pw.print(totalMem.sysMemSamples);
    pw.print(",");
    pw.print(totalMem.sysMemKernelWeight);
    pw.print(":");
    pw.print(totalMem.sysMemSamples);
    pw.print(",");
    pw.print(totalMem.sysMemNativeWeight);
    pw.print(":");
    pw.print(totalMem.sysMemSamples);
    for (int i = 0; i < STATE_COUNT; i++) {
        pw.print(",");
        pw.print(totalMem.processStateWeight[i]);
        pw.print(":");
        pw.print(totalMem.processStateSamples[i]);
    }
    pw.println();
    final int NPAGETYPES = mPageTypeLabels.size();
    for (int i = 0; i < NPAGETYPES; i++) {
        pw.print("availablepages,");
        pw.print(mPageTypeLabels.get(i));
        pw.print(",");
        pw.print(mPageTypeZones.get(i));
        pw.print(",");
        final int[] sizes = mPageTypeSizes.get(i);
        final int N = sizes == null ? 0 : sizes.length;
        for (int j = 0; j < N; j++) {
            if (j != 0) {
                pw.print(",");
            }
            pw.print(sizes[j]);
        }
        pw.println();
    }
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 99 with SparseArray

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;
}
Also used : SparseArray(android.util.SparseArray) BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList)

Example 100 with SparseArray

use of android.util.SparseArray in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageList method bindStats.

/**
     * Bind the given {@link NetworkStats}, or {@code null} to clear list.
     */
public void bindStats(NetworkStats stats, int[] restrictedUids) {
    ArrayList<AppItem> items = new ArrayList<>();
    long largest = 0;
    final int currentUserId = ActivityManager.getCurrentUser();
    UserManager userManager = UserManager.get(getContext());
    final List<UserHandle> profiles = userManager.getUserProfiles();
    final SparseArray<AppItem> knownItems = new SparseArray<AppItem>();
    PackageManager pm = getContext().getPackageManager();
    ApplicationInfo ai = null;
    try {
        ai = pm.getApplicationInfo("com.android.dialer", PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        Log.d(TAG, "get dialer getApplicationInfo failed " + e);
    }
    NetworkStats.Entry entry = null;
    final int size = stats != null ? stats.size() : 0;
    for (int i = 0; i < size; i++) {
        entry = stats.getValues(i, entry);
        // Decide how to collapse items together
        final int uid = entry.uid;
        final int collapseKey;
        final int category;
        final int userId = UserHandle.getUserId(uid);
        if (UserHandle.isApp(uid)) {
            if (profiles.contains(new UserHandle(userId))) {
                if (userId != currentUserId) {
                    // Add to a managed user item.
                    final int managedKey = UidDetailProvider.buildKeyForUser(userId);
                    largest = accumulate(managedKey, knownItems, entry, AppItem.CATEGORY_USER, items, largest);
                }
                // Add to app item.
                collapseKey = uid;
                category = AppItem.CATEGORY_APP;
            } else {
                // If it is a removed user add it to the removed users' key
                final UserInfo info = userManager.getUserInfo(userId);
                if (info == null) {
                    collapseKey = UID_REMOVED;
                    category = AppItem.CATEGORY_APP;
                } else {
                    // Add to other user item.
                    collapseKey = UidDetailProvider.buildKeyForUser(userId);
                    category = AppItem.CATEGORY_USER;
                }
            }
        } else if (uid == UID_REMOVED || uid == UID_TETHERING) {
            collapseKey = uid;
            category = AppItem.CATEGORY_APP;
        } else if ((ai != null) && (uid == ai.uid) && getContext().getResources().getBoolean(com.android.internal.R.bool.config_video_call_datausage_enable)) {
            collapseKey = uid;
            category = AppItem.CATEGORY_APP;
        } else {
            collapseKey = android.os.Process.SYSTEM_UID;
            category = AppItem.CATEGORY_APP;
        }
        largest = accumulate(collapseKey, knownItems, entry, category, items, largest);
    }
    final int restrictedUidsMax = restrictedUids.length;
    for (int i = 0; i < restrictedUidsMax; ++i) {
        final int uid = restrictedUids[i];
        // Only splice in restricted state for current user or managed users
        if (!profiles.contains(new UserHandle(UserHandle.getUserId(uid)))) {
            continue;
        }
        AppItem item = knownItems.get(uid);
        if (item == null) {
            item = new AppItem(uid);
            item.total = -1;
            items.add(item);
            knownItems.put(item.key, item);
        }
        item.restricted = true;
    }
    Collections.sort(items);
    mApps.removeAll();
    for (int i = 0; i < items.size(); i++) {
        final int percentTotal = largest != 0 ? (int) (items.get(i).total * 100 / largest) : 0;
        AppDataUsagePreference preference = new AppDataUsagePreference(getContext(), items.get(i), percentTotal, mUidDetailProvider);
        preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppDataUsagePreference pref = (AppDataUsagePreference) preference;
                AppItem item = pref.getItem();
                startAppDataUsage(item);
                return true;
            }
        });
        mApps.addPreference(preference);
    }
}
Also used : ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) NetworkStats(android.net.NetworkStats) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException) SparseArray(android.util.SparseArray) PackageManager(android.content.pm.PackageManager) AppItem(com.android.settingslib.AppItem) Preference(android.support.v7.preference.Preference) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle)

Aggregations

SparseArray (android.util.SparseArray)250 ArrayList (java.util.ArrayList)75 ProcessState (com.android.internal.app.procstats.ProcessState)41 Parcelable (android.os.Parcelable)37 View (android.view.View)35 ServiceState (com.android.internal.app.procstats.ServiceState)31 RemoteException (android.os.RemoteException)24 Point (android.graphics.Point)19 ArraySet (android.util.ArraySet)17 HashMap (java.util.HashMap)17 ComponentName (android.content.ComponentName)15 ProcessStats (com.android.internal.app.procstats.ProcessStats)15 UserHandle (android.os.UserHandle)14 ArrayMap (android.util.ArrayMap)14 UserInfo (android.content.pm.UserInfo)13 Paint (android.graphics.Paint)13 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)12 ApplicationInfo (android.content.pm.ApplicationInfo)11 SparseIntArray (android.util.SparseIntArray)11