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