diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-08-13 14:15:44 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-08-13 14:22:34 -0700 |
commit | be5994d20152c7194aac79eb8152240655fd3373 (patch) | |
tree | df82ffeaacda62d1deffed81bc4ad74d5178fd5b /src | |
parent | 3673546205ebf1b4c83c212c1032eea38c8adbe7 (diff) | |
download | packages_apps_Settings-be5994d20152c7194aac79eb8152240655fd3373.zip packages_apps_Settings-be5994d20152c7194aac79eb8152240655fd3373.tar.gz packages_apps_Settings-be5994d20152c7194aac79eb8152240655fd3373.tar.bz2 |
Some improvements to the battery usage UI:
- Show wake lock usage in the battery history.
- Show WIFI usage in the battery history.
- Show the amount an app has held a wake lock in the app details.
- Also fix service run time computation in running services.
Change-Id: I5aa959857f83808fbc709f65204f59bbfb73935b
Diffstat (limited to 'src')
5 files changed, 117 insertions, 19 deletions
diff --git a/src/com/android/settings/applications/RunningProcessesView.java b/src/com/android/settings/applications/RunningProcessesView.java index 7dbd8f8..f2d8e9e 100644 --- a/src/com/android/settings/applications/RunningProcessesView.java +++ b/src/com/android/settings/applications/RunningProcessesView.java @@ -115,11 +115,11 @@ public class RunningProcessesView extends FrameLayout } if (uptimeView != null) { - if (mItem.mActiveSince >= 0) { + if (mFirstRunTime >= 0) { //Log.i("foo", "Time for " + mItem.mDisplayLabel // + ": " + (SystemClock.uptimeMillis()-mFirstRunTime)); uptimeView.setText(DateUtils.formatElapsedTime(builder, - (SystemClock.uptimeMillis()-mFirstRunTime)/1000)); + (SystemClock.elapsedRealtime()-mFirstRunTime)/1000)); } else { boolean isService = false; if (mItem instanceof RunningState.MergedItem) { diff --git a/src/com/android/settings/applications/RunningServiceDetails.java b/src/com/android/settings/applications/RunningServiceDetails.java index d57cd4a..6346ec2 100644 --- a/src/com/android/settings/applications/RunningServiceDetails.java +++ b/src/com/android/settings/applications/RunningServiceDetails.java @@ -92,8 +92,8 @@ public class RunningServiceDetails extends Activity & ApplicationInfo.FLAG_SYSTEM) != 0; ApplicationErrorReport.RunningServiceInfo info = new ApplicationErrorReport.RunningServiceInfo(); - if (mActiveItem.mItem.mActiveSince >= 0) { - info.durationMillis = SystemClock.uptimeMillis()-mActiveItem.mFirstRunTime; + if (mActiveItem.mFirstRunTime >= 0) { + info.durationMillis = SystemClock.elapsedRealtime()-mActiveItem.mFirstRunTime; } else { info.durationMillis = -1; } diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index 7750eca..25d8609 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -53,6 +53,8 @@ public class BatteryHistoryChart extends View { final Paint mChargingPaint = new Paint(); final Paint mScreenOnPaint = new Paint(); final Paint mGpsOnPaint = new Paint(); + final Paint mWifiRunningPaint = new Paint(); + final Paint mWakeLockPaint = new Paint(); final Paint[] mPhoneSignalPaints = new Paint[NUM_PHONE_SIGNALS]; final int[] mPhoneSignalColors = new int[] { 0x00000000, 0xffa00000, 0xffa0a000, 0xff808020, @@ -67,6 +69,8 @@ public class BatteryHistoryChart extends View { final Path mChargingPath = new Path(); final Path mScreenOnPath = new Path(); final Path mGpsOnPath = new Path(); + final Path mWifiRunningPath = new Path(); + final Path mWakeLockPath = new Path(); int mFontSize; @@ -77,6 +81,8 @@ public class BatteryHistoryChart extends View { String mChargingLabel; String mScreenOnLabel; String mGpsOnLabel; + String mWifiRunningLabel; + String mWakeLockLabel; String mPhoneSignalLabel; int mTextAscent; @@ -91,6 +97,8 @@ public class BatteryHistoryChart extends View { int mChargingOffset; int mScreenOnOffset; int mGpsOnOffset; + int mWifiRunningOffset; + int mWakeLockOffset; int mPhoneSignalOffset; int mLevelOffset; int mLevelTop; @@ -107,6 +115,8 @@ public class BatteryHistoryChart extends View { long mHistEnd; int mBatLow; int mBatHigh; + boolean mHaveWifi; + boolean mHaveGps; public BatteryHistoryChart(Context context, AttributeSet attrs) { super(context, attrs); @@ -125,6 +135,10 @@ public class BatteryHistoryChart extends View { mScreenOnPaint.setStyle(Paint.Style.STROKE); mGpsOnPaint.setARGB(255, 0, 0, 255); mGpsOnPaint.setStyle(Paint.Style.STROKE); + mWifiRunningPaint.setARGB(255, 0, 0, 255); + mWifiRunningPaint.setStyle(Paint.Style.STROKE); + mWakeLockPaint.setARGB(255, 0, 0, 255); + mWakeLockPaint.setStyle(Paint.Style.STROKE); for (int i=0; i<NUM_PHONE_SIGNALS; i++) { mPhoneSignalPaints[i] = new Paint(); mPhoneSignalPaints[i].setColor(mPhoneSignalColors[i]); @@ -278,6 +292,8 @@ public class BatteryHistoryChart extends View { mChargingLabel = getContext().getString(R.string.battery_stats_charging_label); mScreenOnLabel = getContext().getString(R.string.battery_stats_screen_on_label); mGpsOnLabel = getContext().getString(R.string.battery_stats_gps_on_label); + mWifiRunningLabel = getContext().getString(R.string.battery_stats_wifi_running_label); + mWakeLockLabel = getContext().getString(R.string.battery_stats_wake_lock_label); mPhoneSignalLabel = getContext().getString(R.string.battery_stats_phone_signal_label); BatteryStats.HistoryItem rec = stats.getHistory(); @@ -287,6 +303,7 @@ public class BatteryHistoryChart extends View { byte lastLevel = -1; mBatLow = 0; mBatHigh = 100; + int aggrStates = 0; while (rec != null) { pos++; if (rec.cmd == HistoryItem.CMD_UPDATE) { @@ -299,10 +316,13 @@ public class BatteryHistoryChart extends View { lastInteresting = pos; mHistEnd = rec.time; } + aggrStates |= rec.states; } rec = rec.next; } mNumHist = lastInteresting; + mHaveGps = (aggrStates&HistoryItem.STATE_GPS_ON_FLAG) != 0; + mHaveWifi = (aggrStates&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0; if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1; mTotalDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart); @@ -325,7 +345,7 @@ public class BatteryHistoryChart extends View { void finishPaths(int w, int h, int levelh, int startX, int y, Path curLevelPath, int lastX, boolean lastCharging, boolean lastScreenOn, boolean lastGpsOn, - int lastPhoneSignal, Path lastPath) { + boolean lastWifiRunning, boolean lastWakeLock, int lastPhoneSignal, Path lastPath) { if (curLevelPath != null) { if (lastX >= 0 && lastX < w) { if (lastPath != null) { @@ -347,6 +367,12 @@ public class BatteryHistoryChart extends View { if (lastGpsOn) { mGpsOnPath.lineTo(w, h-mGpsOnOffset); } + if (lastWifiRunning) { + mWifiRunningPath.lineTo(w, h-mWifiRunningOffset); + } + if (lastWakeLock) { + mWakeLockPath.lineTo(w, h-mWakeLockOffset); + } if (lastPhoneSignal != 0) { addPhoneSignalTick(w, 0); } @@ -376,17 +402,22 @@ public class BatteryHistoryChart extends View { mChargingPaint.setStrokeWidth(mLineWidth); mScreenOnPaint.setStrokeWidth(mLineWidth); mGpsOnPaint.setStrokeWidth(mLineWidth); + mWifiRunningPaint.setStrokeWidth(mLineWidth); + mWakeLockPaint.setStrokeWidth(mLineWidth); if (mLargeMode) { int barOffset = textHeight + mLineWidth; - mScreenOnOffset = mLineWidth; - mGpsOnOffset = mScreenOnOffset + barOffset; - mPhoneSignalOffset = mGpsOnOffset + barOffset; - mChargingOffset = mPhoneSignalOffset + barOffset; - mLevelOffset = mChargingOffset + barOffset + mLineWidth; + mChargingOffset = mLineWidth; + mScreenOnOffset = mChargingOffset + barOffset; + mWakeLockOffset = mScreenOnOffset + barOffset; + mWifiRunningOffset = mWakeLockOffset + barOffset; + mGpsOnOffset = mHaveWifi ? (mWifiRunningOffset + barOffset) : mWakeLockOffset; + mPhoneSignalOffset = mHaveGps ? (mGpsOnOffset + barOffset) : mWifiRunningOffset; + mLevelOffset = mPhoneSignalOffset + barOffset + mLineWidth; mPhoneSignalTicks = new int[w+2]; } else { - mScreenOnOffset = mGpsOnOffset = mLineWidth; + mScreenOnOffset = mGpsOnOffset = mWifiRunningOffset + = mWakeLockOffset = mLineWidth; mChargingOffset = mLineWidth*2; mPhoneSignalOffset = 0; mLevelOffset = mLineWidth*3; @@ -399,6 +430,8 @@ public class BatteryHistoryChart extends View { mBatCriticalPath.reset(); mScreenOnPath.reset(); mGpsOnPath.reset(); + mWifiRunningPath.reset(); + mWakeLockPath.reset(); mChargingPath.reset(); final long timeStart = mHistStart; @@ -416,6 +449,7 @@ public class BatteryHistoryChart extends View { Path curLevelPath = null; Path lastLinePath = null; boolean lastCharging = false, lastScreenOn = false, lastGpsOn = false; + boolean lastWifiRunning = false, lastWakeLock = false; int lastPhoneSignalBin = 0; final int N = mNumHist; while (rec != null && i < N) { @@ -487,6 +521,28 @@ public class BatteryHistoryChart extends View { lastGpsOn = gpsOn; } + final boolean wifiRunning = + (rec.states&HistoryItem.STATE_WIFI_RUNNING_FLAG) != 0; + if (wifiRunning != lastWifiRunning) { + if (wifiRunning) { + mWifiRunningPath.moveTo(x, h-mWifiRunningOffset); + } else { + mWifiRunningPath.lineTo(x, h-mWifiRunningOffset); + } + lastWifiRunning = wifiRunning; + } + + final boolean wakeLock = + (rec.states&HistoryItem.STATE_WAKE_LOCK_FLAG) != 0; + if (wakeLock != lastWakeLock) { + if (wakeLock) { + mWakeLockPath.moveTo(x, h-mWakeLockOffset); + } else { + mWakeLockPath.lineTo(x, h-mWakeLockOffset); + } + lastWakeLock = wakeLock; + } + if (mLargeMode) { int bin; if (((rec.states&HistoryItem.STATE_PHONE_STATE_MASK) @@ -509,12 +565,12 @@ public class BatteryHistoryChart extends View { } else if (curLevelPath != null) { finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, - lastCharging, lastScreenOn, lastGpsOn, lastPhoneSignalBin, - lastLinePath); + lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, + lastWakeLock, lastPhoneSignalBin, lastLinePath); lastX = lastY = -1; curLevelPath = null; lastLinePath = null; - lastCharging = lastScreenOn = lastGpsOn = false; + lastCharging = lastScreenOn = lastGpsOn = lastWakeLock = false; lastPhoneSignalBin = 0; } @@ -523,7 +579,8 @@ public class BatteryHistoryChart extends View { } finishPaths(w, h, levelh, startX, lastY, curLevelPath, lastX, - lastCharging, lastScreenOn, lastGpsOn, lastPhoneSignalBin, lastLinePath); + lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, + lastWakeLock, lastPhoneSignalBin, lastLinePath); } @Override @@ -571,15 +628,33 @@ public class BatteryHistoryChart extends View { if (!mChargingPath.isEmpty()) { canvas.drawPath(mChargingPath, mChargingPaint); } - if (!mGpsOnPath.isEmpty()) { - canvas.drawPath(mGpsOnPath, mGpsOnPaint); + if (mHaveGps) { + if (!mGpsOnPath.isEmpty()) { + canvas.drawPath(mGpsOnPath, mGpsOnPaint); + } + } + if (mHaveWifi) { + if (!mWifiRunningPath.isEmpty()) { + canvas.drawPath(mWifiRunningPath, mWifiRunningPaint); + } + } + if (!mWakeLockPath.isEmpty()) { + canvas.drawPath(mWakeLockPath, mWakeLockPaint); } if (mLargeMode) { canvas.drawText(mPhoneSignalLabel, 0, height - mPhoneSignalOffset - mTextDescent, mTextPaint); - canvas.drawText(mGpsOnLabel, 0, - height - mGpsOnOffset - mTextDescent, mTextPaint); + if (mHaveGps) { + canvas.drawText(mGpsOnLabel, 0, + height - mGpsOnOffset - mTextDescent, mTextPaint); + } + if (mHaveWifi) { + canvas.drawText(mWifiRunningLabel, 0, + height - mWifiRunningOffset - mTextDescent, mTextPaint); + } + canvas.drawText(mWakeLockLabel, 0, + height - mWakeLockOffset - mTextDescent, mTextPaint); canvas.drawText(mChargingLabel, 0, height - mChargingOffset - mTextDescent, mTextPaint); canvas.drawText(mScreenOnLabel, 0, diff --git a/src/com/android/settings/fuelgauge/BatterySipper.java b/src/com/android/settings/fuelgauge/BatterySipper.java index 8125146..fc967d3 100644 --- a/src/com/android/settings/fuelgauge/BatterySipper.java +++ b/src/com/android/settings/fuelgauge/BatterySipper.java @@ -46,6 +46,7 @@ class BatterySipper implements Comparable<BatterySipper> { long cpuTime; long gpsTime; long cpuFgTime; + long wakeLockTime; 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 c20caf6..3ff7080 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -160,6 +160,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { types = new int[] { R.string.usage_type_cpu, R.string.usage_type_cpu_foreground, + R.string.usage_type_wake_lock, R.string.usage_type_gps, R.string.usage_type_data_send, R.string.usage_type_data_recv, @@ -169,6 +170,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { values = new double[] { sipper.cpuTime, sipper.cpuFgTime, + sipper.wakeLockTime, sipper.gpsTime, uid != null? uid.getTcpBytesSent(mStatsType) : 0, uid != null? uid.getTcpBytesReceived(mStatsType) : 0, @@ -340,6 +342,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); long cpuTime = 0; long cpuFgTime = 0; + long wakelockTime = 0; long gpsTime = 0; if (processStats.size() > 0) { // Process CPU time @@ -384,6 +387,24 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { } power /= 1000; + // Process wake lock usage + Map<String, ? extends BatteryStats.Uid.Wakelock> wakelockStats = u.getWakelockStats(); + for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> wakelockEntry + : wakelockStats.entrySet()) { + Uid.Wakelock wakelock = wakelockEntry.getValue(); + BatteryStats.Timer timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_FULL); + if (timer != null) { + wakelockTime += timer.getTotalTimeLocked(uSecTime, which); + } + timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL); + if (timer != null) { + wakelockTime += timer.getTotalTimeLocked(uSecTime, which); + } + // Note: not considering window, since that is just the system + // keeping the screen on while the app is running. + } + wakelockTime /= 1000; // convert to millis + // Add cost of data traffic power += (u.getTcpBytesReceived(mStatsType) + u.getTcpBytesSent(mStatsType)) * averageCostPerByte; @@ -424,6 +445,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { app.cpuTime = cpuTime; app.gpsTime = gpsTime; app.cpuFgTime = cpuFgTime; + app.wakeLockTime = wakelockTime; mUsageList.add(app); } if (power > mMaxPower) mMaxPower = power; |