Search in sources :

Example 51 with BatteryStatsImpl

use of com.android.internal.os.BatteryStatsImpl in project android_frameworks_base by DirtyUnicorns.

the class ActivityManagerService method checkExcessivePowerUsageLocked.

final void checkExcessivePowerUsageLocked(boolean doKills) {
    updateCpuStatsNow();
    BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
    boolean doWakeKills = doKills;
    boolean doCpuKills = doKills;
    if (mLastPowerCheckRealtime == 0) {
        doWakeKills = false;
    }
    if (mLastPowerCheckUptime == 0) {
        doCpuKills = false;
    }
    if (stats.isScreenOn()) {
        doWakeKills = false;
    }
    final long curRealtime = SystemClock.elapsedRealtime();
    final long realtimeSince = curRealtime - mLastPowerCheckRealtime;
    final long curUptime = SystemClock.uptimeMillis();
    final long uptimeSince = curUptime - mLastPowerCheckUptime;
    mLastPowerCheckRealtime = curRealtime;
    mLastPowerCheckUptime = curUptime;
    if (realtimeSince < WAKE_LOCK_MIN_CHECK_DURATION) {
        doWakeKills = false;
    }
    if (uptimeSince < CPU_MIN_CHECK_DURATION) {
        doCpuKills = false;
    }
    int i = mLruProcesses.size();
    while (i > 0) {
        i--;
        ProcessRecord app = mLruProcesses.get(i);
        if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) {
            long wtime;
            synchronized (stats) {
                wtime = stats.getProcessWakeTime(app.info.uid, app.pid, curRealtime);
            }
            long wtimeUsed = wtime - app.lastWakeTime;
            long cputimeUsed = app.curCpuTime - app.lastCpuTime;
            if (DEBUG_POWER) {
                StringBuilder sb = new StringBuilder(128);
                sb.append("Wake for ");
                app.toShortString(sb);
                sb.append(": over ");
                TimeUtils.formatDuration(realtimeSince, sb);
                sb.append(" used ");
                TimeUtils.formatDuration(wtimeUsed, sb);
                sb.append(" (");
                sb.append((wtimeUsed * 100) / realtimeSince);
                sb.append("%)");
                Slog.i(TAG_POWER, sb.toString());
                sb.setLength(0);
                sb.append("CPU for ");
                app.toShortString(sb);
                sb.append(": over ");
                TimeUtils.formatDuration(uptimeSince, sb);
                sb.append(" used ");
                TimeUtils.formatDuration(cputimeUsed, sb);
                sb.append(" (");
                sb.append((cputimeUsed * 100) / uptimeSince);
                sb.append("%)");
                Slog.i(TAG_POWER, sb.toString());
            }
            // that sounds bad.  Kill!
            if (doWakeKills && realtimeSince > 0 && ((wtimeUsed * 100) / realtimeSince) >= 50) {
                synchronized (stats) {
                    stats.reportExcessiveWakeLocked(app.info.uid, app.processName, realtimeSince, wtimeUsed);
                }
                app.kill("excessive wake held " + wtimeUsed + " during " + realtimeSince, true);
                app.baseProcessTracker.reportExcessiveWake(app.pkgList);
            } else if (doCpuKills && uptimeSince > 0 && ((cputimeUsed * 100) / uptimeSince) >= 25) {
                synchronized (stats) {
                    stats.reportExcessiveCpuLocked(app.info.uid, app.processName, uptimeSince, cputimeUsed);
                }
                app.kill("excessive cpu " + cputimeUsed + " during " + uptimeSince, true);
                app.baseProcessTracker.reportExcessiveCpu(app.pkgList);
            } else {
                app.lastWakeTime = wtime;
                app.lastCpuTime = app.curCpuTime;
            }
        }
    }
}
Also used : BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) Point(android.graphics.Point)

Example 52 with BatteryStatsImpl

use of com.android.internal.os.BatteryStatsImpl in project android_frameworks_base by DirtyUnicorns.

the class ActiveServices method retrieveServiceLocked.

