@@ -138,6 +138,10 @@ public class WifiStateMachine extends StateMachine {
138138 private boolean mScanResultIsPending = false ;
139139 /* Tracks if the current scan settings are active */
140140 private boolean mSetScanActive = false ;
141+ /* Tracks if state machine has received any screen state change broadcast yet.
142+ * We can miss one of these at boot.
143+ */
144+ private AtomicBoolean mScreenBroadcastReceived = new AtomicBoolean (false );
141145
142146 private boolean mBluetoothConnectionActive = false ;
143147
@@ -635,28 +639,9 @@ public void onReceive(Context context, Intent intent) {
635639 String action = intent .getAction ();
636640
637641 if (action .equals (Intent .ACTION_SCREEN_ON )) {
638- if (DBG ) log ("ACTION_SCREEN_ON" );
639- enableRssiPolling (true );
640- if (mBackgroundScanSupported ) {
641- enableBackgroundScanCommand (false );
642- }
643- enableAllNetworks ();
644- if (mUserWantsSuspendOpt .get ()) {
645- if (DBG ) log ("Clear suspend optimizations" );
646- sendMessage (obtainMessage (CMD_SET_SUSPEND_OPT_ENABLED , 0 , 0 ));
647- }
642+ handleScreenStateChanged (true );
648643 } else if (action .equals (Intent .ACTION_SCREEN_OFF )) {
649- if (DBG ) log ("ACTION_SCREEN_OFF" );
650- enableRssiPolling (false );
651- if (mBackgroundScanSupported ) {
652- enableBackgroundScanCommand (true );
653- }
654- if (mUserWantsSuspendOpt .get ()) {
655- if (DBG ) log ("Enable suspend optimizations" );
656- //Allow 2s for suspend optimizations to be set
657- mSuspendWakeLock .acquire (2000 );
658- sendMessage (obtainMessage (CMD_SET_SUSPEND_OPT_ENABLED , 1 , 0 ));
659- }
644+ handleScreenStateChanged (false );
660645 }
661646 }
662647 };
@@ -1221,6 +1206,26 @@ protected boolean recordLogRec(Message msg) {
12211206 * Internal private functions
12221207 ********************************************************/
12231208
1209+ private void handleScreenStateChanged (boolean screenOn ) {
1210+ if (DBG ) log ("handleScreenStateChanged: " + screenOn );
1211+ enableRssiPolling (screenOn );
1212+ if (mBackgroundScanSupported ) {
1213+ enableBackgroundScanCommand (screenOn == false );
1214+ }
1215+
1216+ if (screenOn ) enableAllNetworks ();
1217+ if (mUserWantsSuspendOpt .get ()) {
1218+ if (screenOn ) {
1219+ sendMessage (obtainMessage (CMD_SET_SUSPEND_OPT_ENABLED , 0 , 0 ));
1220+ } else {
1221+ //Allow 2s for suspend optimizations to be set
1222+ mSuspendWakeLock .acquire (2000 );
1223+ sendMessage (obtainMessage (CMD_SET_SUSPEND_OPT_ENABLED , 1 , 0 ));
1224+ }
1225+ }
1226+ mScreenBroadcastReceived .set (true );
1227+ }
1228+
12241229 private void checkAndSetConnectivityInstance () {
12251230 if (mCm == null ) {
12261231 mCm = (ConnectivityManager ) mContext .getSystemService (Context .CONNECTIVITY_SERVICE );
@@ -2721,6 +2726,17 @@ public void enter() {
27212726 transitionTo (mDisconnectedState );
27222727 }
27232728
2729+ // We may have missed screen update at boot
2730+ if (mScreenBroadcastReceived .get () == false ) {
2731+ PowerManager powerManager = (PowerManager )mContext .getSystemService (
2732+ Context .POWER_SERVICE );
2733+ handleScreenStateChanged (powerManager .isScreenOn ());
2734+ } else {
2735+ // Set the right suspend mode settings
2736+ mWifiNative .setSuspendOptimizations (mSuspendOptNeedsDisabled == 0
2737+ && mUserWantsSuspendOpt .get ());
2738+ }
2739+
27242740 if (mP2pSupported ) mWifiP2pChannel .sendMessage (WifiStateMachine .CMD_ENABLE_P2P );
27252741 }
27262742 @ Override
0 commit comments