blob: cc25e8d099967f0ec2b25a42d5f613a65d006730 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07002 * Copyright (C) 2010 The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.AlarmManager;
Irfan Sheriff0d255342010-07-28 09:35:20 -070020import android.app.Notification;
21import android.app.NotificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.app.PendingIntent;
Jaikumar Ganesh7440fc22010-09-27 17:04:14 -070023import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.BroadcastReceiver;
25import android.content.ContentResolver;
26import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.pm.PackageManager;
Irfan Sheriff0d255342010-07-28 09:35:20 -070030import android.database.ContentObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.net.wifi.IWifiManager;
32import android.net.wifi.WifiInfo;
33import android.net.wifi.WifiManager;
Irfan Sheriff0d255342010-07-28 09:35:20 -070034import android.net.wifi.WifiStateMachine;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.net.wifi.ScanResult;
36import android.net.wifi.WifiConfiguration;
San Mehat0310f9a2009-07-07 10:49:47 -070037import android.net.wifi.SupplicantState;
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -080038import android.net.wifi.WifiConfiguration.KeyMgmt;
Irfan Sheriff02fb46a2010-12-08 11:27:37 -080039import android.net.wifi.WpsConfiguration;
Irfan Sheriffe4c56c92011-01-12 16:33:58 -080040import android.net.wifi.WpsResult;
Irfan Sheriff5321aef2010-02-12 12:35:59 -080041import android.net.ConnectivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.net.DhcpInfo;
Irfan Sheriff0d255342010-07-28 09:35:20 -070043import android.net.NetworkInfo;
44import android.net.NetworkInfo.State;
Irfan Sheriff227bec42011-02-15 19:30:27 -080045import android.net.NetworkInfo.DetailedState;
46import android.net.TrafficStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.os.Binder;
Irfan Sheriff0d255342010-07-28 09:35:20 -070048import android.os.Handler;
Irfan Sheriff227bec42011-02-15 19:30:27 -080049import android.os.Messenger;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.HandlerThread;
51import android.os.IBinder;
Irfan Sheriff5321aef2010-02-12 12:35:59 -080052import android.os.INetworkManagementService;
Irfan Sheriff0d255342010-07-28 09:35:20 -070053import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.RemoteException;
Amith Yamasani47873e52009-07-02 12:05:32 -070055import android.os.ServiceManager;
Irfan Sheriff227bec42011-02-15 19:30:27 -080056import android.os.SystemProperties;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -070057import android.os.WorkSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.provider.Settings;
Irfan Sheriff0d255342010-07-28 09:35:20 -070059import android.text.TextUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080060import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
62import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import java.util.List;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -080064import java.util.Set;
Irfan Sheriffa2a1b912010-06-07 09:03:04 -070065import java.util.concurrent.atomic.AtomicBoolean;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import java.io.FileDescriptor;
67import java.io.PrintWriter;
68
The Android Open Source Project10592532009-03-18 17:39:46 -070069import com.android.internal.app.IBatteryStats;
Wink Saville4b7ba092010-10-20 15:37:41 -070070import com.android.internal.util.AsyncChannel;
The Android Open Source Project10592532009-03-18 17:39:46 -070071import com.android.server.am.BatteryStatsService;
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -080072import com.android.internal.R;
The Android Open Source Project10592532009-03-18 17:39:46 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074/**
75 * WifiService handles remote WiFi operation requests by implementing
Irfan Sheriffa2a1b912010-06-07 09:03:04 -070076 * the IWifiManager interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 *
78 * @hide
79 */
Irfan Sheriffa2a1b912010-06-07 09:03:04 -070080//TODO: Clean up multiple locks and implement WifiService
81// as a SM to track soft AP/client/adhoc bring up based
82// on device idle state, airplane mode and boot.
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084public class WifiService extends IWifiManager.Stub {
85 private static final String TAG = "WifiService";
Irfan Sheriffa2a1b912010-06-07 09:03:04 -070086 private static final boolean DBG = true;
87
Irfan Sheriff0d255342010-07-28 09:35:20 -070088 private final WifiStateMachine mWifiStateMachine;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
90 private Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92 private AlarmManager mAlarmManager;
93 private PendingIntent mIdleIntent;
94 private static final int IDLE_REQUEST = 0;
95 private boolean mScreenOff;
96 private boolean mDeviceIdle;
97 private int mPluggedType;
98
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -070099 // true if the user enabled Wifi while in airplane mode
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700100 private AtomicBoolean mAirplaneModeOverwridden = new AtomicBoolean(false);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 private final LockList mLocks = new LockList();
Eric Shienbrood5711fad2009-03-27 20:25:31 -0700103 // some wifi lock statistics
Irfan Sheriff5876a422010-08-12 20:26:23 -0700104 private int mFullHighPerfLocksAcquired;
105 private int mFullHighPerfLocksReleased;
Eric Shienbrood5711fad2009-03-27 20:25:31 -0700106 private int mFullLocksAcquired;
107 private int mFullLocksReleased;
108 private int mScanLocksAcquired;
109 private int mScanLocksReleased;
The Android Open Source Project10592532009-03-18 17:39:46 -0700110
Robert Greenwalt58ff0212009-05-19 15:53:54 -0700111 private final List<Multicaster> mMulticasters =
112 new ArrayList<Multicaster>();
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700113 private int mMulticastEnabled;
114 private int mMulticastDisabled;
115
The Android Open Source Project10592532009-03-18 17:39:46 -0700116 private final IBatteryStats mBatteryStats;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800117
Irfan Sheriff227bec42011-02-15 19:30:27 -0800118 private boolean mEnableTrafficStatsPoll = false;
119 private int mTrafficStatsPollToken = 0;
120 private long mTxPkts;
121 private long mRxPkts;
122 /* Tracks last reported data activity */
123 private int mDataActivity;
124 private String mInterfaceName;
125
126 /**
127 * Interval in milliseconds between polling for traffic
128 * statistics
129 */
130 private static final int POLL_TRAFFIC_STATS_INTERVAL_MSECS = 1000;
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 /**
Doug Zongker43866e02010-01-07 12:09:54 -0800133 * See {@link Settings.Secure#WIFI_IDLE_MS}. This is the default value if a
134 * Settings.Secure value is not present. This timeout value is chosen as
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 * the approximate point at which the battery drain caused by Wi-Fi
136 * being enabled but not active exceeds the battery drain caused by
137 * re-establishing a connection to the mobile data network.
138 */
Irfan Sheriff4f5f7c92010-10-14 17:01:27 -0700139 private static final long DEFAULT_IDLE_MS = 15 * 60 * 1000; /* 15 minutes */
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 private static final String ACTION_DEVICE_IDLE =
142 "com.android.server.WifiManager.action.DEVICE_IDLE";
143
Irfan Sheriff227bec42011-02-15 19:30:27 -0800144 private static final int CMD_ENABLE_TRAFFIC_STATS_POLL = 1;
145 private static final int CMD_TRAFFIC_STATS_POLL = 2;
146
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700147 private boolean mIsReceiverRegistered = false;
148
Irfan Sheriff0d255342010-07-28 09:35:20 -0700149
150 NetworkInfo mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, "WIFI", "");
151
152 // Variables relating to the 'available networks' notification
153 /**
154 * The icon to show in the 'available networks' notification. This will also
155 * be the ID of the Notification given to the NotificationManager.
156 */
157 private static final int ICON_NETWORKS_AVAILABLE =
158 com.android.internal.R.drawable.stat_notify_wifi_in_range;
159 /**
160 * When a notification is shown, we wait this amount before possibly showing it again.
161 */
162 private final long NOTIFICATION_REPEAT_DELAY_MS;
163 /**
164 * Whether the user has set the setting to show the 'available networks' notification.
165 */
166 private boolean mNotificationEnabled;
167 /**
168 * Observes the user setting to keep {@link #mNotificationEnabled} in sync.
169 */
170 private NotificationEnabledSettingObserver mNotificationEnabledSettingObserver;
171 /**
172 * The {@link System#currentTimeMillis()} must be at least this value for us
173 * to show the notification again.
174 */
175 private long mNotificationRepeatTime;
176 /**
177 * The Notification object given to the NotificationManager.
178 */
179 private Notification mNotification;
180 /**
181 * Whether the notification is being shown, as set by us. That is, if the
182 * user cancels the notification, we will not receive the callback so this
183 * will still be true. We only guarantee if this is false, then the
184 * notification is not showing.
185 */
186 private boolean mNotificationShown;
187 /**
188 * The number of continuous scans that must occur before consider the
189 * supplicant in a scanning state. This allows supplicant to associate with
190 * remembered networks that are in the scan results.
191 */
192 private static final int NUM_SCANS_BEFORE_ACTUALLY_SCANNING = 3;
193 /**
194 * The number of scans since the last network state change. When this
195 * exceeds {@link #NUM_SCANS_BEFORE_ACTUALLY_SCANNING}, we consider the
196 * supplicant to actually be scanning. When the network state changes to
197 * something other than scanning, we reset this to 0.
198 */
199 private int mNumScansSinceNetworkStateChange;
Jaikumar Ganesh7440fc22010-09-27 17:04:14 -0700200
Dianne Hackborn03f3cb02010-09-17 23:12:26 -0700201 /**
Wink Saville4b7ba092010-10-20 15:37:41 -0700202 * Asynchronous channel to WifiStateMachine
203 */
Irfan Sheriff227bec42011-02-15 19:30:27 -0800204 private AsyncChannel mWifiStateMachineChannel;
Wink Saville4b7ba092010-10-20 15:37:41 -0700205
206 /**
Irfan Sheriff227bec42011-02-15 19:30:27 -0800207 * Clients receiving asynchronous messages
Wink Saville4b7ba092010-10-20 15:37:41 -0700208 */
Irfan Sheriff227bec42011-02-15 19:30:27 -0800209 private List<AsyncChannel> mClients = new ArrayList<AsyncChannel>();
Wink Saville4b7ba092010-10-20 15:37:41 -0700210
Irfan Sheriff227bec42011-02-15 19:30:27 -0800211 /**
212 * Handles client connections
213 */
214 private class AsyncServiceHandler extends Handler {
215
216 AsyncServiceHandler(android.os.Looper looper) {
Wink Saville4b7ba092010-10-20 15:37:41 -0700217 super(looper);
Wink Saville4b7ba092010-10-20 15:37:41 -0700218 }
219
220 @Override
221 public void handleMessage(Message msg) {
222 switch (msg.what) {
223 case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
224 if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800225 Slog.d(TAG, "New client listening to asynchronous messages");
226 mClients.add((AsyncChannel) msg.obj);
Wink Saville4b7ba092010-10-20 15:37:41 -0700227 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800228 Slog.e(TAG, "Client connection failure, error=" + msg.arg1);
229 }
230 break;
231 }
232 case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: {
233 AsyncChannel ac = new AsyncChannel();
234 ac.connect(mContext, this, msg.replyTo);
235 break;
236 }
237 case CMD_ENABLE_TRAFFIC_STATS_POLL: {
238 mEnableTrafficStatsPoll = (msg.arg1 == 1);
239 mTrafficStatsPollToken++;
240 if (mEnableTrafficStatsPoll) {
241 notifyOnDataActivity();
242 sendMessageDelayed(Message.obtain(this, CMD_TRAFFIC_STATS_POLL,
243 mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
244 }
245 break;
246 }
247 case CMD_TRAFFIC_STATS_POLL: {
248 if (msg.arg1 == mTrafficStatsPollToken) {
249 notifyOnDataActivity();
250 sendMessageDelayed(Message.obtain(this, CMD_TRAFFIC_STATS_POLL,
251 mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
Wink Saville4b7ba092010-10-20 15:37:41 -0700252 }
253 break;
254 }
255 default: {
256 Slog.d(TAG, "WifiServicehandler.handleMessage ignoring msg=" + msg);
257 break;
258 }
259 }
260 }
261 }
Irfan Sheriff227bec42011-02-15 19:30:27 -0800262 private AsyncServiceHandler mAsyncServiceHandler;
263
264 /**
265 * Handles interaction with WifiStateMachine
266 */
267 private class WifiStateMachineHandler extends Handler {
268 private AsyncChannel mWsmChannel;
269
270 WifiStateMachineHandler(android.os.Looper looper) {
271 super(looper);
272 mWsmChannel = new AsyncChannel();
273 mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler());
274 }
275
276 @Override
277 public void handleMessage(Message msg) {
278 switch (msg.what) {
279 case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
280 if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
281 mWifiStateMachineChannel = mWsmChannel;
282 } else {
283 Slog.e(TAG, "WifiStateMachine connection failure, error=" + msg.arg1);
284 mWifiStateMachineChannel = null;
285 }
286 break;
287 }
288 default: {
289 Slog.d(TAG, "WifiStateMachineHandler.handleMessage ignoring msg=" + msg);
290 break;
291 }
292 }
293 }
294 }
295 WifiStateMachineHandler mWifiStateMachineHandler;
Wink Saville4b7ba092010-10-20 15:37:41 -0700296
297 /**
Dianne Hackborn03f3cb02010-09-17 23:12:26 -0700298 * Temporary for computing UIDS that are responsible for starting WIFI.
299 * Protected by mWifiStateTracker lock.
300 */
301 private final WorkSource mTmpWorkSource = new WorkSource();
Irfan Sheriff0d255342010-07-28 09:35:20 -0700302
303 WifiService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 mContext = context;
Irfan Sheriff227bec42011-02-15 19:30:27 -0800305
306 mInterfaceName = SystemProperties.get("wifi.interface", "wlan0");
307
308 mWifiStateMachine = new WifiStateMachine(mContext, mInterfaceName);
Irfan Sheriff0d255342010-07-28 09:35:20 -0700309 mWifiStateMachine.enableRssiPolling(true);
The Android Open Source Project10592532009-03-18 17:39:46 -0700310 mBatteryStats = BatteryStatsService.getService();
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
313 Intent idleIntent = new Intent(ACTION_DEVICE_IDLE, null);
314 mIdleIntent = PendingIntent.getBroadcast(mContext, IDLE_REQUEST, idleIntent, 0);
315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 mContext.registerReceiver(
317 new BroadcastReceiver() {
318 @Override
319 public void onReceive(Context context, Intent intent) {
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700320 // clear our flag indicating the user has overwridden airplane mode
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700321 mAirplaneModeOverwridden.set(false);
Irfan Sheriffb2e6c012010-04-05 11:57:56 -0700322 // on airplane disable, restore Wifi if the saved state indicates so
323 if (!isAirplaneModeOn() && testAndClearWifiSavedState()) {
324 persistWifiEnabled(true);
325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 updateWifiState();
327 }
328 },
329 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
330
Irfan Sheriff0d255342010-07-28 09:35:20 -0700331 IntentFilter filter = new IntentFilter();
332 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
333 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
334 filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
335
336 mContext.registerReceiver(
337 new BroadcastReceiver() {
338 @Override
339 public void onReceive(Context context, Intent intent) {
340 if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
341 // reset & clear notification on any wifi state change
342 resetNotification();
343 } else if (intent.getAction().equals(
344 WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
345 mNetworkInfo = (NetworkInfo) intent.getParcelableExtra(
346 WifiManager.EXTRA_NETWORK_INFO);
347 // reset & clear notification on a network connect & disconnect
348 switch(mNetworkInfo.getDetailedState()) {
349 case CONNECTED:
350 case DISCONNECTED:
Irfan Sheriff227bec42011-02-15 19:30:27 -0800351 evaluateTrafficStatsPolling();
Irfan Sheriff0d255342010-07-28 09:35:20 -0700352 resetNotification();
353 break;
354 }
355 } else if (intent.getAction().equals(
356 WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
357 checkAndSetNotification();
358 }
359 }
360 }, filter);
361
Irfan Sheriff227bec42011-02-15 19:30:27 -0800362 HandlerThread wifiThread = new HandlerThread("WifiService");
363 wifiThread.start();
364 mAsyncServiceHandler = new AsyncServiceHandler(wifiThread.getLooper());
365 mWifiStateMachineHandler = new WifiStateMachineHandler(wifiThread.getLooper());
366
Irfan Sheriff0d255342010-07-28 09:35:20 -0700367 // Setting is in seconds
368 NOTIFICATION_REPEAT_DELAY_MS = Settings.Secure.getInt(context.getContentResolver(),
369 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l;
370 mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler());
371 mNotificationEnabledSettingObserver.register();
Irfan Sheriff7b009782010-03-11 16:37:45 -0800372 }
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800373
Irfan Sheriff7b009782010-03-11 16:37:45 -0800374 /**
375 * Check if Wi-Fi needs to be enabled and start
376 * if needed
Irfan Sheriff60e3ba02010-04-02 12:18:45 -0700377 *
378 * This function is used only at boot time
Irfan Sheriff7b009782010-03-11 16:37:45 -0800379 */
Irfan Sheriff0d255342010-07-28 09:35:20 -0700380 public void checkAndStartWifi() {
Irfan Sheriffa3bd4092010-03-24 17:58:59 -0700381 /* Start if Wi-Fi is enabled or the saved state indicates Wi-Fi was on */
Irfan Sheriff60e3ba02010-04-02 12:18:45 -0700382 boolean wifiEnabled = !isAirplaneModeOn()
383 && (getPersistedWifiEnabled() || testAndClearWifiSavedState());
Irfan Sheriff7b009782010-03-11 16:37:45 -0800384 Slog.i(TAG, "WifiService starting up with Wi-Fi " +
385 (wifiEnabled ? "enabled" : "disabled"));
Irfan Sheriffb99fe5e2010-03-26 14:56:07 -0700386 setWifiEnabled(wifiEnabled);
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800387 }
388
Irfan Sheriffa3bd4092010-03-24 17:58:59 -0700389 private boolean testAndClearWifiSavedState() {
390 final ContentResolver cr = mContext.getContentResolver();
391 int wifiSavedState = 0;
392 try {
393 wifiSavedState = Settings.Secure.getInt(cr, Settings.Secure.WIFI_SAVED_STATE);
394 if(wifiSavedState == 1)
395 Settings.Secure.putInt(cr, Settings.Secure.WIFI_SAVED_STATE, 0);
396 } catch (Settings.SettingNotFoundException e) {
397 ;
398 }
399 return (wifiSavedState == 1);
400 }
401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 private boolean getPersistedWifiEnabled() {
403 final ContentResolver cr = mContext.getContentResolver();
404 try {
405 return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON) == 1;
406 } catch (Settings.SettingNotFoundException e) {
407 Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, 0);
408 return false;
409 }
410 }
411
412 private void persistWifiEnabled(boolean enabled) {
413 final ContentResolver cr = mContext.getContentResolver();
414 Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, enabled ? 1 : 0);
415 }
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 /**
418 * see {@link android.net.wifi.WifiManager#pingSupplicant()}
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700419 * @return {@code true} if the operation succeeds, {@code false} otherwise
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 */
421 public boolean pingSupplicant() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700422 enforceAccessPermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800423 if (mWifiStateMachineChannel != null) {
424 return mWifiStateMachine.syncPingSupplicant(mWifiStateMachineChannel);
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700425 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800426 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700427 return false;
428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430
431 /**
432 * see {@link android.net.wifi.WifiManager#startScan()}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 */
Irfan Sheriffe4984752010-08-19 11:29:22 -0700434 public void startScan(boolean forceActive) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 enforceChangePermission();
Irfan Sheriffe4984752010-08-19 11:29:22 -0700436 mWifiStateMachine.startScan(forceActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 }
438
439 private void enforceAccessPermission() {
440 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE,
441 "WifiService");
442 }
443
444 private void enforceChangePermission() {
445 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE,
446 "WifiService");
447
448 }
449
Robert Greenwaltfc1b15c2009-05-22 15:09:51 -0700450 private void enforceMulticastChangePermission() {
451 mContext.enforceCallingOrSelfPermission(
452 android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE,
453 "WifiService");
454 }
455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 /**
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700457 * see {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)}
458 * @param enable {@code true} to enable, {@code false} to disable.
459 * @return {@code true} if the enable/disable operation was
460 * started or is already in the queue.
461 */
462 public synchronized boolean setWifiEnabled(boolean enable) {
463 enforceChangePermission();
464
465 if (DBG) {
Irfan Sheriff0d255342010-07-28 09:35:20 -0700466 Slog.e(TAG, "Invoking mWifiStateMachine.setWifiEnabled\n");
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700467 }
468
469 // set a flag if the user is enabling Wifi while in airplane mode
470 if (enable && isAirplaneModeOn() && isAirplaneToggleable()) {
471 mAirplaneModeOverwridden.set(true);
472 }
473
Dianne Hackborn03f3cb02010-09-17 23:12:26 -0700474 if (enable) {
475 reportStartWorkSource();
476 }
Irfan Sheriff0d255342010-07-28 09:35:20 -0700477 mWifiStateMachine.setWifiEnabled(enable);
Irfan Sheriff61180692010-08-18 16:07:39 -0700478
479 /*
480 * Caller might not have WRITE_SECURE_SETTINGS,
481 * only CHANGE_WIFI_STATE is enforced
482 */
483 long ident = Binder.clearCallingIdentity();
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700484 persistWifiEnabled(enable);
Irfan Sheriff61180692010-08-18 16:07:39 -0700485 Binder.restoreCallingIdentity(ident);
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700486
487 if (enable) {
488 if (!mIsReceiverRegistered) {
489 registerForBroadcasts();
490 mIsReceiverRegistered = true;
491 }
492 } else if (mIsReceiverRegistered){
493 mContext.unregisterReceiver(mReceiver);
494 mIsReceiverRegistered = false;
495 }
496
497 return true;
498 }
499
500 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 * see {@link WifiManager#getWifiState()}
502 * @return One of {@link WifiManager#WIFI_STATE_DISABLED},
503 * {@link WifiManager#WIFI_STATE_DISABLING},
504 * {@link WifiManager#WIFI_STATE_ENABLED},
505 * {@link WifiManager#WIFI_STATE_ENABLING},
506 * {@link WifiManager#WIFI_STATE_UNKNOWN}
507 */
508 public int getWifiEnabledState() {
509 enforceAccessPermission();
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700510 return mWifiStateMachine.syncGetWifiState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
512
513 /**
Irfan Sheriffc2f54c22010-03-18 14:02:22 -0700514 * see {@link android.net.wifi.WifiManager#setWifiApEnabled(WifiConfiguration, boolean)}
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800515 * @param wifiConfig SSID, security and channel details as
516 * part of WifiConfiguration
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700517 * @param enabled true to enable and false to disable
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800518 * @return {@code true} if the start operation was
519 * started or is already in the queue.
520 */
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700521 public synchronized boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800522 enforceChangePermission();
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800523
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700524 if (enabled) {
525 /* Use default config if there is no existing config */
526 if (wifiConfig == null && ((wifiConfig = getWifiApConfiguration()) == null)) {
527 wifiConfig = new WifiConfiguration();
528 wifiConfig.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
529 wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
530 }
Irfan Sheriff61180692010-08-18 16:07:39 -0700531 /*
532 * Caller might not have WRITE_SECURE_SETTINGS,
533 * only CHANGE_WIFI_STATE is enforced
534 */
535 long ident = Binder.clearCallingIdentity();
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700536 setWifiApConfiguration(wifiConfig);
Irfan Sheriff61180692010-08-18 16:07:39 -0700537 Binder.restoreCallingIdentity(ident);
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800538 }
539
Irfan Sheriff0d255342010-07-28 09:35:20 -0700540 mWifiStateMachine.setWifiApEnabled(wifiConfig, enabled);
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700541
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800542 return true;
543 }
544
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700545 /**
546 * see {@link WifiManager#getWifiApState()}
547 * @return One of {@link WifiManager#WIFI_AP_STATE_DISABLED},
548 * {@link WifiManager#WIFI_AP_STATE_DISABLING},
549 * {@link WifiManager#WIFI_AP_STATE_ENABLED},
550 * {@link WifiManager#WIFI_AP_STATE_ENABLING},
551 * {@link WifiManager#WIFI_AP_STATE_FAILED}
552 */
553 public int getWifiApEnabledState() {
Irfan Sheriff17b232b2010-06-24 11:32:26 -0700554 enforceAccessPermission();
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700555 return mWifiStateMachine.syncGetWifiApState();
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700556 }
557
558 /**
559 * see {@link WifiManager#getWifiApConfiguration()}
560 * @return soft access point configuration
561 */
562 public synchronized WifiConfiguration getWifiApConfiguration() {
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800563 final ContentResolver cr = mContext.getContentResolver();
564 WifiConfiguration wifiConfig = new WifiConfiguration();
565 int authType;
566 try {
567 wifiConfig.SSID = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_SSID);
568 if (wifiConfig.SSID == null)
569 return null;
570 authType = Settings.Secure.getInt(cr, Settings.Secure.WIFI_AP_SECURITY);
571 wifiConfig.allowedKeyManagement.set(authType);
572 wifiConfig.preSharedKey = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_PASSWD);
573 return wifiConfig;
574 } catch (Settings.SettingNotFoundException e) {
575 Slog.e(TAG,"AP settings not found, returning");
576 return null;
577 }
578 }
579
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700580 /**
581 * see {@link WifiManager#setWifiApConfiguration(WifiConfiguration)}
582 * @param wifiConfig WifiConfiguration details for soft access point
583 */
584 public synchronized void setWifiApConfiguration(WifiConfiguration wifiConfig) {
Irfan Sheriff17b232b2010-06-24 11:32:26 -0700585 enforceChangePermission();
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800586 final ContentResolver cr = mContext.getContentResolver();
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800587 if (wifiConfig == null)
588 return;
Irfan Sheriffec8d23a2011-02-16 17:00:33 -0800589 int authType = wifiConfig.getAuthType();
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800590 Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_SSID, wifiConfig.SSID);
Irfan Sheriffec8d23a2011-02-16 17:00:33 -0800591 Settings.Secure.putInt(cr, Settings.Secure.WIFI_AP_SECURITY, authType);
592 if (authType != KeyMgmt.NONE)
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800593 Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_PASSWD, wifiConfig.preSharedKey);
594 }
595
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800596 /**
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700597 * see {@link android.net.wifi.WifiManager#disconnect()}
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800598 */
Irfan Sheriffe4984752010-08-19 11:29:22 -0700599 public void disconnect() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700600 enforceChangePermission();
Irfan Sheriffe4984752010-08-19 11:29:22 -0700601 mWifiStateMachine.disconnectCommand();
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800602 }
603
604 /**
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700605 * see {@link android.net.wifi.WifiManager#reconnect()}
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800606 */
Irfan Sheriffe4984752010-08-19 11:29:22 -0700607 public void reconnect() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700608 enforceChangePermission();
Irfan Sheriffe4984752010-08-19 11:29:22 -0700609 mWifiStateMachine.reconnectCommand();
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800610 }
611
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700612 /**
613 * see {@link android.net.wifi.WifiManager#reassociate()}
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700614 */
Irfan Sheriffe4984752010-08-19 11:29:22 -0700615 public void reassociate() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700616 enforceChangePermission();
Irfan Sheriffe4984752010-08-19 11:29:22 -0700617 mWifiStateMachine.reassociateCommand();
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800618 }
619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 /**
621 * see {@link android.net.wifi.WifiManager#getConfiguredNetworks()}
622 * @return the list of configured networks
623 */
624 public List<WifiConfiguration> getConfiguredNetworks() {
625 enforceAccessPermission();
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700626 return mWifiStateMachine.syncGetConfiguredNetworks();
Chung-yih Wanga8d15942009-10-09 11:01:49 +0800627 }
628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 /**
630 * see {@link android.net.wifi.WifiManager#addOrUpdateNetwork(WifiConfiguration)}
631 * @return the supplicant-assigned identifier for the new or updated
632 * network if the operation succeeds, or {@code -1} if it fails
633 */
Irfan Sheriff7aac5542009-12-22 21:42:17 -0800634 public int addOrUpdateNetwork(WifiConfiguration config) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800636 if (mWifiStateMachineChannel != null) {
637 return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config);
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700638 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800639 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700640 return -1;
641 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 }
643
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700644 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 * See {@link android.net.wifi.WifiManager#removeNetwork(int)}
646 * @param netId the integer that identifies the network configuration
647 * to the supplicant
648 * @return {@code true} if the operation succeeded
649 */
650 public boolean removeNetwork(int netId) {
651 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800652 if (mWifiStateMachineChannel != null) {
653 return mWifiStateMachine.syncRemoveNetwork(mWifiStateMachineChannel, netId);
Wink Saville4b7ba092010-10-20 15:37:41 -0700654 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800655 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Wink Saville4b7ba092010-10-20 15:37:41 -0700656 return false;
657 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 }
659
660 /**
661 * See {@link android.net.wifi.WifiManager#enableNetwork(int, boolean)}
662 * @param netId the integer that identifies the network configuration
663 * to the supplicant
664 * @param disableOthers if true, disable all other networks.
665 * @return {@code true} if the operation succeeded
666 */
667 public boolean enableNetwork(int netId, boolean disableOthers) {
668 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800669 if (mWifiStateMachineChannel != null) {
670 return mWifiStateMachine.syncEnableNetwork(mWifiStateMachineChannel, netId,
671 disableOthers);
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700672 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800673 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700674 return false;
675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677
678 /**
679 * See {@link android.net.wifi.WifiManager#disableNetwork(int)}
680 * @param netId the integer that identifies the network configuration
681 * to the supplicant
682 * @return {@code true} if the operation succeeded
683 */
684 public boolean disableNetwork(int netId) {
685 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800686 if (mWifiStateMachineChannel != null) {
687 return mWifiStateMachine.syncDisableNetwork(mWifiStateMachineChannel, netId);
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700688 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800689 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700690 return false;
691 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
694 /**
695 * See {@link android.net.wifi.WifiManager#getConnectionInfo()}
696 * @return the Wi-Fi information, contained in {@link WifiInfo}.
697 */
698 public WifiInfo getConnectionInfo() {
699 enforceAccessPermission();
700 /*
701 * Make sure we have the latest information, by sending
702 * a status request to the supplicant.
703 */
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700704 return mWifiStateMachine.syncRequestConnectionInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 }
706
707 /**
708 * Return the results of the most recent access point scan, in the form of
709 * a list of {@link ScanResult} objects.
710 * @return the list of results
711 */
712 public List<ScanResult> getScanResults() {
713 enforceAccessPermission();
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700714 return mWifiStateMachine.syncGetScanResultsList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 }
716
717 /**
718 * Tell the supplicant to persist the current list of configured networks.
719 * @return {@code true} if the operation succeeded
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700720 *
721 * TODO: deprecate this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 */
723 public boolean saveConfiguration() {
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700724 boolean result = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800726 if (mWifiStateMachineChannel != null) {
727 return mWifiStateMachine.syncSaveConfig(mWifiStateMachineChannel);
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700728 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800729 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriff1406bcb2010-10-28 14:41:39 -0700730 return false;
731 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 }
733
734 /**
Irfan Sheriffed4f28b2010-10-29 15:32:10 -0700735 * Set the country code
736 * @param countryCode ISO 3166 country code.
Robert Greenwaltb5010cc2009-05-21 15:11:40 -0700737 * @param persist {@code true} if the setting should be remembered.
Irfan Sheriffed4f28b2010-10-29 15:32:10 -0700738 *
739 * The persist behavior exists so that wifi can fall back to the last
740 * persisted country code on a restart, when the locale information is
741 * not available from telephony.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 */
Irfan Sheriffed4f28b2010-10-29 15:32:10 -0700743 public void setCountryCode(String countryCode, boolean persist) {
744 Slog.i(TAG, "WifiService trying to set country code to " + countryCode +
745 " with persist set to " + persist);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 enforceChangePermission();
Irfan Sheriffed4f28b2010-10-29 15:32:10 -0700747 mWifiStateMachine.setCountryCode(countryCode, persist);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 }
749
750 /**
Irfan Sheriff36f74132010-11-04 16:57:37 -0700751 * Set the operational frequency band
752 * @param band One of
753 * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO},
754 * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ},
755 * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ},
756 * @param persist {@code true} if the setting should be remembered.
757 *
758 */
759 public void setFrequencyBand(int band, boolean persist) {
760 enforceChangePermission();
761 if (!isDualBandSupported()) return;
762 Slog.i(TAG, "WifiService trying to set frequency band to " + band +
763 " with persist set to " + persist);
764 mWifiStateMachine.setFrequencyBand(band, persist);
765 }
766
767
768 /**
769 * Get the operational frequency band
770 */
771 public int getFrequencyBand() {
772 enforceAccessPermission();
773 return mWifiStateMachine.getFrequencyBand();
774 }
775
776 public boolean isDualBandSupported() {
777 //TODO: Should move towards adding a driver API that checks at runtime
778 return mContext.getResources().getBoolean(
779 com.android.internal.R.bool.config_wifi_dual_band_support);
780 }
781
782 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 * Return the DHCP-assigned addresses from the last successful DHCP request,
784 * if any.
785 * @return the DHCP information
786 */
787 public DhcpInfo getDhcpInfo() {
788 enforceAccessPermission();
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700789 return mWifiStateMachine.syncGetDhcpInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 }
791
Irfan Sheriff0d255342010-07-28 09:35:20 -0700792 /**
793 * see {@link android.net.wifi.WifiManager#startWifi}
794 *
795 */
796 public void startWifi() {
797 enforceChangePermission();
798 /* TODO: may be add permissions for access only to connectivity service
799 * TODO: if a start issued, keep wifi alive until a stop issued irrespective
800 * of WifiLock & device idle status unless wifi enabled status is toggled
801 */
802
803 mWifiStateMachine.setDriverStart(true);
804 mWifiStateMachine.reconnectCommand();
805 }
806
807 /**
808 * see {@link android.net.wifi.WifiManager#stopWifi}
809 *
810 */
811 public void stopWifi() {
812 enforceChangePermission();
813 /* TODO: may be add permissions for access only to connectivity service
814 * TODO: if a stop is issued, wifi is brought up only by startWifi
815 * unless wifi enabled status is toggled
816 */
817 mWifiStateMachine.setDriverStart(false);
818 }
819
820
821 /**
822 * see {@link android.net.wifi.WifiManager#addToBlacklist}
823 *
824 */
825 public void addToBlacklist(String bssid) {
826 enforceChangePermission();
827
828 mWifiStateMachine.addToBlacklist(bssid);
829 }
830
831 /**
832 * see {@link android.net.wifi.WifiManager#clearBlacklist}
833 *
834 */
835 public void clearBlacklist() {
836 enforceChangePermission();
837
838 mWifiStateMachine.clearBlacklist();
839 }
840
Irfan Sheriffe04653c2010-08-09 09:09:59 -0700841 public void connectNetworkWithId(int networkId) {
842 enforceChangePermission();
843 mWifiStateMachine.connectNetwork(networkId);
844 }
845
846 public void connectNetworkWithConfig(WifiConfiguration config) {
847 enforceChangePermission();
848 mWifiStateMachine.connectNetwork(config);
849 }
850
851 public void saveNetwork(WifiConfiguration config) {
852 enforceChangePermission();
853 mWifiStateMachine.saveNetwork(config);
854 }
855
856 public void forgetNetwork(int netId) {
857 enforceChangePermission();
858 mWifiStateMachine.forgetNetwork(netId);
859 }
Irfan Sheriff0d255342010-07-28 09:35:20 -0700860
Irfan Sheriffe4c56c92011-01-12 16:33:58 -0800861 public WpsResult startWps(WpsConfiguration config) {
Irfan Sherifff235c5a2010-10-21 16:44:48 -0700862 enforceChangePermission();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800863 if (mWifiStateMachineChannel != null) {
864 return mWifiStateMachine.startWps(mWifiStateMachineChannel, config);
Irfan Sherifff235c5a2010-10-21 16:44:48 -0700865 } else {
Irfan Sheriff227bec42011-02-15 19:30:27 -0800866 Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
Irfan Sheriffe4c56c92011-01-12 16:33:58 -0800867 return new WpsResult(WpsResult.Status.FAILURE);
Irfan Sherifff235c5a2010-10-21 16:44:48 -0700868 }
Irfan Sheriff5ee89802010-09-16 17:53:34 -0700869 }
870
Irfan Sheriff227bec42011-02-15 19:30:27 -0800871 /**
872 * Get a reference to handler. This is used by a client to establish
873 * an AsyncChannel communication with WifiService
874 */
875 public Messenger getMessenger() {
876 enforceAccessPermission();
877 return new Messenger(mAsyncServiceHandler);
878 }
879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
881 @Override
882 public void onReceive(Context context, Intent intent) {
883 String action = intent.getAction();
884
Doug Zongker43866e02010-01-07 12:09:54 -0800885 long idleMillis =
886 Settings.Secure.getLong(mContext.getContentResolver(),
Irfan Sheriff4f5f7c92010-10-14 17:01:27 -0700887 Settings.Secure.WIFI_IDLE_MS, DEFAULT_IDLE_MS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 int stayAwakeConditions =
Doug Zongker43866e02010-01-07 12:09:54 -0800889 Settings.System.getInt(mContext.getContentResolver(),
890 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 if (action.equals(Intent.ACTION_SCREEN_ON)) {
Joe Onorato431bb222010-10-18 19:13:23 -0400892 if (DBG) {
893 Slog.d(TAG, "ACTION_SCREEN_ON");
894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 mAlarmManager.cancel(mIdleIntent);
896 mDeviceIdle = false;
897 mScreenOff = false;
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700898 // Once the screen is on, we are not keeping WIFI running
899 // because of any locks so clear that tracking immediately.
900 reportStartWorkSource();
Irfan Sheriff227bec42011-02-15 19:30:27 -0800901 evaluateTrafficStatsPolling();
Irfan Sheriff0d255342010-07-28 09:35:20 -0700902 mWifiStateMachine.enableRssiPolling(true);
Irfan Sheriff8e86b892010-12-22 11:02:20 -0800903 mWifiStateMachine.enableAllNetworks();
Irfan Sheriff4f5f7c92010-10-14 17:01:27 -0700904 updateWifiState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
Joe Onorato431bb222010-10-18 19:13:23 -0400906 if (DBG) {
907 Slog.d(TAG, "ACTION_SCREEN_OFF");
908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 mScreenOff = true;
Irfan Sheriff227bec42011-02-15 19:30:27 -0800910 evaluateTrafficStatsPolling();
Irfan Sheriff0d255342010-07-28 09:35:20 -0700911 mWifiStateMachine.enableRssiPolling(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 /*
913 * Set a timer to put Wi-Fi to sleep, but only if the screen is off
914 * AND the "stay on while plugged in" setting doesn't match the
915 * current power conditions (i.e, not plugged in, plugged in to USB,
916 * or plugged in to AC).
917 */
918 if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) {
Irfan Sheriffd8134ff2010-08-22 17:06:34 -0700919 WifiInfo info = mWifiStateMachine.syncRequestConnectionInfo();
San Mehatfa6c7112009-07-07 09:34:44 -0700920 if (info.getSupplicantState() != SupplicantState.COMPLETED) {
Robert Greenwalt84612ea62009-09-30 09:04:22 -0700921 // we used to go to sleep immediately, but this caused some race conditions
Irfan Sheriffa2a1b912010-06-07 09:03:04 -0700922 // we don't have time to track down for this release. Delay instead,
923 // but not as long as we would if connected (below)
Robert Greenwalt84612ea62009-09-30 09:04:22 -0700924 // TODO - fix the race conditions and switch back to the immediate turn-off
925 long triggerTime = System.currentTimeMillis() + (2*60*1000); // 2 min
Joe Onorato431bb222010-10-18 19:13:23 -0400926 if (DBG) {
927 Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for 120,000 ms");
928 }
Robert Greenwalt84612ea62009-09-30 09:04:22 -0700929 mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
930 // // do not keep Wifi awake when screen is off if Wifi is not associated
931 // mDeviceIdle = true;
932 // updateWifiState();
Mike Lockwoodd9c32bc2009-05-18 14:14:15 -0400933 } else {
934 long triggerTime = System.currentTimeMillis() + idleMillis;
Joe Onorato431bb222010-10-18 19:13:23 -0400935 if (DBG) {
936 Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis
937 + "ms");
938 }
Mike Lockwoodd9c32bc2009-05-18 14:14:15 -0400939 mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 } else if (action.equals(ACTION_DEVICE_IDLE)) {
Joe Onorato431bb222010-10-18 19:13:23 -0400943 if (DBG) {
944 Slog.d(TAG, "got ACTION_DEVICE_IDLE");
945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 mDeviceIdle = true;
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700947 reportStartWorkSource();
Irfan Sheriff4f5f7c92010-10-14 17:01:27 -0700948 updateWifiState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
950 /*
951 * Set a timer to put Wi-Fi to sleep, but only if the screen is off
952 * AND we are transitioning from a state in which the device was supposed
953 * to stay awake to a state in which it is not supposed to stay awake.
954 * If "stay awake" state is not changing, we do nothing, to avoid resetting
955 * the already-set timer.
956 */
957 int pluggedType = intent.getIntExtra("plugged", 0);
Joe Onorato431bb222010-10-18 19:13:23 -0400958 if (DBG) {
959 Slog.d(TAG, "ACTION_BATTERY_CHANGED pluggedType: " + pluggedType);
960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) &&
962 !shouldWifiStayAwake(stayAwakeConditions, pluggedType)) {
963 long triggerTime = System.currentTimeMillis() + idleMillis;
Joe Onorato431bb222010-10-18 19:13:23 -0400964 if (DBG) {
965 Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms");
966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 }
969 mPluggedType = pluggedType;
Irfan Sheriff65eaec82011-01-05 22:00:16 -0800970 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
971 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
972 BluetoothAdapter.STATE_DISCONNECTED);
973 mWifiStateMachine.sendBluetoothAdapterStateChange(state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 }
976
977 /**
978 * Determines whether the Wi-Fi chipset should stay awake or be put to
979 * sleep. Looks at the setting for the sleep policy and the current
980 * conditions.
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800981 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 * @see #shouldDeviceStayAwake(int, int)
983 */
984 private boolean shouldWifiStayAwake(int stayAwakeConditions, int pluggedType) {
Irfan Sheriff739f6bc2011-01-28 16:43:12 -0800985 //Never sleep as long as the user has not changed the settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 int wifiSleepPolicy = Settings.System.getInt(mContext.getContentResolver(),
Irfan Sheriff96b10d62011-01-11 15:40:35 -0800987 Settings.System.WIFI_SLEEP_POLICY,
Irfan Sheriff739f6bc2011-01-28 16:43:12 -0800988 Settings.System.WIFI_SLEEP_POLICY_NEVER);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989
990 if (wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER) {
991 // Never sleep
992 return true;
993 } else if ((wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED) &&
994 (pluggedType != 0)) {
995 // Never sleep while plugged, and we're plugged
996 return true;
997 } else {
998 // Default
999 return shouldDeviceStayAwake(stayAwakeConditions, pluggedType);
1000 }
1001 }
Jaikumar Ganesh084c6652009-12-07 10:58:18 -08001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 /**
1004 * Determine whether the bit value corresponding to {@code pluggedType} is set in
1005 * the bit string {@code stayAwakeConditions}. Because a {@code pluggedType} value
1006 * of {@code 0} isn't really a plugged type, but rather an indication that the
1007 * device isn't plugged in at all, there is no bit value corresponding to a
1008 * {@code pluggedType} value of {@code 0}. That is why we shift by
Ben Dodson4e8620f2010-08-25 10:55:47 -07001009 * {@code pluggedType - 1} instead of by {@code pluggedType}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 * @param stayAwakeConditions a bit string specifying which "plugged types" should
1011 * keep the device (and hence Wi-Fi) awake.
1012 * @param pluggedType the type of plug (USB, AC, or none) for which the check is
1013 * being made
1014 * @return {@code true} if {@code pluggedType} indicates that the device is
1015 * supposed to stay awake, {@code false} otherwise.
1016 */
1017 private boolean shouldDeviceStayAwake(int stayAwakeConditions, int pluggedType) {
1018 return (stayAwakeConditions & pluggedType) != 0;
1019 }
1020 };
1021
Dianne Hackborn03f3cb02010-09-17 23:12:26 -07001022 private synchronized void reportStartWorkSource() {
1023 mTmpWorkSource.clear();
1024 if (mDeviceIdle) {
1025 for (int i=0; i<mLocks.mList.size(); i++) {
1026 mTmpWorkSource.add(mLocks.mList.get(i).mWorkSource);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001027 }
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001028 }
Dianne Hackborn03f3cb02010-09-17 23:12:26 -07001029 mWifiStateMachine.updateBatteryWorkSource(mTmpWorkSource);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001030 }
Jaikumar Ganesh7440fc22010-09-27 17:04:14 -07001031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 private void updateWifiState() {
1033 boolean wifiEnabled = getPersistedWifiEnabled();
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001034 boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden.get();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 boolean lockHeld = mLocks.hasLocks();
Irfan Sheriff5876a422010-08-12 20:26:23 -07001036 int strongestLockMode = WifiManager.WIFI_MODE_FULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode;
1038 boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld;
Irfan Sheriff5876a422010-08-12 20:26:23 -07001039
1040 if (lockHeld) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 strongestLockMode = mLocks.getStrongestLockMode();
Irfan Sheriff5876a422010-08-12 20:26:23 -07001042 }
1043 /* If device is not idle, lockmode cannot be scan only */
1044 if (!mDeviceIdle && strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 strongestLockMode = WifiManager.WIFI_MODE_FULL;
1046 }
1047
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001048 /* Disable tethering when airplane mode is enabled */
1049 if (airplaneMode) {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001050 mWifiStateMachine.setWifiApEnabled(null, false);
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001051 }
Irfan Sheriffb2e6c012010-04-05 11:57:56 -07001052
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001053 if (wifiShouldBeEnabled) {
1054 if (wifiShouldBeStarted) {
Dianne Hackborn03f3cb02010-09-17 23:12:26 -07001055 reportStartWorkSource();
Irfan Sheriff0d255342010-07-28 09:35:20 -07001056 mWifiStateMachine.setWifiEnabled(true);
1057 mWifiStateMachine.setScanOnlyMode(
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001058 strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY);
Irfan Sheriff0d255342010-07-28 09:35:20 -07001059 mWifiStateMachine.setDriverStart(true);
Irfan Sheriff5876a422010-08-12 20:26:23 -07001060 mWifiStateMachine.setHighPerfModeEnabled(strongestLockMode
1061 == WifiManager.WIFI_MODE_FULL_HIGH_PERF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 } else {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001063 mWifiStateMachine.requestCmWakeLock();
1064 mWifiStateMachine.setDriverStart(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 }
Irfan Sheriffa2a1b912010-06-07 09:03:04 -07001066 } else {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001067 mWifiStateMachine.setWifiEnabled(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 }
1069 }
1070
1071 private void registerForBroadcasts() {
1072 IntentFilter intentFilter = new IntentFilter();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 intentFilter.addAction(Intent.ACTION_SCREEN_ON);
1074 intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
1075 intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
1076 intentFilter.addAction(ACTION_DEVICE_IDLE);
Irfan Sheriff65eaec82011-01-05 22:00:16 -08001077 intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 mContext.registerReceiver(mReceiver, intentFilter);
1079 }
Jaikumar Ganesh084c6652009-12-07 10:58:18 -08001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 private boolean isAirplaneSensitive() {
1082 String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(),
1083 Settings.System.AIRPLANE_MODE_RADIOS);
1084 return airplaneModeRadios == null
1085 || airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
1086 }
1087
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -07001088 private boolean isAirplaneToggleable() {
1089 String toggleableRadios = Settings.System.getString(mContext.getContentResolver(),
1090 Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
1091 return toggleableRadios != null
1092 && toggleableRadios.contains(Settings.System.RADIO_WIFI);
1093 }
1094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 /**
1096 * Returns true if Wi-Fi is sensitive to airplane mode, and airplane mode is
1097 * currently on.
1098 * @return {@code true} if airplane mode is on.
1099 */
1100 private boolean isAirplaneModeOn() {
1101 return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(),
1102 Settings.System.AIRPLANE_MODE_ON, 0) == 1;
1103 }
1104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 @Override
1106 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1107 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1108 != PackageManager.PERMISSION_GRANTED) {
1109 pw.println("Permission Denial: can't dump WifiService from from pid="
1110 + Binder.getCallingPid()
1111 + ", uid=" + Binder.getCallingUid());
1112 return;
1113 }
Irfan Sheriffd8134ff2010-08-22 17:06:34 -07001114 pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 pw.println("Stay-awake conditions: " +
1116 Settings.System.getInt(mContext.getContentResolver(),
1117 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0));
1118 pw.println();
1119
1120 pw.println("Internal state:");
Irfan Sheriff0d255342010-07-28 09:35:20 -07001121 pw.println(mWifiStateMachine);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 pw.println();
1123 pw.println("Latest scan results:");
Irfan Sheriffd8134ff2010-08-22 17:06:34 -07001124 List<ScanResult> scanResults = mWifiStateMachine.syncGetScanResultsList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 if (scanResults != null && scanResults.size() != 0) {
1126 pw.println(" BSSID Frequency RSSI Flags SSID");
1127 for (ScanResult r : scanResults) {
1128 pw.printf(" %17s %9d %5d %-16s %s%n",
1129 r.BSSID,
1130 r.frequency,
1131 r.level,
1132 r.capabilities,
1133 r.SSID == null ? "" : r.SSID);
1134 }
1135 }
1136 pw.println();
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001137 pw.println("Locks acquired: " + mFullLocksAcquired + " full, " +
Irfan Sheriff5876a422010-08-12 20:26:23 -07001138 mFullHighPerfLocksAcquired + " full high perf, " +
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001139 mScanLocksAcquired + " scan");
1140 pw.println("Locks released: " + mFullLocksReleased + " full, " +
Irfan Sheriff5876a422010-08-12 20:26:23 -07001141 mFullHighPerfLocksReleased + " full high perf, " +
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001142 mScanLocksReleased + " scan");
1143 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 pw.println("Locks held:");
1145 mLocks.dump(pw);
1146 }
1147
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001148 private class WifiLock extends DeathRecipient {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001149 WifiLock(int lockMode, String tag, IBinder binder, WorkSource ws) {
1150 super(lockMode, tag, binder, ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152
1153 public void binderDied() {
1154 synchronized (mLocks) {
1155 releaseWifiLockLocked(mBinder);
1156 }
1157 }
1158
1159 public String toString() {
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001160 return "WifiLock{" + mTag + " type=" + mMode + " binder=" + mBinder + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 }
1162 }
1163
1164 private class LockList {
1165 private List<WifiLock> mList;
1166
1167 private LockList() {
1168 mList = new ArrayList<WifiLock>();
1169 }
1170
1171 private synchronized boolean hasLocks() {
1172 return !mList.isEmpty();
1173 }
1174
1175 private synchronized int getStrongestLockMode() {
1176 if (mList.isEmpty()) {
1177 return WifiManager.WIFI_MODE_FULL;
1178 }
Irfan Sheriff5876a422010-08-12 20:26:23 -07001179
1180 if (mFullHighPerfLocksAcquired > mFullHighPerfLocksReleased) {
1181 return WifiManager.WIFI_MODE_FULL_HIGH_PERF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 }
Irfan Sheriff5876a422010-08-12 20:26:23 -07001183
1184 if (mFullLocksAcquired > mFullLocksReleased) {
1185 return WifiManager.WIFI_MODE_FULL;
1186 }
1187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 return WifiManager.WIFI_MODE_SCAN_ONLY;
1189 }
1190
1191 private void addLock(WifiLock lock) {
1192 if (findLockByBinder(lock.mBinder) < 0) {
1193 mList.add(lock);
1194 }
1195 }
1196
1197 private WifiLock removeLock(IBinder binder) {
1198 int index = findLockByBinder(binder);
1199 if (index >= 0) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07001200 WifiLock ret = mList.remove(index);
1201 ret.unlinkDeathRecipient();
1202 return ret;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 } else {
1204 return null;
1205 }
1206 }
1207
1208 private int findLockByBinder(IBinder binder) {
1209 int size = mList.size();
1210 for (int i = size - 1; i >= 0; i--)
1211 if (mList.get(i).mBinder == binder)
1212 return i;
1213 return -1;
1214 }
1215
1216 private void dump(PrintWriter pw) {
1217 for (WifiLock l : mList) {
1218 pw.print(" ");
1219 pw.println(l);
1220 }
1221 }
1222 }
1223
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001224 void enforceWakeSourcePermission(int uid, int pid) {
Dianne Hackborne746f032010-09-13 16:02:57 -07001225 if (uid == android.os.Process.myUid()) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001226 return;
1227 }
1228 mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
1229 pid, uid, null);
1230 }
1231
1232 public boolean acquireWifiLock(IBinder binder, int lockMode, String tag, WorkSource ws) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
Irfan Sheriff5876a422010-08-12 20:26:23 -07001234 if (lockMode != WifiManager.WIFI_MODE_FULL &&
1235 lockMode != WifiManager.WIFI_MODE_SCAN_ONLY &&
1236 lockMode != WifiManager.WIFI_MODE_FULL_HIGH_PERF) {
1237 Slog.e(TAG, "Illegal argument, lockMode= " + lockMode);
1238 if (DBG) throw new IllegalArgumentException("lockMode=" + lockMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 return false;
1240 }
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001241 if (ws != null && ws.size() == 0) {
1242 ws = null;
1243 }
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001244 if (ws != null) {
1245 enforceWakeSourcePermission(Binder.getCallingUid(), Binder.getCallingPid());
1246 }
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001247 if (ws == null) {
1248 ws = new WorkSource(Binder.getCallingUid());
1249 }
1250 WifiLock wifiLock = new WifiLock(lockMode, tag, binder, ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 synchronized (mLocks) {
1252 return acquireWifiLockLocked(wifiLock);
1253 }
1254 }
1255
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001256 private void noteAcquireWifiLock(WifiLock wifiLock) throws RemoteException {
1257 switch(wifiLock.mMode) {
1258 case WifiManager.WIFI_MODE_FULL:
Irfan Sheriff5876a422010-08-12 20:26:23 -07001259 case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001260 mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource);
1261 break;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001262 case WifiManager.WIFI_MODE_SCAN_ONLY:
1263 mBatteryStats.noteScanWifiLockAcquiredFromSource(wifiLock.mWorkSource);
1264 break;
1265 }
1266 }
1267
1268 private void noteReleaseWifiLock(WifiLock wifiLock) throws RemoteException {
1269 switch(wifiLock.mMode) {
1270 case WifiManager.WIFI_MODE_FULL:
Irfan Sheriff5876a422010-08-12 20:26:23 -07001271 case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001272 mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource);
1273 break;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001274 case WifiManager.WIFI_MODE_SCAN_ONLY:
1275 mBatteryStats.noteScanWifiLockReleasedFromSource(wifiLock.mWorkSource);
1276 break;
1277 }
1278 }
1279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 private boolean acquireWifiLockLocked(WifiLock wifiLock) {
Irfan Sheriffc89dd542010-09-28 08:40:54 -07001281 if (DBG) Slog.d(TAG, "acquireWifiLockLocked: " + wifiLock);
Robert Greenwaltf1acb2d2009-10-13 08:20:55 -07001282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 mLocks.addLock(wifiLock);
Robert Greenwaltf1acb2d2009-10-13 08:20:55 -07001284
The Android Open Source Project10592532009-03-18 17:39:46 -07001285 long ident = Binder.clearCallingIdentity();
1286 try {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001287 noteAcquireWifiLock(wifiLock);
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001288 switch(wifiLock.mMode) {
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001289 case WifiManager.WIFI_MODE_FULL:
1290 ++mFullLocksAcquired;
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001291 break;
Irfan Sheriff5876a422010-08-12 20:26:23 -07001292 case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
1293 ++mFullHighPerfLocksAcquired;
1294 break;
1295
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001296 case WifiManager.WIFI_MODE_SCAN_ONLY:
1297 ++mScanLocksAcquired;
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001298 break;
The Android Open Source Project10592532009-03-18 17:39:46 -07001299 }
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001300
1301 // Be aggressive about adding new locks into the accounted state...
1302 // we want to over-report rather than under-report.
1303 reportStartWorkSource();
1304
1305 updateWifiState();
1306 return true;
The Android Open Source Project10592532009-03-18 17:39:46 -07001307 } catch (RemoteException e) {
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001308 return false;
The Android Open Source Project10592532009-03-18 17:39:46 -07001309 } finally {
1310 Binder.restoreCallingIdentity(ident);
1311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 }
1313
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001314 public void updateWifiLockWorkSource(IBinder lock, WorkSource ws) {
1315 int uid = Binder.getCallingUid();
1316 int pid = Binder.getCallingPid();
1317 if (ws != null && ws.size() == 0) {
1318 ws = null;
1319 }
1320 if (ws != null) {
1321 enforceWakeSourcePermission(uid, pid);
1322 }
1323 long ident = Binder.clearCallingIdentity();
1324 try {
1325 synchronized (mLocks) {
1326 int index = mLocks.findLockByBinder(lock);
1327 if (index < 0) {
1328 throw new IllegalArgumentException("Wifi lock not active");
1329 }
1330 WifiLock wl = mLocks.mList.get(index);
1331 noteReleaseWifiLock(wl);
1332 wl.mWorkSource = ws != null ? new WorkSource(ws) : new WorkSource(uid);
1333 noteAcquireWifiLock(wl);
1334 }
1335 } catch (RemoteException e) {
1336 } finally {
1337 Binder.restoreCallingIdentity(ident);
1338 }
1339 }
1340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 public boolean releaseWifiLock(IBinder lock) {
1342 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
1343 synchronized (mLocks) {
1344 return releaseWifiLockLocked(lock);
1345 }
1346 }
1347
1348 private boolean releaseWifiLockLocked(IBinder lock) {
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001349 boolean hadLock;
Robert Greenwaltf1acb2d2009-10-13 08:20:55 -07001350
The Android Open Source Project10592532009-03-18 17:39:46 -07001351 WifiLock wifiLock = mLocks.removeLock(lock);
Robert Greenwaltf1acb2d2009-10-13 08:20:55 -07001352
Irfan Sheriffc89dd542010-09-28 08:40:54 -07001353 if (DBG) Slog.d(TAG, "releaseWifiLockLocked: " + wifiLock);
Robert Greenwaltf1acb2d2009-10-13 08:20:55 -07001354
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001355 hadLock = (wifiLock != null);
1356
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001357 long ident = Binder.clearCallingIdentity();
1358 try {
1359 if (hadLock) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001360 noteAcquireWifiLock(wifiLock);
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001361 switch(wifiLock.mMode) {
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001362 case WifiManager.WIFI_MODE_FULL:
1363 ++mFullLocksReleased;
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001364 break;
Irfan Sheriff5876a422010-08-12 20:26:23 -07001365 case WifiManager.WIFI_MODE_FULL_HIGH_PERF:
1366 ++mFullHighPerfLocksReleased;
1367 break;
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001368 case WifiManager.WIFI_MODE_SCAN_ONLY:
1369 ++mScanLocksReleased;
Eric Shienbrood5711fad2009-03-27 20:25:31 -07001370 break;
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001371 }
The Android Open Source Project10592532009-03-18 17:39:46 -07001372 }
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001373
1374 // TODO - should this only happen if you hadLock?
1375 updateWifiState();
1376
1377 } catch (RemoteException e) {
1378 } finally {
1379 Binder.restoreCallingIdentity(ident);
The Android Open Source Project10592532009-03-18 17:39:46 -07001380 }
Dianne Hackbornecfd7f72010-10-08 14:23:40 -07001381
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001382 return hadLock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 }
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001384
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001385 private abstract class DeathRecipient
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001386 implements IBinder.DeathRecipient {
1387 String mTag;
1388 int mMode;
1389 IBinder mBinder;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001390 WorkSource mWorkSource;
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001391
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001392 DeathRecipient(int mode, String tag, IBinder binder, WorkSource ws) {
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001393 super();
1394 mTag = tag;
1395 mMode = mode;
1396 mBinder = binder;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001397 mWorkSource = ws;
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001398 try {
1399 mBinder.linkToDeath(this, 0);
1400 } catch (RemoteException e) {
1401 binderDied();
1402 }
1403 }
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07001404
1405 void unlinkDeathRecipient() {
1406 mBinder.unlinkToDeath(this, 0);
1407 }
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001408 }
1409
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001410 private class Multicaster extends DeathRecipient {
1411 Multicaster(String tag, IBinder binder) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001412 super(Binder.getCallingUid(), tag, binder, null);
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001413 }
1414
1415 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001416 Slog.e(TAG, "Multicaster binderDied");
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001417 synchronized (mMulticasters) {
1418 int i = mMulticasters.indexOf(this);
1419 if (i != -1) {
1420 removeMulticasterLocked(i, mMode);
1421 }
1422 }
1423 }
1424
1425 public String toString() {
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001426 return "Multicaster{" + mTag + " binder=" + mBinder + "}";
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001427 }
1428
1429 public int getUid() {
1430 return mMode;
1431 }
1432 }
1433
Robert Greenwalte2d155a2009-10-21 14:58:34 -07001434 public void initializeMulticastFiltering() {
1435 enforceMulticastChangePermission();
Irfan Sheriffa8fbe1f2010-03-09 09:13:58 -08001436
Robert Greenwalte2d155a2009-10-21 14:58:34 -07001437 synchronized (mMulticasters) {
1438 // if anybody had requested filters be off, leave off
1439 if (mMulticasters.size() != 0) {
1440 return;
1441 } else {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001442 mWifiStateMachine.startPacketFiltering();
Robert Greenwalte2d155a2009-10-21 14:58:34 -07001443 }
1444 }
1445 }
1446
Robert Greenwaltfc1b15c2009-05-22 15:09:51 -07001447 public void acquireMulticastLock(IBinder binder, String tag) {
1448 enforceMulticastChangePermission();
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001449
1450 synchronized (mMulticasters) {
1451 mMulticastEnabled++;
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001452 mMulticasters.add(new Multicaster(tag, binder));
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001453 // Note that we could call stopPacketFiltering only when
1454 // our new size == 1 (first call), but this function won't
1455 // be called often and by making the stopPacket call each
1456 // time we're less fragile and self-healing.
Irfan Sheriff0d255342010-07-28 09:35:20 -07001457 mWifiStateMachine.stopPacketFiltering();
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001458 }
1459
1460 int uid = Binder.getCallingUid();
1461 Long ident = Binder.clearCallingIdentity();
1462 try {
1463 mBatteryStats.noteWifiMulticastEnabled(uid);
1464 } catch (RemoteException e) {
1465 } finally {
1466 Binder.restoreCallingIdentity(ident);
1467 }
1468 }
1469
Robert Greenwaltfc1b15c2009-05-22 15:09:51 -07001470 public void releaseMulticastLock() {
1471 enforceMulticastChangePermission();
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001472
1473 int uid = Binder.getCallingUid();
1474 synchronized (mMulticasters) {
1475 mMulticastDisabled++;
1476 int size = mMulticasters.size();
1477 for (int i = size - 1; i >= 0; i--) {
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001478 Multicaster m = mMulticasters.get(i);
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001479 if ((m != null) && (m.getUid() == uid)) {
1480 removeMulticasterLocked(i, uid);
1481 }
1482 }
1483 }
1484 }
1485
1486 private void removeMulticasterLocked(int i, int uid)
1487 {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07001488 Multicaster removed = mMulticasters.remove(i);
Irfan Sheriffa8fbe1f2010-03-09 09:13:58 -08001489
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07001490 if (removed != null) {
1491 removed.unlinkDeathRecipient();
1492 }
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001493 if (mMulticasters.size() == 0) {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001494 mWifiStateMachine.startPacketFiltering();
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001495 }
1496
1497 Long ident = Binder.clearCallingIdentity();
1498 try {
1499 mBatteryStats.noteWifiMulticastDisabled(uid);
1500 } catch (RemoteException e) {
1501 } finally {
1502 Binder.restoreCallingIdentity(ident);
1503 }
1504 }
1505
Robert Greenwalt58ff0212009-05-19 15:53:54 -07001506 public boolean isMulticastEnabled() {
Robert Greenwalt5347bd42009-05-13 15:10:16 -07001507 enforceAccessPermission();
1508
1509 synchronized (mMulticasters) {
1510 return (mMulticasters.size() > 0);
1511 }
1512 }
Irfan Sheriff0d255342010-07-28 09:35:20 -07001513
Irfan Sheriff227bec42011-02-15 19:30:27 -08001514 /**
1515 * Evaluate if traffic stats polling is needed based on
1516 * connection and screen on status
1517 */
1518 private void evaluateTrafficStatsPolling() {
1519 Message msg;
1520 if (mNetworkInfo.getDetailedState() == DetailedState.CONNECTED && !mScreenOff) {
1521 msg = Message.obtain(mAsyncServiceHandler, CMD_ENABLE_TRAFFIC_STATS_POLL, 1, 0);
1522 } else {
1523 msg = Message.obtain(mAsyncServiceHandler, CMD_ENABLE_TRAFFIC_STATS_POLL, 0, 0);
1524 }
1525 msg.sendToTarget();
1526 }
1527
1528 private void notifyOnDataActivity() {
1529 long sent, received;
1530 long preTxPkts = mTxPkts, preRxPkts = mRxPkts;
1531 int dataActivity = WifiManager.DATA_ACTIVITY_NONE;
1532
1533 mTxPkts = TrafficStats.getTxPackets(mInterfaceName);
1534 mRxPkts = TrafficStats.getRxPackets(mInterfaceName);
1535
1536 if (preTxPkts > 0 || preRxPkts > 0) {
1537 sent = mTxPkts - preTxPkts;
1538 received = mRxPkts - preRxPkts;
1539 if (sent > 0) {
1540 dataActivity |= WifiManager.DATA_ACTIVITY_OUT;
1541 }
1542 if (received > 0) {
1543 dataActivity |= WifiManager.DATA_ACTIVITY_IN;
1544 }
1545
1546 if (dataActivity != mDataActivity && !mScreenOff) {
1547 mDataActivity = dataActivity;
1548 for (AsyncChannel client : mClients) {
1549 client.sendMessage(WifiManager.DATA_ACTIVITY_NOTIFICATION, mDataActivity);
1550 }
1551 }
1552 }
1553 }
1554
1555
Irfan Sheriff0d255342010-07-28 09:35:20 -07001556 private void checkAndSetNotification() {
1557 // If we shouldn't place a notification on available networks, then
1558 // don't bother doing any of the following
1559 if (!mNotificationEnabled) return;
1560
1561 State state = mNetworkInfo.getState();
1562 if ((state == NetworkInfo.State.DISCONNECTED)
1563 || (state == NetworkInfo.State.UNKNOWN)) {
1564 // Look for an open network
Irfan Sheriffd8134ff2010-08-22 17:06:34 -07001565 List<ScanResult> scanResults = mWifiStateMachine.syncGetScanResultsList();
Irfan Sheriff0d255342010-07-28 09:35:20 -07001566 if (scanResults != null) {
1567 int numOpenNetworks = 0;
1568 for (int i = scanResults.size() - 1; i >= 0; i--) {
1569 ScanResult scanResult = scanResults.get(i);
1570
1571 if (TextUtils.isEmpty(scanResult.capabilities)) {
1572 numOpenNetworks++;
1573 }
1574 }
1575
1576 if (numOpenNetworks > 0) {
1577 if (++mNumScansSinceNetworkStateChange >= NUM_SCANS_BEFORE_ACTUALLY_SCANNING) {
1578 /*
1579 * We've scanned continuously at least
1580 * NUM_SCANS_BEFORE_NOTIFICATION times. The user
1581 * probably does not have a remembered network in range,
1582 * since otherwise supplicant would have tried to
1583 * associate and thus resetting this counter.
1584 */
1585 setNotificationVisible(true, numOpenNetworks, false, 0);
1586 }
1587 return;
1588 }
1589 }
1590 }
1591
1592 // No open networks in range, remove the notification
1593 setNotificationVisible(false, 0, false, 0);
1594 }
1595
1596 /**
1597 * Clears variables related to tracking whether a notification has been
1598 * shown recently and clears the current notification.
1599 */
1600 private void resetNotification() {
1601 mNotificationRepeatTime = 0;
1602 mNumScansSinceNetworkStateChange = 0;
1603 setNotificationVisible(false, 0, false, 0);
1604 }
1605
1606 /**
1607 * Display or don't display a notification that there are open Wi-Fi networks.
1608 * @param visible {@code true} if notification should be visible, {@code false} otherwise
1609 * @param numNetworks the number networks seen
1610 * @param force {@code true} to force notification to be shown/not-shown,
1611 * even if it is already shown/not-shown.
1612 * @param delay time in milliseconds after which the notification should be made
1613 * visible or invisible.
1614 */
1615 private void setNotificationVisible(boolean visible, int numNetworks, boolean force,
1616 int delay) {
1617
1618 // Since we use auto cancel on the notification, when the
1619 // mNetworksAvailableNotificationShown is true, the notification may
1620 // have actually been canceled. However, when it is false we know
1621 // for sure that it is not being shown (it will not be shown any other
1622 // place than here)
1623
1624 // If it should be hidden and it is already hidden, then noop
1625 if (!visible && !mNotificationShown && !force) {
1626 return;
1627 }
1628
1629 NotificationManager notificationManager = (NotificationManager) mContext
1630 .getSystemService(Context.NOTIFICATION_SERVICE);
1631
1632 Message message;
1633 if (visible) {
1634
1635 // Not enough time has passed to show the notification again
1636 if (System.currentTimeMillis() < mNotificationRepeatTime) {
1637 return;
1638 }
1639
1640 if (mNotification == null) {
Wink Savillec7a98342010-08-13 16:11:42 -07001641 // Cache the Notification object.
Irfan Sheriff0d255342010-07-28 09:35:20 -07001642 mNotification = new Notification();
1643 mNotification.when = 0;
1644 mNotification.icon = ICON_NETWORKS_AVAILABLE;
1645 mNotification.flags = Notification.FLAG_AUTO_CANCEL;
1646 mNotification.contentIntent = PendingIntent.getActivity(mContext, 0,
1647 new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK), 0);
1648 }
1649
1650 CharSequence title = mContext.getResources().getQuantityText(
1651 com.android.internal.R.plurals.wifi_available, numNetworks);
1652 CharSequence details = mContext.getResources().getQuantityText(
1653 com.android.internal.R.plurals.wifi_available_detailed, numNetworks);
1654 mNotification.tickerText = title;
1655 mNotification.setLatestEventInfo(mContext, title, details, mNotification.contentIntent);
1656
1657 mNotificationRepeatTime = System.currentTimeMillis() + NOTIFICATION_REPEAT_DELAY_MS;
1658
1659 notificationManager.notify(ICON_NETWORKS_AVAILABLE, mNotification);
Irfan Sheriff0d255342010-07-28 09:35:20 -07001660 } else {
Irfan Sheriff0d255342010-07-28 09:35:20 -07001661 notificationManager.cancel(ICON_NETWORKS_AVAILABLE);
Irfan Sheriff0d255342010-07-28 09:35:20 -07001662 }
1663
Irfan Sheriff0d255342010-07-28 09:35:20 -07001664 mNotificationShown = visible;
1665 }
1666
1667 private class NotificationEnabledSettingObserver extends ContentObserver {
1668
1669 public NotificationEnabledSettingObserver(Handler handler) {
1670 super(handler);
1671 }
1672
1673 public void register() {
1674 ContentResolver cr = mContext.getContentResolver();
1675 cr.registerContentObserver(Settings.Secure.getUriFor(
1676 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON), true, this);
1677 mNotificationEnabled = getValue();
1678 }
1679
1680 @Override
1681 public void onChange(boolean selfChange) {
1682 super.onChange(selfChange);
1683
1684 mNotificationEnabled = getValue();
1685 resetNotification();
1686 }
1687
1688 private boolean getValue() {
1689 return Settings.Secure.getInt(mContext.getContentResolver(),
1690 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1) == 1;
1691 }
1692 }
1693
1694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695}