diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-09-17 15:20:06 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-17 15:20:06 -0700 |
commit | 7222997e342920efb45edc312318fc5751c9a0ef (patch) | |
tree | b47df7dde9d9da54445af37c5255f9ec5ea8a58b | |
parent | 356745ecc63419a2569345186e8612a5b0ced28d (diff) | |
parent | cb818619c669d4257a4df969dd03eff479ba84d0 (diff) | |
download | packages_apps_settings-7222997e342920efb45edc312318fc5751c9a0ef.zip packages_apps_settings-7222997e342920efb45edc312318fc5751c9a0ef.tar.gz packages_apps_settings-7222997e342920efb45edc312318fc5751c9a0ef.tar.bz2 |
am cb818619: Update power usage UI to follow WIFI data changes.
Merge commit 'cb818619c669d4257a4df969dd03eff479ba84d0' into gingerbread-plus-aosp
* commit 'cb818619c669d4257a4df969dd03eff479ba84d0':
Update power usage UI to follow WIFI data changes.
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/settings/fuelgauge/BatteryHistoryChart.java | 20 | ||||
-rw-r--r-- | src/com/android/settings/fuelgauge/BatterySipper.java | 3 | ||||
-rw-r--r-- | src/com/android/settings/fuelgauge/PowerUsageSummary.java | 89 |
4 files changed, 94 insertions, 20 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index a638a69..208561e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2089,6 +2089,8 @@ found in the list of installed applications.</string> <string name="usage_type_wake_lock">Keep awake</string> <!-- Label for GPU usage time --> <string name="usage_type_gps">GPS</string> + <!-- [CHAR LIMIT=25] Label for WIFI usage time --> + <string name="usage_type_wifi_running">Wi-Fi running</string> <!-- Label for Phone usage time --> <string name="usage_type_phone">Phone</string> <!-- Label for Data sent --> diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index acd9ee4..fd36a9d 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -563,15 +563,17 @@ public class BatteryHistoryChart extends View { } } - } else if (curLevelPath != null) { - finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, - lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, - lastWakeLock, lastPhoneSignalBin, lastLinePath); - lastX = lastY = -1; - curLevelPath = null; - lastLinePath = null; - lastCharging = lastScreenOn = lastGpsOn = lastWakeLock = false; - lastPhoneSignalBin = 0; + } else if (rec.cmd != BatteryStats.HistoryItem.CMD_OVERFLOW) { + if (curLevelPath != null) { + finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, + lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, + lastWakeLock, lastPhoneSignalBin, lastLinePath); + lastX = lastY = -1; + curLevelPath = null; + lastLinePath = null; + lastCharging = lastScreenOn = lastGpsOn = lastWakeLock = false; + lastPhoneSignalBin = 0; + } } rec = rec.next; diff --git a/src/com/android/settings/fuelgauge/BatterySipper.java b/src/com/android/settings/fuelgauge/BatterySipper.java index fc967d3..dbd664a 100644 --- a/src/com/android/settings/fuelgauge/BatterySipper.java +++ b/src/com/android/settings/fuelgauge/BatterySipper.java @@ -45,8 +45,11 @@ class BatterySipper implements Comparable<BatterySipper> { long usageTime; long cpuTime; long gpsTime; + long wifiRunningTime; long cpuFgTime; long wakeLockTime; + long tcpBytesReceived; + long tcpBytesSent; double percent; double noCoveragePercent; String defaultPackageName; diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 5d4c1b9..ac9401d 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -25,6 +25,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Parcel; +import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; @@ -67,7 +68,8 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { IBatteryStats mBatteryInfo; BatteryStatsImpl mStats; - private List<BatterySipper> mUsageList = new ArrayList<BatterySipper>(); + private final List<BatterySipper> mUsageList = new ArrayList<BatterySipper>(); + private final List<BatterySipper> mWifiSippers = new ArrayList<BatterySipper>(); private PreferenceGroup mAppListGroup; @@ -79,8 +81,12 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { private long mStatsPeriod = 0; private double mMaxPower = 1; private double mTotalPower; + private double mWifiPower; private PowerProfile mPowerProfile; + // How much the apps together have left WIFI running. + private long mAppWifiRunning; + /** Queue for fetching name and icon for an application */ private ArrayList<BatterySipper> mRequestQueue = new ArrayList<BatterySipper>(); private Thread mRequestThread; @@ -162,6 +168,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { R.string.usage_type_cpu_foreground, R.string.usage_type_wake_lock, R.string.usage_type_gps, + R.string.usage_type_wifi_running, R.string.usage_type_data_send, R.string.usage_type_data_recv, R.string.usage_type_audio, @@ -172,8 +179,9 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { sipper.cpuFgTime, sipper.wakeLockTime, sipper.gpsTime, - uid != null? uid.getTcpBytesSent(mStatsType) : 0, - uid != null? uid.getTcpBytesReceived(mStatsType) : 0, + sipper.wifiRunningTime, + sipper.tcpBytesSent, + sipper.tcpBytesReceived, 0, 0 }; @@ -201,6 +209,25 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { }; } break; + case WIFI: + { + types = new int[] { + R.string.usage_type_wifi_running, + R.string.usage_type_cpu, + R.string.usage_type_cpu_foreground, + R.string.usage_type_wake_lock, + R.string.usage_type_data_send, + R.string.usage_type_data_recv, + }; + values = new double[] { + sipper.usageTime, + sipper.cpuTime, + sipper.cpuFgTime, + sipper.wakeLockTime, + sipper.tcpBytesSent, + sipper.tcpBytesReceived, + }; + } break; default: { types = new int[] { @@ -267,9 +294,12 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { } mMaxPower = 0; mTotalPower = 0; + mWifiPower = 0; + mAppWifiRunning = 0; mAppListGroup.removeAll(); mUsageList.clear(); + mWifiSippers.clear(); processAppUsage(); processMiscUsage(); @@ -402,8 +432,15 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { wakelockTime /= 1000; // convert to millis // Add cost of data traffic - power += (u.getTcpBytesReceived(mStatsType) + u.getTcpBytesSent(mStatsType)) - * averageCostPerByte; + long tcpBytesReceived = u.getTcpBytesReceived(mStatsType); + long tcpBytesSent = u.getTcpBytesSent(mStatsType); + power += (tcpBytesReceived+tcpBytesSent) * averageCostPerByte; + + // Add cost of keeping WIFI running. + long wifiRunningTimeMs = u.getWifiRunningTime(uSecTime, which) / 1000; + mAppWifiRunning += wifiRunningTimeMs; + power += (wifiRunningTimeMs + * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON)) / 1000; // Process Sensor usage Map<Integer, ? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats(); @@ -433,6 +470,8 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { power += (multiplier * sensorTime) / 1000; } + if (DEBUG) Log.i(TAG, "UID " + u.getUid() + ": power=" + power); + // Add the app to the list if it is consuming power if (power != 0) { BatterySipper app = new BatterySipper(this, mRequestQueue, mHandler, @@ -440,12 +479,23 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { new double[] {power}); app.cpuTime = cpuTime; app.gpsTime = gpsTime; + app.wifiRunningTime = wifiRunningTimeMs; app.cpuFgTime = cpuFgTime; app.wakeLockTime = wakelockTime; - mUsageList.add(app); + app.tcpBytesReceived = tcpBytesReceived; + app.tcpBytesSent = tcpBytesSent; + if (u.getUid() == Process.WIFI_UID) { + mWifiSippers.add(app); + } else { + mUsageList.add(app); + } + } + if (u.getUid() == Process.WIFI_UID) { + mWifiPower += power; + } else { + if (power > mMaxPower) mMaxPower = power; + mTotalPower += power; } - if (power > mMaxPower) mMaxPower = power; - mTotalPower += power; if (DEBUG) Log.i(TAG, "Added power = " + power); } } @@ -503,12 +553,28 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { private void addWiFiUsage(long uSecNow) { long onTimeMs = mStats.getWifiOnTime(uSecNow, mStatsType) / 1000; - long runningTimeMs = mStats.getWifiRunningTime(uSecNow, mStatsType) / 1000; + long runningTimeMs = mStats.getGlobalWifiRunningTime(uSecNow, mStatsType) / 1000; + if (DEBUG) Log.i(TAG, "WIFI runningTime=" + runningTimeMs + + " app runningTime=" + mAppWifiRunning); + runningTimeMs -= mAppWifiRunning; + if (runningTimeMs < 0) runningTimeMs = 0; double wifiPower = (onTimeMs * 0 /* TODO */ * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON) + runningTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON)) / 1000; - addEntry(getString(R.string.power_wifi), DrainType.WIFI, runningTimeMs, - R.drawable.ic_settings_wifi, wifiPower); + if (DEBUG) Log.i(TAG, "WIFI power=" + wifiPower + " from procs=" + mWifiPower); + BatterySipper bs = addEntry(getString(R.string.power_wifi), DrainType.WIFI, runningTimeMs, + R.drawable.ic_settings_wifi, wifiPower + mWifiPower); + for (int i=0; i<mWifiSippers.size(); i++) { + BatterySipper wbs = mWifiSippers.get(i); + if (DEBUG) Log.i(TAG, "WIFI adding sipper " + wbs + ": cpu=" + wbs.cpuTime); + bs.cpuTime += wbs.cpuTime; + bs.gpsTime += wbs.gpsTime; + bs.wifiRunningTime += wbs.wifiRunningTime; + bs.cpuFgTime += wbs.cpuFgTime; + bs.wakeLockTime += wbs.wakeLockTime; + bs.tcpBytesReceived += wbs.tcpBytesReceived; + bs.tcpBytesSent += wbs.tcpBytesSent; + } } private void addIdleUsage(long uSecNow) { @@ -594,6 +660,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { parcel.setDataPosition(0); mStats = com.android.internal.os.BatteryStatsImpl.CREATOR .createFromParcel(parcel); + mStats.distributeWorkLocked(BatteryStats.STATS_SINCE_CHARGED); } catch (RemoteException e) { Log.e(TAG, "RemoteException:", e); } |