Search in sources :

Example 31 with ServiceState

use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by crdroidandroid.

the class ActiveServices method bindServiceLocked.

int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service, String resolvedType, final IServiceConnection connection, int flags, String callingPackage, final int userId) throws TransactionTooLargeException {
    if (DEBUG_SERVICE)
        Slog.v(TAG_SERVICE, "bindService: " + service + " type=" + resolvedType + " conn=" + connection.asBinder() + " flags=0x" + Integer.toHexString(flags));
    final ProcessRecord callerApp = mAm.getRecordForAppLocked(caller);
    if (callerApp == null) {
        throw new SecurityException("Unable to find app for caller " + caller + " (pid=" + Binder.getCallingPid() + ") when binding service " + service);
    }
    ActivityRecord activity = null;
    if (token != null) {
        activity = ActivityRecord.isInStackLocked(token);
        if (activity == null) {
            Slog.w(TAG, "Binding with unknown activity: " + token);
            return 0;
        }
    }
    int clientLabel = 0;
    PendingIntent clientIntent = null;
    final boolean isCallerSystem = callerApp.info.uid == Process.SYSTEM_UID;
    if (isCallerSystem) {
        // Hacky kind of thing -- allow system stuff to tell us
        // what they are, so we can report this elsewhere for
        // others to know why certain services are running.
        service.setDefusable(true);
        clientIntent = service.getParcelableExtra(Intent.EXTRA_CLIENT_INTENT);
        if (clientIntent != null) {
            clientLabel = service.getIntExtra(Intent.EXTRA_CLIENT_LABEL, 0);
            if (clientLabel != 0) {
                // There are no useful extras in the intent, trash them.
                // System code calling with this stuff just needs to know
                // this will happen.
                service = service.cloneFilter();
            }
        }
    }
    if ((flags & Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
        mAm.enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS, "BIND_TREAT_LIKE_ACTIVITY");
    }
    if ((flags & Context.BIND_ALLOW_WHITELIST_MANAGEMENT) != 0 && !isCallerSystem) {
        throw new SecurityException("Non-system caller " + caller + " (pid=" + Binder.getCallingPid() + ") set BIND_ALLOW_WHITELIST_MANAGEMENT when binding service " + service);
    }
    final boolean callerFg = callerApp.setSchedGroup != ProcessList.SCHED_GROUP_BACKGROUND;
    final boolean isBindExternal = (flags & Context.BIND_EXTERNAL_SERVICE) != 0;
    ServiceLookupResult res = retrieveServiceLocked(service, resolvedType, callingPackage, Binder.getCallingPid(), Binder.getCallingUid(), userId, true, callerFg, isBindExternal);
    if (res == null) {
        return 0;
    }
    if (res.record == null) {
        return -1;
    }
    ServiceRecord s = res.record;
    boolean permissionsReviewRequired = false;
    // when done to start the bound service's process to completing the binding.
    if (mAm.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
        if (mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(s.packageName, s.userId)) {
            permissionsReviewRequired = true;
            // Show a permission review UI only for binding from a foreground app
            if (!callerFg) {
                Slog.w(TAG, "u" + s.userId + " Binding to a service in package" + s.packageName + " requires a permissions review");
                return 0;
            }
            final ServiceRecord serviceRecord = s;
            final Intent serviceIntent = service;
            RemoteCallback callback = new RemoteCallback(new RemoteCallback.OnResultListener() {

                @Override
                public void onResult(Bundle result) {
                    synchronized (mAm) {
                        final long identity = Binder.clearCallingIdentity();
                        try {
                            if (!mPendingServices.contains(serviceRecord)) {
                                return;
                            }
                            // otherwise we unbind because the user didn't approve.
                            if (!mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(serviceRecord.packageName, serviceRecord.userId)) {
                                try {
                                    bringUpServiceLocked(serviceRecord, serviceIntent.getFlags(), callerFg, false, false);
                                } catch (RemoteException e) {
                                /* ignore - local call */
                                }
                            } else {
                                unbindServiceLocked(connection);
                            }
                        } finally {
                            Binder.restoreCallingIdentity(identity);
                        }
                    }
                }
            });
            final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, s.packageName);
            intent.putExtra(Intent.EXTRA_REMOTE_CALLBACK, callback);
            if (DEBUG_PERMISSIONS_REVIEW) {
                Slog.i(TAG, "u" + s.userId + " Launching permission review for package " + s.packageName);
            }
            mAm.mHandler.post(new Runnable() {

                @Override
                public void run() {
                    mAm.mContext.startActivityAsUser(intent, new UserHandle(userId));
                }
            });
        }
    }
    final long origId = Binder.clearCallingIdentity();
    IBinder ibinder = connection.asBinder();
    ArrayList<ConnectionRecord> list = s.connections.get(ibinder);
    if (list != null && list.size() >= MAX_SERVICE_COUNT) {
        Slog.e(TAG_SERVICE, s + " has already bind " + MAX_SERVICE_COUNT + " connections. Not allow to bind more.");
        return 0;
    }
    try {
        if (unscheduleServiceRestartLocked(s, callerApp.info.uid, false)) {
            if (DEBUG_SERVICE)
                Slog.v(TAG_SERVICE, "BIND SERVICE WHILE RESTART PENDING: " + s);
        }
        if ((flags & Context.BIND_AUTO_CREATE) != 0) {
            s.lastActivity = SystemClock.uptimeMillis();
            if (!s.hasAutoCreateConnections()) {
                // This is the first binding, let the tracker know.
                ServiceState stracker = s.getTracker();
                if (stracker != null) {
                    stracker.setBound(true, mAm.mProcessStats.getMemFactorLocked(), s.lastActivity);
                }
            }
        }
        mAm.startAssociationLocked(callerApp.uid, callerApp.processName, callerApp.curProcState, s.appInfo.uid, s.name, s.processName);
        AppBindRecord b = s.retrieveAppBindingLocked(service, callerApp);
        ConnectionRecord c = new ConnectionRecord(b, activity, connection, flags, clientLabel, clientIntent);
        IBinder binder = connection.asBinder();
        ArrayList<ConnectionRecord> clist = s.connections.get(binder);
        if (clist == null) {
            clist = new ArrayList<ConnectionRecord>();
            s.connections.put(binder, clist);
        }
        clist.add(c);
        b.connections.add(c);
        if (activity != null) {
            if (activity.connections == null) {
                activity.connections = new HashSet<ConnectionRecord>();
            }
            activity.connections.add(c);
        }
        b.client.connections.add(c);
        if ((c.flags & Context.BIND_ABOVE_CLIENT) != 0) {
            b.client.hasAboveClient = true;
        }
        if ((c.flags & Context.BIND_ALLOW_WHITELIST_MANAGEMENT) != 0) {
            s.whitelistManager = true;
        }
        if (s.app != null) {
            updateServiceClientActivitiesLocked(s.app, c, true);
        }
        clist = mServiceConnections.get(binder);
        if (clist == null) {
            clist = new ArrayList<ConnectionRecord>();
            mServiceConnections.put(binder, clist);
        }
        clist.add(c);
        if ((flags & Context.BIND_AUTO_CREATE) != 0) {
            s.lastActivity = SystemClock.uptimeMillis();
            if (bringUpServiceLocked(s, service.getFlags(), callerFg, false, permissionsReviewRequired) != null) {
                return 0;
            }
        }
        if (s.app != null) {
            if ((flags & Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
                s.app.treatLikeActivity = true;
            }
            if (s.whitelistManager) {
                s.app.whitelistManager = true;
            }
            // This could have made the service more important.
            mAm.updateLruProcessLocked(s.app, s.app.hasClientActivities || s.app.treatLikeActivity, b.client);
            mAm.updateOomAdjLocked(s.app);
        }
        if (DEBUG_SERVICE)
            Slog.v(TAG_SERVICE, "Bind " + s + " with " + b + ": received=" + b.intent.received + " apps=" + b.intent.apps.size() + " doRebind=" + b.intent.doRebind);
        if (s.app != null && b.intent.received) {
            // publish the connection.
            try {
                c.conn.connected(s.name, b.intent.binder);
            } catch (Exception e) {
                Slog.w(TAG, "Failure sending service " + s.shortName + " to connection " + c.conn.asBinder() + " (in " + c.binding.client.processName + ")", e);
            }
            // rebound, then do so.
            if (b.intent.apps.size() == 1 && b.intent.doRebind) {
                requestServiceBindingLocked(s, b.intent, callerFg, true);
            }
        } else if (!b.intent.requested) {
            requestServiceBindingLocked(s, b.intent, callerFg, false);
        }
        getServiceMap(s.userId).ensureNotStartingBackground(s);
    } finally {
        Binder.restoreCallingIdentity(origId);
    }
    return 1;
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteCallback(android.os.RemoteCallback) RemoteException(android.os.RemoteException) TransactionTooLargeException(android.os.TransactionTooLargeException) IOException(java.io.IOException) DeadObjectException(android.os.DeadObjectException) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Example 32 with ServiceState

use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by crdroidandroid.

the class ActiveServices method bumpServiceExecutingLocked.

private final void bumpServiceExecutingLocked(ServiceRecord r, boolean fg, String why) {
    if (DEBUG_SERVICE)
        Slog.v(TAG_SERVICE, ">>> EXECUTING " + why + " of " + r + " in app " + r.app);
    else if (DEBUG_SERVICE_EXECUTING)
        Slog.v(TAG_SERVICE_EXECUTING, ">>> EXECUTING " + why + " of " + r.shortName);
    long now = SystemClock.uptimeMillis();
    if (r.executeNesting == 0) {
        r.executeFg = fg;
        ServiceState stracker = r.getTracker();
        if (stracker != null) {
            stracker.setExecuting(true, mAm.mProcessStats.getMemFactorLocked(), now);
        }
        if (r.app != null) {
            r.app.executingServices.add(r);
            r.app.execServicesFg |= fg;
            if (r.app.executingServices.size() == 1) {
                scheduleServiceTimeoutLocked(r.app);
            }
        }
    } else if (r.app != null && fg && !r.app.execServicesFg) {
        r.app.execServicesFg = true;
        scheduleServiceTimeoutLocked(r.app);
    }
    r.executeFg |= fg;
    r.executeNesting++;
    r.executingStart = now;
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState)

Example 33 with ServiceState

use of com.android.internal.app.procstats.ServiceState in project platform_frameworks_base by android.

the class ProcessStats method getProcessStateLocked.

public ProcessState getProcessStateLocked(String packageName, int uid, int vers, String processName) {
    final PackageState pkgState = getPackageStateLocked(packageName, uid, vers);
    ProcessState ps = pkgState.mProcesses.get(processName);
    if (ps != null) {
        return ps;
    }
    ProcessState commonProc = mProcesses.get(processName, uid);
    if (commonProc == null) {
        commonProc = new ProcessState(this, packageName, uid, vers, processName);
        mProcesses.put(processName, uid, commonProc);
        if (DEBUG)
            Slog.d(TAG, "GETPROC created new common " + commonProc);
    }
    if (!commonProc.isMultiPackage()) {
        if (packageName.equals(commonProc.getPackage()) && vers == commonProc.getVersion()) {
            // This common process is not in use by multiple packages, and
            // is for the calling package, so we can just use it directly.
            ps = commonProc;
            if (DEBUG)
                Slog.d(TAG, "GETPROC also using for pkg " + commonProc);
        } else {
            if (DEBUG)
                Slog.d(TAG, "GETPROC need to split common proc!");
            // This common process has not been in use by multiple packages,
            // but it was created for a different package than the caller.
            // We need to convert it to a multi-package process.
            commonProc.setMultiPackage(true);
            // To do this, we need to make two new process states, one a copy
            // of the current state for the process under the original package
            // name, and the second a free new process state for it as the
            // new package name.
            long now = SystemClock.uptimeMillis();
            // First let's make a copy of the current process state and put
            // that under the now unique state for its original package name.
            final PackageState commonPkgState = getPackageStateLocked(commonProc.getPackage(), uid, commonProc.getVersion());
            if (commonPkgState != null) {
                ProcessState cloned = commonProc.clone(now);
                if (DEBUG)
                    Slog.d(TAG, "GETPROC setting clone to pkg " + commonProc.getPackage() + ": " + cloned);
                commonPkgState.mProcesses.put(commonProc.getName(), cloned);
                // to point to the new package-specific process state.
                for (int i = commonPkgState.mServices.size() - 1; i >= 0; i--) {
                    ServiceState ss = commonPkgState.mServices.valueAt(i);
                    if (ss.getProcess() == commonProc) {
                        if (DEBUG)
                            Slog.d(TAG, "GETPROC switching service to cloned: " + ss);
                        ss.setProcess(cloned);
                    } else if (DEBUG) {
                        Slog.d(TAG, "GETPROC leaving proc of " + ss);
                    }
                }
            } else {
                Slog.w(TAG, "Cloning proc state: no package state " + commonProc.getPackage() + "/" + uid + " for proc " + commonProc.getName());
            }
            // And now make a fresh new process state for the new package name.
            ps = new ProcessState(commonProc, packageName, uid, vers, processName, now);
            if (DEBUG)
                Slog.d(TAG, "GETPROC created new pkg " + ps);
        }
    } else {
        // The common process is for multiple packages, we need to create a
        // separate object for the per-package data.
        ps = new ProcessState(commonProc, packageName, uid, vers, processName, SystemClock.uptimeMillis());
        if (DEBUG)
            Slog.d(TAG, "GETPROC created new pkg " + ps);
    }
    pkgState.mProcesses.put(processName, ps);
    if (DEBUG)
        Slog.d(TAG, "GETPROC adding new pkg " + ps);
    return ps;
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ServiceState(com.android.internal.app.procstats.ServiceState)

Example 34 with ServiceState

use of com.android.internal.app.procstats.ServiceState in project platform_frameworks_base by android.

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 35 with ServiceState

use of com.android.internal.app.procstats.ServiceState in project platform_frameworks_base by android.

the class ProcessStats method dumpLocked.

public void dumpLocked(PrintWriter pw, String reqPackage, long now, boolean dumpSummary, boolean dumpAll, boolean activeOnly) {
    long totalTime = DumpUtils.dumpSingleTime(null, null, mMemFactorDurations, mMemFactor, mStartTime, now);
    boolean sepNeeded = false;
    if (mSysMemUsage.getKeyCount() > 0) {
        pw.println("System memory usage:");
        mSysMemUsage.dump(pw, "  ", ALL_SCREEN_ADJ, ALL_MEM_ADJ);
        sepNeeded = true;
    }
    ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
    boolean printedHeader = false;
    for (int ip = 0; ip < pkgMap.size(); ip++) {
        final String pkgName = pkgMap.keyAt(ip);
        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();
                final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
                if (!pkgMatch) {
                    boolean procMatch = false;
                    for (int iproc = 0; iproc < NPROCS; iproc++) {
                        ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                        if (reqPackage.equals(proc.getName())) {
                            procMatch = true;
                            break;
                        }
                    }
                    if (!procMatch) {
                        continue;
                    }
                }
                if (NPROCS > 0 || NSRVS > 0) {
                    if (!printedHeader) {
                        if (sepNeeded)
                            pw.println();
                        pw.println("Per-Package Stats:");
                        printedHeader = true;
                        sepNeeded = true;
                    }
                    pw.print("  * ");
                    pw.print(pkgName);
                    pw.print(" / ");
                    UserHandle.formatUid(pw, uid);
                    pw.print(" / v");
                    pw.print(vers);
                    pw.println(":");
                }
                if (!dumpSummary || dumpAll) {
                    for (int iproc = 0; iproc < NPROCS; iproc++) {
                        ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                        if (!pkgMatch && !reqPackage.equals(proc.getName())) {
                            continue;
                        }
                        if (activeOnly && !proc.isInUse()) {
                            pw.print("      (Not active: ");
                            pw.print(pkgState.mProcesses.keyAt(iproc));
                            pw.println(")");
                            continue;
                        }
                        pw.print("      Process ");
                        pw.print(pkgState.mProcesses.keyAt(iproc));
                        if (proc.getCommonProcess().isMultiPackage()) {
                            pw.print(" (multi, ");
                        } else {
                            pw.print(" (unique, ");
                        }
                        pw.print(proc.getDurationsBucketCount());
                        pw.print(" entries)");
                        pw.println(":");
                        proc.dumpProcessState(pw, "        ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES, now);
                        proc.dumpPss(pw, "        ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES);
                        proc.dumpInternalLocked(pw, "        ", dumpAll);
                    }
                } else {
                    ArrayList<ProcessState> procs = new ArrayList<ProcessState>();
                    for (int iproc = 0; iproc < NPROCS; iproc++) {
                        ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                        if (!pkgMatch && !reqPackage.equals(proc.getName())) {
                            continue;
                        }
                        if (activeOnly && !proc.isInUse()) {
                            continue;
                        }
                        procs.add(proc);
                    }
                    DumpUtils.dumpProcessSummaryLocked(pw, "      ", procs, ALL_SCREEN_ADJ, ALL_MEM_ADJ, NON_CACHED_PROC_STATES, now, totalTime);
                }
                for (int isvc = 0; isvc < NSRVS; isvc++) {
                    ServiceState svc = pkgState.mServices.valueAt(isvc);
                    if (!pkgMatch && !reqPackage.equals(svc.getProcessName())) {
                        continue;
                    }
                    if (activeOnly && !svc.isInUse()) {
                        pw.print("      (Not active: ");
                        pw.print(pkgState.mServices.keyAt(isvc));
                        pw.println(")");
                        continue;
                    }
                    if (dumpAll) {
                        pw.print("      Service ");
                    } else {
                        pw.print("      * ");
                    }
                    pw.print(pkgState.mServices.keyAt(isvc));
                    pw.println(":");
                    pw.print("        Process: ");
                    pw.println(svc.getProcessName());
                    svc.dumpStats(pw, "        ", "          ", "    ", now, totalTime, dumpSummary, dumpAll);
                }
            }
        }
    }
    ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
    printedHeader = false;
    int numShownProcs = 0, numTotalProcs = 0;
    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++) {
            int uid = uids.keyAt(iu);
            numTotalProcs++;
            final ProcessState proc = uids.valueAt(iu);
            if (proc.hasAnyData()) {
                continue;
            }
            if (!proc.isMultiPackage()) {
                continue;
            }
            if (reqPackage != null && !reqPackage.equals(procName) && !reqPackage.equals(proc.getPackage())) {
                continue;
            }
            numShownProcs++;
            if (sepNeeded) {
                pw.println();
            }
            sepNeeded = true;
            if (!printedHeader) {
                pw.println("Multi-Package Common Processes:");
                printedHeader = true;
            }
            if (activeOnly && !proc.isInUse()) {
                pw.print("      (Not active: ");
                pw.print(procName);
                pw.println(")");
                continue;
            }
            pw.print("  * ");
            pw.print(procName);
            pw.print(" / ");
            UserHandle.formatUid(pw, uid);
            pw.print(" (");
            pw.print(proc.getDurationsBucketCount());
            pw.print(" entries)");
            pw.println(":");
            proc.dumpProcessState(pw, "        ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES, now);
            proc.dumpPss(pw, "        ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES);
            proc.dumpInternalLocked(pw, "        ", dumpAll);
        }
    }
    if (dumpAll) {
        pw.println();
        pw.print("  Total procs: ");
        pw.print(numShownProcs);
        pw.print(" shown of ");
        pw.print(numTotalProcs);
        pw.println(" total");
    }
    if (sepNeeded) {
        pw.println();
    }
    if (dumpSummary) {
        pw.println("Summary:");
        dumpSummaryLocked(pw, reqPackage, now, activeOnly);
    } else {
        dumpTotalsLocked(pw, now);
    }
    if (dumpAll) {
        pw.println();
        pw.println("Internal state:");
        /*
            pw.print("  Num long arrays: "); pw.println(mLongs.size());
            pw.print("  Next long entry: "); pw.println(mNextLong);
            */
        pw.print("  mRunning=");
        pw.println(mRunning);
    }
    dumpFragmentationLocked(pw);
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState) ArrayList(java.util.ArrayList) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Aggregations

ServiceState (com.android.internal.app.procstats.ServiceState)61 ProcessState (com.android.internal.app.procstats.ProcessState)41 SparseArray (android.util.SparseArray)31 IProcessStats (com.android.internal.app.procstats.IProcessStats)6 ProcessStats (com.android.internal.app.procstats.ProcessStats)6 ArrayList (java.util.ArrayList)6 PendingIntent (android.app.PendingIntent)5 ComponentName (android.content.ComponentName)5 Intent (android.content.Intent)5 Bundle (android.os.Bundle)5 DeadObjectException (android.os.DeadObjectException)5 IBinder (android.os.IBinder)5 RemoteCallback (android.os.RemoteCallback)5 RemoteException (android.os.RemoteException)5 TransactionTooLargeException (android.os.TransactionTooLargeException)5 UserHandle (android.os.UserHandle)5 IOException (java.io.IOException)5 ProcessMap (com.android.internal.app.ProcessMap)1