private ServiceLookupResult retrieveServiceLocked(Intent service, String resolvedType, String callingPackage, int callingPid, int callingUid, int userId, boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal) {
    ServiceRecord r = null;
    if (DEBUG_SERVICE)
        Slog.v(TAG_SERVICE, "retrieveServiceLocked: " + service + " type=" + resolvedType + " callingUid=" + callingUid);
    userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false, ActivityManagerService.ALLOW_NON_FULL_IN_PROFILE, "service", null);
    ServiceMap smap = getServiceMap(userId);
    final ComponentName comp = service.getComponent();
    if (comp != null) {
        r = smap.mServicesByName.get(comp);
    }
    if (r == null && !isBindExternal) {
        Intent.FilterComparison filter = new Intent.FilterComparison(service);
        r = smap.mServicesByIntent.get(filter);
    }
    if (r != null && (r.serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0 && !callingPackage.equals(r.packageName)) {
        // If an external service is running within its own package, other packages
        // should not bind to that instance.
        r = null;
    }
    if (r == null) {
        try {
            // TODO: come back and remove this assumption to triage all services
            ResolveInfo rInfo = AppGlobals.getPackageManager().resolveService(service, resolvedType, ActivityManagerService.STOCK_PM_FLAGS | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
            ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null;
            if (sInfo == null) {
                Slog.w(TAG_SERVICE, "Unable to start service " + service + " U=" + userId + ": not found");
                return null;
            }
            ComponentName name = new ComponentName(sInfo.applicationInfo.packageName, sInfo.name);
            if ((sInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0) {
                if (isBindExternal) {
                    if (!sInfo.exported) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not exported");
                    }
                    if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an isolatedProcess");
                    }
                    // Run the service under the calling package's application.
                    ApplicationInfo aInfo = AppGlobals.getPackageManager().getApplicationInfo(callingPackage, ActivityManagerService.STOCK_PM_FLAGS, userId);
                    if (aInfo == null) {
                        throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + "could not resolve client package " + callingPackage);
                    }
                    sInfo = new ServiceInfo(sInfo);
                    sInfo.applicationInfo = new ApplicationInfo(sInfo.applicationInfo);
                    sInfo.applicationInfo.packageName = aInfo.packageName;
                    sInfo.applicationInfo.uid = aInfo.uid;
                    name = new ComponentName(aInfo.packageName, name.getClassName());
                    service.setComponent(name);
                } else {
                    throw new SecurityException("BIND_EXTERNAL_SERVICE required for " + name);
                }
            } else if (isBindExternal) {
                throw new SecurityException("BIND_EXTERNAL_SERVICE failed, " + name + " is not an externalService");
            }
            if (userId > 0) {
                if (mAm.isSingleton(sInfo.processName, sInfo.applicationInfo, sInfo.name, sInfo.flags) && mAm.isValidSingletonCall(callingUid, sInfo.applicationInfo.uid)) {
                    userId = 0;
                    smap = getServiceMap(0);
                }
                sInfo = new ServiceInfo(sInfo);
                sInfo.applicationInfo = mAm.getAppInfoForUser(sInfo.applicationInfo, userId);
            }
            r = smap.mServicesByName.get(name);
            if (r == null && createIfNeeded) {
                Intent.FilterComparison filter = new Intent.FilterComparison(service.cloneFilter());
                ServiceRestarter res = new ServiceRestarter();
                BatteryStatsImpl.Uid.Pkg.Serv ss = null;
                BatteryStatsImpl stats = mAm.mBatteryStatsService.getActiveStatistics();
                synchronized (stats) {
                    ss = stats.getServiceStatsLocked(sInfo.applicationInfo.uid, sInfo.packageName, sInfo.name);
                }
                r = new ServiceRecord(mAm, ss, name, filter, sInfo, callingFromFg, res);
                res.setService(r);
                smap.mServicesByName.put(name, r);
                smap.mServicesByIntent.put(filter, r);
                // Make sure this component isn't in the pending list.
                for (int i = mPendingServices.size() - 1; i >= 0; i--) {
                    ServiceRecord pr = mPendingServices.get(i);
                    if (pr.serviceInfo.applicationInfo.uid == sInfo.applicationInfo.uid && pr.name.equals(name)) {
                        mPendingServices.remove(i);
                    }
                }
            }
        } catch (RemoteException ex) {
        // pm is in same process, this will never happen.
        }
    }
    if (r != null) {
        if (mAm.checkComponentPermission(r.permission, callingPid, callingUid, r.appInfo.uid, r.exported) != PackageManager.PERMISSION_GRANTED) {
            if (!r.exported) {
                Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " that is not exported from uid " + r.appInfo.uid);
                return new ServiceLookupResult(null, "not exported from uid " + r.appInfo.uid);
            }
            Slog.w(TAG, "Permission Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires " + r.permission);
            return new ServiceLookupResult(null, r.permission);
        } else if (r.permission != null && callingPackage != null) {
            final int opCode = AppOpsManager.permissionToOpCode(r.permission);
            if (opCode != AppOpsManager.OP_NONE && mAm.mAppOpsService.noteOperation(opCode, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
                Slog.w(TAG, "Appop Denial: Accessing service " + r.name + " from pid=" + callingPid + ", uid=" + callingUid + " requires appop " + AppOpsManager.opToName(opCode));
                return null;
            }
        }
        if (!mAm.mIntentFirewall.checkService(r.name, service, callingUid, callingPid, resolvedType, r.appInfo)) {
            return null;
        }
        return new ServiceLookupResult(r, null);
    }
    return null;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 53 with BatteryStatsImpl

