private AlarmManager mAlarmManager;
private PendingIntent mIdleIntent;
- private PendingIntent mScanIntent;
private BluetoothA2dp mBluetoothA2dp;
private static final int IDLE_REQUEST = 0;
- private static final int SCAN_REQUEST = 0;
private boolean mScreenOff;
private boolean mDeviceIdle;
private int mPluggedType;
*/
private static final long DEFAULT_IDLE_MS = 15 * 60 * 1000; /* 15 minutes */
- /**
- * See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
- * Settings.Secure value is not present.
- */
- private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
-
private static final String ACTION_DEVICE_IDLE =
"com.android.server.WifiManager.action.DEVICE_IDLE";
- private static final String ACTION_START_SCAN =
- "com.android.server.WifiManager.action.START_SCAN";
-
private boolean mIsReceiverRegistered = false;
Intent idleIntent = new Intent(ACTION_DEVICE_IDLE, null);
mIdleIntent = PendingIntent.getBroadcast(mContext, IDLE_REQUEST, idleIntent, 0);
- Intent scanIntent = new Intent(ACTION_START_SCAN, null);
- mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
-
HandlerThread wifiThread = new HandlerThread("WifiService");
wifiThread.start();
mHandler = new WifiServiceHandler(wifiThread.getLooper(), context);
int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
BluetoothA2dp.STATE_NOT_PLAYING);
mWifiStateMachine.setBluetoothScanMode(state == BluetoothA2dp.STATE_PLAYING);
- } else if (action.equals(ACTION_START_SCAN)) {
- mWifiStateMachine.startScan(true);
}
}
strongestLockMode = WifiManager.WIFI_MODE_FULL;
}
- /* Scan interval when driver is started */
- long scanMs = Settings.Secure.getLong(mContext.getContentResolver(),
- Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS);
-
/* Disable tethering when airplane mode is enabled */
if (airplaneMode) {
mWifiStateMachine.setWifiApEnabled(null, false);
mWifiStateMachine.setScanOnlyMode(
strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY);
mWifiStateMachine.setDriverStart(true);
- mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
- System.currentTimeMillis() + scanMs, scanMs, mScanIntent);
mWifiStateMachine.setHighPerfModeEnabled(strongestLockMode
== WifiManager.WIFI_MODE_FULL_HIGH_PERF);
} else {
mWifiStateMachine.requestCmWakeLock();
mWifiStateMachine.setDriverStart(false);
- mAlarmManager.cancel(mScanIntent);
}
} else {
mWifiStateMachine.setWifiEnabled(false);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
intentFilter.addAction(ACTION_DEVICE_IDLE);
- intentFilter.addAction(ACTION_START_SCAN);
intentFilter.addAction(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED);
mContext.registerReceiver(mReceiver, intentFilter);
}
import static android.net.wifi.WifiManager.WIFI_AP_STATE_FAILED;
import android.app.ActivityManagerNative;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
import android.net.LinkAddress;
import android.net.NetworkInfo;
import android.net.DhcpInfo;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
+import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
+import android.content.IntentFilter;
+
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
import com.android.internal.util.HierarchicalState;
* and load configuration afterwards */
private boolean mWpsStarted = false;
+ private AlarmManager mAlarmManager;
+ private PendingIntent mScanIntent;
+
// Channel for sending replies.
private AsyncChannel mReplyChannel = new AsyncChannel();
private static final int POWER_MODE_ACTIVE = 1;
private static final int POWER_MODE_AUTO = 0;
+ /**
+ * See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
+ * Settings.Secure value is not present.
+ */
+ private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
+
/* Default parent state */
private HierarchicalState mDefaultState = new DefaultState();
/* Temporary initial state */
private final AtomicInteger mLastEnableUid = new AtomicInteger(Process.myUid());
private final AtomicInteger mLastApEnableUid = new AtomicInteger(Process.myUid());
+ private static final int SCAN_REQUEST = 0;
+ private static final String ACTION_START_SCAN =
+ "com.android.server.WifiManager.action.START_SCAN";
+
/**
* Keep track of whether WIFI is running.
*/
mLastNetworkId = -1;
mLastSignalLevel = -1;
+ mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
+ Intent scanIntent = new Intent(ACTION_START_SCAN, null);
+ mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
+
+ mContext.registerReceiver(
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ startScan(false);
+ }
+ },
+ new IntentFilter(ACTION_START_SCAN));
+
mScanResultCache = new LinkedHashMap<String, ScanResult>(
SCAN_RESULT_CACHE_SIZE, 0.75f, true) {
/*
if (scanResult != null) {
scanList.add(scanResult);
} else {
- Log.w(TAG, "misformatted scan result for: " + line);
+ //TODO: hidden network handling
}
}
lineBeg = lineEnd + 1;
} else {
WifiNative.setScanResultHandlingCommand(CONNECT_MODE);
WifiNative.reconnectCommand();
- transitionTo(mConnectModeState);
+ transitionTo(mDisconnectedState);
}
}
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
+
+ /**
+ * In a disconnected state, an infrequent scan that wakes
+ * up the device is needed to ensure a user connects to
+ * an access point on the move
+ */
+ long scanMs = Settings.Secure.getLong(mContext.getContentResolver(),
+ Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS);
+
+ mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
+ System.currentTimeMillis() + scanMs, scanMs, mScanIntent);
}
@Override
public boolean processMessage(Message message) {
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
return HANDLED;
}
+
+ @Override
+ public void exit() {
+ mAlarmManager.cancel(mScanIntent);
+ }
}
class SoftApStartedState extends HierarchicalState {