summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRockchip2015-09-07 11:06:47 +0800
committerRockchip2015-09-07 11:06:47 +0800
commit0392bf8c69dfdf89e2625f9bc3b86d7d5a787636 (patch)
tree7c7b85e869a47cc86fdcf65d08c6dc9d77f6e9a7
parent37f7fdc8dc715a9c887719f57968caf1bcacae96 (diff)
Wlan: add wifi power saver, prompt user to turn off wifi for reduce power consumption when no available AP around.
Signed-off-by: Rockchip <service@rock-chips.com>
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 4d380a7..9969be7 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -35,12 +35,17 @@ import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.backup.IBackupManager;
+import android.app.AlertDialog;
+import android.view.WindowManager;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.res.Resources;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.DhcpResults;
@@ -836,6 +841,8 @@ public class WifiStateMachine extends StateMachine {
"com.android.server.WifiManager.action.WLAN_SECOND_ALARM";
private static final String ACTION_NETWORK_CHECKER =
"com.android.server.WifiManager.action.NETWORK_CHECKER";
+ private static final String ACTION_WIFI_OFF_FOR_POWER_SAVE =
+ "com.android.server.WifiManager.action.WIFI_OFF_FOR_POWER_SAVE";
private static final String DELAYED_STOP_COUNTER = "DelayedStopCounter";
private static final int DRIVER_STOP_REQUEST = 0;
@@ -1057,6 +1064,15 @@ public class WifiStateMachine extends StateMachine {
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ processWifiOffAsk();
+ }
+ },
+ new IntentFilter(ACTION_WIFI_OFF_FOR_POWER_SAVE));
+
+ mContext.registerReceiver(
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
int counter = intent.getIntExtra(DELAYED_STOP_COUNTER, 0);
sendMessage(CMD_DELAYED_STOP_DRIVER, counter, 0);
}
@@ -1302,6 +1318,57 @@ public class WifiStateMachine extends StateMachine {
System.currentTimeMillis() + wifi_checker_time, mNetworkCheckerIntent);
}
+ private int noSavedInScanResultCount = 0;
+ public void WifiPowerSaveChecker() {
+ if ("0".equals(SystemProperties.get("wifi.powersaver.enable", "0")) ||
+ mNetworkInfo.getState() == NetworkInfo.State.CONNECTED || mP2pConnected.get()) {
+ noSavedInScanResultCount = 0;
+ return;
+ }
+ if (mWifiConfigStore.getConfiguredNetworks().size() != 0) {
+ for(ScanResult result: mScanResults) {
+ for (WifiConfiguration conf : mWifiConfigStore.getConfiguredNetworks()) {
+ if (conf != null && conf.SSID.equals("\"" + result.SSID + "\"")) {
+ loge("WifiPowerSaveChecker found a saved AP from scanresult:" + result.SSID);
+ noSavedInScanResultCount = 0;
+ return;
+ }
+ }
+ }
+ }
+ noSavedInScanResultCount++;
+ loge("WifiPowerSaveChecker no available AP found. Count = " + noSavedInScanResultCount);
+ if (noSavedInScanResultCount >= 20) {
+ noSavedInScanResultCount = 0;
+ if (syncGetWifiState() == WIFI_STATE_ENABLED && mNetworkInfo.getState()
+ != NetworkInfo.State.CONNECTED) {
+ Intent intent = new Intent(ACTION_WIFI_OFF_FOR_POWER_SAVE);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ }
+ }
+ return;
+ }
+
+ private void processWifiOffAsk() {
+ Resources r = Resources.getSystem();
+ SystemProperties.set("wifi.powersaver.enable", "0");
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_power_saver_title))
+ .setMessage(r.getString(R.string.wifi_power_saver_message))
+ .setPositiveButton("OK", new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ WifiManager mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+ if (mWifiManager != null)
+ mWifiManager.setWifiEnabled(false);
+ }
+ })
+ .setNegativeButton("Cancel", null)
+ .create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
/*
*
* Framework scan control
@@ -5437,6 +5504,8 @@ public class WifiStateMachine extends StateMachine {
closeRadioScanStats();
noteScanEnd();
setScanResults();
+ if (isSofia)
+ WifiPowerSaveChecker();
if (mIsFullScanOngoing || mSendScanResultsBroadcast) {
/* Just updated results from full scan, let apps know about this */
sendScanResultsAvailableBroadcast();
@@ -7918,6 +7987,7 @@ public class WifiStateMachine extends StateMachine {
//gwl
doWifiOperationChecker();
+ SystemProperties.set("wifi.powersaver.enable", "1");
loge("Wifi Connected, start to check if need to enable wifi intelligent sleep.");
if (mScreenOn == false && Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_SLEEP_POLICY, 2)