use of com.android.internal.os.BatteryStatsImpl in project android_frameworks_base by DirtyUnicorns.

the class BatteryStatsService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump BatteryStats from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " without permission " + android.Manifest.permission.DUMP);
        return;
    }
    int flags = 0;
    boolean useCheckinFormat = false;
    boolean isRealCheckin = false;
    boolean noOutput = false;
    boolean writeData = false;
    long historyStart = -1;
    int reqUid = -1;
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if ("--checkin".equals(arg)) {
                useCheckinFormat = true;
                isRealCheckin = true;
            } else if ("--history".equals(arg)) {
                flags |= BatteryStats.DUMP_HISTORY_ONLY;
            } else if ("--history-start".equals(arg)) {
                flags |= BatteryStats.DUMP_HISTORY_ONLY;
                i++;
                if (i >= args.length) {
                    pw.println("Missing time argument for --history-since");
                    dumpHelp(pw);
                    return;
                }
                historyStart = Long.parseLong(args[i]);
                writeData = true;
            } else if ("-c".equals(arg)) {
                useCheckinFormat = true;
                flags |= BatteryStats.DUMP_INCLUDE_HISTORY;
            } else if ("--charged".equals(arg)) {
                flags |= BatteryStats.DUMP_CHARGED_ONLY;
            } else if ("--daily".equals(arg)) {
                flags |= BatteryStats.DUMP_DAILY_ONLY;
            } else if ("--reset".equals(arg)) {
                synchronized (mStats) {
                    mStats.resetAllStatsCmdLocked();
                    pw.println("Battery stats reset.");
                    noOutput = true;
                }
                updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
            } else if ("--write".equals(arg)) {
                updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
                synchronized (mStats) {
                    mStats.writeSyncLocked();
                    pw.println("Battery stats written.");
                    noOutput = true;
                }
            } else if ("--new-daily".equals(arg)) {
                synchronized (mStats) {
                    mStats.recordDailyStatsLocked();
                    pw.println("New daily stats written.");
                    noOutput = true;
                }
            } else if ("--read-daily".equals(arg)) {
                synchronized (mStats) {
                    mStats.readDailyStatsLocked();
                    pw.println("Last daily stats read.");
                    noOutput = true;
                }
            } else if ("--enable".equals(arg) || "enable".equals(arg)) {
                i = doEnableOrDisable(pw, i, args, true);
                if (i < 0) {
                    return;
                }
                pw.println("Enabled: " + args[i]);
                return;
            } else if ("--disable".equals(arg) || "disable".equals(arg)) {
                i = doEnableOrDisable(pw, i, args, false);
                if (i < 0) {
                    return;
                }
                pw.println("Disabled: " + args[i]);
                return;
            } else if ("-h".equals(arg)) {
                dumpHelp(pw);
                return;
            } else if ("-a".equals(arg)) {
                flags |= BatteryStats.DUMP_VERBOSE;
            } else if (arg.length() > 0 && arg.charAt(0) == '-') {
                pw.println("Unknown option: " + arg);
                dumpHelp(pw);
                return;
            } else {
                // Not an option, last argument must be a package name.
                try {
                    reqUid = mContext.getPackageManager().getPackageUidAsUser(arg, UserHandle.getCallingUserId());
                } catch (PackageManager.NameNotFoundException e) {
                    pw.println("Unknown package: " + arg);
                    dumpHelp(pw);
                    return;
                }
            }
        }
    }
    if (noOutput) {
        return;
    }
    long ident = Binder.clearCallingIdentity();
    try {
        if (BatteryStatsHelper.checkWifiOnly(mContext)) {
            flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
        }
        // Fetch data from external sources and update the BatteryStatsImpl object with them.
        updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    if (reqUid >= 0) {
        // we only dump the aggregated data since charged.
        if ((flags & (BatteryStats.DUMP_HISTORY_ONLY | BatteryStats.DUMP_CHARGED_ONLY)) == 0) {
            flags |= BatteryStats.DUMP_CHARGED_ONLY;
            // Also if they are doing -c, we don't want history.
            flags &= ~BatteryStats.DUMP_INCLUDE_HISTORY;
        }
    }
    if (useCheckinFormat) {
        List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_ALL);
        if (isRealCheckin) {
            // file if there is one.
            synchronized (mStats.mCheckinFile) {
                if (mStats.mCheckinFile.exists()) {
                    try {
                        byte[] raw = mStats.mCheckinFile.readFully();
                        if (raw != null) {
                            Parcel in = Parcel.obtain();
                            in.unmarshall(raw, 0, raw.length);
                            in.setDataPosition(0);
                            BatteryStatsImpl checkinStats = new BatteryStatsImpl(null, mStats.mHandler, null);
                            checkinStats.readSummaryFromParcel(in);
                            in.recycle();
                            checkinStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
                            mStats.mCheckinFile.delete();
                            return;
                        }
                    } catch (IOException | ParcelFormatException e) {
                        Slog.w(TAG, "Failure reading checkin file " + mStats.mCheckinFile.getBaseFile(), e);
                    }
                }
            }
        }
        synchronized (mStats) {
            mStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
        }
    } else {
        synchronized (mStats) {
            mStats.dumpLocked(mContext, pw, flags, reqUid, historyStart);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
        }
    }
}
Also used : ParcelFormatException(android.os.ParcelFormatException) Parcel(android.os.Parcel) ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) PackageManager(android.content.pm.PackageManager)

Example 54 with BatteryStatsImpl

use of com.android.internal.os.BatteryStatsImpl in project android_frameworks_base by AOSPA.

the class ActivityStack method completePauseLocked.

private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) {
    ActivityRecord prev = mPausingActivity;
    if (DEBUG_PAUSE)
        Slog.v(TAG_PAUSE, "Complete pause: " + prev);
    if (prev != null) {
        final boolean wasStopping = prev.state == ActivityState.STOPPING;
        prev.state = ActivityState.PAUSED;
        if (prev.finishing) {
            if (DEBUG_PAUSE)
                Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev);
            prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false);
        } else if (prev.app != null) {
            if (DEBUG_PAUSE)
                Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev + " wasStopping=" + wasStopping + " visible=" + prev.visible);
            if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) {
                if (DEBUG_SWITCH || DEBUG_PAUSE)
                    Slog.v(TAG_PAUSE, "Complete pause, no longer waiting: " + prev);
            }
            if (prev.deferRelaunchUntilPaused) {
                // Complete the deferred relaunch that was waiting for pause to complete.
                if (DEBUG_PAUSE)
                    Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev);
                relaunchActivityLocked(prev, prev.configChangeFlags, false, prev.preserveWindowOnDeferredRelaunch);
            } else if (wasStopping) {
                // We are also stopping, the stop request must have gone soon after the pause.
                // We can't clobber it, because the stop confirmation will not be handled.
                // We don't need to schedule another stop, we only need to let it happen.
                prev.state = ActivityState.STOPPING;
            } else if ((!prev.visible && !hasVisibleBehindActivity()) || mService.isSleepingOrShuttingDownLocked()) {
                // If we were visible then resumeTopActivities will release resources before
                // stopping.
                addToStopping(prev, true);
            }
        } else {
            if (DEBUG_PAUSE)
                Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev);
            prev = null;
        }
        // since it is no longer visible.
        if (prev != null) {
            prev.stopFreezingScreenLocked(true);
        }
        mPausingActivity = null;
    }
    if (resumeNext) {
        final ActivityStack topStack = mStackSupervisor.getFocusedStack();
        if (!mService.isSleepingOrShuttingDownLocked()) {
            mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null);
        } else {
            mStackSupervisor.checkReadyForSleepLocked();
            ActivityRecord top = topStack.topRunningActivityLocked();
            if (top == null || (prev != null && top != prev)) {
                // If there are no more activities available to run, do resume anyway to start
                // something. Also if the top activity on the stack is not the just paused
                // activity, we need to go ahead and resume it to ensure we complete an
                // in-flight app switch.
                mStackSupervisor.resumeFocusedStackTopActivityLocked();
            }
        }
    }
    if (prev != null) {
        prev.resumeKeyDispatchingLocked();
        if (prev.app != null && prev.cpuTimeAtResume > 0 && mService.mBatteryStatsService.isOnBattery()) {
            long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) - prev.cpuTimeAtResume;
            if (diff > 0) {
                BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics();
                synchronized (bsi) {
                    BatteryStatsImpl.Uid.Proc ps = bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, prev.info.packageName);
                    if (ps != null) {
                        ps.addForegroundTimeLocked(diff);
                    }
                }
            }
        }
        // reset it
        prev.cpuTimeAtResume = 0;
    }
    // task stack changes, because its positioning may depend on it.
    if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause || mService.mStackSupervisor.getStack(PINNED_STACK_ID) != null) {
        mService.notifyTaskStackChangedLocked();
        mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false;
    }
    mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS);
}
Also used : BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl)

