| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.app.AlarmManager; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 20 | import android.app.Notification; |
| 21 | import android.app.NotificationManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.app.PendingIntent; |
| Jaikumar Ganesh | 7440fc2 | 2010-09-27 17:04:14 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothAdapter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
| 29 | import android.content.pm.PackageManager; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 30 | import android.database.ContentObserver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.net.wifi.IWifiManager; |
| 32 | import android.net.wifi.WifiInfo; |
| 33 | import android.net.wifi.WifiManager; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 34 | import android.net.wifi.WifiStateMachine; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.net.wifi.ScanResult; |
| 36 | import android.net.wifi.WifiConfiguration; |
| San Mehat | 0310f9a | 2009-07-07 10:49:47 -0700 | [diff] [blame] | 37 | import android.net.wifi.SupplicantState; |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 38 | import android.net.wifi.WifiConfiguration.KeyMgmt; |
| Irfan Sheriff | 02fb46a | 2010-12-08 11:27:37 -0800 | [diff] [blame] | 39 | import android.net.wifi.WpsConfiguration; |
| Irfan Sheriff | e4c56c9 | 2011-01-12 16:33:58 -0800 | [diff] [blame] | 40 | import android.net.wifi.WpsResult; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 41 | import android.net.ConnectivityManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.net.DhcpInfo; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 43 | import android.net.NetworkInfo; |
| 44 | import android.net.NetworkInfo.State; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Binder; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 46 | import android.os.Handler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.HandlerThread; |
| 48 | import android.os.IBinder; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 49 | import android.os.INetworkManagementService; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 50 | import android.os.Message; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
| Amith Yamasani | 47873e5 | 2009-07-02 12:05:32 -0700 | [diff] [blame] | 52 | import android.os.ServiceManager; |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 53 | import android.os.WorkSource; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 55 | import android.text.TextUtils; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 56 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | import java.util.ArrayList; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import java.util.List; |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 60 | import java.util.Set; |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 61 | import java.util.concurrent.atomic.AtomicBoolean; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import java.io.FileDescriptor; |
| 63 | import java.io.PrintWriter; |
| 64 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 65 | import com.android.internal.app.IBatteryStats; |
| Wink Saville | 4b7ba09 | 2010-10-20 15:37:41 -0700 | [diff] [blame] | 66 | import com.android.internal.util.AsyncChannel; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 67 | import com.android.server.am.BatteryStatsService; |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 68 | import com.android.internal.R; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 69 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | /** |
| 71 | * WifiService handles remote WiFi operation requests by implementing |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 72 | * the IWifiManager interface. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | * |
| 74 | * @hide |
| 75 | */ |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 76 | //TODO: Clean up multiple locks and implement WifiService |
| 77 | // as a SM to track soft AP/client/adhoc bring up based |
| 78 | // on device idle state, airplane mode and boot. |
| 79 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | public class WifiService extends IWifiManager.Stub { |
| 81 | private static final String TAG = "WifiService"; |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 82 | private static final boolean DBG = true; |
| 83 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 84 | private final WifiStateMachine mWifiStateMachine; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | |
| 86 | private Context mContext; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | |
| 88 | private AlarmManager mAlarmManager; |
| 89 | private PendingIntent mIdleIntent; |
| 90 | private static final int IDLE_REQUEST = 0; |
| 91 | private boolean mScreenOff; |
| 92 | private boolean mDeviceIdle; |
| 93 | private int mPluggedType; |
| 94 | |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 95 | // true if the user enabled Wifi while in airplane mode |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 96 | private AtomicBoolean mAirplaneModeOverwridden = new AtomicBoolean(false); |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 97 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | private final LockList mLocks = new LockList(); |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 99 | // some wifi lock statistics |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 100 | private int mFullHighPerfLocksAcquired; |
| 101 | private int mFullHighPerfLocksReleased; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 102 | private int mFullLocksAcquired; |
| 103 | private int mFullLocksReleased; |
| 104 | private int mScanLocksAcquired; |
| 105 | private int mScanLocksReleased; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 106 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 107 | private final List<Multicaster> mMulticasters = |
| 108 | new ArrayList<Multicaster>(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 109 | private int mMulticastEnabled; |
| 110 | private int mMulticastDisabled; |
| 111 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 112 | private final IBatteryStats mBatteryStats; |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | /** |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 115 | * See {@link Settings.Secure#WIFI_IDLE_MS}. This is the default value if a |
| 116 | * Settings.Secure value is not present. This timeout value is chosen as |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | * the approximate point at which the battery drain caused by Wi-Fi |
| 118 | * being enabled but not active exceeds the battery drain caused by |
| 119 | * re-establishing a connection to the mobile data network. |
| 120 | */ |
| Irfan Sheriff | 4f5f7c9 | 2010-10-14 17:01:27 -0700 | [diff] [blame] | 121 | private static final long DEFAULT_IDLE_MS = 15 * 60 * 1000; /* 15 minutes */ |
| 122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | private static final String ACTION_DEVICE_IDLE = |
| 124 | "com.android.server.WifiManager.action.DEVICE_IDLE"; |
| 125 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 126 | private boolean mIsReceiverRegistered = false; |
| 127 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 128 | |
| 129 | NetworkInfo mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, "WIFI", ""); |
| 130 | |
| 131 | // Variables relating to the 'available networks' notification |
| 132 | /** |
| 133 | * The icon to show in the 'available networks' notification. This will also |
| 134 | * be the ID of the Notification given to the NotificationManager. |
| 135 | */ |
| 136 | private static final int ICON_NETWORKS_AVAILABLE = |
| 137 | com.android.internal.R.drawable.stat_notify_wifi_in_range; |
| 138 | /** |
| 139 | * When a notification is shown, we wait this amount before possibly showing it again. |
| 140 | */ |
| 141 | private final long NOTIFICATION_REPEAT_DELAY_MS; |
| 142 | /** |
| 143 | * Whether the user has set the setting to show the 'available networks' notification. |
| 144 | */ |
| 145 | private boolean mNotificationEnabled; |
| 146 | /** |
| 147 | * Observes the user setting to keep {@link #mNotificationEnabled} in sync. |
| 148 | */ |
| 149 | private NotificationEnabledSettingObserver mNotificationEnabledSettingObserver; |
| 150 | /** |
| 151 | * The {@link System#currentTimeMillis()} must be at least this value for us |
| 152 | * to show the notification again. |
| 153 | */ |
| 154 | private long mNotificationRepeatTime; |
| 155 | /** |
| 156 | * The Notification object given to the NotificationManager. |
| 157 | */ |
| 158 | private Notification mNotification; |
| 159 | /** |
| 160 | * Whether the notification is being shown, as set by us. That is, if the |
| 161 | * user cancels the notification, we will not receive the callback so this |
| 162 | * will still be true. We only guarantee if this is false, then the |
| 163 | * notification is not showing. |
| 164 | */ |
| 165 | private boolean mNotificationShown; |
| 166 | /** |
| 167 | * The number of continuous scans that must occur before consider the |
| 168 | * supplicant in a scanning state. This allows supplicant to associate with |
| 169 | * remembered networks that are in the scan results. |
| 170 | */ |
| 171 | private static final int NUM_SCANS_BEFORE_ACTUALLY_SCANNING = 3; |
| 172 | /** |
| 173 | * The number of scans since the last network state change. When this |
| 174 | * exceeds {@link #NUM_SCANS_BEFORE_ACTUALLY_SCANNING}, we consider the |
| 175 | * supplicant to actually be scanning. When the network state changes to |
| 176 | * something other than scanning, we reset this to 0. |
| 177 | */ |
| 178 | private int mNumScansSinceNetworkStateChange; |
| Jaikumar Ganesh | 7440fc2 | 2010-09-27 17:04:14 -0700 | [diff] [blame] | 179 | |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 180 | /** |
| Wink Saville | 4b7ba09 | 2010-10-20 15:37:41 -0700 | [diff] [blame] | 181 | * Asynchronous channel to WifiStateMachine |
| 182 | */ |
| 183 | private AsyncChannel mChannel; |
| 184 | |
| 185 | /** |
| 186 | * TODO: Possibly change WifiService into an AsyncService. |
| 187 | */ |
| 188 | private class WifiServiceHandler extends Handler { |
| 189 | private AsyncChannel mWshChannel; |
| 190 | |
| 191 | WifiServiceHandler(android.os.Looper looper, Context context) { |
| 192 | super(looper); |
| 193 | mWshChannel = new AsyncChannel(); |
| Wink Saville | cfce303 | 2010-12-01 23:20:25 -0800 | [diff] [blame] | 194 | mWshChannel.connect(context, this, mWifiStateMachine.getHandler()); |
| Wink Saville | 4b7ba09 | 2010-10-20 15:37:41 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void handleMessage(Message msg) { |
| 199 | switch (msg.what) { |
| 200 | case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: { |
| 201 | if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { |
| 202 | mChannel = mWshChannel; |
| 203 | } else { |
| 204 | Slog.d(TAG, "WifiServicehandler.handleMessage could not connect error=" + |
| 205 | msg.arg1); |
| 206 | mChannel = null; |
| 207 | } |
| 208 | break; |
| 209 | } |
| 210 | default: { |
| 211 | Slog.d(TAG, "WifiServicehandler.handleMessage ignoring msg=" + msg); |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | WifiServiceHandler mHandler; |
| 218 | |
| 219 | /** |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 220 | * Temporary for computing UIDS that are responsible for starting WIFI. |
| 221 | * Protected by mWifiStateTracker lock. |
| 222 | */ |
| 223 | private final WorkSource mTmpWorkSource = new WorkSource(); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 224 | |
| 225 | WifiService(Context context) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | mContext = context; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 227 | mWifiStateMachine = new WifiStateMachine(mContext); |
| 228 | mWifiStateMachine.enableRssiPolling(true); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 229 | mBatteryStats = BatteryStatsService.getService(); |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); |
| 232 | Intent idleIntent = new Intent(ACTION_DEVICE_IDLE, null); |
| 233 | mIdleIntent = PendingIntent.getBroadcast(mContext, IDLE_REQUEST, idleIntent, 0); |
| 234 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 235 | HandlerThread wifiThread = new HandlerThread("WifiService"); |
| 236 | wifiThread.start(); |
| Wink Saville | 4b7ba09 | 2010-10-20 15:37:41 -0700 | [diff] [blame] | 237 | mHandler = new WifiServiceHandler(wifiThread.getLooper(), context); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | mContext.registerReceiver( |
| 240 | new BroadcastReceiver() { |
| 241 | @Override |
| 242 | public void onReceive(Context context, Intent intent) { |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 243 | // clear our flag indicating the user has overwridden airplane mode |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 244 | mAirplaneModeOverwridden.set(false); |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 245 | // on airplane disable, restore Wifi if the saved state indicates so |
| 246 | if (!isAirplaneModeOn() && testAndClearWifiSavedState()) { |
| 247 | persistWifiEnabled(true); |
| 248 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | updateWifiState(); |
| 250 | } |
| 251 | }, |
| 252 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); |
| 253 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 254 | IntentFilter filter = new IntentFilter(); |
| 255 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 256 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 257 | filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); |
| 258 | |
| 259 | mContext.registerReceiver( |
| 260 | new BroadcastReceiver() { |
| 261 | @Override |
| 262 | public void onReceive(Context context, Intent intent) { |
| 263 | if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
| 264 | // reset & clear notification on any wifi state change |
| 265 | resetNotification(); |
| 266 | } else if (intent.getAction().equals( |
| 267 | WifiManager.NETWORK_STATE_CHANGED_ACTION)) { |
| 268 | mNetworkInfo = (NetworkInfo) intent.getParcelableExtra( |
| 269 | WifiManager.EXTRA_NETWORK_INFO); |
| 270 | // reset & clear notification on a network connect & disconnect |
| 271 | switch(mNetworkInfo.getDetailedState()) { |
| 272 | case CONNECTED: |
| 273 | case DISCONNECTED: |
| 274 | resetNotification(); |
| 275 | break; |
| 276 | } |
| 277 | } else if (intent.getAction().equals( |
| 278 | WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { |
| 279 | checkAndSetNotification(); |
| 280 | } |
| 281 | } |
| 282 | }, filter); |
| 283 | |
| 284 | // Setting is in seconds |
| 285 | NOTIFICATION_REPEAT_DELAY_MS = Settings.Secure.getInt(context.getContentResolver(), |
| 286 | Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l; |
| 287 | mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler()); |
| 288 | mNotificationEnabledSettingObserver.register(); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 289 | } |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 290 | |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 291 | /** |
| 292 | * Check if Wi-Fi needs to be enabled and start |
| 293 | * if needed |
| Irfan Sheriff | 60e3ba0 | 2010-04-02 12:18:45 -0700 | [diff] [blame] | 294 | * |
| 295 | * This function is used only at boot time |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 296 | */ |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 297 | public void checkAndStartWifi() { |
| Irfan Sheriff | a3bd409 | 2010-03-24 17:58:59 -0700 | [diff] [blame] | 298 | /* Start if Wi-Fi is enabled or the saved state indicates Wi-Fi was on */ |
| Irfan Sheriff | 60e3ba0 | 2010-04-02 12:18:45 -0700 | [diff] [blame] | 299 | boolean wifiEnabled = !isAirplaneModeOn() |
| 300 | && (getPersistedWifiEnabled() || testAndClearWifiSavedState()); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 301 | Slog.i(TAG, "WifiService starting up with Wi-Fi " + |
| 302 | (wifiEnabled ? "enabled" : "disabled")); |
| Irfan Sheriff | b99fe5e | 2010-03-26 14:56:07 -0700 | [diff] [blame] | 303 | setWifiEnabled(wifiEnabled); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| Irfan Sheriff | a3bd409 | 2010-03-24 17:58:59 -0700 | [diff] [blame] | 306 | private boolean testAndClearWifiSavedState() { |
| 307 | final ContentResolver cr = mContext.getContentResolver(); |
| 308 | int wifiSavedState = 0; |
| 309 | try { |
| 310 | wifiSavedState = Settings.Secure.getInt(cr, Settings.Secure.WIFI_SAVED_STATE); |
| 311 | if(wifiSavedState == 1) |
| 312 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_SAVED_STATE, 0); |
| 313 | } catch (Settings.SettingNotFoundException e) { |
| 314 | ; |
| 315 | } |
| 316 | return (wifiSavedState == 1); |
| 317 | } |
| 318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | private boolean getPersistedWifiEnabled() { |
| 320 | final ContentResolver cr = mContext.getContentResolver(); |
| 321 | try { |
| 322 | return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON) == 1; |
| 323 | } catch (Settings.SettingNotFoundException e) { |
| 324 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, 0); |
| 325 | return false; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | private void persistWifiEnabled(boolean enabled) { |
| 330 | final ContentResolver cr = mContext.getContentResolver(); |
| 331 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, enabled ? 1 : 0); |
| 332 | } |
| 333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | /** |
| 335 | * see {@link android.net.wifi.WifiManager#pingSupplicant()} |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 336 | * @return {@code true} if the operation succeeds, {@code false} otherwise |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | */ |
| 338 | public boolean pingSupplicant() { |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 339 | enforceAccessPermission(); |
| Irfan Sheriff | 1406bcb | 2010-10-28 14:41:39 -0700 | [diff] [blame] | 340 | if (mChannel != null) { |
| 341 | return mWifiStateMachine.syncPingSupplicant(mChannel); |
| 342 | } else { |
| 343 | Slog.e(TAG, "mChannel is not initialized"); |
| 344 | return false; |
| 345 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /** |
| 349 | * see {@link android.net.wifi.WifiManager#startScan()} |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | */ |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 351 | public void startScan(boolean forceActive) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | enforceChangePermission(); |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 353 | mWifiStateMachine.startScan(forceActive); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | private void enforceAccessPermission() { |
| 357 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE, |
| 358 | "WifiService"); |
| 359 | } |
| 360 | |
| 361 | private void enforceChangePermission() { |
| 362 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE, |
| 363 | "WifiService"); |
| 364 | |
| 365 | } |
| 366 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 367 | private void enforceMulticastChangePermission() { |
| 368 | mContext.enforceCallingOrSelfPermission( |
| 369 | android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, |
| 370 | "WifiService"); |
| 371 | } |
| 372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | /** |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 374 | * see {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} |
| 375 | * @param enable {@code true} to enable, {@code false} to disable. |
| 376 | * @return {@code true} if the enable/disable operation was |
| 377 | * started or is already in the queue. |
| 378 | */ |
| 379 | public synchronized boolean setWifiEnabled(boolean enable) { |
| 380 | enforceChangePermission(); |
| 381 | |
| 382 | if (DBG) { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 383 | Slog.e(TAG, "Invoking mWifiStateMachine.setWifiEnabled\n"); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | // set a flag if the user is enabling Wifi while in airplane mode |
| 387 | if (enable && isAirplaneModeOn() && isAirplaneToggleable()) { |
| 388 | mAirplaneModeOverwridden.set(true); |
| 389 | } |
| 390 | |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 391 | if (enable) { |
| 392 | reportStartWorkSource(); |
| 393 | } |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 394 | mWifiStateMachine.setWifiEnabled(enable); |
| Irfan Sheriff | 6118069 | 2010-08-18 16:07:39 -0700 | [diff] [blame] | 395 | |
| 396 | /* |
| 397 | * Caller might not have WRITE_SECURE_SETTINGS, |
| 398 | * only CHANGE_WIFI_STATE is enforced |
| 399 | */ |
| 400 | long ident = Binder.clearCallingIdentity(); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 401 | persistWifiEnabled(enable); |
| Irfan Sheriff | 6118069 | 2010-08-18 16:07:39 -0700 | [diff] [blame] | 402 | Binder.restoreCallingIdentity(ident); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 403 | |
| 404 | if (enable) { |
| 405 | if (!mIsReceiverRegistered) { |
| 406 | registerForBroadcasts(); |
| 407 | mIsReceiverRegistered = true; |
| 408 | } |
| 409 | } else if (mIsReceiverRegistered){ |
| 410 | mContext.unregisterReceiver(mReceiver); |
| 411 | mIsReceiverRegistered = false; |
| 412 | } |
| 413 | |
| 414 | return true; |
| 415 | } |
| 416 | |
| 417 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | * see {@link WifiManager#getWifiState()} |
| 419 | * @return One of {@link WifiManager#WIFI_STATE_DISABLED}, |
| 420 | * {@link WifiManager#WIFI_STATE_DISABLING}, |
| 421 | * {@link WifiManager#WIFI_STATE_ENABLED}, |
| 422 | * {@link WifiManager#WIFI_STATE_ENABLING}, |
| 423 | * {@link WifiManager#WIFI_STATE_UNKNOWN} |
| 424 | */ |
| 425 | public int getWifiEnabledState() { |
| 426 | enforceAccessPermission(); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 427 | return mWifiStateMachine.syncGetWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 431 | * see {@link android.net.wifi.WifiManager#setWifiApEnabled(WifiConfiguration, boolean)} |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 432 | * @param wifiConfig SSID, security and channel details as |
| 433 | * part of WifiConfiguration |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 434 | * @param enabled true to enable and false to disable |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 435 | * @return {@code true} if the start operation was |
| 436 | * started or is already in the queue. |
| 437 | */ |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 438 | public synchronized boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 439 | enforceChangePermission(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 440 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 441 | if (enabled) { |
| 442 | /* Use default config if there is no existing config */ |
| 443 | if (wifiConfig == null && ((wifiConfig = getWifiApConfiguration()) == null)) { |
| 444 | wifiConfig = new WifiConfiguration(); |
| 445 | wifiConfig.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default); |
| 446 | wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE); |
| 447 | } |
| Irfan Sheriff | 6118069 | 2010-08-18 16:07:39 -0700 | [diff] [blame] | 448 | /* |
| 449 | * Caller might not have WRITE_SECURE_SETTINGS, |
| 450 | * only CHANGE_WIFI_STATE is enforced |
| 451 | */ |
| 452 | long ident = Binder.clearCallingIdentity(); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 453 | setWifiApConfiguration(wifiConfig); |
| Irfan Sheriff | 6118069 | 2010-08-18 16:07:39 -0700 | [diff] [blame] | 454 | Binder.restoreCallingIdentity(ident); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 457 | mWifiStateMachine.setWifiApEnabled(wifiConfig, enabled); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 458 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 462 | /** |
| 463 | * see {@link WifiManager#getWifiApState()} |
| 464 | * @return One of {@link WifiManager#WIFI_AP_STATE_DISABLED}, |
| 465 | * {@link WifiManager#WIFI_AP_STATE_DISABLING}, |
| 466 | * {@link WifiManager#WIFI_AP_STATE_ENABLED}, |
| 467 | * {@link WifiManager#WIFI_AP_STATE_ENABLING}, |
| 468 | * {@link WifiManager#WIFI_AP_STATE_FAILED} |
| 469 | */ |
| 470 | public int getWifiApEnabledState() { |
| Irfan Sheriff | 17b232b | 2010-06-24 11:32:26 -0700 | [diff] [blame] | 471 | enforceAccessPermission(); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 472 | return mWifiStateMachine.syncGetWifiApState(); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
| 476 | * see {@link WifiManager#getWifiApConfiguration()} |
| 477 | * @return soft access point configuration |
| 478 | */ |
| 479 | public synchronized WifiConfiguration getWifiApConfiguration() { |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 480 | final ContentResolver cr = mContext.getContentResolver(); |
| 481 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 482 | int authType; |
| 483 | try { |
| 484 | wifiConfig.SSID = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_SSID); |
| 485 | if (wifiConfig.SSID == null) |
| 486 | return null; |
| 487 | authType = Settings.Secure.getInt(cr, Settings.Secure.WIFI_AP_SECURITY); |
| 488 | wifiConfig.allowedKeyManagement.set(authType); |
| 489 | wifiConfig.preSharedKey = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_PASSWD); |
| 490 | return wifiConfig; |
| 491 | } catch (Settings.SettingNotFoundException e) { |
| 492 | Slog.e(TAG,"AP settings not found, returning"); |
| 493 | return null; |
| 494 | } |
| 495 | } |
| 496 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 497 | /** |
| 498 | * see {@link WifiManager#setWifiApConfiguration(WifiConfiguration)} |
| 499 | * @param wifiConfig WifiConfiguration details for soft access point |
| 500 | */ |
| 501 | public synchronized void setWifiApConfiguration(WifiConfiguration wifiConfig) { |
| Irfan Sheriff | 17b232b | 2010-06-24 11:32:26 -0700 | [diff] [blame] | 502 | enforceChangePermission(); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 503 | final ContentResolver cr = mContext.getContentResolver(); |
| 504 | boolean isWpa; |
| 505 | if (wifiConfig == null) |
| 506 | return; |
| 507 | Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_SSID, wifiConfig.SSID); |
| 508 | isWpa = wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK); |
| 509 | Settings.Secure.putInt(cr, |
| 510 | Settings.Secure.WIFI_AP_SECURITY, |
| 511 | isWpa ? KeyMgmt.WPA_PSK : KeyMgmt.NONE); |
| 512 | if (isWpa) |
| 513 | Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_PASSWD, wifiConfig.preSharedKey); |
| 514 | } |
| 515 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 516 | /** |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 517 | * see {@link android.net.wifi.WifiManager#disconnect()} |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 518 | */ |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 519 | public void disconnect() { |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 520 | enforceChangePermission(); |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 521 | mWifiStateMachine.disconnectCommand(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | /** |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 525 | * see {@link android.net.wifi.WifiManager#reconnect()} |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 526 | */ |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 527 | public void reconnect() { |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 528 | enforceChangePermission(); |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 529 | mWifiStateMachine.reconnectCommand(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 532 | /** |
| 533 | * see {@link android.net.wifi.WifiManager#reassociate()} |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 534 | */ |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 535 | public void reassociate() { |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 536 | enforceChangePermission(); |
| Irfan Sheriff | e498475 | 2010-08-19 11:29:22 -0700 | [diff] [blame] | 537 | mWifiStateMachine.reassociateCommand(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | /** |
| 541 | * see {@link android.net.wifi.WifiManager#getConfiguredNetworks()} |
| 542 | * @return the list of configured networks |
| 543 | */ |
| 544 | public List<WifiConfiguration> getConfiguredNetworks() { |
| 545 | enforceAccessPermission(); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 546 | return mWifiStateMachine.syncGetConfiguredNetworks(); |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 547 | } |
| 548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | /** |
| 550 | * see {@link android.net.wifi.WifiManager#addOrUpdateNetwork(WifiConfiguration)} |
| 551 | * @return the supplicant-assigned identifier for the new or updated |
| 552 | * network if the operation succeeds, or {@code -1} if it fails |
| 553 | */ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 554 | public int addOrUpdateNetwork(WifiConfiguration config) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | enforceChangePermission(); |
| Irfan Sheriff | 1406bcb | 2010-10-28 14:41:39 -0700 | [diff] [blame] | 556 | if (mChannel != null) { |
| 557 | return mWifiStateMachine.syncAddOrUpdateNetwork(mChannel, config); |
| 558 | } else { |
| 559 | Slog.e(TAG, "mChannel is not initialized"); |
| 560 | return -1; |
| 561 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 564 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | * See {@link android.net.wifi.WifiManager#removeNetwork(int)} |
| 566 | * @param netId the integer that identifies the network configuration |
| 567 | * to the supplicant |
| 568 | * @return {@code true} if the operation succeeded |
| 569 | */ |
| 570 | public boolean removeNetwork(int netId) { |
| 571 | enforceChangePermission(); |
| Wink Saville | 4b7ba09 | 2010-10-20 15:37:41 -0700 | [diff] [blame] | 572 | if (mChannel != null) { |
| 573 | return mWifiStateMachine.syncRemoveNetwork(mChannel, netId); |
| 574 | } else { |
| 575 | Slog.e(TAG, "mChannel is not initialized"); |
| 576 | return false; |
| 577 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /** |
| 581 | * See {@link android.net.wifi.WifiManager#enableNetwork(int, boolean)} |
| 582 | * @param netId the integer that identifies the network configuration |
| 583 | * to the supplicant |
| 584 | * @param disableOthers if true, disable all other networks. |
| 585 | * @return {@code true} if the operation succeeded |
| 586 | */ |
| 587 | public boolean enableNetwork(int netId, boolean disableOthers) { |
| 588 | enforceChangePermission(); |
| Irfan Sheriff | 1406bcb | 2010-10-28 14:41:39 -0700 | [diff] [blame] | 589 | if (mChannel != null) { |
| 590 | return mWifiStateMachine.syncEnableNetwork(mChannel, netId, disableOthers); |
| 591 | } else { |
| 592 | Slog.e(TAG, "mChannel is not initialized"); |
| 593 | return false; |
| 594 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
| 598 | * See {@link android.net.wifi.WifiManager#disableNetwork(int)} |
| 599 | * @param netId the integer that identifies the network configuration |
| 600 | * to the supplicant |
| 601 | * @return {@code true} if the operation succeeded |
| 602 | */ |
| 603 | public boolean disableNetwork(int netId) { |
| 604 | enforceChangePermission(); |
| Irfan Sheriff | 1406bcb | 2010-10-28 14:41:39 -0700 | [diff] [blame] | 605 | if (mChannel != null) { |
| 606 | return mWifiStateMachine.syncDisableNetwork(mChannel, netId); |
| 607 | } else { |
| 608 | Slog.e(TAG, "mChannel is not initialized"); |
| 609 | return false; |
| 610 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
| 614 | * See {@link android.net.wifi.WifiManager#getConnectionInfo()} |
| 615 | * @return the Wi-Fi information, contained in {@link WifiInfo}. |
| 616 | */ |
| 617 | public WifiInfo getConnectionInfo() { |
| 618 | enforceAccessPermission(); |
| 619 | /* |
| 620 | * Make sure we have the latest information, by sending |
| 621 | * a status request to the supplicant. |
| 622 | */ |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 623 | return mWifiStateMachine.syncRequestConnectionInfo(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Return the results of the most recent access point scan, in the form of |
| 628 | * a list of {@link ScanResult} objects. |
| 629 | * @return the list of results |
| 630 | */ |
| 631 | public List<ScanResult> getScanResults() { |
| 632 | enforceAccessPermission(); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 633 | return mWifiStateMachine.syncGetScanResultsList(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Tell the supplicant to persist the current list of configured networks. |
| 638 | * @return {@code true} if the operation succeeded |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 639 | * |
| 640 | * TODO: deprecate this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | */ |
| 642 | public boolean saveConfiguration() { |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 643 | boolean result = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | enforceChangePermission(); |
| Irfan Sheriff | 1406bcb | 2010-10-28 14:41:39 -0700 | [diff] [blame] | 645 | if (mChannel != null) { |
| 646 | return mWifiStateMachine.syncSaveConfig(mChannel); |
| 647 | } else { |
| 648 | Slog.e(TAG, "mChannel is not initialized"); |
| 649 | return false; |
| 650 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
| Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 654 | * Set the country code |
| 655 | * @param countryCode ISO 3166 country code. |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 656 | * @param persist {@code true} if the setting should be remembered. |
| Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 657 | * |
| 658 | * The persist behavior exists so that wifi can fall back to the last |
| 659 | * persisted country code on a restart, when the locale information is |
| 660 | * not available from telephony. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | */ |
| Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 662 | public void setCountryCode(String countryCode, boolean persist) { |
| 663 | Slog.i(TAG, "WifiService trying to set country code to " + countryCode + |
| 664 | " with persist set to " + persist); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | enforceChangePermission(); |
| Irfan Sheriff | ed4f28b | 2010-10-29 15:32:10 -0700 | [diff] [blame] | 666 | mWifiStateMachine.setCountryCode(countryCode, persist); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** |
| Irfan Sheriff | 36f7413 | 2010-11-04 16:57:37 -0700 | [diff] [blame] | 670 | * Set the operational frequency band |
| 671 | * @param band One of |
| 672 | * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO}, |
| 673 | * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ}, |
| 674 | * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ}, |
| 675 | * @param persist {@code true} if the setting should be remembered. |
| 676 | * |
| 677 | */ |
| 678 | public void setFrequencyBand(int band, boolean persist) { |
| 679 | enforceChangePermission(); |
| 680 | if (!isDualBandSupported()) return; |
| 681 | Slog.i(TAG, "WifiService trying to set frequency band to " + band + |
| 682 | " with persist set to " + persist); |
| 683 | mWifiStateMachine.setFrequencyBand(band, persist); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | /** |
| 688 | * Get the operational frequency band |
| 689 | */ |
| 690 | public int getFrequencyBand() { |
| 691 | enforceAccessPermission(); |
| 692 | return mWifiStateMachine.getFrequencyBand(); |
| 693 | } |
| 694 | |
| 695 | public boolean isDualBandSupported() { |
| 696 | //TODO: Should move towards adding a driver API that checks at runtime |
| 697 | return mContext.getResources().getBoolean( |
| 698 | com.android.internal.R.bool.config_wifi_dual_band_support); |
| 699 | } |
| 700 | |
| 701 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | * Return the DHCP-assigned addresses from the last successful DHCP request, |
| 703 | * if any. |
| 704 | * @return the DHCP information |
| 705 | */ |
| 706 | public DhcpInfo getDhcpInfo() { |
| 707 | enforceAccessPermission(); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 708 | return mWifiStateMachine.syncGetDhcpInfo(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 711 | /** |
| 712 | * see {@link android.net.wifi.WifiManager#startWifi} |
| 713 | * |
| 714 | */ |
| 715 | public void startWifi() { |
| 716 | enforceChangePermission(); |
| 717 | /* TODO: may be add permissions for access only to connectivity service |
| 718 | * TODO: if a start issued, keep wifi alive until a stop issued irrespective |
| 719 | * of WifiLock & device idle status unless wifi enabled status is toggled |
| 720 | */ |
| 721 | |
| 722 | mWifiStateMachine.setDriverStart(true); |
| 723 | mWifiStateMachine.reconnectCommand(); |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * see {@link android.net.wifi.WifiManager#stopWifi} |
| 728 | * |
| 729 | */ |
| 730 | public void stopWifi() { |
| 731 | enforceChangePermission(); |
| 732 | /* TODO: may be add permissions for access only to connectivity service |
| 733 | * TODO: if a stop is issued, wifi is brought up only by startWifi |
| 734 | * unless wifi enabled status is toggled |
| 735 | */ |
| 736 | mWifiStateMachine.setDriverStart(false); |
| 737 | } |
| 738 | |
| 739 | |
| 740 | /** |
| 741 | * see {@link android.net.wifi.WifiManager#addToBlacklist} |
| 742 | * |
| 743 | */ |
| 744 | public void addToBlacklist(String bssid) { |
| 745 | enforceChangePermission(); |
| 746 | |
| 747 | mWifiStateMachine.addToBlacklist(bssid); |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * see {@link android.net.wifi.WifiManager#clearBlacklist} |
| 752 | * |
| 753 | */ |
| 754 | public void clearBlacklist() { |
| 755 | enforceChangePermission(); |
| 756 | |
| 757 | mWifiStateMachine.clearBlacklist(); |
| 758 | } |
| 759 | |
| Irfan Sheriff | e04653c | 2010-08-09 09:09:59 -0700 | [diff] [blame] | 760 | public void connectNetworkWithId(int networkId) { |
| 761 | enforceChangePermission(); |
| 762 | mWifiStateMachine.connectNetwork(networkId); |
| 763 | } |
| 764 | |
| 765 | public void connectNetworkWithConfig(WifiConfiguration config) { |
| 766 | enforceChangePermission(); |
| 767 | mWifiStateMachine.connectNetwork(config); |
| 768 | } |
| 769 | |
| 770 | public void saveNetwork(WifiConfiguration config) { |
| 771 | enforceChangePermission(); |
| 772 | mWifiStateMachine.saveNetwork(config); |
| 773 | } |
| 774 | |
| 775 | public void forgetNetwork(int netId) { |
| 776 | enforceChangePermission(); |
| 777 | mWifiStateMachine.forgetNetwork(netId); |
| 778 | } |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 779 | |
| Irfan Sheriff | e4c56c9 | 2011-01-12 16:33:58 -0800 | [diff] [blame] | 780 | public WpsResult startWps(WpsConfiguration config) { |
| Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 781 | enforceChangePermission(); |
| 782 | if (mChannel != null) { |
| Irfan Sheriff | 02fb46a | 2010-12-08 11:27:37 -0800 | [diff] [blame] | 783 | return mWifiStateMachine.startWps(mChannel, config); |
| Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 784 | } else { |
| 785 | Slog.e(TAG, "mChannel is not initialized"); |
| Irfan Sheriff | e4c56c9 | 2011-01-12 16:33:58 -0800 | [diff] [blame] | 786 | return new WpsResult(WpsResult.Status.FAILURE); |
| Irfan Sheriff | f235c5a | 2010-10-21 16:44:48 -0700 | [diff] [blame] | 787 | } |
| Irfan Sheriff | 5ee8980 | 2010-09-16 17:53:34 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 791 | @Override |
| 792 | public void onReceive(Context context, Intent intent) { |
| 793 | String action = intent.getAction(); |
| 794 | |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 795 | long idleMillis = |
| 796 | Settings.Secure.getLong(mContext.getContentResolver(), |
| Irfan Sheriff | 4f5f7c9 | 2010-10-14 17:01:27 -0700 | [diff] [blame] | 797 | Settings.Secure.WIFI_IDLE_MS, DEFAULT_IDLE_MS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | int stayAwakeConditions = |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 799 | Settings.System.getInt(mContext.getContentResolver(), |
| 800 | Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | if (action.equals(Intent.ACTION_SCREEN_ON)) { |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 802 | if (DBG) { |
| 803 | Slog.d(TAG, "ACTION_SCREEN_ON"); |
| 804 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | mAlarmManager.cancel(mIdleIntent); |
| 806 | mDeviceIdle = false; |
| 807 | mScreenOff = false; |
| Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 808 | // Once the screen is on, we are not keeping WIFI running |
| 809 | // because of any locks so clear that tracking immediately. |
| 810 | reportStartWorkSource(); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 811 | mWifiStateMachine.enableRssiPolling(true); |
| Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 812 | mWifiStateMachine.enableAllNetworks(); |
| Irfan Sheriff | 4f5f7c9 | 2010-10-14 17:01:27 -0700 | [diff] [blame] | 813 | updateWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 815 | if (DBG) { |
| 816 | Slog.d(TAG, "ACTION_SCREEN_OFF"); |
| 817 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | mScreenOff = true; |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 819 | mWifiStateMachine.enableRssiPolling(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | /* |
| 821 | * Set a timer to put Wi-Fi to sleep, but only if the screen is off |
| 822 | * AND the "stay on while plugged in" setting doesn't match the |
| 823 | * current power conditions (i.e, not plugged in, plugged in to USB, |
| 824 | * or plugged in to AC). |
| 825 | */ |
| 826 | if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) { |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 827 | WifiInfo info = mWifiStateMachine.syncRequestConnectionInfo(); |
| San Mehat | fa6c711 | 2009-07-07 09:34:44 -0700 | [diff] [blame] | 828 | if (info.getSupplicantState() != SupplicantState.COMPLETED) { |
| Robert Greenwalt | 84612ea6 | 2009-09-30 09:04:22 -0700 | [diff] [blame] | 829 | // we used to go to sleep immediately, but this caused some race conditions |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 830 | // we don't have time to track down for this release. Delay instead, |
| 831 | // but not as long as we would if connected (below) |
| Robert Greenwalt | 84612ea6 | 2009-09-30 09:04:22 -0700 | [diff] [blame] | 832 | // TODO - fix the race conditions and switch back to the immediate turn-off |
| 833 | long triggerTime = System.currentTimeMillis() + (2*60*1000); // 2 min |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 834 | if (DBG) { |
| 835 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for 120,000 ms"); |
| 836 | } |
| Robert Greenwalt | 84612ea6 | 2009-09-30 09:04:22 -0700 | [diff] [blame] | 837 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| 838 | // // do not keep Wifi awake when screen is off if Wifi is not associated |
| 839 | // mDeviceIdle = true; |
| 840 | // updateWifiState(); |
| Mike Lockwood | d9c32bc | 2009-05-18 14:14:15 -0400 | [diff] [blame] | 841 | } else { |
| 842 | long triggerTime = System.currentTimeMillis() + idleMillis; |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 843 | if (DBG) { |
| 844 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis |
| 845 | + "ms"); |
| 846 | } |
| Mike Lockwood | d9c32bc | 2009-05-18 14:14:15 -0400 | [diff] [blame] | 847 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| 848 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } else if (action.equals(ACTION_DEVICE_IDLE)) { |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 851 | if (DBG) { |
| 852 | Slog.d(TAG, "got ACTION_DEVICE_IDLE"); |
| 853 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | mDeviceIdle = true; |
| Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 855 | reportStartWorkSource(); |
| Irfan Sheriff | 4f5f7c9 | 2010-10-14 17:01:27 -0700 | [diff] [blame] | 856 | updateWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
| 858 | /* |
| 859 | * Set a timer to put Wi-Fi to sleep, but only if the screen is off |
| 860 | * AND we are transitioning from a state in which the device was supposed |
| 861 | * to stay awake to a state in which it is not supposed to stay awake. |
| 862 | * If "stay awake" state is not changing, we do nothing, to avoid resetting |
| 863 | * the already-set timer. |
| 864 | */ |
| 865 | int pluggedType = intent.getIntExtra("plugged", 0); |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 866 | if (DBG) { |
| 867 | Slog.d(TAG, "ACTION_BATTERY_CHANGED pluggedType: " + pluggedType); |
| 868 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) && |
| 870 | !shouldWifiStayAwake(stayAwakeConditions, pluggedType)) { |
| 871 | long triggerTime = System.currentTimeMillis() + idleMillis; |
| Joe Onorato | 431bb22 | 2010-10-18 19:13:23 -0400 | [diff] [blame] | 872 | if (DBG) { |
| 873 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms"); |
| 874 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | } |
| 877 | mPluggedType = pluggedType; |
| Irfan Sheriff | 65eaec8 | 2011-01-05 22:00:16 -0800 | [diff] [blame] | 878 | } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
| 879 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, |
| 880 | BluetoothAdapter.STATE_DISCONNECTED); |
| 881 | mWifiStateMachine.sendBluetoothAdapterStateChange(state); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /** |
| 886 | * Determines whether the Wi-Fi chipset should stay awake or be put to |
| 887 | * sleep. Looks at the setting for the sleep policy and the current |
| 888 | * conditions. |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 889 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | * @see #shouldDeviceStayAwake(int, int) |
| 891 | */ |
| 892 | private boolean shouldWifiStayAwake(int stayAwakeConditions, int pluggedType) { |
| Irfan Sheriff | 739f6bc | 2011-01-28 16:43:12 -0800 | [diff] [blame] | 893 | //Never sleep as long as the user has not changed the settings |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | int wifiSleepPolicy = Settings.System.getInt(mContext.getContentResolver(), |
| Irfan Sheriff | 96b10d6 | 2011-01-11 15:40:35 -0800 | [diff] [blame] | 895 | Settings.System.WIFI_SLEEP_POLICY, |
| Irfan Sheriff | 739f6bc | 2011-01-28 16:43:12 -0800 | [diff] [blame] | 896 | Settings.System.WIFI_SLEEP_POLICY_NEVER); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | |
| 898 | if (wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER) { |
| 899 | // Never sleep |
| 900 | return true; |
| 901 | } else if ((wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED) && |
| 902 | (pluggedType != 0)) { |
| 903 | // Never sleep while plugged, and we're plugged |
| 904 | return true; |
| 905 | } else { |
| 906 | // Default |
| 907 | return shouldDeviceStayAwake(stayAwakeConditions, pluggedType); |
| 908 | } |
| 909 | } |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | /** |
| 912 | * Determine whether the bit value corresponding to {@code pluggedType} is set in |
| 913 | * the bit string {@code stayAwakeConditions}. Because a {@code pluggedType} value |
| 914 | * of {@code 0} isn't really a plugged type, but rather an indication that the |
| 915 | * device isn't plugged in at all, there is no bit value corresponding to a |
| 916 | * {@code pluggedType} value of {@code 0}. That is why we shift by |
| Ben Dodson | 4e8620f | 2010-08-25 10:55:47 -0700 | [diff] [blame] | 917 | * {@code pluggedType - 1} instead of by {@code pluggedType}. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | * @param stayAwakeConditions a bit string specifying which "plugged types" should |
| 919 | * keep the device (and hence Wi-Fi) awake. |
| 920 | * @param pluggedType the type of plug (USB, AC, or none) for which the check is |
| 921 | * being made |
| 922 | * @return {@code true} if {@code pluggedType} indicates that the device is |
| 923 | * supposed to stay awake, {@code false} otherwise. |
| 924 | */ |
| 925 | private boolean shouldDeviceStayAwake(int stayAwakeConditions, int pluggedType) { |
| 926 | return (stayAwakeConditions & pluggedType) != 0; |
| 927 | } |
| 928 | }; |
| 929 | |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 930 | private synchronized void reportStartWorkSource() { |
| 931 | mTmpWorkSource.clear(); |
| 932 | if (mDeviceIdle) { |
| 933 | for (int i=0; i<mLocks.mList.size(); i++) { |
| 934 | mTmpWorkSource.add(mLocks.mList.get(i).mWorkSource); |
| Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 935 | } |
| Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 936 | } |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 937 | mWifiStateMachine.updateBatteryWorkSource(mTmpWorkSource); |
| Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 938 | } |
| Jaikumar Ganesh | 7440fc2 | 2010-09-27 17:04:14 -0700 | [diff] [blame] | 939 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | private void updateWifiState() { |
| 941 | boolean wifiEnabled = getPersistedWifiEnabled(); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 942 | boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden.get(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | boolean lockHeld = mLocks.hasLocks(); |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 944 | int strongestLockMode = WifiManager.WIFI_MODE_FULL; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode; |
| 946 | boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld; |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 947 | |
| 948 | if (lockHeld) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | strongestLockMode = mLocks.getStrongestLockMode(); |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 950 | } |
| 951 | /* If device is not idle, lockmode cannot be scan only */ |
| 952 | if (!mDeviceIdle && strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | strongestLockMode = WifiManager.WIFI_MODE_FULL; |
| 954 | } |
| 955 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 956 | /* Disable tethering when airplane mode is enabled */ |
| 957 | if (airplaneMode) { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 958 | mWifiStateMachine.setWifiApEnabled(null, false); |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 959 | } |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 960 | |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 961 | if (wifiShouldBeEnabled) { |
| 962 | if (wifiShouldBeStarted) { |
| Dianne Hackborn | 03f3cb0 | 2010-09-17 23:12:26 -0700 | [diff] [blame] | 963 | reportStartWorkSource(); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 964 | mWifiStateMachine.setWifiEnabled(true); |
| 965 | mWifiStateMachine.setScanOnlyMode( |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 966 | strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 967 | mWifiStateMachine.setDriverStart(true); |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 968 | mWifiStateMachine.setHighPerfModeEnabled(strongestLockMode |
| 969 | == WifiManager.WIFI_MODE_FULL_HIGH_PERF); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } else { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 971 | mWifiStateMachine.requestCmWakeLock(); |
| 972 | mWifiStateMachine.setDriverStart(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
| Irfan Sheriff | a2a1b91 | 2010-06-07 09:03:04 -0700 | [diff] [blame] | 974 | } else { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 975 | mWifiStateMachine.setWifiEnabled(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
| 979 | private void registerForBroadcasts() { |
| 980 | IntentFilter intentFilter = new IntentFilter(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
| 982 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 983 | intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 984 | intentFilter.addAction(ACTION_DEVICE_IDLE); |
| Irfan Sheriff | 65eaec8 | 2011-01-05 22:00:16 -0800 | [diff] [blame] | 985 | intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | mContext.registerReceiver(mReceiver, intentFilter); |
| 987 | } |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | private boolean isAirplaneSensitive() { |
| 990 | String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(), |
| 991 | Settings.System.AIRPLANE_MODE_RADIOS); |
| 992 | return airplaneModeRadios == null |
| 993 | || airplaneModeRadios.contains(Settings.System.RADIO_WIFI); |
| 994 | } |
| 995 | |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 996 | private boolean isAirplaneToggleable() { |
| 997 | String toggleableRadios = Settings.System.getString(mContext.getContentResolver(), |
| 998 | Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
| 999 | return toggleableRadios != null |
| 1000 | && toggleableRadios.contains(Settings.System.RADIO_WIFI); |
| 1001 | } |
| 1002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | /** |
| 1004 | * Returns true if Wi-Fi is sensitive to airplane mode, and airplane mode is |
| 1005 | * currently on. |
| 1006 | * @return {@code true} if airplane mode is on. |
| 1007 | */ |
| 1008 | private boolean isAirplaneModeOn() { |
| 1009 | return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(), |
| 1010 | Settings.System.AIRPLANE_MODE_ON, 0) == 1; |
| 1011 | } |
| 1012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | @Override |
| 1014 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1015 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1016 | != PackageManager.PERMISSION_GRANTED) { |
| 1017 | pw.println("Permission Denial: can't dump WifiService from from pid=" |
| 1018 | + Binder.getCallingPid() |
| 1019 | + ", uid=" + Binder.getCallingUid()); |
| 1020 | return; |
| 1021 | } |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 1022 | pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | pw.println("Stay-awake conditions: " + |
| 1024 | Settings.System.getInt(mContext.getContentResolver(), |
| 1025 | Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0)); |
| 1026 | pw.println(); |
| 1027 | |
| 1028 | pw.println("Internal state:"); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1029 | pw.println(mWifiStateMachine); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | pw.println(); |
| 1031 | pw.println("Latest scan results:"); |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 1032 | List<ScanResult> scanResults = mWifiStateMachine.syncGetScanResultsList(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | if (scanResults != null && scanResults.size() != 0) { |
| 1034 | pw.println(" BSSID Frequency RSSI Flags SSID"); |
| 1035 | for (ScanResult r : scanResults) { |
| 1036 | pw.printf(" %17s %9d %5d %-16s %s%n", |
| 1037 | r.BSSID, |
| 1038 | r.frequency, |
| 1039 | r.level, |
| 1040 | r.capabilities, |
| 1041 | r.SSID == null ? "" : r.SSID); |
| 1042 | } |
| 1043 | } |
| 1044 | pw.println(); |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1045 | pw.println("Locks acquired: " + mFullLocksAcquired + " full, " + |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1046 | mFullHighPerfLocksAcquired + " full high perf, " + |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1047 | mScanLocksAcquired + " scan"); |
| 1048 | pw.println("Locks released: " + mFullLocksReleased + " full, " + |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1049 | mFullHighPerfLocksReleased + " full high perf, " + |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1050 | mScanLocksReleased + " scan"); |
| 1051 | pw.println(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | pw.println("Locks held:"); |
| 1053 | mLocks.dump(pw); |
| 1054 | } |
| 1055 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1056 | private class WifiLock extends DeathRecipient { |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1057 | WifiLock(int lockMode, String tag, IBinder binder, WorkSource ws) { |
| 1058 | super(lockMode, tag, binder, ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | public void binderDied() { |
| 1062 | synchronized (mLocks) { |
| 1063 | releaseWifiLockLocked(mBinder); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | public String toString() { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1068 | return "WifiLock{" + mTag + " type=" + mMode + " binder=" + mBinder + "}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | private class LockList { |
| 1073 | private List<WifiLock> mList; |
| 1074 | |
| 1075 | private LockList() { |
| 1076 | mList = new ArrayList<WifiLock>(); |
| 1077 | } |
| 1078 | |
| 1079 | private synchronized boolean hasLocks() { |
| 1080 | return !mList.isEmpty(); |
| 1081 | } |
| 1082 | |
| 1083 | private synchronized int getStrongestLockMode() { |
| 1084 | if (mList.isEmpty()) { |
| 1085 | return WifiManager.WIFI_MODE_FULL; |
| 1086 | } |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1087 | |
| 1088 | if (mFullHighPerfLocksAcquired > mFullHighPerfLocksReleased) { |
| 1089 | return WifiManager.WIFI_MODE_FULL_HIGH_PERF; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | } |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1091 | |
| 1092 | if (mFullLocksAcquired > mFullLocksReleased) { |
| 1093 | return WifiManager.WIFI_MODE_FULL; |
| 1094 | } |
| 1095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | return WifiManager.WIFI_MODE_SCAN_ONLY; |
| 1097 | } |
| 1098 | |
| 1099 | private void addLock(WifiLock lock) { |
| 1100 | if (findLockByBinder(lock.mBinder) < 0) { |
| 1101 | mList.add(lock); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | private WifiLock removeLock(IBinder binder) { |
| 1106 | int index = findLockByBinder(binder); |
| 1107 | if (index >= 0) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 1108 | WifiLock ret = mList.remove(index); |
| 1109 | ret.unlinkDeathRecipient(); |
| 1110 | return ret; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | } else { |
| 1112 | return null; |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | private int findLockByBinder(IBinder binder) { |
| 1117 | int size = mList.size(); |
| 1118 | for (int i = size - 1; i >= 0; i--) |
| 1119 | if (mList.get(i).mBinder == binder) |
| 1120 | return i; |
| 1121 | return -1; |
| 1122 | } |
| 1123 | |
| 1124 | private void dump(PrintWriter pw) { |
| 1125 | for (WifiLock l : mList) { |
| 1126 | pw.print(" "); |
| 1127 | pw.println(l); |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1132 | void enforceWakeSourcePermission(int uid, int pid) { |
| Dianne Hackborn | e746f03 | 2010-09-13 16:02:57 -0700 | [diff] [blame] | 1133 | if (uid == android.os.Process.myUid()) { |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS, |
| 1137 | pid, uid, null); |
| 1138 | } |
| 1139 | |
| 1140 | public boolean acquireWifiLock(IBinder binder, int lockMode, String tag, WorkSource ws) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1142 | if (lockMode != WifiManager.WIFI_MODE_FULL && |
| 1143 | lockMode != WifiManager.WIFI_MODE_SCAN_ONLY && |
| 1144 | lockMode != WifiManager.WIFI_MODE_FULL_HIGH_PERF) { |
| 1145 | Slog.e(TAG, "Illegal argument, lockMode= " + lockMode); |
| 1146 | if (DBG) throw new IllegalArgumentException("lockMode=" + lockMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | return false; |
| 1148 | } |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1149 | if (ws != null && ws.size() == 0) { |
| 1150 | ws = null; |
| 1151 | } |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1152 | if (ws != null) { |
| 1153 | enforceWakeSourcePermission(Binder.getCallingUid(), Binder.getCallingPid()); |
| 1154 | } |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1155 | if (ws == null) { |
| 1156 | ws = new WorkSource(Binder.getCallingUid()); |
| 1157 | } |
| 1158 | WifiLock wifiLock = new WifiLock(lockMode, tag, binder, ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | synchronized (mLocks) { |
| 1160 | return acquireWifiLockLocked(wifiLock); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1164 | private void noteAcquireWifiLock(WifiLock wifiLock) throws RemoteException { |
| 1165 | switch(wifiLock.mMode) { |
| 1166 | case WifiManager.WIFI_MODE_FULL: |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1167 | case WifiManager.WIFI_MODE_FULL_HIGH_PERF: |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1168 | mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource); |
| 1169 | break; |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1170 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 1171 | mBatteryStats.noteScanWifiLockAcquiredFromSource(wifiLock.mWorkSource); |
| 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | private void noteReleaseWifiLock(WifiLock wifiLock) throws RemoteException { |
| 1177 | switch(wifiLock.mMode) { |
| 1178 | case WifiManager.WIFI_MODE_FULL: |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1179 | case WifiManager.WIFI_MODE_FULL_HIGH_PERF: |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1180 | mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource); |
| 1181 | break; |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1182 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 1183 | mBatteryStats.noteScanWifiLockReleasedFromSource(wifiLock.mWorkSource); |
| 1184 | break; |
| 1185 | } |
| 1186 | } |
| 1187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | private boolean acquireWifiLockLocked(WifiLock wifiLock) { |
| Irfan Sheriff | c89dd54 | 2010-09-28 08:40:54 -0700 | [diff] [blame] | 1189 | if (DBG) Slog.d(TAG, "acquireWifiLockLocked: " + wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 1190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | mLocks.addLock(wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 1192 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1193 | long ident = Binder.clearCallingIdentity(); |
| 1194 | try { |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1195 | noteAcquireWifiLock(wifiLock); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1196 | switch(wifiLock.mMode) { |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1197 | case WifiManager.WIFI_MODE_FULL: |
| 1198 | ++mFullLocksAcquired; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1199 | break; |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1200 | case WifiManager.WIFI_MODE_FULL_HIGH_PERF: |
| 1201 | ++mFullHighPerfLocksAcquired; |
| 1202 | break; |
| 1203 | |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1204 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 1205 | ++mScanLocksAcquired; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1206 | break; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1207 | } |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1208 | |
| 1209 | // Be aggressive about adding new locks into the accounted state... |
| 1210 | // we want to over-report rather than under-report. |
| 1211 | reportStartWorkSource(); |
| 1212 | |
| 1213 | updateWifiState(); |
| 1214 | return true; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1215 | } catch (RemoteException e) { |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1216 | return false; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1217 | } finally { |
| 1218 | Binder.restoreCallingIdentity(ident); |
| 1219 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1222 | public void updateWifiLockWorkSource(IBinder lock, WorkSource ws) { |
| 1223 | int uid = Binder.getCallingUid(); |
| 1224 | int pid = Binder.getCallingPid(); |
| 1225 | if (ws != null && ws.size() == 0) { |
| 1226 | ws = null; |
| 1227 | } |
| 1228 | if (ws != null) { |
| 1229 | enforceWakeSourcePermission(uid, pid); |
| 1230 | } |
| 1231 | long ident = Binder.clearCallingIdentity(); |
| 1232 | try { |
| 1233 | synchronized (mLocks) { |
| 1234 | int index = mLocks.findLockByBinder(lock); |
| 1235 | if (index < 0) { |
| 1236 | throw new IllegalArgumentException("Wifi lock not active"); |
| 1237 | } |
| 1238 | WifiLock wl = mLocks.mList.get(index); |
| 1239 | noteReleaseWifiLock(wl); |
| 1240 | wl.mWorkSource = ws != null ? new WorkSource(ws) : new WorkSource(uid); |
| 1241 | noteAcquireWifiLock(wl); |
| 1242 | } |
| 1243 | } catch (RemoteException e) { |
| 1244 | } finally { |
| 1245 | Binder.restoreCallingIdentity(ident); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | public boolean releaseWifiLock(IBinder lock) { |
| 1250 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); |
| 1251 | synchronized (mLocks) { |
| 1252 | return releaseWifiLockLocked(lock); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | private boolean releaseWifiLockLocked(IBinder lock) { |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1257 | boolean hadLock; |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 1258 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1259 | WifiLock wifiLock = mLocks.removeLock(lock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 1260 | |
| Irfan Sheriff | c89dd54 | 2010-09-28 08:40:54 -0700 | [diff] [blame] | 1261 | if (DBG) Slog.d(TAG, "releaseWifiLockLocked: " + wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 1262 | |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1263 | hadLock = (wifiLock != null); |
| 1264 | |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1265 | long ident = Binder.clearCallingIdentity(); |
| 1266 | try { |
| 1267 | if (hadLock) { |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1268 | noteAcquireWifiLock(wifiLock); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1269 | switch(wifiLock.mMode) { |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1270 | case WifiManager.WIFI_MODE_FULL: |
| 1271 | ++mFullLocksReleased; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1272 | break; |
| Irfan Sheriff | 5876a42 | 2010-08-12 20:26:23 -0700 | [diff] [blame] | 1273 | case WifiManager.WIFI_MODE_FULL_HIGH_PERF: |
| 1274 | ++mFullHighPerfLocksReleased; |
| 1275 | break; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1276 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 1277 | ++mScanLocksReleased; |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1278 | break; |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1279 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1280 | } |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1281 | |
| 1282 | // TODO - should this only happen if you hadLock? |
| 1283 | updateWifiState(); |
| 1284 | |
| 1285 | } catch (RemoteException e) { |
| 1286 | } finally { |
| 1287 | Binder.restoreCallingIdentity(ident); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1288 | } |
| Dianne Hackborn | ecfd7f7 | 2010-10-08 14:23:40 -0700 | [diff] [blame] | 1289 | |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1290 | return hadLock; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1292 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1293 | private abstract class DeathRecipient |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1294 | implements IBinder.DeathRecipient { |
| 1295 | String mTag; |
| 1296 | int mMode; |
| 1297 | IBinder mBinder; |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1298 | WorkSource mWorkSource; |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1299 | |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1300 | DeathRecipient(int mode, String tag, IBinder binder, WorkSource ws) { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1301 | super(); |
| 1302 | mTag = tag; |
| 1303 | mMode = mode; |
| 1304 | mBinder = binder; |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1305 | mWorkSource = ws; |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1306 | try { |
| 1307 | mBinder.linkToDeath(this, 0); |
| 1308 | } catch (RemoteException e) { |
| 1309 | binderDied(); |
| 1310 | } |
| 1311 | } |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 1312 | |
| 1313 | void unlinkDeathRecipient() { |
| 1314 | mBinder.unlinkToDeath(this, 0); |
| 1315 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1318 | private class Multicaster extends DeathRecipient { |
| 1319 | Multicaster(String tag, IBinder binder) { |
| Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1320 | super(Binder.getCallingUid(), tag, binder, null); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | public void binderDied() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1324 | Slog.e(TAG, "Multicaster binderDied"); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1325 | synchronized (mMulticasters) { |
| 1326 | int i = mMulticasters.indexOf(this); |
| 1327 | if (i != -1) { |
| 1328 | removeMulticasterLocked(i, mMode); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | public String toString() { |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1334 | return "Multicaster{" + mTag + " binder=" + mBinder + "}"; |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | public int getUid() { |
| 1338 | return mMode; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 1342 | public void initializeMulticastFiltering() { |
| 1343 | enforceMulticastChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1344 | |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 1345 | synchronized (mMulticasters) { |
| 1346 | // if anybody had requested filters be off, leave off |
| 1347 | if (mMulticasters.size() != 0) { |
| 1348 | return; |
| 1349 | } else { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1350 | mWifiStateMachine.startPacketFiltering(); |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 1355 | public void acquireMulticastLock(IBinder binder, String tag) { |
| 1356 | enforceMulticastChangePermission(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1357 | |
| 1358 | synchronized (mMulticasters) { |
| 1359 | mMulticastEnabled++; |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1360 | mMulticasters.add(new Multicaster(tag, binder)); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1361 | // Note that we could call stopPacketFiltering only when |
| 1362 | // our new size == 1 (first call), but this function won't |
| 1363 | // be called often and by making the stopPacket call each |
| 1364 | // time we're less fragile and self-healing. |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1365 | mWifiStateMachine.stopPacketFiltering(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | int uid = Binder.getCallingUid(); |
| 1369 | Long ident = Binder.clearCallingIdentity(); |
| 1370 | try { |
| 1371 | mBatteryStats.noteWifiMulticastEnabled(uid); |
| 1372 | } catch (RemoteException e) { |
| 1373 | } finally { |
| 1374 | Binder.restoreCallingIdentity(ident); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 1378 | public void releaseMulticastLock() { |
| 1379 | enforceMulticastChangePermission(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1380 | |
| 1381 | int uid = Binder.getCallingUid(); |
| 1382 | synchronized (mMulticasters) { |
| 1383 | mMulticastDisabled++; |
| 1384 | int size = mMulticasters.size(); |
| 1385 | for (int i = size - 1; i >= 0; i--) { |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1386 | Multicaster m = mMulticasters.get(i); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1387 | if ((m != null) && (m.getUid() == uid)) { |
| 1388 | removeMulticasterLocked(i, uid); |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | private void removeMulticasterLocked(int i, int uid) |
| 1395 | { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 1396 | Multicaster removed = mMulticasters.remove(i); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1397 | |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 1398 | if (removed != null) { |
| 1399 | removed.unlinkDeathRecipient(); |
| 1400 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1401 | if (mMulticasters.size() == 0) { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1402 | mWifiStateMachine.startPacketFiltering(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | Long ident = Binder.clearCallingIdentity(); |
| 1406 | try { |
| 1407 | mBatteryStats.noteWifiMulticastDisabled(uid); |
| 1408 | } catch (RemoteException e) { |
| 1409 | } finally { |
| 1410 | Binder.restoreCallingIdentity(ident); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1414 | public boolean isMulticastEnabled() { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1415 | enforceAccessPermission(); |
| 1416 | |
| 1417 | synchronized (mMulticasters) { |
| 1418 | return (mMulticasters.size() > 0); |
| 1419 | } |
| 1420 | } |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1421 | |
| 1422 | private void checkAndSetNotification() { |
| 1423 | // If we shouldn't place a notification on available networks, then |
| 1424 | // don't bother doing any of the following |
| 1425 | if (!mNotificationEnabled) return; |
| 1426 | |
| 1427 | State state = mNetworkInfo.getState(); |
| 1428 | if ((state == NetworkInfo.State.DISCONNECTED) |
| 1429 | || (state == NetworkInfo.State.UNKNOWN)) { |
| 1430 | // Look for an open network |
| Irfan Sheriff | d8134ff | 2010-08-22 17:06:34 -0700 | [diff] [blame] | 1431 | List<ScanResult> scanResults = mWifiStateMachine.syncGetScanResultsList(); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1432 | if (scanResults != null) { |
| 1433 | int numOpenNetworks = 0; |
| 1434 | for (int i = scanResults.size() - 1; i >= 0; i--) { |
| 1435 | ScanResult scanResult = scanResults.get(i); |
| 1436 | |
| 1437 | if (TextUtils.isEmpty(scanResult.capabilities)) { |
| 1438 | numOpenNetworks++; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | if (numOpenNetworks > 0) { |
| 1443 | if (++mNumScansSinceNetworkStateChange >= NUM_SCANS_BEFORE_ACTUALLY_SCANNING) { |
| 1444 | /* |
| 1445 | * We've scanned continuously at least |
| 1446 | * NUM_SCANS_BEFORE_NOTIFICATION times. The user |
| 1447 | * probably does not have a remembered network in range, |
| 1448 | * since otherwise supplicant would have tried to |
| 1449 | * associate and thus resetting this counter. |
| 1450 | */ |
| 1451 | setNotificationVisible(true, numOpenNetworks, false, 0); |
| 1452 | } |
| 1453 | return; |
| 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | // No open networks in range, remove the notification |
| 1459 | setNotificationVisible(false, 0, false, 0); |
| 1460 | } |
| 1461 | |
| 1462 | /** |
| 1463 | * Clears variables related to tracking whether a notification has been |
| 1464 | * shown recently and clears the current notification. |
| 1465 | */ |
| 1466 | private void resetNotification() { |
| 1467 | mNotificationRepeatTime = 0; |
| 1468 | mNumScansSinceNetworkStateChange = 0; |
| 1469 | setNotificationVisible(false, 0, false, 0); |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * Display or don't display a notification that there are open Wi-Fi networks. |
| 1474 | * @param visible {@code true} if notification should be visible, {@code false} otherwise |
| 1475 | * @param numNetworks the number networks seen |
| 1476 | * @param force {@code true} to force notification to be shown/not-shown, |
| 1477 | * even if it is already shown/not-shown. |
| 1478 | * @param delay time in milliseconds after which the notification should be made |
| 1479 | * visible or invisible. |
| 1480 | */ |
| 1481 | private void setNotificationVisible(boolean visible, int numNetworks, boolean force, |
| 1482 | int delay) { |
| 1483 | |
| 1484 | // Since we use auto cancel on the notification, when the |
| 1485 | // mNetworksAvailableNotificationShown is true, the notification may |
| 1486 | // have actually been canceled. However, when it is false we know |
| 1487 | // for sure that it is not being shown (it will not be shown any other |
| 1488 | // place than here) |
| 1489 | |
| 1490 | // If it should be hidden and it is already hidden, then noop |
| 1491 | if (!visible && !mNotificationShown && !force) { |
| 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | NotificationManager notificationManager = (NotificationManager) mContext |
| 1496 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 1497 | |
| 1498 | Message message; |
| 1499 | if (visible) { |
| 1500 | |
| 1501 | // Not enough time has passed to show the notification again |
| 1502 | if (System.currentTimeMillis() < mNotificationRepeatTime) { |
| 1503 | return; |
| 1504 | } |
| 1505 | |
| 1506 | if (mNotification == null) { |
| Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 1507 | // Cache the Notification object. |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1508 | mNotification = new Notification(); |
| 1509 | mNotification.when = 0; |
| 1510 | mNotification.icon = ICON_NETWORKS_AVAILABLE; |
| 1511 | mNotification.flags = Notification.FLAG_AUTO_CANCEL; |
| 1512 | mNotification.contentIntent = PendingIntent.getActivity(mContext, 0, |
| 1513 | new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK), 0); |
| 1514 | } |
| 1515 | |
| 1516 | CharSequence title = mContext.getResources().getQuantityText( |
| 1517 | com.android.internal.R.plurals.wifi_available, numNetworks); |
| 1518 | CharSequence details = mContext.getResources().getQuantityText( |
| 1519 | com.android.internal.R.plurals.wifi_available_detailed, numNetworks); |
| 1520 | mNotification.tickerText = title; |
| 1521 | mNotification.setLatestEventInfo(mContext, title, details, mNotification.contentIntent); |
| 1522 | |
| 1523 | mNotificationRepeatTime = System.currentTimeMillis() + NOTIFICATION_REPEAT_DELAY_MS; |
| 1524 | |
| 1525 | notificationManager.notify(ICON_NETWORKS_AVAILABLE, mNotification); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1526 | } else { |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1527 | notificationManager.cancel(ICON_NETWORKS_AVAILABLE); |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| Irfan Sheriff | 0d25534 | 2010-07-28 09:35:20 -0700 | [diff] [blame] | 1530 | mNotificationShown = visible; |
| 1531 | } |
| 1532 | |
| 1533 | private class NotificationEnabledSettingObserver extends ContentObserver { |
| 1534 | |
| 1535 | public NotificationEnabledSettingObserver(Handler handler) { |
| 1536 | super(handler); |
| 1537 | } |
| 1538 | |
| 1539 | public void register() { |
| 1540 | ContentResolver cr = mContext.getContentResolver(); |
| 1541 | cr.registerContentObserver(Settings.Secure.getUriFor( |
| 1542 | Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON), true, this); |
| 1543 | mNotificationEnabled = getValue(); |
| 1544 | } |
| 1545 | |
| 1546 | @Override |
| 1547 | public void onChange(boolean selfChange) { |
| 1548 | super.onChange(selfChange); |
| 1549 | |
| 1550 | mNotificationEnabled = getValue(); |
| 1551 | resetNotification(); |
| 1552 | } |
| 1553 | |
| 1554 | private boolean getValue() { |
| 1555 | return Settings.Secure.getInt(mContext.getContentResolver(), |
| 1556 | Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1) == 1; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | } |