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