Example 55 with BatteryStatsImpl

use of com.android.internal.os.BatteryStatsImpl in project cornerstone by Onskreen.

the class ActivityStack method completePauseLocked.

private final void completePauseLocked() {
    ActivityRecord prev = mPausingActivity;
    if (DEBUG_PAUSE)
        Slog.v(TAG, "Complete pause: " + prev);
    if (prev != null) {
        if (prev.finishing) {
            if (DEBUG_PAUSE)
                Slog.v(TAG, "Executing finish of activity: " + prev);
            /*
                 * Onscreen-Cornerstone
                 * Version: 0.84
                 * Date: 08.11.2011
                 *
                 * When cornerstone is exiting, we must kill the activities in the specific stack.
                 * As we don't want to resume any previous activity in the stack, we should call the
                 * finishCurrentActivityLocked with FINISH_IMMEDIATELY mode.
                 */
            if (mService.mActivityStackExiting) {
                mStackPaused = false;
                prev = finishCurrentActivityLocked(prev, FINISH_IMMEDIATELY);
            } else {
                prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE);
            }
        } else if (prev.app != null) {
            if (DEBUG_PAUSE)
                Slog.v(TAG, "Enqueueing pending stop: " + prev);
            if (prev.waitingVisible) {
                prev.waitingVisible = false;
                mWaitingVisibleActivities.remove(prev);
                if (DEBUG_SWITCH || DEBUG_PAUSE)
                    Slog.v(TAG, "Complete pause, no longer waiting: " + prev);
            }
            if (prev.configDestroy) {
                // the current instance before starting the new one.
                if (DEBUG_PAUSE)
                    Slog.v(TAG, "Destroying after pause: " + prev);
                destroyActivityLocked(prev, true, false, "pause-config");
            } else {
                mStoppingActivities.add(prev);
                if (mStoppingActivities.size() > 3) {
                    // them out.
                    if (DEBUG_PAUSE)
                        Slog.v(TAG, "To many pending stops, forcing idle");
                    scheduleIdleLocked();
                } else {
                    checkReadyForSleepLocked();
                }
            }
        } else {
            if (DEBUG_PAUSE)
                Slog.v(TAG, "App died during pause, not stopping: " + prev);
            prev = null;
        }
        mPausingActivity = null;
    }
    if (!mService.isSleeping()) {
        resumeTopActivityLocked(prev);
    } else {
        checkReadyForSleepLocked();
        if (topRunningActivityLocked(null) == null) {
            // If there are no more activities available to run, then
            // do resume anyway to start something.
            resumeTopActivityLocked(null);
        }
    }
    if (prev != null) {
        prev.resumeKeyDispatchingLocked();
    }
    if (prev.app != null && prev.cpuTimeAtResume > 0 && mService.mBatteryStatsService.isOnBattery()) {
        long diff = 0;
        synchronized (mService.mProcessStatsThread) {
            diff = mService.mProcessStats.getCpuTimeForPid(prev.app.pid) - prev.cpuTimeAtResume;
        }
        if (diff > 0) {
            BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics();
            synchronized (bsi) {
                BatteryStatsImpl.Uid.Proc ps = bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, prev.info.packageName);
                if (ps != null) {
                    ps.addForegroundTimeLocked(diff);
                }
            }
        }
    }
    // reset it
    prev.cpuTimeAtResume = 0;
}
Also used : BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl)

Aggregations

BatteryStatsImpl (com.android.internal.os.BatteryStatsImpl)62 RemoteException (android.os.RemoteException)19 Point (android.graphics.Point)18 ComponentName (android.content.ComponentName)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 PendingIntent (android.app.PendingIntent)11 Intent (android.content.Intent)11 ResolveInfo (android.content.pm.ResolveInfo)11 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 PackageManager (android.content.pm.PackageManager)7 ServiceInfo (android.content.pm.ServiceInfo)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 Parcel (android.os.Parcel)5 ParcelFormatException (android.os.ParcelFormatException)5 ActivityNotFoundException (android.content.ActivityNotFoundException)4 IPackageManager (android.content.pm.IPackageManager)4 Uri (android.net.Uri)4 Bundle (android.os.Bundle)4 RemoteCallbackList (android.os.RemoteCallbackList)4