4141import android .content .Intent ;
4242import android .content .IntentFilter ;
4343import android .content .pm .PackageManager ;
44+ import android .database .ContentObserver ;
4445import android .net .ConnectivityManager ;
4546import android .net .DhcpInfo ;
4647import android .net .DhcpInfoInternal ;
@@ -138,6 +139,8 @@ public class WifiStateMachine extends StateMachine {
138139 private boolean mSetScanActive = false ;
139140 /* High perf mode is true if an app has held a high perf Wifi Lock */
140141 private boolean mHighPerfMode = false ;
142+ /* Tracks if user has disabled suspend optimizations through settings */
143+ private AtomicBoolean mSuspendOptEnabled = new AtomicBoolean (true );
141144
142145 private boolean mBluetoothConnectionActive = false ;
143146
@@ -591,6 +594,9 @@ public WifiStateMachine(Context context, String wlanInterface) {
591594 mPrimaryDeviceType = mContext .getResources ().getString (
592595 com .android .internal .R .string .config_wifi_p2p_device_type );
593596
597+ mSuspendOptEnabled .set (Settings .Secure .getInt (mContext .getContentResolver (),
598+ Settings .Secure .WIFI_SUSPEND_OPTIMIZATIONS_ENABLED , 1 ) == 1 );
599+
594600 mContext .registerReceiver (
595601 new BroadcastReceiver () {
596602 @ Override
@@ -626,18 +632,25 @@ public void onReceive(Context context, Intent intent) {
626632 enableBackgroundScanCommand (false );
627633 }
628634 enableAllNetworks ();
629- sendMessage (CMD_CLEAR_SUSPEND_OPTIMIZATIONS );
635+ if (mSuspendOptEnabled .get ()) {
636+ if (DBG ) log ("Clear suspend optimizations" );
637+ sendMessage (CMD_CLEAR_SUSPEND_OPTIMIZATIONS );
638+ }
630639 } else if (action .equals (Intent .ACTION_SCREEN_OFF )) {
631640 enableRssiPolling (false );
632641 if (mBackgroundScanSupported ) {
633642 enableBackgroundScanCommand (true );
634643 }
635- //Allow 2s for suspend optimizations to be set
636- mSuspendWakeLock .acquire (2000 );
637- sendMessage (CMD_SET_SUSPEND_OPTIMIZATIONS );
644+ if (mSuspendOptEnabled .get ()) {
645+ if (DBG ) log ("Enable suspend optimizations" );
646+ //Allow 2s for suspend optimizations to be set
647+ mSuspendWakeLock .acquire (2000 );
648+ sendMessage (CMD_SET_SUSPEND_OPTIMIZATIONS );
649+ }
638650 }
639651 }
640652 };
653+
641654 mContext .registerReceiver (
642655 new BroadcastReceiver () {
643656 @ Override
@@ -648,6 +661,16 @@ public void onReceive(Context context, Intent intent) {
648661 },
649662 new IntentFilter (ACTION_DELAYED_DRIVER_STOP ));
650663
664+ mContext .getContentResolver ().registerContentObserver (Settings .Secure .getUriFor (
665+ Settings .Secure .WIFI_SUSPEND_OPTIMIZATIONS_ENABLED ), false ,
666+ new ContentObserver (getHandler ()) {
667+ @ Override
668+ public void onChange (boolean selfChange ) {
669+ mSuspendOptEnabled .set (Settings .Secure .getInt (mContext .getContentResolver (),
670+ Settings .Secure .WIFI_SUSPEND_OPTIMIZATIONS_ENABLED , 1 ) == 1 );
671+ }
672+ });
673+
651674 mScanResultCache = new LruCache <String , ScanResult >(SCAN_RESULT_CACHE_SIZE );
652675
653676 PowerManager powerManager = (PowerManager )mContext .getSystemService (Context .POWER_SERVICE );
@@ -1133,6 +1156,8 @@ public String toString() {
11331156 sb .append ("mLastNetworkId " ).append (mLastNetworkId ).append (LS );
11341157 sb .append ("mReconnectCount " ).append (mReconnectCount ).append (LS );
11351158 sb .append ("mIsScanMode " ).append (mIsScanMode ).append (LS );
1159+ sb .append ("mHighPerfMode" ).append (mHighPerfMode ).append (LS );
1160+ sb .append ("mSuspendOptEnabled" ).append (mSuspendOptEnabled ).append (LS );
11361161 sb .append ("Supplicant status" ).append (LS )
11371162 .append (mWifiNative .status ()).append (LS ).append (LS );
11381163
0 commit comments