summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/WifiService.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/java/com/android/server/WifiService.java')
-rw-r--r--services/java/com/android/server/WifiService.java79
1 files changed, 47 insertions, 32 deletions
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 1f03d17..53fb60b 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -58,6 +58,7 @@ import android.os.SystemProperties;
import android.os.WorkSource;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.Log;
import android.util.Slog;
import java.util.ArrayList;
@@ -110,10 +111,6 @@ public class WifiService extends IWifiManager.Stub {
private int mScanLocksAcquired;
private int mScanLocksReleased;
- /* A mapping from UID to scan count */
- private HashMap<Integer, Integer> mScanCount =
- new HashMap<Integer, Integer>();
-
private final List<Multicaster> mMulticasters =
new ArrayList<Multicaster>();
private int mMulticastEnabled;
@@ -161,6 +158,10 @@ public class WifiService extends IWifiManager.Stub {
/* Tracks whether wifi is enabled from WifiStateMachine's perspective */
private boolean mWifiEnabled;
+ /* The work source (UID) that triggered the current WIFI scan, synchronized
+ * on this */
+ private WorkSource mScanWorkSource;
+
private boolean mIsReceiverRegistered = false;
@@ -413,6 +414,7 @@ public class WifiService extends IWifiManager.Stub {
}
} else if (intent.getAction().equals(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
+ noteScanEnd();
checkAndSetNotification();
}
}
@@ -430,6 +432,44 @@ public class WifiService extends IWifiManager.Stub {
mNotificationEnabledSettingObserver.register();
}
+ /** Tell battery stats about a new WIFI scan */
+ private void noteScanStart() {
+ WorkSource scanWorkSource = null;
+ synchronized (WifiService.this) {
+ if (mScanWorkSource != null) {
+ // Scan already in progress, don't add this one to battery stats
+ return;
+ }
+ scanWorkSource = new WorkSource(Binder.getCallingUid());
+ mScanWorkSource = scanWorkSource;
+ }
+
+ long id = Binder.clearCallingIdentity();
+ try {
+ mBatteryStats.noteWifiScanStartedFromSource(scanWorkSource);
+ } catch (RemoteException e) {
+ Log.w(TAG, e);
+ } finally {
+ Binder.restoreCallingIdentity(id);
+ }
+ }
+
+ /** Tell battery stats that the current WIFI scan has completed */
+ private void noteScanEnd() {
+ WorkSource scanWorkSource = null;
+ synchronized (WifiService.this) {
+ scanWorkSource = mScanWorkSource;
+ mScanWorkSource = null;
+ }
+ if (scanWorkSource != null) {
+ try {
+ mBatteryStats.noteWifiScanStoppedFromSource(scanWorkSource);
+ } catch (RemoteException e) {
+ Log.w(TAG, e);
+ }
+ }
+ }
+
/**
* Check if Wi-Fi needs to be enabled and start
* if needed
@@ -541,16 +581,8 @@ public class WifiService extends IWifiManager.Stub {
*/
public void startScan(boolean forceActive) {
enforceChangePermission();
-
- int uid = Binder.getCallingUid();
- int count = 0;
- synchronized (mScanCount) {
- if (mScanCount.containsKey(uid)) {
- count = mScanCount.get(uid);
- }
- mScanCount.put(uid, ++count);
- }
mWifiStateMachine.startScan(forceActive);
+ noteScanStart();
}
private void enforceAccessPermission() {
@@ -1011,12 +1043,6 @@ public class WifiService extends IWifiManager.Stub {
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
}
- //Start scan stats tracking when device unplugged
- if (pluggedType == 0) {
- synchronized (mScanCount) {
- mScanCount.clear();
- }
- }
mPluggedType = pluggedType;
} else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
@@ -1207,13 +1233,6 @@ public class WifiService extends IWifiManager.Stub {
pw.println("Locks held:");
mLocks.dump(pw);
- pw.println("Scan count since last plugged in");
- synchronized (mScanCount) {
- for(int sc : mScanCount.keySet()) {
- pw.println("UID: " + sc + " Scan count: " + mScanCount.get(sc));
- }
- }
-
pw.println();
pw.println("WifiWatchdogStateMachine dump");
mWifiWatchdogStateMachine.dump(pw);
@@ -1333,10 +1352,8 @@ public class WifiService extends IWifiManager.Stub {
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
- mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource);
- break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
- mBatteryStats.noteScanWifiLockAcquiredFromSource(wifiLock.mWorkSource);
+ mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource);
break;
}
}
@@ -1345,10 +1362,8 @@ public class WifiService extends IWifiManager.Stub {
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
- mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource);
- break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
- mBatteryStats.noteScanWifiLockReleasedFromSource(wifiLock.mWorkSource);
+ mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource);
break;
}
}