Skip to content

Commit 3fb4ba6

Browse files
committed
Add control to disable suspend optimizations
Add an advanced setting that allows user to turn off power savings at screen off. Bug: 5885175 Change-Id: I2dd013b86d7500a2ad1f9ec75d86551808f05543
1 parent 2c02933 commit 3fb4ba6

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

core/java/android/provider/Settings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,14 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
32873287
public static final String WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED =
32883288
"wifi_watchdog_poor_network_test_enabled";
32893289

3290+
/**
3291+
* Setting to turn on suspend optimizations at screen off on Wi-Fi. Enabled by default and
3292+
* needs to be set to 0 to disable it.
3293+
* @hide
3294+
*/
3295+
public static final String WIFI_SUSPEND_OPTIMIZATIONS_ENABLED =
3296+
"wifi_suspend_optimizations_enabled";
3297+
32903298
/**
32913299
* Setting to turn off walled garden test on Wi-Fi. Feature is enabled by default and
32923300
* the setting needs to be set to 0 to disable it.

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import android.content.Intent;
4242
import android.content.IntentFilter;
4343
import android.content.pm.PackageManager;
44+
import android.database.ContentObserver;
4445
import android.net.ConnectivityManager;
4546
import android.net.DhcpInfo;
4647
import 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

Comments
 (0)