| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 | |
| 19 | import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED; |
| 20 | import static android.net.wifi.WifiManager.WIFI_STATE_DISABLING; |
| 21 | import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED; |
| 22 | import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING; |
| 23 | import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN; |
| 24 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 25 | import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; |
| 26 | import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING; |
| 27 | import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED; |
| 28 | import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLING; |
| 29 | import static android.net.wifi.WifiManager.WIFI_AP_STATE_FAILED; |
| 30 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.app.AlarmManager; |
| 32 | import android.app.PendingIntent; |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 33 | import android.bluetooth.BluetoothA2dp; |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 34 | import android.bluetooth.BluetoothDevice; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.BroadcastReceiver; |
| 36 | import android.content.ContentResolver; |
| 37 | import android.content.Context; |
| 38 | import android.content.Intent; |
| 39 | import android.content.IntentFilter; |
| 40 | import android.content.pm.PackageManager; |
| 41 | import android.net.wifi.IWifiManager; |
| 42 | import android.net.wifi.WifiInfo; |
| 43 | import android.net.wifi.WifiManager; |
| 44 | import android.net.wifi.WifiNative; |
| 45 | import android.net.wifi.WifiStateTracker; |
| 46 | import android.net.wifi.ScanResult; |
| 47 | import android.net.wifi.WifiConfiguration; |
| San Mehat | 0310f9a | 2009-07-07 10:49:47 -0700 | [diff] [blame] | 48 | import android.net.wifi.SupplicantState; |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 49 | import android.net.wifi.WifiConfiguration.KeyMgmt; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 50 | import android.net.ConnectivityManager; |
| 51 | import android.net.InterfaceConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.net.NetworkStateTracker; |
| 53 | import android.net.DhcpInfo; |
| Mike Lockwood | 0900f36 | 2009-07-10 17:24:07 -0400 | [diff] [blame] | 54 | import android.net.NetworkUtils; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.Binder; |
| 56 | import android.os.Handler; |
| 57 | import android.os.HandlerThread; |
| 58 | import android.os.IBinder; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 59 | import android.os.INetworkManagementService; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.os.Looper; |
| 61 | import android.os.Message; |
| 62 | import android.os.PowerManager; |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 63 | import android.os.Process; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.os.RemoteException; |
| Amith Yamasani | 47873e5 | 2009-07-02 12:05:32 -0700 | [diff] [blame] | 65 | import android.os.ServiceManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.provider.Settings; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 67 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.text.TextUtils; |
| 69 | |
| 70 | import java.util.ArrayList; |
| 71 | import java.util.BitSet; |
| 72 | import java.util.HashMap; |
| 73 | import java.util.LinkedHashMap; |
| 74 | import java.util.List; |
| 75 | import java.util.Map; |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 76 | import java.util.Set; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import java.util.regex.Pattern; |
| 78 | import java.io.FileDescriptor; |
| 79 | import java.io.PrintWriter; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 80 | import java.net.UnknownHostException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 82 | import com.android.internal.app.IBatteryStats; |
| Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 83 | import android.app.backup.IBackupManager; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 84 | import com.android.server.am.BatteryStatsService; |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 85 | import com.android.internal.R; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 86 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | /** |
| 88 | * WifiService handles remote WiFi operation requests by implementing |
| 89 | * the IWifiManager interface. It also creates a WifiMonitor to listen |
| 90 | * for Wifi-related events. |
| 91 | * |
| 92 | * @hide |
| 93 | */ |
| 94 | public class WifiService extends IWifiManager.Stub { |
| 95 | private static final String TAG = "WifiService"; |
| 96 | private static final boolean DBG = false; |
| 97 | private static final Pattern scanResultPattern = Pattern.compile("\t+"); |
| 98 | private final WifiStateTracker mWifiStateTracker; |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 99 | /* TODO: fetch a configurable interface */ |
| 100 | private static final String SOFTAP_IFACE = "wl0.1"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
| 102 | private Context mContext; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 103 | private int mWifiApState; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
| 105 | private AlarmManager mAlarmManager; |
| 106 | private PendingIntent mIdleIntent; |
| 107 | private static final int IDLE_REQUEST = 0; |
| 108 | private boolean mScreenOff; |
| 109 | private boolean mDeviceIdle; |
| 110 | private int mPluggedType; |
| 111 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 112 | private enum DriverAction {DRIVER_UNLOAD, NO_DRIVER_UNLOAD}; |
| 113 | |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 114 | // true if the user enabled Wifi while in airplane mode |
| 115 | private boolean mAirplaneModeOverwridden; |
| 116 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | private final LockList mLocks = new LockList(); |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 118 | // some wifi lock statistics |
| 119 | private int mFullLocksAcquired; |
| 120 | private int mFullLocksReleased; |
| 121 | private int mScanLocksAcquired; |
| 122 | private int mScanLocksReleased; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 123 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 124 | private final List<Multicaster> mMulticasters = |
| 125 | new ArrayList<Multicaster>(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 126 | private int mMulticastEnabled; |
| 127 | private int mMulticastDisabled; |
| 128 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 129 | private final IBatteryStats mBatteryStats; |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 130 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 131 | private INetworkManagementService nwService; |
| 132 | ConnectivityManager mCm; |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 133 | private WifiWatchdogService mWifiWatchdogService = null; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 134 | private String[] mWifiRegexs; |
| 135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | /** |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 137 | * See {@link Settings.Secure#WIFI_IDLE_MS}. This is the default value if a |
| 138 | * 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] | 139 | * the approximate point at which the battery drain caused by Wi-Fi |
| 140 | * being enabled but not active exceeds the battery drain caused by |
| 141 | * re-establishing a connection to the mobile data network. |
| 142 | */ |
| 143 | private static final long DEFAULT_IDLE_MILLIS = 15 * 60 * 1000; /* 15 minutes */ |
| 144 | |
| 145 | private static final String WAKELOCK_TAG = "WifiService"; |
| 146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | // Wake lock used by other operations |
| 148 | private static PowerManager.WakeLock sWakeLock; |
| 149 | |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 150 | private static final int MESSAGE_ENABLE_WIFI = 0; |
| 151 | private static final int MESSAGE_DISABLE_WIFI = 1; |
| 152 | private static final int MESSAGE_STOP_WIFI = 2; |
| 153 | private static final int MESSAGE_START_WIFI = 3; |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 154 | private static final int MESSAGE_UPDATE_STATE = 5; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 155 | private static final int MESSAGE_START_ACCESS_POINT = 6; |
| 156 | private static final int MESSAGE_STOP_ACCESS_POINT = 7; |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 157 | private static final int MESSAGE_SET_CHANNELS = 8; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
| 160 | private final WifiHandler mWifiHandler; |
| 161 | |
| 162 | /* |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | * Cache of scan results objects (size is somewhat arbitrary) |
| 164 | */ |
| 165 | private static final int SCAN_RESULT_CACHE_SIZE = 80; |
| 166 | private final LinkedHashMap<String, ScanResult> mScanResultCache; |
| 167 | |
| 168 | /* |
| 169 | * Character buffer used to parse scan results (optimization) |
| 170 | */ |
| 171 | private static final int SCAN_RESULT_BUFFER_SIZE = 512; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | private boolean mNeedReconfig; |
| 173 | |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Last UID that asked to enable WIFI. |
| 176 | */ |
| 177 | private int mLastEnableUid = Process.myUid(); |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 178 | |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 179 | /* |
| 180 | * Last UID that asked to enable WIFI AP. |
| 181 | */ |
| 182 | private int mLastApEnableUid = Process.myUid(); |
| 183 | |
| 184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | /** |
| 186 | * Number of allowed radio frequency channels in various regulatory domains. |
| 187 | * This list is sufficient for 802.11b/g networks (2.4GHz range). |
| 188 | */ |
| 189 | private static int[] sValidRegulatoryChannelCounts = new int[] {11, 13, 14}; |
| 190 | |
| 191 | private static final String ACTION_DEVICE_IDLE = |
| 192 | "com.android.server.WifiManager.action.DEVICE_IDLE"; |
| 193 | |
| 194 | WifiService(Context context, WifiStateTracker tracker) { |
| 195 | mContext = context; |
| 196 | mWifiStateTracker = tracker; |
| Mike Lockwood | f32be16 | 2009-07-14 17:44:37 -0400 | [diff] [blame] | 197 | mWifiStateTracker.enableRssiPolling(true); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 198 | mBatteryStats = BatteryStatsService.getService(); |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 199 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 200 | IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); |
| 201 | nwService = INetworkManagementService.Stub.asInterface(b); |
| 202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | mScanResultCache = new LinkedHashMap<String, ScanResult>( |
| 204 | SCAN_RESULT_CACHE_SIZE, 0.75f, true) { |
| 205 | /* |
| 206 | * Limit the cache size by SCAN_RESULT_CACHE_SIZE |
| 207 | * elements |
| 208 | */ |
| 209 | public boolean removeEldestEntry(Map.Entry eldest) { |
| 210 | return SCAN_RESULT_CACHE_SIZE < this.size(); |
| 211 | } |
| 212 | }; |
| 213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | HandlerThread wifiThread = new HandlerThread("WifiService"); |
| 215 | wifiThread.start(); |
| 216 | mWifiHandler = new WifiHandler(wifiThread.getLooper()); |
| 217 | |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 218 | mWifiStateTracker.setWifiState(WIFI_STATE_DISABLED); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 219 | mWifiApState = WIFI_AP_STATE_DISABLED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | |
| 221 | mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); |
| 222 | Intent idleIntent = new Intent(ACTION_DEVICE_IDLE, null); |
| 223 | mIdleIntent = PendingIntent.getBroadcast(mContext, IDLE_REQUEST, idleIntent, 0); |
| 224 | |
| 225 | PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 226 | sWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | mContext.registerReceiver( |
| 229 | new BroadcastReceiver() { |
| 230 | @Override |
| 231 | public void onReceive(Context context, Intent intent) { |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 232 | // clear our flag indicating the user has overwridden airplane mode |
| 233 | mAirplaneModeOverwridden = false; |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 234 | // on airplane disable, restore Wifi if the saved state indicates so |
| 235 | if (!isAirplaneModeOn() && testAndClearWifiSavedState()) { |
| 236 | persistWifiEnabled(true); |
| 237 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | updateWifiState(); |
| 239 | } |
| 240 | }, |
| 241 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); |
| 242 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 243 | mContext.registerReceiver( |
| 244 | new BroadcastReceiver() { |
| 245 | @Override |
| 246 | public void onReceive(Context context, Intent intent) { |
| 247 | |
| 248 | ArrayList<String> available = intent.getStringArrayListExtra( |
| 249 | ConnectivityManager.EXTRA_AVAILABLE_TETHER); |
| 250 | ArrayList<String> active = intent.getStringArrayListExtra( |
| 251 | ConnectivityManager.EXTRA_ACTIVE_TETHER); |
| 252 | updateTetherState(available, active); |
| 253 | |
| 254 | } |
| 255 | },new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED)); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 256 | } |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 257 | |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 258 | /** |
| 259 | * Check if Wi-Fi needs to be enabled and start |
| 260 | * if needed |
| Irfan Sheriff | 60e3ba0 | 2010-04-02 12:18:45 -0700 | [diff] [blame] | 261 | * |
| 262 | * This function is used only at boot time |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 263 | */ |
| 264 | public void startWifi() { |
| Irfan Sheriff | a3bd409 | 2010-03-24 17:58:59 -0700 | [diff] [blame] | 265 | /* Start if Wi-Fi is enabled or the saved state indicates Wi-Fi was on */ |
| Irfan Sheriff | 60e3ba0 | 2010-04-02 12:18:45 -0700 | [diff] [blame] | 266 | boolean wifiEnabled = !isAirplaneModeOn() |
| 267 | && (getPersistedWifiEnabled() || testAndClearWifiSavedState()); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 268 | Slog.i(TAG, "WifiService starting up with Wi-Fi " + |
| 269 | (wifiEnabled ? "enabled" : "disabled")); |
| Irfan Sheriff | b99fe5e | 2010-03-26 14:56:07 -0700 | [diff] [blame] | 270 | setWifiEnabled(wifiEnabled); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | private void updateTetherState(ArrayList<String> available, ArrayList<String> tethered) { |
| 274 | |
| 275 | boolean wifiTethered = false; |
| 276 | boolean wifiAvailable = false; |
| 277 | |
| 278 | IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); |
| 279 | INetworkManagementService service = INetworkManagementService.Stub.asInterface(b); |
| 280 | |
| Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame^] | 281 | if (mCm == null) { |
| 282 | mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 283 | } |
| 284 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 285 | mWifiRegexs = mCm.getTetherableWifiRegexs(); |
| 286 | |
| 287 | for (String intf : available) { |
| 288 | for (String regex : mWifiRegexs) { |
| 289 | if (intf.matches(regex)) { |
| 290 | |
| 291 | InterfaceConfiguration ifcg = null; |
| 292 | try { |
| 293 | ifcg = service.getInterfaceConfig(intf); |
| 294 | if (ifcg != null) { |
| Robert Greenwalt | bfb7bfa | 2010-03-24 16:03:21 -0700 | [diff] [blame] | 295 | /* IP/netmask: 192.168.43.1/255.255.255.0 */ |
| 296 | ifcg.ipAddr = (192 << 24) + (168 << 16) + (43 << 8) + 1; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 297 | ifcg.netmask = (255 << 24) + (255 << 16) + (255 << 8) + 0; |
| 298 | ifcg.interfaceFlags = "up"; |
| 299 | |
| 300 | service.setInterfaceConfig(intf, ifcg); |
| 301 | } |
| 302 | } catch (Exception e) { |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 303 | Slog.e(TAG, "Error configuring interface " + intf + ", :" + e); |
| Irfan Sheriff | 1a54301 | 2010-03-17 19:46:32 -0700 | [diff] [blame] | 304 | try { |
| 305 | nwService.stopAccessPoint(); |
| 306 | } catch (Exception ee) { |
| 307 | Slog.e(TAG, "Could not stop AP, :" + ee); |
| 308 | } |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 309 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, 0, DriverAction.DRIVER_UNLOAD); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 313 | if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) { |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 314 | Slog.e(TAG, "Error tethering "+intf); |
| 315 | } |
| 316 | break; |
| 317 | } |
| 318 | } |
| 319 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| Irfan Sheriff | a3bd409 | 2010-03-24 17:58:59 -0700 | [diff] [blame] | 322 | private boolean testAndClearWifiSavedState() { |
| 323 | final ContentResolver cr = mContext.getContentResolver(); |
| 324 | int wifiSavedState = 0; |
| 325 | try { |
| 326 | wifiSavedState = Settings.Secure.getInt(cr, Settings.Secure.WIFI_SAVED_STATE); |
| 327 | if(wifiSavedState == 1) |
| 328 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_SAVED_STATE, 0); |
| 329 | } catch (Settings.SettingNotFoundException e) { |
| 330 | ; |
| 331 | } |
| 332 | return (wifiSavedState == 1); |
| 333 | } |
| 334 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | private boolean getPersistedWifiEnabled() { |
| 336 | final ContentResolver cr = mContext.getContentResolver(); |
| 337 | try { |
| 338 | return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON) == 1; |
| 339 | } catch (Settings.SettingNotFoundException e) { |
| 340 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, 0); |
| 341 | return false; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | private void persistWifiEnabled(boolean enabled) { |
| 346 | final ContentResolver cr = mContext.getContentResolver(); |
| 347 | Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, enabled ? 1 : 0); |
| 348 | } |
| 349 | |
| 350 | NetworkStateTracker getNetworkStateTracker() { |
| 351 | return mWifiStateTracker; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * see {@link android.net.wifi.WifiManager#pingSupplicant()} |
| 356 | * @return {@code true} if the operation succeeds |
| 357 | */ |
| 358 | public boolean pingSupplicant() { |
| 359 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 360 | |
| 361 | return mWifiStateTracker.ping(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
| 365 | * see {@link android.net.wifi.WifiManager#startScan()} |
| 366 | * @return {@code true} if the operation succeeds |
| 367 | */ |
| Mike Lockwood | a5ec95c | 2009-07-08 17:11:17 -0400 | [diff] [blame] | 368 | public boolean startScan(boolean forceActive) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 370 | |
| 371 | switch (mWifiStateTracker.getSupplicantState()) { |
| 372 | case DISCONNECTED: |
| 373 | case INACTIVE: |
| 374 | case SCANNING: |
| 375 | case DORMANT: |
| 376 | break; |
| 377 | default: |
| 378 | mWifiStateTracker.setScanResultHandling( |
| 379 | WifiStateTracker.SUPPL_SCAN_HANDLING_LIST_ONLY); |
| 380 | break; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 382 | return mWifiStateTracker.scan(forceActive); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /** |
| 386 | * see {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} |
| 387 | * @param enable {@code true} to enable, {@code false} to disable. |
| 388 | * @return {@code true} if the enable/disable operation was |
| 389 | * started or is already in the queue. |
| 390 | */ |
| 391 | public boolean setWifiEnabled(boolean enable) { |
| 392 | enforceChangePermission(); |
| 393 | if (mWifiHandler == null) return false; |
| 394 | |
| 395 | synchronized (mWifiHandler) { |
| Robert Greenwalt | a99f461 | 2009-09-19 18:14:32 -0700 | [diff] [blame] | 396 | // caller may not have WAKE_LOCK permission - it's not required here |
| 397 | long ident = Binder.clearCallingIdentity(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | sWakeLock.acquire(); |
| Robert Greenwalt | a99f461 | 2009-09-19 18:14:32 -0700 | [diff] [blame] | 399 | Binder.restoreCallingIdentity(ident); |
| 400 | |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 401 | mLastEnableUid = Binder.getCallingUid(); |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 402 | // set a flag if the user is enabling Wifi while in airplane mode |
| 403 | mAirplaneModeOverwridden = (enable && isAirplaneModeOn() && isAirplaneToggleable()); |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 404 | sendEnableMessage(enable, true, Binder.getCallingUid()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | return true; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Enables/disables Wi-Fi synchronously. |
| 412 | * @param enable {@code true} to turn Wi-Fi on, {@code false} to turn it off. |
| 413 | * @param persist {@code true} if the setting should be persisted. |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 414 | * @param uid The UID of the process making the request. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | * @return {@code true} if the operation succeeds (or if the existing state |
| 416 | * is the same as the requested state) |
| 417 | */ |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 418 | private boolean setWifiEnabledBlocking(boolean enable, boolean persist, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | final int eventualWifiState = enable ? WIFI_STATE_ENABLED : WIFI_STATE_DISABLED; |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 420 | final int wifiState = mWifiStateTracker.getWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 422 | if (wifiState == eventualWifiState) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | return true; |
| 424 | } |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 425 | if (enable && isAirplaneModeOn() && !mAirplaneModeOverwridden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | |
| Irfan Sheriff | cd77037 | 2010-01-08 09:36:04 -0800 | [diff] [blame] | 429 | /** |
| 430 | * Multiple calls to unregisterReceiver() cause exception and a system crash. |
| 431 | * This can happen if a supplicant is lost (or firmware crash occurs) and user indicates |
| 432 | * disable wifi at the same time. |
| 433 | * Avoid doing a disable when the current Wifi state is UNKNOWN |
| 434 | * TODO: Handle driver load fail and supplicant lost as seperate states |
| 435 | */ |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 436 | if ((wifiState == WIFI_STATE_UNKNOWN) && !enable) { |
| Irfan Sheriff | cd77037 | 2010-01-08 09:36:04 -0800 | [diff] [blame] | 437 | return false; |
| 438 | } |
| 439 | |
| Irfan Sheriff | f91444c | 2010-03-24 12:11:00 -0700 | [diff] [blame] | 440 | /** |
| 441 | * Fail Wifi if AP is enabled |
| 442 | * TODO: Deprecate WIFI_STATE_UNKNOWN and rename it |
| 443 | * WIFI_STATE_FAILED |
| 444 | */ |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 445 | if ((mWifiApState == WIFI_AP_STATE_ENABLED) && enable) { |
| Irfan Sheriff | f91444c | 2010-03-24 12:11:00 -0700 | [diff] [blame] | 446 | setWifiEnabledState(WIFI_STATE_UNKNOWN, uid); |
| 447 | return false; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| Irfan Sheriff | f91444c | 2010-03-24 12:11:00 -0700 | [diff] [blame] | 450 | setWifiEnabledState(enable ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING, uid); |
| 451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | if (enable) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 453 | if (!mWifiStateTracker.loadDriver()) { |
| 454 | Slog.e(TAG, "Failed to load Wi-Fi driver."); |
| 455 | setWifiEnabledState(WIFI_STATE_UNKNOWN, uid); |
| 456 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 458 | if (!mWifiStateTracker.startSupplicant()) { |
| 459 | mWifiStateTracker.unloadDriver(); |
| 460 | Slog.e(TAG, "Failed to start supplicant daemon."); |
| 461 | setWifiEnabledState(WIFI_STATE_UNKNOWN, uid); |
| 462 | return false; |
| 463 | } |
| 464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | registerForBroadcasts(); |
| 466 | mWifiStateTracker.startEventLoop(); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | } else { |
| 469 | |
| 470 | mContext.unregisterReceiver(mReceiver); |
| 471 | // Remove notification (it will no-op if it isn't visible) |
| 472 | mWifiStateTracker.setNotificationVisible(false, 0, false, 0); |
| 473 | |
| 474 | boolean failedToStopSupplicantOrUnloadDriver = false; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 475 | |
| 476 | if (!mWifiStateTracker.stopSupplicant()) { |
| 477 | Slog.e(TAG, "Failed to stop supplicant daemon."); |
| 478 | setWifiEnabledState(WIFI_STATE_UNKNOWN, uid); |
| 479 | failedToStopSupplicantOrUnloadDriver = true; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Reset connections and disable interface |
| 484 | * before we unload the driver |
| 485 | */ |
| 486 | mWifiStateTracker.resetConnections(true); |
| 487 | |
| 488 | if (!mWifiStateTracker.unloadDriver()) { |
| 489 | Slog.e(TAG, "Failed to unload Wi-Fi driver."); |
| 490 | if (!failedToStopSupplicantOrUnloadDriver) { |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 491 | setWifiEnabledState(WIFI_STATE_UNKNOWN, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | failedToStopSupplicantOrUnloadDriver = true; |
| 493 | } |
| 494 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | if (failedToStopSupplicantOrUnloadDriver) { |
| 497 | return false; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // Success! |
| 502 | |
| 503 | if (persist) { |
| 504 | persistWifiEnabled(enable); |
| 505 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 506 | setWifiEnabledState(eventualWifiState, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | return true; |
| 508 | } |
| 509 | |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 510 | private void setWifiEnabledState(int wifiState, int uid) { |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 511 | final int previousWifiState = mWifiStateTracker.getWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 513 | long ident = Binder.clearCallingIdentity(); |
| 514 | try { |
| 515 | if (wifiState == WIFI_STATE_ENABLED) { |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 516 | mBatteryStats.noteWifiOn(uid); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 517 | } else if (wifiState == WIFI_STATE_DISABLED) { |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 518 | mBatteryStats.noteWifiOff(uid); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 519 | } |
| 520 | } catch (RemoteException e) { |
| 521 | } finally { |
| 522 | Binder.restoreCallingIdentity(ident); |
| 523 | } |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | // Update state |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 526 | mWifiStateTracker.setWifiState(wifiState); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | |
| 528 | // Broadcast |
| 529 | final Intent intent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 530 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 531 | intent.putExtra(WifiManager.EXTRA_WIFI_STATE, wifiState); |
| 532 | intent.putExtra(WifiManager.EXTRA_PREVIOUS_WIFI_STATE, previousWifiState); |
| 533 | mContext.sendStickyBroadcast(intent); |
| 534 | } |
| 535 | |
| 536 | private void enforceAccessPermission() { |
| 537 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE, |
| 538 | "WifiService"); |
| 539 | } |
| 540 | |
| 541 | private void enforceChangePermission() { |
| 542 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE, |
| 543 | "WifiService"); |
| 544 | |
| 545 | } |
| 546 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 547 | private void enforceMulticastChangePermission() { |
| 548 | mContext.enforceCallingOrSelfPermission( |
| 549 | android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, |
| 550 | "WifiService"); |
| 551 | } |
| 552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | /** |
| 554 | * see {@link WifiManager#getWifiState()} |
| 555 | * @return One of {@link WifiManager#WIFI_STATE_DISABLED}, |
| 556 | * {@link WifiManager#WIFI_STATE_DISABLING}, |
| 557 | * {@link WifiManager#WIFI_STATE_ENABLED}, |
| 558 | * {@link WifiManager#WIFI_STATE_ENABLING}, |
| 559 | * {@link WifiManager#WIFI_STATE_UNKNOWN} |
| 560 | */ |
| 561 | public int getWifiEnabledState() { |
| 562 | enforceAccessPermission(); |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 563 | return mWifiStateTracker.getWifiState(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
| 567 | * see {@link android.net.wifi.WifiManager#disconnect()} |
| 568 | * @return {@code true} if the operation succeeds |
| 569 | */ |
| 570 | public boolean disconnect() { |
| 571 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 572 | |
| 573 | return mWifiStateTracker.disconnect(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
| 577 | * see {@link android.net.wifi.WifiManager#reconnect()} |
| 578 | * @return {@code true} if the operation succeeds |
| 579 | */ |
| 580 | public boolean reconnect() { |
| 581 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 582 | |
| 583 | return mWifiStateTracker.reconnectCommand(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
| 587 | * see {@link android.net.wifi.WifiManager#reassociate()} |
| 588 | * @return {@code true} if the operation succeeds |
| 589 | */ |
| 590 | public boolean reassociate() { |
| 591 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 592 | |
| 593 | return mWifiStateTracker.reassociate(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 596 | /** |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 597 | * see {@link android.net.wifi.WifiManager#setWifiApEnabled(WifiConfiguration, boolean)} |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 598 | * @param wifiConfig SSID, security and channel details as |
| 599 | * part of WifiConfiguration |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 600 | * @param enabled, true to enable and false to disable |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 601 | * @return {@code true} if the start operation was |
| 602 | * started or is already in the queue. |
| 603 | */ |
| 604 | public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { |
| 605 | enforceChangePermission(); |
| 606 | if (mWifiHandler == null) return false; |
| 607 | |
| 608 | synchronized (mWifiHandler) { |
| 609 | |
| 610 | long ident = Binder.clearCallingIdentity(); |
| 611 | sWakeLock.acquire(); |
| 612 | Binder.restoreCallingIdentity(ident); |
| 613 | |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 614 | mLastApEnableUid = Binder.getCallingUid(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 615 | sendAccessPointMessage(enabled, wifiConfig, Binder.getCallingUid()); |
| 616 | } |
| 617 | |
| 618 | return true; |
| 619 | } |
| 620 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 621 | public WifiConfiguration getWifiApConfiguration() { |
| 622 | final ContentResolver cr = mContext.getContentResolver(); |
| 623 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 624 | int authType; |
| 625 | try { |
| 626 | wifiConfig.SSID = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_SSID); |
| 627 | if (wifiConfig.SSID == null) |
| 628 | return null; |
| 629 | authType = Settings.Secure.getInt(cr, Settings.Secure.WIFI_AP_SECURITY); |
| 630 | wifiConfig.allowedKeyManagement.set(authType); |
| 631 | wifiConfig.preSharedKey = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_PASSWD); |
| 632 | return wifiConfig; |
| 633 | } catch (Settings.SettingNotFoundException e) { |
| 634 | Slog.e(TAG,"AP settings not found, returning"); |
| 635 | return null; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | private void persistApConfiguration(WifiConfiguration wifiConfig) { |
| 640 | final ContentResolver cr = mContext.getContentResolver(); |
| 641 | boolean isWpa; |
| 642 | if (wifiConfig == null) |
| 643 | return; |
| 644 | Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_SSID, wifiConfig.SSID); |
| 645 | isWpa = wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK); |
| 646 | Settings.Secure.putInt(cr, |
| 647 | Settings.Secure.WIFI_AP_SECURITY, |
| 648 | isWpa ? KeyMgmt.WPA_PSK : KeyMgmt.NONE); |
| 649 | if (isWpa) |
| 650 | Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_PASSWD, wifiConfig.preSharedKey); |
| 651 | } |
| 652 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 653 | /** |
| 654 | * Enables/disables Wi-Fi AP synchronously. The driver is loaded |
| 655 | * and soft access point configured as a single operation. |
| 656 | * @param enable {@code true} to turn Wi-Fi on, {@code false} to turn it off. |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 657 | * @param uid The UID of the process making the request. |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 658 | * @param wifiConfig The WifiConfiguration for AP |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 659 | * @return {@code true} if the operation succeeds (or if the existing state |
| 660 | * is the same as the requested state) |
| 661 | */ |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 662 | private boolean setWifiApEnabledBlocking(boolean enable, |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 663 | int uid, WifiConfiguration wifiConfig) { |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 664 | final int eventualWifiApState = enable ? WIFI_AP_STATE_ENABLED : WIFI_AP_STATE_DISABLED; |
| 665 | |
| 666 | if (mWifiApState == eventualWifiApState) { |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 667 | /* Configuration changed on a running access point */ |
| 668 | if(enable && (wifiConfig != null)) { |
| 669 | try { |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 670 | nwService.setAccessPoint(wifiConfig, mWifiStateTracker.getInterfaceName(), |
| 671 | SOFTAP_IFACE); |
| Irfan Sheriff | afadc8b | 2010-06-11 14:43:14 -0700 | [diff] [blame] | 672 | persistApConfiguration(wifiConfig); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 673 | return true; |
| 674 | } catch(Exception e) { |
| 675 | Slog.e(TAG, "Exception in nwService during AP restart"); |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 676 | try { |
| 677 | nwService.stopAccessPoint(); |
| 678 | } catch (Exception ee) { |
| 679 | Slog.e(TAG, "Could not stop AP, :" + ee); |
| 680 | } |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 681 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD); |
| 682 | return false; |
| 683 | } |
| 684 | } else { |
| 685 | return true; |
| 686 | } |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 687 | } |
| 688 | |
| Irfan Sheriff | f91444c | 2010-03-24 12:11:00 -0700 | [diff] [blame] | 689 | /** |
| 690 | * Fail AP if Wifi is enabled |
| 691 | */ |
| 692 | if ((mWifiStateTracker.getWifiState() == WIFI_STATE_ENABLED) && enable) { |
| 693 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD); |
| 694 | return false; |
| 695 | } |
| 696 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 697 | setWifiApEnabledState(enable ? WIFI_AP_STATE_ENABLING : |
| 698 | WIFI_AP_STATE_DISABLING, uid, DriverAction.NO_DRIVER_UNLOAD); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 699 | |
| 700 | if (enable) { |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 701 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 702 | /* Use default config if there is no existing config */ |
| 703 | if (wifiConfig == null && ((wifiConfig = getWifiApConfiguration()) == null)) { |
| 704 | wifiConfig = new WifiConfiguration(); |
| 705 | wifiConfig.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default); |
| 706 | wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE); |
| 707 | } |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 708 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 709 | if (!mWifiStateTracker.loadDriver()) { |
| 710 | Slog.e(TAG, "Failed to load Wi-Fi driver for AP mode"); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 711 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 712 | return false; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | try { |
| Irfan Sheriff | c2f54c2 | 2010-03-18 14:02:22 -0700 | [diff] [blame] | 716 | nwService.startAccessPoint(wifiConfig, mWifiStateTracker.getInterfaceName(), |
| 717 | SOFTAP_IFACE); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 718 | } catch(Exception e) { |
| 719 | Slog.e(TAG, "Exception in startAccessPoint()"); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 720 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD); |
| 721 | return false; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| Irfan Sheriff | afadc8b | 2010-06-11 14:43:14 -0700 | [diff] [blame] | 724 | persistApConfiguration(wifiConfig); |
| 725 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 726 | } else { |
| 727 | |
| 728 | try { |
| 729 | nwService.stopAccessPoint(); |
| 730 | } catch(Exception e) { |
| 731 | Slog.e(TAG, "Exception in stopAccessPoint()"); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 732 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD); |
| 733 | return false; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 736 | if (!mWifiStateTracker.unloadDriver()) { |
| 737 | Slog.e(TAG, "Failed to unload Wi-Fi driver for AP mode"); |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 738 | setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 739 | return false; |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 743 | setWifiApEnabledState(eventualWifiApState, uid, DriverAction.NO_DRIVER_UNLOAD); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 744 | return true; |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * see {@link WifiManager#getWifiApState()} |
| 749 | * @return One of {@link WifiManager#WIFI_AP_STATE_DISABLED}, |
| 750 | * {@link WifiManager#WIFI_AP_STATE_DISABLING}, |
| 751 | * {@link WifiManager#WIFI_AP_STATE_ENABLED}, |
| 752 | * {@link WifiManager#WIFI_AP_STATE_ENABLING}, |
| 753 | * {@link WifiManager#WIFI_AP_STATE_FAILED} |
| 754 | */ |
| 755 | public int getWifiApEnabledState() { |
| 756 | enforceAccessPermission(); |
| 757 | return mWifiApState; |
| 758 | } |
| 759 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 760 | private void setWifiApEnabledState(int wifiAPState, int uid, DriverAction flag) { |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 761 | final int previousWifiApState = mWifiApState; |
| 762 | |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 763 | /** |
| 764 | * Unload the driver if going to a failed state |
| 765 | */ |
| 766 | if ((mWifiApState == WIFI_AP_STATE_FAILED) && (flag == DriverAction.DRIVER_UNLOAD)) { |
| 767 | mWifiStateTracker.unloadDriver(); |
| 768 | } |
| 769 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 770 | long ident = Binder.clearCallingIdentity(); |
| 771 | try { |
| 772 | if (wifiAPState == WIFI_AP_STATE_ENABLED) { |
| 773 | mBatteryStats.noteWifiOn(uid); |
| 774 | } else if (wifiAPState == WIFI_AP_STATE_DISABLED) { |
| 775 | mBatteryStats.noteWifiOff(uid); |
| 776 | } |
| 777 | } catch (RemoteException e) { |
| 778 | } finally { |
| 779 | Binder.restoreCallingIdentity(ident); |
| 780 | } |
| 781 | |
| 782 | // Update state |
| 783 | mWifiApState = wifiAPState; |
| 784 | |
| 785 | // Broadcast |
| 786 | final Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION); |
| 787 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 788 | intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, wifiAPState); |
| 789 | intent.putExtra(WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE, previousWifiApState); |
| 790 | mContext.sendStickyBroadcast(intent); |
| 791 | } |
| 792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | /** |
| 794 | * see {@link android.net.wifi.WifiManager#getConfiguredNetworks()} |
| 795 | * @return the list of configured networks |
| 796 | */ |
| 797 | public List<WifiConfiguration> getConfiguredNetworks() { |
| 798 | enforceAccessPermission(); |
| 799 | String listStr; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | /* |
| 802 | * We don't cache the list, because we want to allow |
| 803 | * for the possibility that the configuration file |
| 804 | * has been modified through some external means, |
| 805 | * such as the wpa_cli command line program. |
| 806 | */ |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 807 | listStr = mWifiStateTracker.listNetworks(); |
| 808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | List<WifiConfiguration> networks = |
| 810 | new ArrayList<WifiConfiguration>(); |
| 811 | if (listStr == null) |
| 812 | return networks; |
| 813 | |
| 814 | String[] lines = listStr.split("\n"); |
| 815 | // Skip the first line, which is a header |
| 816 | for (int i = 1; i < lines.length; i++) { |
| 817 | String[] result = lines[i].split("\t"); |
| 818 | // network-id | ssid | bssid | flags |
| 819 | WifiConfiguration config = new WifiConfiguration(); |
| 820 | try { |
| 821 | config.networkId = Integer.parseInt(result[0]); |
| 822 | } catch(NumberFormatException e) { |
| 823 | continue; |
| 824 | } |
| 825 | if (result.length > 3) { |
| 826 | if (result[3].indexOf("[CURRENT]") != -1) |
| 827 | config.status = WifiConfiguration.Status.CURRENT; |
| 828 | else if (result[3].indexOf("[DISABLED]") != -1) |
| 829 | config.status = WifiConfiguration.Status.DISABLED; |
| 830 | else |
| 831 | config.status = WifiConfiguration.Status.ENABLED; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 832 | } else { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | config.status = WifiConfiguration.Status.ENABLED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 835 | readNetworkVariables(config); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | networks.add(config); |
| 837 | } |
| 838 | |
| 839 | return networks; |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Read the variables from the supplicant daemon that are needed to |
| 844 | * fill in the WifiConfiguration object. |
| 845 | * <p/> |
| 846 | * The caller must hold the synchronization monitor. |
| 847 | * @param config the {@link WifiConfiguration} object to be filled in. |
| 848 | */ |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 849 | private void readNetworkVariables(WifiConfiguration config) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | |
| 851 | int netId = config.networkId; |
| 852 | if (netId < 0) |
| 853 | return; |
| 854 | |
| 855 | /* |
| 856 | * TODO: maybe should have a native method that takes an array of |
| 857 | * variable names and returns an array of values. But we'd still |
| 858 | * be doing a round trip to the supplicant daemon for each variable. |
| 859 | */ |
| 860 | String value; |
| 861 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 862 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.ssidVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | if (!TextUtils.isEmpty(value)) { |
| Chung-yih Wang | 047076d | 2010-05-15 11:03:30 +0800 | [diff] [blame] | 864 | config.SSID = value; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | } else { |
| 866 | config.SSID = null; |
| 867 | } |
| 868 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 869 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.bssidVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | if (!TextUtils.isEmpty(value)) { |
| 871 | config.BSSID = value; |
| 872 | } else { |
| 873 | config.BSSID = null; |
| 874 | } |
| 875 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 876 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.priorityVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | config.priority = -1; |
| 878 | if (!TextUtils.isEmpty(value)) { |
| 879 | try { |
| 880 | config.priority = Integer.parseInt(value); |
| 881 | } catch (NumberFormatException ignore) { |
| 882 | } |
| 883 | } |
| 884 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 885 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.hiddenSSIDVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | config.hiddenSSID = false; |
| 887 | if (!TextUtils.isEmpty(value)) { |
| 888 | try { |
| 889 | config.hiddenSSID = Integer.parseInt(value) != 0; |
| 890 | } catch (NumberFormatException ignore) { |
| 891 | } |
| 892 | } |
| 893 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 894 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.wepTxKeyIdxVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | config.wepTxKeyIndex = -1; |
| 896 | if (!TextUtils.isEmpty(value)) { |
| 897 | try { |
| 898 | config.wepTxKeyIndex = Integer.parseInt(value); |
| 899 | } catch (NumberFormatException ignore) { |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /* |
| 904 | * Get up to 4 WEP keys. Note that the actual keys are not passed back, |
| 905 | * just a "*" if the key is set, or the null string otherwise. |
| 906 | */ |
| 907 | for (int i = 0; i < 4; i++) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 908 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.wepKeyVarNames[i]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | if (!TextUtils.isEmpty(value)) { |
| 910 | config.wepKeys[i] = value; |
| 911 | } else { |
| 912 | config.wepKeys[i] = null; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | * Get the private shared key. Note that the actual keys are not passed back, |
| 918 | * just a "*" if the key is set, or the null string otherwise. |
| 919 | */ |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 920 | value = mWifiStateTracker.getNetworkVariable(netId, WifiConfiguration.pskVarName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | if (!TextUtils.isEmpty(value)) { |
| 922 | config.preSharedKey = value; |
| 923 | } else { |
| 924 | config.preSharedKey = null; |
| 925 | } |
| 926 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 927 | value = mWifiStateTracker.getNetworkVariable(config.networkId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | WifiConfiguration.Protocol.varName); |
| 929 | if (!TextUtils.isEmpty(value)) { |
| 930 | String vals[] = value.split(" "); |
| 931 | for (String val : vals) { |
| 932 | int index = |
| 933 | lookupString(val, WifiConfiguration.Protocol.strings); |
| 934 | if (0 <= index) { |
| 935 | config.allowedProtocols.set(index); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 940 | value = mWifiStateTracker.getNetworkVariable(config.networkId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | WifiConfiguration.KeyMgmt.varName); |
| 942 | if (!TextUtils.isEmpty(value)) { |
| 943 | String vals[] = value.split(" "); |
| 944 | for (String val : vals) { |
| 945 | int index = |
| 946 | lookupString(val, WifiConfiguration.KeyMgmt.strings); |
| 947 | if (0 <= index) { |
| 948 | config.allowedKeyManagement.set(index); |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 953 | value = mWifiStateTracker.getNetworkVariable(config.networkId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | WifiConfiguration.AuthAlgorithm.varName); |
| 955 | if (!TextUtils.isEmpty(value)) { |
| 956 | String vals[] = value.split(" "); |
| 957 | for (String val : vals) { |
| 958 | int index = |
| 959 | lookupString(val, WifiConfiguration.AuthAlgorithm.strings); |
| 960 | if (0 <= index) { |
| 961 | config.allowedAuthAlgorithms.set(index); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 966 | value = mWifiStateTracker.getNetworkVariable(config.networkId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | WifiConfiguration.PairwiseCipher.varName); |
| 968 | if (!TextUtils.isEmpty(value)) { |
| 969 | String vals[] = value.split(" "); |
| 970 | for (String val : vals) { |
| 971 | int index = |
| 972 | lookupString(val, WifiConfiguration.PairwiseCipher.strings); |
| 973 | if (0 <= index) { |
| 974 | config.allowedPairwiseCiphers.set(index); |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 979 | value = mWifiStateTracker.getNetworkVariable(config.networkId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | WifiConfiguration.GroupCipher.varName); |
| 981 | if (!TextUtils.isEmpty(value)) { |
| 982 | String vals[] = value.split(" "); |
| 983 | for (String val : vals) { |
| 984 | int index = |
| 985 | lookupString(val, WifiConfiguration.GroupCipher.strings); |
| 986 | if (0 <= index) { |
| 987 | config.allowedGroupCiphers.set(index); |
| 988 | } |
| 989 | } |
| 990 | } |
| Chung-yih Wang | 4337476 | 2009-09-16 14:28:42 +0800 | [diff] [blame] | 991 | |
| 992 | for (WifiConfiguration.EnterpriseField field : |
| 993 | config.enterpriseFields) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 994 | value = mWifiStateTracker.getNetworkVariable(netId, |
| Chung-yih Wang | 4337476 | 2009-09-16 14:28:42 +0800 | [diff] [blame] | 995 | field.varName()); |
| 996 | if (!TextUtils.isEmpty(value)) { |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 997 | if (field != config.eap) value = removeDoubleQuotes(value); |
| Chung-yih Wang | 4337476 | 2009-09-16 14:28:42 +0800 | [diff] [blame] | 998 | field.setValue(value); |
| 999 | } |
| 1000 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 1003 | private static String removeDoubleQuotes(String string) { |
| 1004 | if (string.length() <= 2) return ""; |
| 1005 | return string.substring(1, string.length() - 1); |
| 1006 | } |
| 1007 | |
| 1008 | private static String convertToQuotedString(String string) { |
| 1009 | return "\"" + string + "\""; |
| 1010 | } |
| 1011 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | /** |
| 1013 | * see {@link android.net.wifi.WifiManager#addOrUpdateNetwork(WifiConfiguration)} |
| 1014 | * @return the supplicant-assigned identifier for the new or updated |
| 1015 | * network if the operation succeeds, or {@code -1} if it fails |
| 1016 | */ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1017 | public int addOrUpdateNetwork(WifiConfiguration config) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | /* |
| 1021 | * If the supplied networkId is -1, we create a new empty |
| 1022 | * network configuration. Otherwise, the networkId should |
| 1023 | * refer to an existing configuration. |
| 1024 | */ |
| 1025 | int netId = config.networkId; |
| 1026 | boolean newNetwork = netId == -1; |
| Irfan Sheriff | 44113ba3 | 2010-03-16 14:54:07 -0700 | [diff] [blame] | 1027 | boolean doReconfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | // networkId of -1 means we want to create a new network |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1029 | synchronized (mWifiStateTracker) { |
| 1030 | if (newNetwork) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1031 | netId = mWifiStateTracker.addNetwork(); |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1032 | if (netId < 0) { |
| 1033 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1034 | Slog.d(TAG, "Failed to add a network!"); |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1035 | } |
| 1036 | return -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1038 | doReconfig = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1040 | mNeedReconfig = mNeedReconfig || doReconfig; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1041 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1043 | setVariables: { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | /* |
| 1045 | * Note that if a networkId for a non-existent network |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1046 | * was supplied, then the first setNetworkVariable() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | * will fail, so we don't bother to make a separate check |
| 1048 | * for the validity of the ID up front. |
| 1049 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | if (config.SSID != null && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1051 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1052 | netId, |
| 1053 | WifiConfiguration.ssidVarName, |
| Chung-yih Wang | 047076d | 2010-05-15 11:03:30 +0800 | [diff] [blame] | 1054 | config.SSID)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1056 | Slog.d(TAG, "failed to set SSID: "+config.SSID); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | } |
| 1058 | break setVariables; |
| 1059 | } |
| 1060 | |
| 1061 | if (config.BSSID != null && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1062 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1063 | netId, |
| 1064 | WifiConfiguration.bssidVarName, |
| 1065 | config.BSSID)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1067 | Slog.d(TAG, "failed to set BSSID: "+config.BSSID); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | } |
| 1069 | break setVariables; |
| 1070 | } |
| 1071 | |
| 1072 | String allowedKeyManagementString = |
| 1073 | makeString(config.allowedKeyManagement, WifiConfiguration.KeyMgmt.strings); |
| 1074 | if (config.allowedKeyManagement.cardinality() != 0 && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1075 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1076 | netId, |
| 1077 | WifiConfiguration.KeyMgmt.varName, |
| 1078 | allowedKeyManagementString)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1080 | Slog.d(TAG, "failed to set key_mgmt: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1081 | allowedKeyManagementString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | } |
| 1083 | break setVariables; |
| 1084 | } |
| 1085 | |
| 1086 | String allowedProtocolsString = |
| 1087 | makeString(config.allowedProtocols, WifiConfiguration.Protocol.strings); |
| 1088 | if (config.allowedProtocols.cardinality() != 0 && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1089 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1090 | netId, |
| 1091 | WifiConfiguration.Protocol.varName, |
| 1092 | allowedProtocolsString)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1094 | Slog.d(TAG, "failed to set proto: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1095 | allowedProtocolsString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | } |
| 1097 | break setVariables; |
| 1098 | } |
| 1099 | |
| 1100 | String allowedAuthAlgorithmsString = |
| 1101 | makeString(config.allowedAuthAlgorithms, WifiConfiguration.AuthAlgorithm.strings); |
| 1102 | if (config.allowedAuthAlgorithms.cardinality() != 0 && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1103 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1104 | netId, |
| 1105 | WifiConfiguration.AuthAlgorithm.varName, |
| 1106 | allowedAuthAlgorithmsString)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1108 | Slog.d(TAG, "failed to set auth_alg: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1109 | allowedAuthAlgorithmsString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | } |
| 1111 | break setVariables; |
| 1112 | } |
| 1113 | |
| 1114 | String allowedPairwiseCiphersString = |
| 1115 | makeString(config.allowedPairwiseCiphers, WifiConfiguration.PairwiseCipher.strings); |
| 1116 | if (config.allowedPairwiseCiphers.cardinality() != 0 && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1117 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1118 | netId, |
| 1119 | WifiConfiguration.PairwiseCipher.varName, |
| 1120 | allowedPairwiseCiphersString)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1122 | Slog.d(TAG, "failed to set pairwise: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1123 | allowedPairwiseCiphersString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | } |
| 1125 | break setVariables; |
| 1126 | } |
| 1127 | |
| 1128 | String allowedGroupCiphersString = |
| 1129 | makeString(config.allowedGroupCiphers, WifiConfiguration.GroupCipher.strings); |
| 1130 | if (config.allowedGroupCiphers.cardinality() != 0 && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1131 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1132 | netId, |
| 1133 | WifiConfiguration.GroupCipher.varName, |
| 1134 | allowedGroupCiphersString)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1136 | Slog.d(TAG, "failed to set group: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1137 | allowedGroupCiphersString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | } |
| 1139 | break setVariables; |
| 1140 | } |
| 1141 | |
| 1142 | // Prevent client screw-up by passing in a WifiConfiguration we gave it |
| 1143 | // by preventing "*" as a key. |
| 1144 | if (config.preSharedKey != null && !config.preSharedKey.equals("*") && |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1145 | !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1146 | netId, |
| 1147 | WifiConfiguration.pskVarName, |
| 1148 | config.preSharedKey)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1150 | Slog.d(TAG, "failed to set psk: "+config.preSharedKey); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | } |
| 1152 | break setVariables; |
| 1153 | } |
| 1154 | |
| 1155 | boolean hasSetKey = false; |
| 1156 | if (config.wepKeys != null) { |
| 1157 | for (int i = 0; i < config.wepKeys.length; i++) { |
| 1158 | // Prevent client screw-up by passing in a WifiConfiguration we gave it |
| 1159 | // by preventing "*" as a key. |
| 1160 | if (config.wepKeys[i] != null && !config.wepKeys[i].equals("*")) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1161 | if (!mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1162 | netId, |
| 1163 | WifiConfiguration.wepKeyVarNames[i], |
| 1164 | config.wepKeys[i])) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1166 | Slog.d(TAG, |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1167 | "failed to set wep_key"+i+": " + |
| 1168 | config.wepKeys[i]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | } |
| 1170 | break setVariables; |
| 1171 | } |
| 1172 | hasSetKey = true; |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | if (hasSetKey) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1178 | if (!mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1179 | netId, |
| 1180 | WifiConfiguration.wepTxKeyIdxVarName, |
| 1181 | Integer.toString(config.wepTxKeyIndex))) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1183 | Slog.d(TAG, |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1184 | "failed to set wep_tx_keyidx: "+ |
| 1185 | config.wepTxKeyIndex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | } |
| 1187 | break setVariables; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1191 | if (!mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1192 | netId, |
| 1193 | WifiConfiguration.priorityVarName, |
| 1194 | Integer.toString(config.priority))) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1196 | Slog.d(TAG, config.SSID + ": failed to set priority: " |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1197 | +config.priority); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } |
| 1199 | break setVariables; |
| 1200 | } |
| 1201 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1202 | if (config.hiddenSSID && !mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1203 | netId, |
| 1204 | WifiConfiguration.hiddenSSIDVarName, |
| 1205 | Integer.toString(config.hiddenSSID ? 1 : 0))) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1207 | Slog.d(TAG, config.SSID + ": failed to set hiddenSSID: "+ |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1208 | config.hiddenSSID); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | } |
| 1210 | break setVariables; |
| 1211 | } |
| 1212 | |
| Chung-yih Wang | 4337476 | 2009-09-16 14:28:42 +0800 | [diff] [blame] | 1213 | for (WifiConfiguration.EnterpriseField field |
| 1214 | : config.enterpriseFields) { |
| 1215 | String varName = field.varName(); |
| 1216 | String value = field.value(); |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 1217 | if (value != null) { |
| 1218 | if (field != config.eap) { |
| Chia-chi Yeh | 784d53e | 2010-01-29 16:26:28 +0800 | [diff] [blame] | 1219 | value = (value.length() == 0) ? "NULL" : convertToQuotedString(value); |
| Chung-yih Wang | 4337476 | 2009-09-16 14:28:42 +0800 | [diff] [blame] | 1220 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1221 | if (!mWifiStateTracker.setNetworkVariable( |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1222 | netId, |
| 1223 | varName, |
| 1224 | value)) { |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 1225 | if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1226 | Slog.d(TAG, config.SSID + ": failed to set " + varName + |
| Irfan Sheriff | 7aac554 | 2009-12-22 21:42:17 -0800 | [diff] [blame] | 1227 | ": " + value); |
| Chung-yih Wang | a8d1594 | 2009-10-09 11:01:49 +0800 | [diff] [blame] | 1228 | } |
| 1229 | break setVariables; |
| 1230 | } |
| Chung-yih Wang | 5069cc7 | 2009-06-03 17:33:47 +0800 | [diff] [blame] | 1231 | } |
| Chung-yih Wang | 5069cc7 | 2009-06-03 17:33:47 +0800 | [diff] [blame] | 1232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | return netId; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1234 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1236 | /* |
| 1237 | * For an update, if one of the setNetworkVariable operations fails, |
| 1238 | * we might want to roll back all the changes already made. But the |
| 1239 | * chances are that if anything is going to go wrong, it'll happen |
| 1240 | * the first time we try to set one of the variables. |
| 1241 | */ |
| 1242 | if (newNetwork) { |
| 1243 | removeNetwork(netId); |
| 1244 | if (DBG) { |
| 1245 | Slog.d(TAG, |
| 1246 | "Failed to set a network variable, removed network: " |
| 1247 | + netId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | } |
| 1249 | } |
| 1250 | return -1; |
| 1251 | } |
| 1252 | |
| 1253 | private static String makeString(BitSet set, String[] strings) { |
| 1254 | StringBuffer buf = new StringBuffer(); |
| 1255 | int nextSetBit = -1; |
| 1256 | |
| 1257 | /* Make sure all set bits are in [0, strings.length) to avoid |
| 1258 | * going out of bounds on strings. (Shouldn't happen, but...) */ |
| 1259 | set = set.get(0, strings.length); |
| 1260 | |
| 1261 | while ((nextSetBit = set.nextSetBit(nextSetBit + 1)) != -1) { |
| 1262 | buf.append(strings[nextSetBit].replace('_', '-')).append(' '); |
| 1263 | } |
| 1264 | |
| 1265 | // remove trailing space |
| 1266 | if (set.cardinality() > 0) { |
| 1267 | buf.setLength(buf.length() - 1); |
| 1268 | } |
| 1269 | |
| 1270 | return buf.toString(); |
| 1271 | } |
| 1272 | |
| 1273 | private static int lookupString(String string, String[] strings) { |
| 1274 | int size = strings.length; |
| 1275 | |
| 1276 | string = string.replace('-', '_'); |
| 1277 | |
| 1278 | for (int i = 0; i < size; i++) |
| 1279 | if (string.equals(strings[i])) |
| 1280 | return i; |
| 1281 | |
| 1282 | if (DBG) { |
| 1283 | // if we ever get here, we should probably add the |
| 1284 | // value to WifiConfiguration to reflect that it's |
| 1285 | // supported by the WPA supplicant |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1286 | Slog.w(TAG, "Failed to look-up a string: " + string); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | return -1; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * See {@link android.net.wifi.WifiManager#removeNetwork(int)} |
| 1294 | * @param netId the integer that identifies the network configuration |
| 1295 | * to the supplicant |
| 1296 | * @return {@code true} if the operation succeeded |
| 1297 | */ |
| 1298 | public boolean removeNetwork(int netId) { |
| 1299 | enforceChangePermission(); |
| 1300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | return mWifiStateTracker.removeNetwork(netId); |
| 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * See {@link android.net.wifi.WifiManager#enableNetwork(int, boolean)} |
| 1306 | * @param netId the integer that identifies the network configuration |
| 1307 | * to the supplicant |
| 1308 | * @param disableOthers if true, disable all other networks. |
| 1309 | * @return {@code true} if the operation succeeded |
| 1310 | */ |
| 1311 | public boolean enableNetwork(int netId, boolean disableOthers) { |
| 1312 | enforceChangePermission(); |
| 1313 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1314 | String ifname = mWifiStateTracker.getInterfaceName(); |
| 1315 | NetworkUtils.enableInterface(ifname); |
| 1316 | boolean result = mWifiStateTracker.enableNetwork(netId, disableOthers); |
| 1317 | if (!result) { |
| 1318 | NetworkUtils.disableInterface(ifname); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | } |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1320 | return result; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * See {@link android.net.wifi.WifiManager#disableNetwork(int)} |
| 1325 | * @param netId the integer that identifies the network configuration |
| 1326 | * to the supplicant |
| 1327 | * @return {@code true} if the operation succeeded |
| 1328 | */ |
| 1329 | public boolean disableNetwork(int netId) { |
| 1330 | enforceChangePermission(); |
| 1331 | |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1332 | return mWifiStateTracker.disableNetwork(netId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | /** |
| 1336 | * See {@link android.net.wifi.WifiManager#getConnectionInfo()} |
| 1337 | * @return the Wi-Fi information, contained in {@link WifiInfo}. |
| 1338 | */ |
| 1339 | public WifiInfo getConnectionInfo() { |
| 1340 | enforceAccessPermission(); |
| 1341 | /* |
| 1342 | * Make sure we have the latest information, by sending |
| 1343 | * a status request to the supplicant. |
| 1344 | */ |
| 1345 | return mWifiStateTracker.requestConnectionInfo(); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * Return the results of the most recent access point scan, in the form of |
| 1350 | * a list of {@link ScanResult} objects. |
| 1351 | * @return the list of results |
| 1352 | */ |
| 1353 | public List<ScanResult> getScanResults() { |
| 1354 | enforceAccessPermission(); |
| 1355 | String reply; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1356 | |
| 1357 | reply = mWifiStateTracker.scanResults(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | if (reply == null) { |
| 1359 | return null; |
| 1360 | } |
| 1361 | |
| 1362 | List<ScanResult> scanList = new ArrayList<ScanResult>(); |
| 1363 | |
| 1364 | int lineCount = 0; |
| 1365 | |
| 1366 | int replyLen = reply.length(); |
| 1367 | // Parse the result string, keeping in mind that the last line does |
| 1368 | // not end with a newline. |
| 1369 | for (int lineBeg = 0, lineEnd = 0; lineEnd <= replyLen; ++lineEnd) { |
| 1370 | if (lineEnd == replyLen || reply.charAt(lineEnd) == '\n') { |
| 1371 | ++lineCount; |
| 1372 | /* |
| 1373 | * Skip the first line, which is a header |
| 1374 | */ |
| 1375 | if (lineCount == 1) { |
| 1376 | lineBeg = lineEnd + 1; |
| 1377 | continue; |
| 1378 | } |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1379 | if (lineEnd > lineBeg) { |
| 1380 | String line = reply.substring(lineBeg, lineEnd); |
| 1381 | ScanResult scanResult = parseScanResult(line); |
| 1382 | if (scanResult != null) { |
| 1383 | scanList.add(scanResult); |
| 1384 | } else if (DBG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1385 | Slog.w(TAG, "misformatted scan result for: " + line); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | lineBeg = lineEnd + 1; |
| 1389 | } |
| 1390 | } |
| 1391 | mWifiStateTracker.setScanResultsList(scanList); |
| 1392 | return scanList; |
| 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * Parse the scan result line passed to us by wpa_supplicant (helper). |
| 1397 | * @param line the line to parse |
| 1398 | * @return the {@link ScanResult} object |
| 1399 | */ |
| 1400 | private ScanResult parseScanResult(String line) { |
| 1401 | ScanResult scanResult = null; |
| 1402 | if (line != null) { |
| 1403 | /* |
| 1404 | * Cache implementation (LinkedHashMap) is not synchronized, thus, |
| 1405 | * must synchronized here! |
| 1406 | */ |
| 1407 | synchronized (mScanResultCache) { |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1408 | String[] result = scanResultPattern.split(line); |
| 1409 | if (3 <= result.length && result.length <= 5) { |
| 1410 | String bssid = result[0]; |
| 1411 | // bssid | frequency | level | flags | ssid |
| 1412 | int frequency; |
| 1413 | int level; |
| 1414 | try { |
| 1415 | frequency = Integer.parseInt(result[1]); |
| 1416 | level = Integer.parseInt(result[2]); |
| 1417 | /* some implementations avoid negative values by adding 256 |
| 1418 | * so we need to adjust for that here. |
| 1419 | */ |
| 1420 | if (level > 0) level -= 256; |
| 1421 | } catch (NumberFormatException e) { |
| 1422 | frequency = 0; |
| 1423 | level = 0; |
| 1424 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | |
| Mike Lockwood | 1a64505 | 2009-06-25 13:01:12 -0400 | [diff] [blame] | 1426 | /* |
| 1427 | * The formatting of the results returned by |
| 1428 | * wpa_supplicant is intended to make the fields |
| 1429 | * line up nicely when printed, |
| 1430 | * not to make them easy to parse. So we have to |
| 1431 | * apply some heuristics to figure out which field |
| 1432 | * is the SSID and which field is the flags. |
| 1433 | */ |
| 1434 | String ssid; |
| 1435 | String flags; |
| 1436 | if (result.length == 4) { |
| 1437 | if (result[3].charAt(0) == '[') { |
| 1438 | flags = result[3]; |
| 1439 | ssid = ""; |
| 1440 | } else { |
| 1441 | flags = ""; |
| 1442 | ssid = result[3]; |
| 1443 | } |
| 1444 | } else if (result.length == 5) { |
| 1445 | flags = result[3]; |
| 1446 | ssid = result[4]; |
| 1447 | } else { |
| 1448 | // Here, we must have 3 fields: no flags and ssid |
| 1449 | // set |
| 1450 | flags = ""; |
| 1451 | ssid = ""; |
| 1452 | } |
| 1453 | |
| Mike Lockwood | 00717e2 | 2009-08-17 10:09:36 -0400 | [diff] [blame] | 1454 | // bssid + ssid is the hash key |
| 1455 | String key = bssid + ssid; |
| 1456 | scanResult = mScanResultCache.get(key); |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1457 | if (scanResult != null) { |
| 1458 | scanResult.level = level; |
| Mike Lockwood | 1a64505 | 2009-06-25 13:01:12 -0400 | [diff] [blame] | 1459 | scanResult.SSID = ssid; |
| 1460 | scanResult.capabilities = flags; |
| 1461 | scanResult.frequency = frequency; |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1462 | } else { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | // Do not add scan results that have no SSID set |
| 1464 | if (0 < ssid.trim().length()) { |
| 1465 | scanResult = |
| 1466 | new ScanResult( |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1467 | ssid, bssid, flags, level, frequency); |
| Mike Lockwood | 00717e2 | 2009-08-17 10:09:36 -0400 | [diff] [blame] | 1468 | mScanResultCache.put(key, scanResult); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | } |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1471 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1472 | Slog.w(TAG, "Misformatted scan result text with " + |
| Mike Lockwood | b30475e | 2009-04-21 13:55:07 -0700 | [diff] [blame] | 1473 | result.length + " fields: " + line); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | return scanResult; |
| 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * Parse the "flags" field passed back in a scan result by wpa_supplicant, |
| 1483 | * and construct a {@code WifiConfiguration} that describes the encryption, |
| 1484 | * key management, and authenticaion capabilities of the access point. |
| 1485 | * @param flags the string returned by wpa_supplicant |
| 1486 | * @return the {@link WifiConfiguration} object, filled in |
| 1487 | */ |
| 1488 | WifiConfiguration parseScanFlags(String flags) { |
| 1489 | WifiConfiguration config = new WifiConfiguration(); |
| 1490 | |
| 1491 | if (flags.length() == 0) { |
| 1492 | config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); |
| 1493 | } |
| 1494 | // ... to be implemented |
| 1495 | return config; |
| 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * Tell the supplicant to persist the current list of configured networks. |
| 1500 | * @return {@code true} if the operation succeeded |
| 1501 | */ |
| 1502 | public boolean saveConfiguration() { |
| 1503 | boolean result; |
| 1504 | enforceChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | synchronized (mWifiStateTracker) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1507 | result = mWifiStateTracker.saveConfig(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | if (result && mNeedReconfig) { |
| 1509 | mNeedReconfig = false; |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1510 | result = mWifiStateTracker.reloadConfig(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | |
| 1512 | if (result) { |
| 1513 | Intent intent = new Intent(WifiManager.NETWORK_IDS_CHANGED_ACTION); |
| 1514 | mContext.sendBroadcast(intent); |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| Amith Yamasani | 47873e5 | 2009-07-02 12:05:32 -0700 | [diff] [blame] | 1518 | // Inform the backup manager about a data change |
| 1519 | IBackupManager ibm = IBackupManager.Stub.asInterface( |
| 1520 | ServiceManager.getService(Context.BACKUP_SERVICE)); |
| 1521 | if (ibm != null) { |
| 1522 | try { |
| 1523 | ibm.dataChanged("com.android.providers.settings"); |
| 1524 | } catch (Exception e) { |
| 1525 | // Try again later |
| 1526 | } |
| 1527 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | return result; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Set the number of radio frequency channels that are allowed to be used |
| 1533 | * in the current regulatory domain. This method should be used only |
| 1534 | * if the correct number of channels cannot be determined automatically |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1535 | * for some reason. If the operation is successful, the new value may be |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | * persisted as a Secure setting. |
| 1537 | * @param numChannels the number of allowed channels. Must be greater than 0 |
| 1538 | * and less than or equal to 16. |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1539 | * @param persist {@code true} if the setting should be remembered. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g., |
| 1541 | * {@code numChannels} is outside the valid range. |
| 1542 | */ |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1543 | public boolean setNumAllowedChannels(int numChannels, boolean persist) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1544 | Slog.i(TAG, "WifiService trying to setNumAllowed to "+numChannels+ |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1545 | " with persist set to "+persist); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1546 | enforceChangePermission(); |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 1547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | /* |
| 1549 | * Validate the argument. We'd like to let the Wi-Fi driver do this, |
| 1550 | * but if Wi-Fi isn't currently enabled, that's not possible, and |
| 1551 | * we want to persist the setting anyway,so that it will take |
| 1552 | * effect when Wi-Fi does become enabled. |
| 1553 | */ |
| 1554 | boolean found = false; |
| 1555 | for (int validChan : sValidRegulatoryChannelCounts) { |
| 1556 | if (validChan == numChannels) { |
| 1557 | found = true; |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | if (!found) { |
| 1562 | return false; |
| 1563 | } |
| 1564 | |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 1565 | if (mWifiHandler == null) return false; |
| 1566 | |
| 1567 | Message.obtain(mWifiHandler, |
| 1568 | MESSAGE_SET_CHANNELS, numChannels, (persist ? 1 : 0)).sendToTarget(); |
| 1569 | |
| 1570 | return true; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * sets the number of allowed radio frequency channels synchronously |
| 1575 | * @param numChannels the number of allowed channels. Must be greater than 0 |
| 1576 | * and less than or equal to 16. |
| 1577 | * @param persist {@code true} if the setting should be remembered. |
| 1578 | * @return {@code true} if the operation succeeds, {@code false} otherwise |
| 1579 | */ |
| 1580 | private boolean setNumAllowedChannelsBlocking(int numChannels, boolean persist) { |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1581 | if (persist) { |
| 1582 | Settings.Secure.putInt(mContext.getContentResolver(), |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 1583 | Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS, |
| 1584 | numChannels); |
| Robert Greenwalt | b5010cc | 2009-05-21 15:11:40 -0700 | [diff] [blame] | 1585 | } |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 1586 | return mWifiStateTracker.setNumAllowedChannels(numChannels); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * Return the number of frequency channels that are allowed |
| 1591 | * to be used in the current regulatory domain. |
| 1592 | * @return the number of allowed channels, or {@code -1} if an error occurs |
| 1593 | */ |
| 1594 | public int getNumAllowedChannels() { |
| 1595 | int numChannels; |
| 1596 | |
| 1597 | enforceAccessPermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 1598 | |
| 1599 | /* |
| 1600 | * If we can't get the value from the driver (e.g., because |
| 1601 | * Wi-Fi is not currently enabled), get the value from |
| 1602 | * Settings. |
| 1603 | */ |
| 1604 | numChannels = mWifiStateTracker.getNumAllowedChannels(); |
| 1605 | if (numChannels < 0) { |
| 1606 | numChannels = Settings.Secure.getInt(mContext.getContentResolver(), |
| 1607 | Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS, |
| 1608 | -1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } |
| 1610 | return numChannels; |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * Return the list of valid values for the number of allowed radio channels |
| 1615 | * for various regulatory domains. |
| 1616 | * @return the list of channel counts |
| 1617 | */ |
| 1618 | public int[] getValidChannelCounts() { |
| 1619 | enforceAccessPermission(); |
| 1620 | return sValidRegulatoryChannelCounts; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Return the DHCP-assigned addresses from the last successful DHCP request, |
| 1625 | * if any. |
| 1626 | * @return the DHCP information |
| 1627 | */ |
| 1628 | public DhcpInfo getDhcpInfo() { |
| 1629 | enforceAccessPermission(); |
| 1630 | return mWifiStateTracker.getDhcpInfo(); |
| 1631 | } |
| 1632 | |
| 1633 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1634 | @Override |
| 1635 | public void onReceive(Context context, Intent intent) { |
| 1636 | String action = intent.getAction(); |
| 1637 | |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 1638 | long idleMillis = |
| 1639 | Settings.Secure.getLong(mContext.getContentResolver(), |
| 1640 | Settings.Secure.WIFI_IDLE_MS, DEFAULT_IDLE_MILLIS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | int stayAwakeConditions = |
| Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 1642 | Settings.System.getInt(mContext.getContentResolver(), |
| 1643 | Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | if (action.equals(Intent.ACTION_SCREEN_ON)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1645 | Slog.d(TAG, "ACTION_SCREEN_ON"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | mAlarmManager.cancel(mIdleIntent); |
| 1647 | mDeviceIdle = false; |
| 1648 | mScreenOff = false; |
| Mike Lockwood | f32be16 | 2009-07-14 17:44:37 -0400 | [diff] [blame] | 1649 | mWifiStateTracker.enableRssiPolling(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1651 | Slog.d(TAG, "ACTION_SCREEN_OFF"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | mScreenOff = true; |
| Mike Lockwood | f32be16 | 2009-07-14 17:44:37 -0400 | [diff] [blame] | 1653 | mWifiStateTracker.enableRssiPolling(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | /* |
| 1655 | * Set a timer to put Wi-Fi to sleep, but only if the screen is off |
| 1656 | * AND the "stay on while plugged in" setting doesn't match the |
| 1657 | * current power conditions (i.e, not plugged in, plugged in to USB, |
| 1658 | * or plugged in to AC). |
| 1659 | */ |
| 1660 | if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) { |
| San Mehat | fa6c711 | 2009-07-07 09:34:44 -0700 | [diff] [blame] | 1661 | WifiInfo info = mWifiStateTracker.requestConnectionInfo(); |
| 1662 | if (info.getSupplicantState() != SupplicantState.COMPLETED) { |
| Robert Greenwalt | 84612ea6 | 2009-09-30 09:04:22 -0700 | [diff] [blame] | 1663 | // we used to go to sleep immediately, but this caused some race conditions |
| 1664 | // we don't have time to track down for this release. Delay instead, but not |
| 1665 | // as long as we would if connected (below) |
| 1666 | // TODO - fix the race conditions and switch back to the immediate turn-off |
| 1667 | long triggerTime = System.currentTimeMillis() + (2*60*1000); // 2 min |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1668 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for 120,000 ms"); |
| Robert Greenwalt | 84612ea6 | 2009-09-30 09:04:22 -0700 | [diff] [blame] | 1669 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| 1670 | // // do not keep Wifi awake when screen is off if Wifi is not associated |
| 1671 | // mDeviceIdle = true; |
| 1672 | // updateWifiState(); |
| Mike Lockwood | d9c32bc | 2009-05-18 14:14:15 -0400 | [diff] [blame] | 1673 | } else { |
| 1674 | long triggerTime = System.currentTimeMillis() + idleMillis; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1675 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms"); |
| Mike Lockwood | d9c32bc | 2009-05-18 14:14:15 -0400 | [diff] [blame] | 1676 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| 1677 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | } |
| 1679 | /* we can return now -- there's nothing to do until we get the idle intent back */ |
| 1680 | return; |
| 1681 | } else if (action.equals(ACTION_DEVICE_IDLE)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1682 | Slog.d(TAG, "got ACTION_DEVICE_IDLE"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | mDeviceIdle = true; |
| 1684 | } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
| 1685 | /* |
| 1686 | * Set a timer to put Wi-Fi to sleep, but only if the screen is off |
| 1687 | * AND we are transitioning from a state in which the device was supposed |
| 1688 | * to stay awake to a state in which it is not supposed to stay awake. |
| 1689 | * If "stay awake" state is not changing, we do nothing, to avoid resetting |
| 1690 | * the already-set timer. |
| 1691 | */ |
| 1692 | int pluggedType = intent.getIntExtra("plugged", 0); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1693 | Slog.d(TAG, "ACTION_BATTERY_CHANGED pluggedType: " + pluggedType); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) && |
| 1695 | !shouldWifiStayAwake(stayAwakeConditions, pluggedType)) { |
| 1696 | long triggerTime = System.currentTimeMillis() + idleMillis; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1697 | Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); |
| 1699 | mPluggedType = pluggedType; |
| 1700 | return; |
| 1701 | } |
| 1702 | mPluggedType = pluggedType; |
| Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1703 | } else if (action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED)) { |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 1704 | BluetoothA2dp a2dp = new BluetoothA2dp(mContext); |
| 1705 | Set<BluetoothDevice> sinks = a2dp.getConnectedSinks(); |
| 1706 | boolean isBluetoothPlaying = false; |
| 1707 | for (BluetoothDevice sink : sinks) { |
| 1708 | if (a2dp.getSinkState(sink) == BluetoothA2dp.STATE_PLAYING) { |
| 1709 | isBluetoothPlaying = true; |
| 1710 | } |
| 1711 | } |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1712 | mWifiStateTracker.setBluetoothScanMode(isBluetoothPlaying); |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 1713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | } else { |
| 1715 | return; |
| 1716 | } |
| 1717 | |
| 1718 | updateWifiState(); |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * Determines whether the Wi-Fi chipset should stay awake or be put to |
| 1723 | * sleep. Looks at the setting for the sleep policy and the current |
| 1724 | * conditions. |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 1725 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | * @see #shouldDeviceStayAwake(int, int) |
| 1727 | */ |
| 1728 | private boolean shouldWifiStayAwake(int stayAwakeConditions, int pluggedType) { |
| 1729 | int wifiSleepPolicy = Settings.System.getInt(mContext.getContentResolver(), |
| 1730 | Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_DEFAULT); |
| 1731 | |
| 1732 | if (wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER) { |
| 1733 | // Never sleep |
| 1734 | return true; |
| 1735 | } else if ((wifiSleepPolicy == Settings.System.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED) && |
| 1736 | (pluggedType != 0)) { |
| 1737 | // Never sleep while plugged, and we're plugged |
| 1738 | return true; |
| 1739 | } else { |
| 1740 | // Default |
| 1741 | return shouldDeviceStayAwake(stayAwakeConditions, pluggedType); |
| 1742 | } |
| 1743 | } |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 1744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1745 | /** |
| 1746 | * Determine whether the bit value corresponding to {@code pluggedType} is set in |
| 1747 | * the bit string {@code stayAwakeConditions}. Because a {@code pluggedType} value |
| 1748 | * of {@code 0} isn't really a plugged type, but rather an indication that the |
| 1749 | * device isn't plugged in at all, there is no bit value corresponding to a |
| 1750 | * {@code pluggedType} value of {@code 0}. That is why we shift by |
| 1751 | * {@code pluggedType — 1} instead of by {@code pluggedType}. |
| 1752 | * @param stayAwakeConditions a bit string specifying which "plugged types" should |
| 1753 | * keep the device (and hence Wi-Fi) awake. |
| 1754 | * @param pluggedType the type of plug (USB, AC, or none) for which the check is |
| 1755 | * being made |
| 1756 | * @return {@code true} if {@code pluggedType} indicates that the device is |
| 1757 | * supposed to stay awake, {@code false} otherwise. |
| 1758 | */ |
| 1759 | private boolean shouldDeviceStayAwake(int stayAwakeConditions, int pluggedType) { |
| 1760 | return (stayAwakeConditions & pluggedType) != 0; |
| 1761 | } |
| 1762 | }; |
| 1763 | |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1764 | private void sendEnableMessage(boolean enable, boolean persist, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | Message msg = Message.obtain(mWifiHandler, |
| 1766 | (enable ? MESSAGE_ENABLE_WIFI : MESSAGE_DISABLE_WIFI), |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1767 | (persist ? 1 : 0), uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | msg.sendToTarget(); |
| 1769 | } |
| 1770 | |
| 1771 | private void sendStartMessage(boolean scanOnlyMode) { |
| 1772 | Message.obtain(mWifiHandler, MESSAGE_START_WIFI, scanOnlyMode ? 1 : 0, 0).sendToTarget(); |
| 1773 | } |
| 1774 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1775 | private void sendAccessPointMessage(boolean enable, WifiConfiguration wifiConfig, int uid) { |
| 1776 | Message.obtain(mWifiHandler, |
| 1777 | (enable ? MESSAGE_START_ACCESS_POINT : MESSAGE_STOP_ACCESS_POINT), |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 1778 | uid, 0, wifiConfig).sendToTarget(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1779 | } |
| 1780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | private void updateWifiState() { |
| Robert Greenwalt | f75aa36fc | 2009-10-22 17:03:47 -0700 | [diff] [blame] | 1782 | // send a message so it's all serialized |
| 1783 | Message.obtain(mWifiHandler, MESSAGE_UPDATE_STATE, 0, 0).sendToTarget(); |
| 1784 | } |
| 1785 | |
| 1786 | private void doUpdateWifiState() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | boolean wifiEnabled = getPersistedWifiEnabled(); |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 1788 | boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | boolean lockHeld = mLocks.hasLocks(); |
| 1790 | int strongestLockMode; |
| 1791 | boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode; |
| 1792 | boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld; |
| 1793 | if (mDeviceIdle && lockHeld) { |
| 1794 | strongestLockMode = mLocks.getStrongestLockMode(); |
| 1795 | } else { |
| 1796 | strongestLockMode = WifiManager.WIFI_MODE_FULL; |
| 1797 | } |
| 1798 | |
| 1799 | synchronized (mWifiHandler) { |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 1800 | if ((mWifiStateTracker.getWifiState() == WIFI_STATE_ENABLING) && !airplaneMode) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | return; |
| 1802 | } |
| Irfan Sheriff | b2e6c01 | 2010-04-05 11:57:56 -0700 | [diff] [blame] | 1803 | |
| 1804 | /* Disable tethering when airplane mode is enabled */ |
| 1805 | if (airplaneMode && |
| 1806 | (mWifiApState == WIFI_AP_STATE_ENABLING || mWifiApState == WIFI_AP_STATE_ENABLED)) { |
| 1807 | sWakeLock.acquire(); |
| 1808 | sendAccessPointMessage(false, null, mLastApEnableUid); |
| 1809 | } |
| 1810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | if (wifiShouldBeEnabled) { |
| 1812 | if (wifiShouldBeStarted) { |
| 1813 | sWakeLock.acquire(); |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1814 | sendEnableMessage(true, false, mLastEnableUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1815 | sWakeLock.acquire(); |
| 1816 | sendStartMessage(strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY); |
| Irfan Sheriff | 3bf504d | 2010-03-23 12:24:33 -0700 | [diff] [blame] | 1817 | } else if (!mWifiStateTracker.isDriverStopped()) { |
| Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame^] | 1818 | if (mCm == null) { |
| 1819 | mCm = (ConnectivityManager)mContext. |
| 1820 | getSystemService(Context.CONNECTIVITY_SERVICE); |
| 1821 | } |
| 1822 | mCm.requestNetworkTransitionWakelock(TAG); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | mWifiHandler.sendEmptyMessage(MESSAGE_STOP_WIFI); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | } |
| 1825 | } else { |
| 1826 | sWakeLock.acquire(); |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1827 | sendEnableMessage(false, false, mLastEnableUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | private void registerForBroadcasts() { |
| 1833 | IntentFilter intentFilter = new IntentFilter(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
| 1835 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1836 | intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 1837 | intentFilter.addAction(ACTION_DEVICE_IDLE); |
| Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1838 | intentFilter.addAction(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | mContext.registerReceiver(mReceiver, intentFilter); |
| 1840 | } |
| Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 1841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | private boolean isAirplaneSensitive() { |
| 1843 | String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(), |
| 1844 | Settings.System.AIRPLANE_MODE_RADIOS); |
| 1845 | return airplaneModeRadios == null |
| 1846 | || airplaneModeRadios.contains(Settings.System.RADIO_WIFI); |
| 1847 | } |
| 1848 | |
| Mike Lockwood | bd5ddf0 | 2009-07-29 21:37:14 -0700 | [diff] [blame] | 1849 | private boolean isAirplaneToggleable() { |
| 1850 | String toggleableRadios = Settings.System.getString(mContext.getContentResolver(), |
| 1851 | Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
| 1852 | return toggleableRadios != null |
| 1853 | && toggleableRadios.contains(Settings.System.RADIO_WIFI); |
| 1854 | } |
| 1855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | /** |
| 1857 | * Returns true if Wi-Fi is sensitive to airplane mode, and airplane mode is |
| 1858 | * currently on. |
| 1859 | * @return {@code true} if airplane mode is on. |
| 1860 | */ |
| 1861 | private boolean isAirplaneModeOn() { |
| 1862 | return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(), |
| 1863 | Settings.System.AIRPLANE_MODE_ON, 0) == 1; |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * Handler that allows posting to the WifiThread. |
| 1868 | */ |
| 1869 | private class WifiHandler extends Handler { |
| 1870 | public WifiHandler(Looper looper) { |
| 1871 | super(looper); |
| 1872 | } |
| 1873 | |
| 1874 | @Override |
| 1875 | public void handleMessage(Message msg) { |
| 1876 | switch (msg.what) { |
| 1877 | |
| 1878 | case MESSAGE_ENABLE_WIFI: |
| Irfan Sheriff | b99fe5e | 2010-03-26 14:56:07 -0700 | [diff] [blame] | 1879 | setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2); |
| Irfan Sheriff | 7b00978 | 2010-03-11 16:37:45 -0800 | [diff] [blame] | 1880 | if (mWifiWatchdogService == null) { |
| 1881 | mWifiWatchdogService = new WifiWatchdogService(mContext, mWifiStateTracker); |
| 1882 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | sWakeLock.release(); |
| 1884 | break; |
| 1885 | |
| 1886 | case MESSAGE_START_WIFI: |
| 1887 | mWifiStateTracker.setScanOnlyMode(msg.arg1 != 0); |
| 1888 | mWifiStateTracker.restart(); |
| 1889 | sWakeLock.release(); |
| 1890 | break; |
| 1891 | |
| Robert Greenwalt | f75aa36fc | 2009-10-22 17:03:47 -0700 | [diff] [blame] | 1892 | case MESSAGE_UPDATE_STATE: |
| 1893 | doUpdateWifiState(); |
| 1894 | break; |
| 1895 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | case MESSAGE_DISABLE_WIFI: |
| 1897 | // a non-zero msg.arg1 value means the "enabled" setting |
| 1898 | // should be persisted |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1899 | setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2); |
| Irfan Sheriff | b99fe5e | 2010-03-26 14:56:07 -0700 | [diff] [blame] | 1900 | mWifiWatchdogService = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | sWakeLock.release(); |
| 1902 | break; |
| 1903 | |
| 1904 | case MESSAGE_STOP_WIFI: |
| 1905 | mWifiStateTracker.disconnectAndStop(); |
| 1906 | // don't release wakelock |
| 1907 | break; |
| 1908 | |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1909 | case MESSAGE_START_ACCESS_POINT: |
| 1910 | setWifiApEnabledBlocking(true, |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 1911 | msg.arg1, |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1912 | (WifiConfiguration) msg.obj); |
| Irfan Sheriff | 80cb598 | 2010-03-19 10:40:18 -0700 | [diff] [blame] | 1913 | sWakeLock.release(); |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1914 | break; |
| 1915 | |
| 1916 | case MESSAGE_STOP_ACCESS_POINT: |
| 1917 | setWifiApEnabledBlocking(false, |
| Irfan Sheriff | 9ab518ad | 2010-03-12 15:48:17 -0800 | [diff] [blame] | 1918 | msg.arg1, |
| Irfan Sheriff | 5321aef | 2010-02-12 12:35:59 -0800 | [diff] [blame] | 1919 | (WifiConfiguration) msg.obj); |
| 1920 | sWakeLock.release(); |
| 1921 | break; |
| Irfan Sheriff | 59610c0 | 2010-03-30 11:00:41 -0700 | [diff] [blame] | 1922 | |
| 1923 | case MESSAGE_SET_CHANNELS: |
| 1924 | setNumAllowedChannelsBlocking(msg.arg1, msg.arg2 == 1); |
| 1925 | break; |
| 1926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | @Override |
| 1932 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1933 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1934 | != PackageManager.PERMISSION_GRANTED) { |
| 1935 | pw.println("Permission Denial: can't dump WifiService from from pid=" |
| 1936 | + Binder.getCallingPid() |
| 1937 | + ", uid=" + Binder.getCallingUid()); |
| 1938 | return; |
| 1939 | } |
| Irfan Sheriff | 0f34406009 | 2010-03-10 10:05:51 -0800 | [diff] [blame] | 1940 | pw.println("Wi-Fi is " + stateName(mWifiStateTracker.getWifiState())); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | pw.println("Stay-awake conditions: " + |
| 1942 | Settings.System.getInt(mContext.getContentResolver(), |
| 1943 | Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0)); |
| 1944 | pw.println(); |
| 1945 | |
| 1946 | pw.println("Internal state:"); |
| 1947 | pw.println(mWifiStateTracker); |
| 1948 | pw.println(); |
| 1949 | pw.println("Latest scan results:"); |
| 1950 | List<ScanResult> scanResults = mWifiStateTracker.getScanResultsList(); |
| 1951 | if (scanResults != null && scanResults.size() != 0) { |
| 1952 | pw.println(" BSSID Frequency RSSI Flags SSID"); |
| 1953 | for (ScanResult r : scanResults) { |
| 1954 | pw.printf(" %17s %9d %5d %-16s %s%n", |
| 1955 | r.BSSID, |
| 1956 | r.frequency, |
| 1957 | r.level, |
| 1958 | r.capabilities, |
| 1959 | r.SSID == null ? "" : r.SSID); |
| 1960 | } |
| 1961 | } |
| 1962 | pw.println(); |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 1963 | pw.println("Locks acquired: " + mFullLocksAcquired + " full, " + |
| 1964 | mScanLocksAcquired + " scan"); |
| 1965 | pw.println("Locks released: " + mFullLocksReleased + " full, " + |
| 1966 | mScanLocksReleased + " scan"); |
| 1967 | pw.println(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | pw.println("Locks held:"); |
| 1969 | mLocks.dump(pw); |
| 1970 | } |
| 1971 | |
| 1972 | private static String stateName(int wifiState) { |
| 1973 | switch (wifiState) { |
| 1974 | case WIFI_STATE_DISABLING: |
| 1975 | return "disabling"; |
| 1976 | case WIFI_STATE_DISABLED: |
| 1977 | return "disabled"; |
| 1978 | case WIFI_STATE_ENABLING: |
| 1979 | return "enabling"; |
| 1980 | case WIFI_STATE_ENABLED: |
| 1981 | return "enabled"; |
| 1982 | case WIFI_STATE_UNKNOWN: |
| 1983 | return "unknown state"; |
| 1984 | default: |
| 1985 | return "[invalid state]"; |
| 1986 | } |
| 1987 | } |
| 1988 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 1989 | private class WifiLock extends DeathRecipient { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | WifiLock(int lockMode, String tag, IBinder binder) { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 1991 | super(lockMode, tag, binder); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | public void binderDied() { |
| 1995 | synchronized (mLocks) { |
| 1996 | releaseWifiLockLocked(mBinder); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | public String toString() { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2001 | return "WifiLock{" + mTag + " type=" + mMode + " binder=" + mBinder + "}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | private class LockList { |
| 2006 | private List<WifiLock> mList; |
| 2007 | |
| 2008 | private LockList() { |
| 2009 | mList = new ArrayList<WifiLock>(); |
| 2010 | } |
| 2011 | |
| 2012 | private synchronized boolean hasLocks() { |
| 2013 | return !mList.isEmpty(); |
| 2014 | } |
| 2015 | |
| 2016 | private synchronized int getStrongestLockMode() { |
| 2017 | if (mList.isEmpty()) { |
| 2018 | return WifiManager.WIFI_MODE_FULL; |
| 2019 | } |
| 2020 | for (WifiLock l : mList) { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2021 | if (l.mMode == WifiManager.WIFI_MODE_FULL) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | return WifiManager.WIFI_MODE_FULL; |
| 2023 | } |
| 2024 | } |
| 2025 | return WifiManager.WIFI_MODE_SCAN_ONLY; |
| 2026 | } |
| 2027 | |
| 2028 | private void addLock(WifiLock lock) { |
| 2029 | if (findLockByBinder(lock.mBinder) < 0) { |
| 2030 | mList.add(lock); |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | private WifiLock removeLock(IBinder binder) { |
| 2035 | int index = findLockByBinder(binder); |
| 2036 | if (index >= 0) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 2037 | WifiLock ret = mList.remove(index); |
| 2038 | ret.unlinkDeathRecipient(); |
| 2039 | return ret; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | } else { |
| 2041 | return null; |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | private int findLockByBinder(IBinder binder) { |
| 2046 | int size = mList.size(); |
| 2047 | for (int i = size - 1; i >= 0; i--) |
| 2048 | if (mList.get(i).mBinder == binder) |
| 2049 | return i; |
| 2050 | return -1; |
| 2051 | } |
| 2052 | |
| 2053 | private void dump(PrintWriter pw) { |
| 2054 | for (WifiLock l : mList) { |
| 2055 | pw.print(" "); |
| 2056 | pw.println(l); |
| 2057 | } |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | public boolean acquireWifiLock(IBinder binder, int lockMode, String tag) { |
| 2062 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); |
| 2063 | if (lockMode != WifiManager.WIFI_MODE_FULL && lockMode != WifiManager.WIFI_MODE_SCAN_ONLY) { |
| 2064 | return false; |
| 2065 | } |
| 2066 | WifiLock wifiLock = new WifiLock(lockMode, tag, binder); |
| 2067 | synchronized (mLocks) { |
| 2068 | return acquireWifiLockLocked(wifiLock); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | private boolean acquireWifiLockLocked(WifiLock wifiLock) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2073 | Slog.d(TAG, "acquireWifiLockLocked: " + wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | mLocks.addLock(wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2076 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2077 | int uid = Binder.getCallingUid(); |
| 2078 | long ident = Binder.clearCallingIdentity(); |
| 2079 | try { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2080 | switch(wifiLock.mMode) { |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 2081 | case WifiManager.WIFI_MODE_FULL: |
| 2082 | ++mFullLocksAcquired; |
| 2083 | mBatteryStats.noteFullWifiLockAcquired(uid); |
| 2084 | break; |
| 2085 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 2086 | ++mScanLocksAcquired; |
| 2087 | mBatteryStats.noteScanWifiLockAcquired(uid); |
| 2088 | break; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } catch (RemoteException e) { |
| 2091 | } finally { |
| 2092 | Binder.restoreCallingIdentity(ident); |
| 2093 | } |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2094 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | updateWifiState(); |
| 2096 | return true; |
| 2097 | } |
| 2098 | |
| 2099 | public boolean releaseWifiLock(IBinder lock) { |
| 2100 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); |
| 2101 | synchronized (mLocks) { |
| 2102 | return releaseWifiLockLocked(lock); |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | private boolean releaseWifiLockLocked(IBinder lock) { |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2107 | boolean hadLock; |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2108 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2109 | WifiLock wifiLock = mLocks.removeLock(lock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2110 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2111 | Slog.d(TAG, "releaseWifiLockLocked: " + wifiLock); |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2112 | |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2113 | hadLock = (wifiLock != null); |
| 2114 | |
| 2115 | if (hadLock) { |
| 2116 | int uid = Binder.getCallingUid(); |
| 2117 | long ident = Binder.clearCallingIdentity(); |
| 2118 | try { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2119 | switch(wifiLock.mMode) { |
| Eric Shienbrood | 5711fad | 2009-03-27 20:25:31 -0700 | [diff] [blame] | 2120 | case WifiManager.WIFI_MODE_FULL: |
| 2121 | ++mFullLocksReleased; |
| 2122 | mBatteryStats.noteFullWifiLockReleased(uid); |
| 2123 | break; |
| 2124 | case WifiManager.WIFI_MODE_SCAN_ONLY: |
| 2125 | ++mScanLocksReleased; |
| 2126 | mBatteryStats.noteScanWifiLockReleased(uid); |
| 2127 | break; |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2128 | } |
| 2129 | } catch (RemoteException e) { |
| 2130 | } finally { |
| 2131 | Binder.restoreCallingIdentity(ident); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2132 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2133 | } |
| Robert Greenwalt | f1acb2d | 2009-10-13 08:20:55 -0700 | [diff] [blame] | 2134 | // TODO - should this only happen if you hadLock? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | updateWifiState(); |
| Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2136 | return hadLock; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2138 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2139 | private abstract class DeathRecipient |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2140 | implements IBinder.DeathRecipient { |
| 2141 | String mTag; |
| 2142 | int mMode; |
| 2143 | IBinder mBinder; |
| 2144 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2145 | DeathRecipient(int mode, String tag, IBinder binder) { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2146 | super(); |
| 2147 | mTag = tag; |
| 2148 | mMode = mode; |
| 2149 | mBinder = binder; |
| 2150 | try { |
| 2151 | mBinder.linkToDeath(this, 0); |
| 2152 | } catch (RemoteException e) { |
| 2153 | binderDied(); |
| 2154 | } |
| 2155 | } |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 2156 | |
| 2157 | void unlinkDeathRecipient() { |
| 2158 | mBinder.unlinkToDeath(this, 0); |
| 2159 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2162 | private class Multicaster extends DeathRecipient { |
| 2163 | Multicaster(String tag, IBinder binder) { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2164 | super(Binder.getCallingUid(), tag, binder); |
| 2165 | } |
| 2166 | |
| 2167 | public void binderDied() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2168 | Slog.e(TAG, "Multicaster binderDied"); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2169 | synchronized (mMulticasters) { |
| 2170 | int i = mMulticasters.indexOf(this); |
| 2171 | if (i != -1) { |
| 2172 | removeMulticasterLocked(i, mMode); |
| 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | public String toString() { |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2178 | return "Multicaster{" + mTag + " binder=" + mBinder + "}"; |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | public int getUid() { |
| 2182 | return mMode; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 2186 | public void initializeMulticastFiltering() { |
| 2187 | enforceMulticastChangePermission(); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 2188 | |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 2189 | synchronized (mMulticasters) { |
| 2190 | // if anybody had requested filters be off, leave off |
| 2191 | if (mMulticasters.size() != 0) { |
| 2192 | return; |
| 2193 | } else { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 2194 | mWifiStateTracker.startPacketFiltering(); |
| Robert Greenwalt | e2d155a | 2009-10-21 14:58:34 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | } |
| 2198 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 2199 | public void acquireMulticastLock(IBinder binder, String tag) { |
| 2200 | enforceMulticastChangePermission(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2201 | |
| 2202 | synchronized (mMulticasters) { |
| 2203 | mMulticastEnabled++; |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2204 | mMulticasters.add(new Multicaster(tag, binder)); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2205 | // Note that we could call stopPacketFiltering only when |
| 2206 | // our new size == 1 (first call), but this function won't |
| 2207 | // be called often and by making the stopPacket call each |
| 2208 | // time we're less fragile and self-healing. |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 2209 | mWifiStateTracker.stopPacketFiltering(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | int uid = Binder.getCallingUid(); |
| 2213 | Long ident = Binder.clearCallingIdentity(); |
| 2214 | try { |
| 2215 | mBatteryStats.noteWifiMulticastEnabled(uid); |
| 2216 | } catch (RemoteException e) { |
| 2217 | } finally { |
| 2218 | Binder.restoreCallingIdentity(ident); |
| 2219 | } |
| 2220 | } |
| 2221 | |
| Robert Greenwalt | fc1b15c | 2009-05-22 15:09:51 -0700 | [diff] [blame] | 2222 | public void releaseMulticastLock() { |
| 2223 | enforceMulticastChangePermission(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2224 | |
| 2225 | int uid = Binder.getCallingUid(); |
| 2226 | synchronized (mMulticasters) { |
| 2227 | mMulticastDisabled++; |
| 2228 | int size = mMulticasters.size(); |
| 2229 | for (int i = size - 1; i >= 0; i--) { |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2230 | Multicaster m = mMulticasters.get(i); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2231 | if ((m != null) && (m.getUid() == uid)) { |
| 2232 | removeMulticasterLocked(i, uid); |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | private void removeMulticasterLocked(int i, int uid) |
| 2239 | { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 2240 | Multicaster removed = mMulticasters.remove(i); |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 2241 | |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 2242 | if (removed != null) { |
| 2243 | removed.unlinkDeathRecipient(); |
| 2244 | } |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2245 | if (mMulticasters.size() == 0) { |
| Irfan Sheriff | a8fbe1f | 2010-03-09 09:13:58 -0800 | [diff] [blame] | 2246 | mWifiStateTracker.startPacketFiltering(); |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | Long ident = Binder.clearCallingIdentity(); |
| 2250 | try { |
| 2251 | mBatteryStats.noteWifiMulticastDisabled(uid); |
| 2252 | } catch (RemoteException e) { |
| 2253 | } finally { |
| 2254 | Binder.restoreCallingIdentity(ident); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| Robert Greenwalt | 58ff021 | 2009-05-19 15:53:54 -0700 | [diff] [blame] | 2258 | public boolean isMulticastEnabled() { |
| Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 2259 | enforceAccessPermission(); |
| 2260 | |
| 2261 | synchronized (mMulticasters) { |
| 2262 | return (mMulticasters.size() > 0); |
| 2263 | } |
| 2264 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2265 | } |