diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-08-13 14:09:56 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-08-13 15:17:49 -0700 |
commit | 9adb9c3b10991ef315c270993f4155709c8a232d (patch) | |
tree | 445c2437eeb4b3b5fa5597dc0538c04e0fdf490e /tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java | |
parent | 3f442ece257d416b48f7803a4cc263f0215faa0d (diff) | |
download | frameworks_base-9adb9c3b10991ef315c270993f4155709c8a232d.zip frameworks_base-9adb9c3b10991ef315c270993f4155709c8a232d.tar.gz frameworks_base-9adb9c3b10991ef315c270993f4155709c8a232d.tar.bz2 |
Various battery info things:
- Now track wake locks in battery history.
- Now track sensors in battery history.
- Some filtering of sensory data.
- Fixes to some data that wasn't cleared when resetting battery stats.
- Print amount discharged since last charge.
And the big part -- keep track of wake locks held per process,
and kill processes that hold wake locks too much while they are in
the background. This includes information in the battery stats
about the process being killed, which will be available to the
developer if the app is reported.
Change-Id: I97202e94d00aafe0526ba2db74a03212e7539c54
Diffstat (limited to 'tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java')
-rw-r--r-- | tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java b/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java index 8ea7e00..499330f 100644 --- a/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java +++ b/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java @@ -41,6 +41,8 @@ public class BatteryWaster extends Activity { PowerManager.WakeLock mWakeLock; SpinThread mThread; + boolean mWasting, mWaking; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,6 +52,7 @@ public class BatteryWaster extends Activity { setContentView(R.layout.battery_waster); findViewById(R.id.checkbox).setOnClickListener(mClickListener); + findViewById(R.id.checkbox_wake).setOnClickListener(mWakeClickListener); mLog = (TextView)findViewById(R.id.log); mDateFormat = DateFormat.getInstance(); @@ -67,9 +70,18 @@ public class BatteryWaster extends Activity { @Override public void onPause() { + super.onPause(); stopRunning(); } + @Override + public void onDestroy() { + super.onDestroy(); + if (mWakeLock.isHeld()) { + mWakeLock.release(); + } + } + View.OnClickListener mClickListener = new View.OnClickListener() { public void onClick(View v) { CheckBox checkbox = (CheckBox)v; @@ -81,23 +93,54 @@ public class BatteryWaster extends Activity { } }; + View.OnClickListener mWakeClickListener = new View.OnClickListener() { + public void onClick(View v) { + CheckBox checkbox = (CheckBox)v; + if (checkbox.isChecked()) { + mWaking = true; + updateWakeLock(); + } else { + mWaking = false; + updateWakeLock(); + } + } + }; + void startRunning() { - log("Start"); - registerReceiver(mReceiver, mFilter); - mWakeLock.acquire(); - if (mThread == null) { - mThread = new SpinThread(); - mThread.start(); + if (!mWasting) { + log("Start"); + registerReceiver(mReceiver, mFilter); + mWasting = true; + updateWakeLock(); + if (mThread == null) { + mThread = new SpinThread(); + mThread.start(); + } } } void stopRunning() { - log("Stop"); - unregisterReceiver(mReceiver); - mWakeLock.release(); - if (mThread != null) { - mThread.quit(); - mThread = null; + if (mWasting) { + log("Stop"); + unregisterReceiver(mReceiver); + mWasting = false; + updateWakeLock(); + if (mThread != null) { + mThread.quit(); + mThread = null; + } + } + } + + void updateWakeLock() { + if (mWasting || mWaking) { + if (!mWakeLock.isHeld()) { + mWakeLock.acquire(); + } + } else { + if (mWakeLock.isHeld()) { + mWakeLock.release(); + } } } |