diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-09-16 01:22:10 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-09-17 15:14:57 -0700 |
commit | 58e0eefeb5e2e270e2b04369bbf29fc22abda8d5 (patch) | |
tree | b4ac8f5dd31ceb5ee39590c56a95a77c79b3059b /wifi | |
parent | 0741a5ed38757ef2f6b52945ad494d965b3b83de (diff) | |
download | frameworks_base-58e0eefeb5e2e270e2b04369bbf29fc22abda8d5.zip frameworks_base-58e0eefeb5e2e270e2b04369bbf29fc22abda8d5.tar.gz frameworks_base-58e0eefeb5e2e270e2b04369bbf29fc22abda8d5.tar.bz2 |
Improve power tracking of WIFI use.
We now distribute "wifi started" time across all apps that are
holding WIFI locks that cause it to be started. But only when
WIFI would not normally be running. Also have a mechanism to
distribute other WIFI work that has happened across those processes
based on their use.
Also fixed a bug where we were not retaining the CPU speed step
stats across boots...!
Change-Id: I00e3153b98429166273750512cc37e7975211ab9
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 22dbda3..9d27bde 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -38,6 +38,7 @@ import android.os.SystemProperties; import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.WorkSource; import android.provider.Settings; import android.text.TextUtils; import android.util.EventLog; @@ -323,6 +324,21 @@ public class WifiStateTracker extends NetworkStateTracker { private static String[] sDnsPropNames; /** + * Keep track of whether we last told the battery stats we had started. + */ + private boolean mReportedRunning = false; + + /** + * Most recently set source of starting WIFI. + */ + private final WorkSource mRunningWifiUids = new WorkSource(); + + /** + * The last reported UIDs that were responsible for starting WIFI. + */ + private final WorkSource mLastRunningWifiUids = new WorkSource(); + + /** * A structure for supplying information about a supplicant state * change in the STATE_CHANGE event message that comes from the * WifiMonitor @@ -632,12 +648,35 @@ public class WifiStateTracker extends NetworkStateTracker { return mRunState == RUN_STATE_STOPPED || mRunState == RUN_STATE_STOPPING; } - private void noteRunState() { + public void updateBatteryWorkSourceLocked(WorkSource newSource) { try { + if (newSource != null) { + mRunningWifiUids.set(newSource); + } if (mRunState == RUN_STATE_RUNNING) { - mBatteryStats.noteWifiRunning(); + if (mReportedRunning) { + // If the work source has changed since last time, need + // to remove old work from battery stats. + if (mLastRunningWifiUids.diff(mRunningWifiUids)) { + mBatteryStats.noteWifiRunningChanged(mLastRunningWifiUids, + mRunningWifiUids); + mLastRunningWifiUids.set(mRunningWifiUids); + } + } else { + // Now being started, report it. + mBatteryStats.noteWifiRunning(mRunningWifiUids); + mLastRunningWifiUids.set(mRunningWifiUids); + mReportedRunning = true; + } } else if (mRunState == RUN_STATE_STOPPED) { - mBatteryStats.noteWifiStopped(); + if (mReportedRunning) { + // Last reported we were running, time to stop. + mBatteryStats.noteWifiStopped(mLastRunningWifiUids); + mLastRunningWifiUids.clear(); + mReportedRunning = false; + } + } else { + // State in transition -- nothing to update yet. } } catch (RemoteException ignore) { } @@ -801,7 +840,9 @@ public class WifiStateTracker extends NetworkStateTracker { switch (msg.what) { case EVENT_SUPPLICANT_CONNECTION: mRunState = RUN_STATE_RUNNING; - noteRunState(); + synchronized (this) { + updateBatteryWorkSourceLocked(null); + } checkUseStaticIp(); /* Reset notification state on new connection */ resetNotificationTimer(); @@ -875,7 +916,9 @@ public class WifiStateTracker extends NetworkStateTracker { case EVENT_SUPPLICANT_DISCONNECT: mRunState = RUN_STATE_STOPPED; - noteRunState(); + synchronized (this) { + updateBatteryWorkSourceLocked(null); + } boolean died = mWifiState.get() != WIFI_STATE_DISABLED && mWifiState.get() != WIFI_STATE_DISABLING; if (died) { @@ -1267,7 +1310,9 @@ public class WifiStateTracker extends NetworkStateTracker { mWM.setWifiEnabled(true); break; } - noteRunState(); + synchronized (this) { + updateBatteryWorkSourceLocked(null); + } break; case EVENT_PASSWORD_KEY_MAY_BE_INCORRECT: |