diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2013-06-26 10:55:00 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-06-26 10:55:00 -0700 |
commit | c869696ef3c1dca3efbc6ce8ab804e8a1b117900 (patch) | |
tree | 9c35274b69c658685077515d8804a3b9fb331c1e /wifi/java | |
parent | bfc53ab2def0d58872b70e7f4afb2ca184143ff6 (diff) | |
parent | 65f7a95fc4c06127e7372bcb0d14e561cc23dd80 (diff) | |
download | frameworks_base-c869696ef3c1dca3efbc6ce8ab804e8a1b117900.zip frameworks_base-c869696ef3c1dca3efbc6ce8ab804e8a1b117900.tar.gz frameworks_base-c869696ef3c1dca3efbc6ce8ab804e8a1b117900.tar.bz2 |
am 65f7a95f: am 2f50097a: Merge "Fix power issues around wifi scans." into jb-mr2-dev
* commit '65f7a95fc4c06127e7372bcb0d14e561cc23dd80':
Fix power issues around wifi scans.
Diffstat (limited to 'wifi/java')
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 12 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 56 |
2 files changed, 63 insertions, 5 deletions
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index ec76a8b..a3c172a 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -70,6 +70,18 @@ public class WifiManager { public static final int ERROR_AUTHENTICATING = 1; /** + * Broadcast intent action indicating whether Wi-Fi scanning is allowed currently + * @hide + */ + public static final String WIFI_SCAN_AVAILABLE = "wifi_scan_available"; + + /** + * Extra int indicating scan availability, WIFI_STATE_ENABLED and WIFI_STATE_DISABLED + * @hide + */ + public static final String EXTRA_SCAN_AVAILABLE = "scan_enabled"; + + /** * Broadcast intent action indicating that Wi-Fi has been enabled, disabled, * enabling, disabling, or unknown. One extra provides this state as an int. * Another extra provides the previous state, if available. diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index bb61339..985ca1d 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -141,6 +141,8 @@ public class WifiStateMachine extends StateMachine { */ private int mOperationalMode = CONNECT_MODE; private boolean mScanResultIsPending = false; + private WorkSource mScanWorkSource = null; + private static final int UNKNOWN_SCAN_SOURCE = -1; /* Tracks if state machine has received any screen state change broadcast yet. * We can miss one of these at boot. */ @@ -601,7 +603,7 @@ public class WifiStateMachine extends StateMachine { new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - startScan(); + startScan(UNKNOWN_SCAN_SOURCE); } }, new IntentFilter(ACTION_START_SCAN)); @@ -694,6 +696,11 @@ public class WifiStateMachine extends StateMachine { //start the state machine start(); + + final Intent intent = new Intent(WifiManager.WIFI_SCAN_AVAILABLE); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WIFI_STATE_DISABLED); + mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } /********************************************************* @@ -716,8 +723,31 @@ public class WifiStateMachine extends StateMachine { /** * TODO: doc */ - public void startScan() { - sendMessage(CMD_START_SCAN); + public void startScan(int callingUid) { + sendMessage(CMD_START_SCAN, callingUid); + } + + private void noteScanStart(int callingUid) { + if (mScanWorkSource == null && callingUid != UNKNOWN_SCAN_SOURCE) { + mScanWorkSource = new WorkSource(callingUid); + try { + mBatteryStats.noteWifiScanStartedFromSource(mScanWorkSource); + } catch (RemoteException e) { + log(e.toString()); + } + } + } + + private void noteScanEnd() { + if (mScanWorkSource != null) { + try { + mBatteryStats.noteWifiScanStoppedFromSource(mScanWorkSource); + } catch (RemoteException e) { + log(e.toString()); + } finally { + mScanWorkSource = null; + } + } } private void startScanNative(int type) { @@ -1575,6 +1605,7 @@ public class WifiStateMachine extends StateMachine { } private void sendScanResultsAvailableBroadcast() { + noteScanEnd(); Intent intent = new Intent(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mContext.sendBroadcastAsUser(intent, UserHandle.ALL); @@ -1919,6 +1950,7 @@ public class WifiStateMachine extends StateMachine { } break; /* Discard */ + case CMD_START_SCAN: case CMD_START_SUPPLICANT: case CMD_STOP_SUPPLICANT: case CMD_STOP_SUPPLICANT_FAILED: @@ -1933,7 +1965,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_AP: case CMD_TETHER_STATE_CHANGE: case CMD_TETHER_NOTIFICATION_TIMED_OUT: - case CMD_START_SCAN: case CMD_DISCONNECT: case CMD_RECONNECT: case CMD_REASSOCIATE: @@ -2438,11 +2469,18 @@ public class WifiStateMachine extends StateMachine { mWifiNative.setPowerSave(true); if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); + + final Intent intent = new Intent(WifiManager.WIFI_SCAN_AVAILABLE); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WIFI_STATE_ENABLED); + mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } + @Override public boolean processMessage(Message message) { switch(message.what) { case CMD_START_SCAN: + noteScanStart(message.arg1); startScanNative(WifiNative.SCAN_WITH_CONNECTION_SETUP); break; case CMD_SET_COUNTRY_CODE: @@ -2563,6 +2601,12 @@ public class WifiStateMachine extends StateMachine { mIsRunning = false; updateBatteryWorkSource(null); mScanResults = new ArrayList<ScanResult>(); + + final Intent intent = new Intent(WifiManager.WIFI_SCAN_AVAILABLE); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WIFI_STATE_DISABLED); + mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); + noteScanEnd(); // wrap up any pending request. } } @@ -2713,6 +2757,7 @@ public class WifiStateMachine extends StateMachine { // Handle scan. All the connection related commands are // handled only in ConnectModeState case CMD_START_SCAN: + noteScanStart(message.arg1); startScanNative(WifiNative.SCAN_WITHOUT_CONNECTION_SETUP); break; default: @@ -2979,6 +3024,7 @@ public class WifiStateMachine extends StateMachine { break; case CMD_START_SCAN: /* Do not attempt to connect when we are already connected */ + noteScanStart(message.arg1); startScanNative(WifiNative.SCAN_WITHOUT_CONNECTION_SETUP); break; /* Ignore connection to same network */ @@ -3296,7 +3342,7 @@ public class WifiStateMachine extends StateMachine { if (mP2pConnected.get()) break; if (message.arg1 == mPeriodicScanToken && mWifiConfigStore.getConfiguredNetworks().size() == 0) { - sendMessage(CMD_START_SCAN); + sendMessage(CMD_START_SCAN, UNKNOWN_SCAN_SOURCE); sendMessageDelayed(obtainMessage(CMD_NO_NETWORKS_PERIODIC_SCAN, ++mPeriodicScanToken, 0), mSupplicantScanIntervalMs); } |