From fb03058dc9827c9f588cc4f42a74201b8ae06e8c Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Thu, 12 Dec 2013 16:17:49 -0800 Subject: [PATCH] Update to follow BatteryStats. Change data use to be based on packets instead of bytes. Change-Id: I536dd2c2fc3fbeb12689e793f79e5fac984fe3af --- res/values/strings.xml | 8 +- .../settings/fuelgauge/BatteryHistoryChart.java | 4 +- .../android/settings/fuelgauge/BatterySipper.java | 4 + .../settings/fuelgauge/BatteryStatsHelper.java | 88 ++++++++++++---------- .../settings/fuelgauge/PowerUsageDetail.java | 4 +- 5 files changed, 62 insertions(+), 46 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 08fe28fb55..efdaf7526e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3616,13 +3616,13 @@ Phone - Mobile data sent + Mobile packets sent - Mobile data received + Mobile packets received - Wi\u2011Fi data sent + Wi\u2011Fi packets sent - Wi\u2011Fi data received + Wi\u2011Fi packets received Audio diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index 55a0457470..dfed5c4b53 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -361,7 +361,7 @@ public class BatteryHistoryChart extends View { final HistoryItem rec = new HistoryItem(); while (stats.getNextHistoryLocked(rec)) { pos++; - if (rec.cmd == HistoryItem.CMD_UPDATE) { + if (rec.isDeltaData()) { if (first) { first = false; mHistStart = rec.time; @@ -523,7 +523,7 @@ public class BatteryHistoryChart extends View { if (mStats.startIteratingHistoryLocked()) { final HistoryItem rec = new HistoryItem(); while (mStats.getNextHistoryLocked(rec) && i < N) { - if (rec.cmd == BatteryStats.HistoryItem.CMD_UPDATE) { + if (rec.isDeltaData()) { x = (int)(((rec.time-timeStart)*w)/timeChange); y = mLevelTop + levelh - ((rec.batteryLevel-batLow)*(levelh-1))/batChange; diff --git a/src/com/android/settings/fuelgauge/BatterySipper.java b/src/com/android/settings/fuelgauge/BatterySipper.java index fcc8f69704..d1f885c03a 100644 --- a/src/com/android/settings/fuelgauge/BatterySipper.java +++ b/src/com/android/settings/fuelgauge/BatterySipper.java @@ -53,6 +53,10 @@ public class BatterySipper implements Comparable { long wifiRunningTime; long cpuFgTime; long wakeLockTime; + long mobileRxPackets; + long mobileTxPackets; + long wifiRxPackets; + long wifiTxPackets; long mobileRxBytes; long mobileTxBytes; long wifiRxBytes; diff --git a/src/com/android/settings/fuelgauge/BatteryStatsHelper.java b/src/com/android/settings/fuelgauge/BatteryStatsHelper.java index 0191692a17..8ae940990b 100644 --- a/src/com/android/settings/fuelgauge/BatteryStatsHelper.java +++ b/src/com/android/settings/fuelgauge/BatteryStatsHelper.java @@ -16,10 +16,10 @@ package com.android.settings.fuelgauge; -import static android.os.BatteryStats.NETWORK_MOBILE_RX_BYTES; -import static android.os.BatteryStats.NETWORK_MOBILE_TX_BYTES; -import static android.os.BatteryStats.NETWORK_WIFI_RX_BYTES; -import static android.os.BatteryStats.NETWORK_WIFI_TX_BYTES; +import static android.os.BatteryStats.NETWORK_MOBILE_RX_DATA; +import static android.os.BatteryStats.NETWORK_MOBILE_TX_DATA; +import static android.os.BatteryStats.NETWORK_WIFI_RX_DATA; +import static android.os.BatteryStats.NETWORK_WIFI_TX_DATA; import android.app.Activity; import android.content.Context; @@ -222,10 +222,10 @@ public class BatteryStatsHelper { sipper.wakeLockTime, sipper.gpsTime, sipper.wifiRunningTime, - sipper.mobileRxBytes, - sipper.mobileTxBytes, - sipper.wifiRxBytes, - sipper.wifiTxBytes, + sipper.mobileRxPackets, + sipper.mobileTxPackets, + sipper.wifiRxPackets, + sipper.wifiTxPackets, 0, 0 }; @@ -275,10 +275,10 @@ public class BatteryStatsHelper { sipper.cpuTime, sipper.cpuFgTime, sipper.wakeLockTime, - sipper.mobileRxBytes, - sipper.mobileTxBytes, - sipper.wifiRxBytes, - sipper.wifiTxBytes, + sipper.mobileRxPackets, + sipper.mobileTxPackets, + sipper.wifiRxPackets, + sipper.wifiTxPackets, }; } break; case BLUETOOTH: @@ -298,10 +298,10 @@ public class BatteryStatsHelper { sipper.cpuTime, sipper.cpuFgTime, sipper.wakeLockTime, - sipper.mobileRxBytes, - sipper.mobileTxBytes, - sipper.wifiRxBytes, - sipper.wifiTxBytes, + sipper.mobileRxPackets, + sipper.mobileTxPackets, + sipper.wifiRxPackets, + sipper.wifiTxPackets, }; } break; default: @@ -371,8 +371,8 @@ public class BatteryStatsHelper { for (int p = 0; p < speedSteps; p++) { powerCpuNormal[p] = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p); } - final double mobilePowerPerByte = getMobilePowerPerByte(); - final double wifiPowerPerByte = getWifiPowerPerByte(); + final double mobilePowerPerPacket = getMobilePowerPerPacket(); + final double wifiPowerPerPacket = getWifiPowerPerPacket(); long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which); long appWakelockTime = 0; BatterySipper osApp = null; @@ -463,16 +463,20 @@ public class BatteryStatsHelper { if (DEBUG && p != 0) Log.i(TAG, String.format("wakelock power=%.2f", p)); // Add cost of mobile traffic - final long mobileRx = u.getNetworkActivityCount(NETWORK_MOBILE_RX_BYTES, mStatsType); - final long mobileTx = u.getNetworkActivityCount(NETWORK_MOBILE_TX_BYTES, mStatsType); - p = (mobileRx + mobileTx) * mobilePowerPerByte; + final long mobileRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, mStatsType); + final long mobileTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, mStatsType); + final long mobileRxB = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, mStatsType); + final long mobileTxB = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, mStatsType); + p = (mobileRx + mobileTx) * mobilePowerPerPacket; power += p; if (DEBUG && p != 0) Log.i(TAG, String.format("mobile power=%.2f", p)); // Add cost of wifi traffic - final long wifiRx = u.getNetworkActivityCount(NETWORK_WIFI_RX_BYTES, mStatsType); - final long wifiTx = u.getNetworkActivityCount(NETWORK_WIFI_TX_BYTES, mStatsType); - p = (wifiRx + wifiTx) * wifiPowerPerByte; + final long wifiRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, mStatsType); + final long wifiTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, mStatsType); + final long wifiRxB = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, mStatsType); + final long wifiTxB = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, mStatsType); + p = (wifiRx + wifiTx) * wifiPowerPerPacket; power += p; if (DEBUG && p != 0) Log.i(TAG, String.format("wifi power=%.2f", p)); @@ -545,10 +549,14 @@ public class BatteryStatsHelper { app.wifiRunningTime = wifiRunningTimeMs; app.cpuFgTime = cpuFgTime; app.wakeLockTime = wakelockTime; - app.mobileRxBytes = mobileRx; - app.mobileTxBytes = mobileTx; - app.wifiRxBytes = wifiRx; - app.wifiTxBytes = wifiTx; + app.mobileRxPackets = mobileRx; + app.mobileTxPackets = mobileTx; + app.wifiRxPackets = wifiRx; + app.wifiTxPackets = wifiTx; + app.mobileRxBytes = mobileRxB; + app.mobileTxBytes = mobileTxB; + app.wifiRxBytes = wifiRxB; + app.wifiTxBytes = wifiTxB; if (u.getUid() == Process.WIFI_UID) { mWifiSippers.add(app); } else if (u.getUid() == Process.BLUETOOTH_UID) { @@ -670,6 +678,10 @@ public class BatteryStatsHelper { bs.wifiRunningTime += wbs.wifiRunningTime; bs.cpuFgTime += wbs.cpuFgTime; bs.wakeLockTime += wbs.wakeLockTime; + bs.mobileRxPackets += wbs.mobileRxPackets; + bs.mobileTxPackets += wbs.mobileTxPackets; + bs.wifiRxPackets += wbs.wifiRxPackets; + bs.wifiTxPackets += wbs.wifiTxPackets; bs.mobileRxBytes += wbs.mobileRxBytes; bs.mobileTxBytes += wbs.mobileTxBytes; bs.wifiRxBytes += wbs.wifiRxBytes; @@ -743,33 +755,33 @@ public class BatteryStatsHelper { } /** - * Return estimated power (in mAs) of sending a byte with the mobile radio. + * Return estimated power (in mAs) of sending or receiving a packet with the mobile radio. */ - private double getMobilePowerPerByte() { + private double getMobilePowerPerPacket() { final long MOBILE_BPS = 200000; // TODO: Extract average bit rates from system final double MOBILE_POWER = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE) / 3600; - final long mobileRx = mStats.getNetworkActivityCount(NETWORK_MOBILE_RX_BYTES, mStatsType); - final long mobileTx = mStats.getNetworkActivityCount(NETWORK_MOBILE_TX_BYTES, mStatsType); + final long mobileRx = mStats.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, mStatsType); + final long mobileTx = mStats.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, mStatsType); final long mobileData = mobileRx + mobileTx; final long radioDataUptimeMs = mStats.getRadioDataUptime() / 1000; - final long mobileBps = radioDataUptimeMs != 0 - ? mobileData * 8 * 1000 / radioDataUptimeMs - : MOBILE_BPS; + final double mobilePps = radioDataUptimeMs != 0 + ? mobileData / (double)radioDataUptimeMs + : (((double)MOBILE_BPS) / 8 / 2048); - return MOBILE_POWER / (mobileBps / 8); + return MOBILE_POWER / mobilePps; } /** * Return estimated power (in mAs) of sending a byte with the Wi-Fi radio. */ - private double getWifiPowerPerByte() { + private double getWifiPowerPerPacket() { final long WIFI_BPS = 1000000; // TODO: Extract average bit rates from system final double WIFI_POWER = mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ACTIVE) / 3600; - return WIFI_POWER / (WIFI_BPS / 8); + return WIFI_POWER / (((double)WIFI_BPS) / 8 / 2048); } private void processMiscUsage() { diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java index 45e4516552..8d316cfc0c 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java +++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java @@ -322,8 +322,8 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener case R.string.usage_type_data_send: case R.string.usage_type_data_wifi_recv: case R.string.usage_type_data_wifi_send: - final long bytes = (long) (mValues[i]); - value = Formatter.formatFileSize(getActivity(), bytes); + final long packets = (long) (mValues[i]); + value = Long.toString(packets); break; case R.string.usage_type_no_coverage: final int percentage = (int) Math.floor(mValues[i]); -- 2.11.0