use of com.android.internal.os.BatterySipper in project android_frameworks_base by ResurrectionRemix.
the class BatteryStats method dumpCheckinLocked.
/**
* Checkin server version of dump to produce more compact, computer-readable log.
*
* NOTE: all times are expressed in 'ms'.
*/
public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, boolean wifiOnly) {
final long rawUptime = SystemClock.uptimeMillis() * 1000;
final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
final long batteryUptime = getBatteryUptime(rawUptime);
final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, which);
final long totalRealtime = computeRealtime(rawRealtime, which);
final long totalUptime = computeUptime(rawUptime, which);
final long screenOnTime = getScreenOnTime(rawRealtime, which);
final long interactiveTime = getInteractiveTime(rawRealtime, which);
final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtime, which);
final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtime, which);
final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtime, which);
final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtime, which);
final int connChanges = getNumConnectivityChange(which);
final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter().getCountLocked(which);
final StringBuilder sb = new StringBuilder(128);
final SparseArray<? extends Uid> uidStats = getUidStats();
final int NU = uidStats.size();
final String category = STAT_NAMES[which];
// Dump "battery" stat
dumpLine(pw, 0, /* uid */
category, BATTERY_DATA, which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", whichBatteryRealtime / 1000, whichBatteryUptime / 1000, totalRealtime / 1000, totalUptime / 1000, getStartClockTime(), whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, getEstimatedBatteryCapacity());
// Calculate wakelock times across all uids.
long fullWakeLockTimeTotal = 0;
long partialWakeLockTimeTotal = 0;
for (int iu = 0; iu < NU; iu++) {
final Uid u = uidStats.valueAt(iu);
final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
for (int iw = wakelocks.size() - 1; iw >= 0; iw--) {
final Uid.Wakelock wl = wakelocks.valueAt(iw);
final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
if (fullWakeTimer != null) {
fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, which);
}
final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
if (partialWakeTimer != null) {
partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(rawRealtime, which);
}
}
}
// Dump network stats
final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
dumpLine(pw, 0, /* uid */
category, GLOBAL_NETWORK_DATA, mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, btRxTotalBytes, btTxTotalBytes);
// Dump Modem controller stats
dumpControllerActivityLine(pw, 0, /* uid */
category, GLOBAL_MODEM_CONTROLLER_DATA, getModemControllerActivity(), which);
// Dump Wifi controller stats
final long wifiOnTime = getWifiOnTime(rawRealtime, which);
final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
dumpLine(pw, 0, /* uid */
category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */
0, 0, 0);
dumpControllerActivityLine(pw, 0, /* uid */
category, GLOBAL_WIFI_CONTROLLER_DATA, getWifiControllerActivity(), which);
// Dump Bluetooth controller stats
dumpControllerActivityLine(pw, 0, /* uid */
category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, getBluetoothControllerActivity(), which);
// Dump misc stats
dumpLine(pw, 0, /* uid */
category, MISC_DATA, screenOnTime / 1000, phoneOnTime / 1000, fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, getMobileRadioActiveTime(rawRealtime, which) / 1000, getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), getMobileRadioActiveCount(which), getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
// Dump screen brightness stats
Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; i++) {
args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, SCREEN_BRIGHTNESS_DATA, args);
// Dump signal strength stats
args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, SIGNAL_STRENGTH_TIME_DATA, args);
dumpLine(pw, 0, /* uid */
category, SIGNAL_SCANNING_TIME_DATA, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
args[i] = getPhoneSignalStrengthCount(i, which);
}
dumpLine(pw, 0, /* uid */
category, SIGNAL_STRENGTH_COUNT_DATA, args);
// Dump network type stats
args = new Object[NUM_DATA_CONNECTION_TYPES];
for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; i++) {
args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, DATA_CONNECTION_TIME_DATA, args);
for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; i++) {
args[i] = getPhoneDataConnectionCount(i, which);
}
dumpLine(pw, 0, /* uid */
category, DATA_CONNECTION_COUNT_DATA, args);
// Dump wifi state stats
args = new Object[NUM_WIFI_STATES];
for (int i = 0; i < NUM_WIFI_STATES; i++) {
args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, WIFI_STATE_TIME_DATA, args);
for (int i = 0; i < NUM_WIFI_STATES; i++) {
args[i] = getWifiStateCount(i, which);
}
dumpLine(pw, 0, /* uid */
category, WIFI_STATE_COUNT_DATA, args);
// Dump wifi suppl state stats
args = new Object[NUM_WIFI_SUPPL_STATES];
for (int i = 0; i < NUM_WIFI_SUPPL_STATES; i++) {
args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, WIFI_SUPPL_STATE_TIME_DATA, args);
for (int i = 0; i < NUM_WIFI_SUPPL_STATES; i++) {
args[i] = getWifiSupplStateCount(i, which);
}
dumpLine(pw, 0, /* uid */
category, WIFI_SUPPL_STATE_COUNT_DATA, args);
// Dump wifi signal strength stats
args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
}
dumpLine(pw, 0, /* uid */
category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
args[i] = getWifiSignalStrengthCount(i, which);
}
dumpLine(pw, 0, /* uid */
category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
if (which == STATS_SINCE_UNPLUGGED) {
dumpLine(pw, 0, /* uid */
category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), getDischargeCurrentLevel());
}
if (which == STATS_SINCE_UNPLUGGED) {
dumpLine(pw, 0, /* uid */
category, BATTERY_DISCHARGE_DATA, getDischargeStartLevel() - getDischargeCurrentLevel(), getDischargeStartLevel() - getDischargeCurrentLevel(), getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), dischargeCount / 1000, dischargeScreenOffCount / 1000);
} else {
dumpLine(pw, 0, /* uid */
category, BATTERY_DISCHARGE_DATA, getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), getDischargeAmountScreenOnSinceCharge(), getDischargeAmountScreenOffSinceCharge(), dischargeCount / 1000, dischargeScreenOffCount / 1000);
}
if (reqUid < 0) {
final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
if (kernelWakelocks.size() > 0) {
for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
sb.setLength(0);
printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
dumpLine(pw, 0, /* uid */
category, KERNEL_WAKELOCK_DATA, ent.getKey(), sb.toString());
}
}
final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
if (wakeupReasons.size() > 0) {
for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
// Not doing the regular wake lock formatting to remain compatible
// with the old checkin format.
long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
int count = ent.getValue().getCountLocked(which);
dumpLine(pw, 0, /* uid */
category, WAKEUP_REASON_DATA, "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
}
}
}
final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
helper.create(this);
helper.refreshStats(which, UserHandle.USER_ALL);
final List<BatterySipper> sippers = helper.getUsageList();
if (sippers != null && sippers.size() > 0) {
dumpLine(pw, 0, /* uid */
category, POWER_USE_SUMMARY_DATA, BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), BatteryStatsHelper.makemAh(helper.getComputedPower()), BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
for (int i = 0; i < sippers.size(); i++) {
final BatterySipper bs = sippers.get(i);
int uid = 0;
String label;
switch(bs.drainType) {
case IDLE:
label = "idle";
break;
case CELL:
label = "cell";
break;
case PHONE:
label = "phone";
break;
case WIFI:
label = "wifi";
break;
case BLUETOOTH:
label = "blue";
break;
case SCREEN:
label = "scrn";
break;
case FLASHLIGHT:
label = "flashlight";
break;
case APP:
uid = bs.uidObj.getUid();
label = "uid";
break;
case USER:
uid = UserHandle.getUid(bs.userId, 0);
label = "user";
break;
case UNACCOUNTED:
label = "unacc";
break;
case OVERCOUNTED:
label = "over";
break;
case CAMERA:
label = "camera";
break;
default:
label = "???";
}
dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, BatteryStatsHelper.makemAh(bs.totalPowerMah));
}
}
for (int iu = 0; iu < NU; iu++) {
final int uid = uidStats.keyAt(iu);
if (reqUid >= 0 && uid != reqUid) {
continue;
}
final Uid u = uidStats.valueAt(iu);
// Dump Network stats per uid, if any
final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
final long mobileActiveTime = u.getMobileRadioActiveTime(which);
final int mobileActiveCount = u.getMobileRadioActiveCount(which);
final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, wifiBytesRx, wifiBytesTx, mobilePacketsRx, mobilePacketsTx, wifiPacketsRx, wifiPacketsTx, mobileActiveTime, mobileActiveCount, btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
}
// Dump modem controller data, per UID.
dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, u.getModemControllerActivity(), which);
// Dump Wifi controller data, per UID.
final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
final int wifiScanCount = u.getWifiScanCount(which);
final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 || uidWifiRunningTime != 0) {
dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount, /* legacy fields follow, keep at 0 */
0, 0, 0);
}
dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, u.getWifiControllerActivity(), which);
dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(), rawRealtime, which);
dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, u.getBluetoothControllerActivity(), which);
if (u.hasUserActivity()) {
args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
boolean hasData = false;
for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; i++) {
int val = u.getUserActivityCount(i, which);
args[i] = val;
if (val != 0)
hasData = true;
}
if (hasData) {
dumpLine(pw, uid, /* uid */
category, USER_ACTIVITY_DATA, args);
}
}
final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
for (int iw = wakelocks.size() - 1; iw >= 0; iw--) {
final Uid.Wakelock wl = wakelocks.valueAt(iw);
String linePrefix = "";
sb.setLength(0);
linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, "f", which, linePrefix);
linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, "p", which, linePrefix);
linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, "w", which, linePrefix);
// Only log if we had at lease one wakelock...
if (sb.length() > 0) {
String name = wakelocks.keyAt(iw);
if (name.indexOf(',') >= 0) {
name = name.replace(',', '_');
}
dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
}
}
final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
for (int isy = syncs.size() - 1; isy >= 0; isy--) {
final Timer timer = syncs.valueAt(isy);
// Convert from microseconds to milliseconds with rounding
final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
final int count = timer.getCountLocked(which);
if (totalTime != 0) {
dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
}
}
final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
for (int ij = jobs.size() - 1; ij >= 0; ij--) {
final Timer timer = jobs.valueAt(ij);
// Convert from microseconds to milliseconds with rounding
final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
final int count = timer.getCountLocked(which);
if (totalTime != 0) {
dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
}
}
dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), rawRealtime, which);
dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), rawRealtime, which);
dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), rawRealtime, which);
dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), rawRealtime, which);
final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
final int NSE = sensors.size();
for (int ise = 0; ise < NSE; ise++) {
final Uid.Sensor se = sensors.valueAt(ise);
final int sensorNumber = sensors.keyAt(ise);
final Timer timer = se.getSensorTime();
if (timer != null) {
// Convert from microseconds to milliseconds with rounding
final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
final int count = timer.getCountLocked(which);
if (totalTime != 0) {
dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
}
}
}
dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), rawRealtime, which);
dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), rawRealtime, which);
final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
long totalStateTime = 0;
for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ips++) {
final long time = u.getProcessStateTime(ips, rawRealtime, which);
totalStateTime += time;
stateTimes[ips] = (time + 500) / 1000;
}
if (totalStateTime > 0) {
dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
}
final long userCpuTimeUs = u.getUserCpuTimeUs(which);
final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
final long powerCpuMaUs = u.getCpuPowerMaUs(which);
if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, powerCpuMaUs / 1000);
}
final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
for (int ipr = processStats.size() - 1; ipr >= 0; ipr--) {
final Uid.Proc ps = processStats.valueAt(ipr);
final long userMillis = ps.getUserTime(which);
final long systemMillis = ps.getSystemTime(which);
final long foregroundMillis = ps.getForegroundTime(which);
final int starts = ps.getStarts(which);
final int numCrashes = ps.getNumCrashes(which);
final int numAnrs = ps.getNumAnrs(which);
if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
}
}
final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
for (int ipkg = packageStats.size() - 1; ipkg >= 0; ipkg--) {
final Uid.Pkg ps = packageStats.valueAt(ipkg);
int wakeups = 0;
final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
for (int iwa = alarms.size() - 1; iwa >= 0; iwa--) {
int count = alarms.valueAt(iwa).getCountLocked(which);
wakeups += count;
String name = alarms.keyAt(iwa).replace(',', '_');
dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
}
final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
for (int isvc = serviceStats.size() - 1; isvc >= 0; isvc--) {
final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
final long startTime = ss.getStartTime(batteryUptime, which);
final int starts = ss.getStarts(which);
final int launches = ss.getLaunches(which);
if (startTime != 0 || starts != 0 || launches != 0) {
dumpLine(pw, uid, category, APK_DATA, // wakeup alarms
wakeups, // Apk
packageStats.keyAt(ipkg), // service
serviceStats.keyAt(isvc), // time spent started, in ms
startTime / 1000, starts, launches);
}
}
}
}
}
use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PowerUsageSummary method refreshStats.
protected void refreshStats() {
super.refreshStats();
updatePreference(mHistPref);
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
boolean addedSome = false;
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
int colorControl = getContext().getColor(value.resourceId);
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
final int dischargeAmount = USE_FAKE_DATA ? 5000 : stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
final BatterySipper sipper = usageList.get(i);
if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) {
continue;
}
double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
final double percentOfTotal = ((sipper.totalPowerMah / totalPower) * dischargeAmount);
if (((int) (percentOfTotal + .5)) < 1) {
continue;
}
if (sipper.drainType == BatterySipper.DrainType.OVERCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < ((mStatsHelper.getMaxRealPower() * 2) / 3)) {
continue;
}
if (percentOfTotal < 10) {
continue;
}
if ("user".equals(Build.TYPE) || "userdebug".equals(Build.TYPE)) {
continue;
}
}
if (sipper.drainType == BatterySipper.DrainType.UNACCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < (mStatsHelper.getMaxRealPower() / 2)) {
continue;
}
if (percentOfTotal < 5) {
continue;
}
if ("user".equals(Build.TYPE) || "userdebug".equals(Build.TYPE)) {
continue;
}
}
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
final Drawable badgedIcon = mUm.getBadgedIconForUser(entry.getIcon(), userHandle);
final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(), userHandle);
final String key = sipper.drainType == DrainType.APP ? sipper.getPackages() != null ? TextUtils.concat(sipper.getPackages()).toString() : String.valueOf(sipper.getUid()) : sipper.drainType.toString();
PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
if (pref == null) {
pref = new PowerGaugePreference(getPrefContext(), badgedIcon, contentDescription, entry);
pref.setKey(key);
}
final double percentOfMax = (sipper.totalPowerMah * 100) / mStatsHelper.getMaxPower();
sipper.percent = percentOfTotal;
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfMax, percentOfTotal);
if (sipper.uidObj != null) {
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
}
if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == 0) && sipper.drainType != DrainType.USER) {
pref.setTint(colorControl);
}
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() - getCachedCount() > (MAX_ITEMS_TO_LIST + 1)) {
break;
}
}
}
if (!addedSome) {
addNotAvailableMessage();
}
removeCachedPrefs(mAppListGroup);
BatteryEntry.startRequestQueue();
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class AdvancedPowerUsageDetail method startBatteryDetailPage.
@VisibleForTesting
static void startBatteryDetailPage(SettingsActivity caller, BatteryUtils batteryUtils, PreferenceFragment fragment, BatteryStatsHelper helper, int which, BatteryEntry entry, String usagePercent, List<Anomaly> anomalies) {
// Initialize mStats if necessary.
helper.getStats();
final Bundle args = new Bundle();
final BatterySipper sipper = entry.sipper;
final BatteryStats.Uid uid = sipper.uidObj;
final boolean isTypeApp = sipper.drainType == BatterySipper.DrainType.APP;
final long foregroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, uid, which) : sipper.usageTimeMs;
final long backgroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.BACKGROUND, uid, which) : 0;
if (ArrayUtils.isEmpty(sipper.mPackages)) {
// populate data for system app
args.putString(EXTRA_LABEL, entry.getLabel());
args.putInt(EXTRA_ICON_ID, entry.iconId);
args.putString(EXTRA_PACKAGE_NAME, null);
} else {
// populate data for normal app
args.putString(EXTRA_PACKAGE_NAME, entry.defaultPackageName != null ? entry.defaultPackageName : sipper.mPackages[0]);
}
args.putInt(EXTRA_UID, sipper.getUid());
args.putLong(EXTRA_BACKGROUND_TIME, backgroundTimeMs);
args.putLong(EXTRA_FOREGROUND_TIME, foregroundTimeMs);
args.putString(EXTRA_POWER_USAGE_PERCENT, usagePercent);
args.putInt(EXTRA_POWER_USAGE_AMOUNT, (int) sipper.totalPowerMah);
args.putParcelableList(EXTRA_ANOMALY_LIST, anomalies);
caller.startPreferencePanelAsUser(fragment, AdvancedPowerUsageDetail.class.getName(), args, R.string.battery_details_title, null, new UserHandle(UserHandle.getUserId(sipper.getUid())));
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class PowerUsageAdvanced method parsePowerUsageData.
@VisibleForTesting
List<PowerUsageData> parsePowerUsageData(BatteryStatsHelper statusHelper) {
final List<BatterySipper> batterySippers = statusHelper.getUsageList();
final Map<Integer, PowerUsageData> batteryDataMap = new HashMap<>();
for (@UsageType final Integer type : mUsageTypes) {
batteryDataMap.put(type, new PowerUsageData(type));
}
// Accumulate power usage based on usage type
for (final BatterySipper sipper : batterySippers) {
sipper.mPackages = mPackageManager.getPackagesForUid(sipper.getUid());
final PowerUsageData usageData = batteryDataMap.get(extractUsageType(sipper));
usageData.totalPowerMah += sipper.totalPowerMah;
if (sipper.drainType == DrainType.APP && sipper.usageTimeMs != 0) {
sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, STATUS_TYPE);
}
usageData.totalUsageTimeMs += sipper.usageTimeMs;
if (shouldShowBatterySipper(sipper)) {
usageData.usageList.add(sipper);
}
}
final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
final double totalPower = statusHelper.getTotalPower();
final double hiddenPower = calculateHiddenPower(batteryDataList);
for (final PowerUsageData usageData : batteryDataList) {
usageData.percentage = mBatteryUtils.calculateBatteryPercent(usageData.totalPowerMah, totalPower, hiddenPower, dischargeAmount);
updateUsageDataSummary(usageData, totalPower, dischargeAmount);
}
Collections.sort(batteryDataList);
mBatteryDataMap = batteryDataMap;
return batteryDataList;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class PowerUsageSummary method updateScreenPreference.
@VisibleForTesting
void updateScreenPreference() {
final BatterySipper sipper = findBatterySipperByType(mStatsHelper.getUsageList(), DrainType.SCREEN);
final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
}
Aggregations