WifiServiceImpl.java revision e87a8da7bb513ca720b0160e3bff8c9f355faabb
1155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/* 2155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Copyright (C) 2010 The Android Open Source Project 3155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 4155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Licensed under the Apache License, Version 2.0 (the "License"); 5155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * you may not use this file except in compliance with the License. 6155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * You may obtain a copy of the License at 7155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 8155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * http://www.apache.org/licenses/LICENSE-2.0 9155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 10155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Unless required by applicable law or agreed to in writing, software 11155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * distributed under the License is distributed on an "AS IS" BASIS, 12155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See the License for the specific language governing permissions and 14155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * limitations under the License. 15155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 16155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 17155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepackage com.android.server.wifi; 18155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 199086afccf6938a49eb9a2cd248917c1cb0943942vandwalleimport android.Manifest; 20155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.app.ActivityManager; 21155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.app.AppOpsManager; 22155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.bluetooth.BluetoothAdapter; 23155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.content.BroadcastReceiver; 24155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.content.Context; 25155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.content.Intent; 26155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.content.IntentFilter; 27155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.content.pm.PackageManager; 28fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghinaimport android.content.pm.UserInfo; 29155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.database.ContentObserver; 3034f173a54307c39ffe5dfab52e7ef8166a00539eRobert Greenwaltimport android.net.ConnectivityManager; 31155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.DhcpInfo; 32155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.DhcpResults; 333ecf5a032e94b6538a56f94a5b33e50cbc464007Jaewan Kimimport android.net.IpConfiguration.ProxySettings; 34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.LinkAddress; 359846078598c3468f8813dbfa58238a1846bd81efSanket Padaweimport android.net.Network; 36155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.NetworkUtils; 37155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.net.RouteInfo; 38e487a4648dd41881e754f1224aaedead78a0777dSky Faberimport android.net.Uri; 39c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalleimport android.net.wifi.*; 403ecf5a032e94b6538a56f94a5b33e50cbc464007Jaewan Kimimport android.net.wifi.IWifiManager; 413ecf5a032e94b6538a56f94a5b33e50cbc464007Jaewan Kimimport android.os.AsyncTask; 42155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.Binder; 43155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.Handler; 44155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.HandlerThread; 45155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.IBinder; 46155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.Message; 473ecf5a032e94b6538a56f94a5b33e50cbc464007Jaewan Kimimport android.os.Messenger; 4803b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackbornimport android.os.PowerManager; 49155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.RemoteException; 50186f7513a080eb1a419b6d83286d62961168a5feAdam Lesinskiimport android.os.SystemClock; 51155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.SystemProperties; 52155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.UserHandle; 53fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghinaimport android.os.UserManager; 54155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.os.WorkSource; 55155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.provider.Settings; 564d381bc39f5263effdae73ec99065eb299b806caVinit Deshpandeimport android.text.TextUtils; 57992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalleimport android.util.Log; 58155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport android.util.Slog; 59155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 60155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.FileNotFoundException; 61155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.BufferedReader; 62155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.FileDescriptor; 63155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.FileReader; 64155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.IOException; 65155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.io.PrintWriter; 66155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.lang.Override; 67155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.net.InetAddress; 68155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.net.Inet4Address; 69a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvistimport java.net.URISyntaxException; 70a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvistimport java.security.GeneralSecurityException; 7131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.KeyStore; 7231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.CertPath; 7331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.CertPathValidator; 7431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.CertPathValidatorException; 7531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.CertificateFactory; 7631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.PKIXParameters; 7731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.security.cert.X509Certificate; 78155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.ArrayList; 7931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvistimport java.util.Arrays; 80155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport java.util.List; 81155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 82155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport com.android.internal.R; 83155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport com.android.internal.app.IBatteryStats; 84155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport com.android.internal.telephony.TelephonyIntents; 85155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport com.android.internal.util.AsyncChannel; 86155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport com.android.server.am.BatteryStatsService; 87a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvistimport com.android.server.wifi.configparse.ConfigBuilder; 88a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist 89a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvistimport org.xml.sax.SAXException; 90a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng 91155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_AIRPLANE_TOGGLED; 92155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_BATTERY_CHANGED; 93155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_EMERGENCY_MODE_CHANGED; 94155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_LOCKS_CHANGED; 95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_SCAN_ALWAYS_MODE_CHANGED; 96155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_SCREEN_OFF; 97155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_SCREEN_ON; 98155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_SET_AP; 99155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_USER_PRESENT; 100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeimport static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED; 101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/** 102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * WifiService handles remote WiFi operation requests by implementing 103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * the IWifiManager interface. 104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @hide 106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandepublic final class WifiServiceImpl extends IWifiManager.Stub { 108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private static final String TAG = "WifiService"; 109f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle private static final boolean DBG = true; 11070b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle private static final boolean VDBG = false; 111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final WifiStateMachine mWifiStateMachine; 113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final Context mContext; 115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final LockList mLocks = new LockList(); 117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // some wifi lock statistics 118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mFullHighPerfLocksAcquired; 119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mFullHighPerfLocksReleased; 120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mFullLocksAcquired; 121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mFullLocksReleased; 122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mScanLocksAcquired; 123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mScanLocksReleased; 124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final List<Multicaster> mMulticasters = 126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande new ArrayList<Multicaster>(); 127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mMulticastEnabled; 128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int mMulticastDisabled; 129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final IBatteryStats mBatteryStats; 13103b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn private final PowerManager mPowerManager; 132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final AppOpsManager mAppOps; 133f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott private final UserManager mUserManager; 134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private String mInterfaceName; 136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 137ebb7e0cb4572f73325a749539d589ebdefb8635cvandwalle // Debug counter tracking scan requests sent by WifiManager 138ebb7e0cb4572f73325a749539d589ebdefb8635cvandwalle private int scanRequestCounter = 0; 139ebb7e0cb4572f73325a749539d589ebdefb8635cvandwalle 140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Tracks the open wi-fi network notification */ 141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private WifiNotificationController mNotificationController; 142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Polls traffic stats and notifies clients */ 143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private WifiTrafficPoller mTrafficPoller; 144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Tracks the persisted states for wi-fi & airplane mode */ 145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final WifiSettingsStore mSettingsStore; 146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Asynchronous channel to WifiStateMachine 149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private AsyncChannel mWifiStateMachineChannel; 151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Handles client connections 154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private class ClientHandler extends Handler { 156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ClientHandler(android.os.Looper looper) { 158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande super(looper); 159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void handleMessage(Message msg) { 163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (msg.what) { 164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: { 165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { 166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "New client listening to asynchronous messages"); 167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // We track the clients by the Messenger 168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // since it is expected to be always available 169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTrafficPoller.addClient(msg.replyTo); 170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Client connection failure, error=" + msg.arg1); 172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case AsyncChannel.CMD_CHANNEL_DISCONNECTED: { 176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (msg.arg1 == AsyncChannel.STATUS_SEND_UNSUCCESSFUL) { 177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "Send failed, client connection lost"); 178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1); 180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTrafficPoller.removeClient(msg.replyTo); 182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 183155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: { 185155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande AsyncChannel ac = new AsyncChannel(); 186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ac.connect(mContext, this, msg.replyTo); 187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* Client commands are forwarded to state machine */ 190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.CONNECT_NETWORK: 191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.SAVE_NETWORK: { 192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiConfiguration config = (WifiConfiguration) msg.obj; 193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int networkId = msg.arg1; 194992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle if (msg.what == WifiManager.SAVE_NETWORK) { 195992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle Slog.e("WiFiServiceImpl ", "SAVE" 196992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle + " nid=" + Integer.toString(networkId) 197e487a4648dd41881e754f1224aaedead78a0777dSky Faber + " uid=" + msg.sendingUid 198e487a4648dd41881e754f1224aaedead78a0777dSky Faber + " name=" 199e487a4648dd41881e754f1224aaedead78a0777dSky Faber + mContext.getPackageManager().getNameForUid(msg.sendingUid)); 200992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle } 201992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle if (msg.what == WifiManager.CONNECT_NETWORK) { 202992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle Slog.e("WiFiServiceImpl ", "CONNECT " 203992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle + " nid=" + Integer.toString(networkId) 204e487a4648dd41881e754f1224aaedead78a0777dSky Faber + " uid=" + msg.sendingUid 205e487a4648dd41881e754f1224aaedead78a0777dSky Faber + " name=" 206e487a4648dd41881e754f1224aaedead78a0777dSky Faber + mContext.getPackageManager().getNameForUid(msg.sendingUid)); 207992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle } 208e487a4648dd41881e754f1224aaedead78a0777dSky Faber 209d03a9283285bb7adef6c687eb3a91fa4a8c4b502Vinit Deshpande if (config != null && isValid(config)) { 21064c98f4afda6c7970c5d563580165a308d5e7c15Jason Monk if (DBG) Slog.d(TAG, "Connect with config" + config); 21164c98f4afda6c7970c5d563580165a308d5e7c15Jason Monk mWifiStateMachine.sendMessage(Message.obtain(msg)); 212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (config == null 213155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande && networkId != WifiConfiguration.INVALID_NETWORK_ID) { 214155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "Connect with networkId" + networkId); 215155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.sendMessage(Message.obtain(msg)); 216155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 217155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "ClientHandler.handleMessage ignoring invalid msg=" + msg); 218155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (msg.what == WifiManager.CONNECT_NETWORK) { 219c35d728a15e9270f5642ef79f5245c89d749285fSky Faber replyFailed(msg, WifiManager.CONNECT_NETWORK_FAILED, 220c35d728a15e9270f5642ef79f5245c89d749285fSky Faber WifiManager.INVALID_ARGS); 221155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 222c35d728a15e9270f5642ef79f5245c89d749285fSky Faber replyFailed(msg, WifiManager.SAVE_NETWORK_FAILED, 223c35d728a15e9270f5642ef79f5245c89d749285fSky Faber WifiManager.INVALID_ARGS); 224155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 225155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.FORGET_NETWORK: 2292a325cd07d40941adb93c1284abb263ba650c213Sky Faber if (isOwner(msg.sendingUid)) { 230002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber mWifiStateMachine.sendMessage(Message.obtain(msg)); 231002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } else { 232002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber Slog.e(TAG, "Forget is not authorized for user"); 233002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber replyFailed(msg, WifiManager.FORGET_NETWORK_FAILED, 234002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber WifiManager.NOT_AUTHORIZED); 235002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 236002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber break; 237155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.START_WPS: 238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.CANCEL_WPS: 239155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.DISABLE_NETWORK: 240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.RSSI_PKTCNT_FETCH: { 241155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.sendMessage(Message.obtain(msg)); 242155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 243155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 244155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: { 245155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.d(TAG, "ClientHandler.handleMessage ignoring msg=" + msg); 246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 251c35d728a15e9270f5642ef79f5245c89d749285fSky Faber private void replyFailed(Message msg, int what, int why) { 252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Message reply = msg.obtain(); 253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande reply.what = what; 254c35d728a15e9270f5642ef79f5245c89d749285fSky Faber reply.arg1 = why; 255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande msg.replyTo.send(reply); 257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // There's not much we can do if reply can't be sent! 259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private ClientHandler mClientHandler; 263155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 264155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 265155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Handles interaction with WifiStateMachine 266155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 267155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private class WifiStateMachineHandler extends Handler { 268155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private AsyncChannel mWsmChannel; 269155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiStateMachineHandler(android.os.Looper looper) { 271155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande super(looper); 272155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWsmChannel = new AsyncChannel(); 273155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler()); 274155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 275155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 276155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void handleMessage(Message msg) { 278155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch (msg.what) { 279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: { 280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { 281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachineChannel = mWsmChannel; 282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 283155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "WifiStateMachine connection failure, error=" + msg.arg1); 284155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachineChannel = null; 285155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 286155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 287155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 288155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case AsyncChannel.CMD_CHANNEL_DISCONNECTED: { 289155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "WifiStateMachine channel lost, msg.arg1 =" + msg.arg1); 290155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachineChannel = null; 291155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //Re-establish connection to state machine 292155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler()); 293155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 294155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 295155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande default: { 296155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.d(TAG, "WifiStateMachineHandler.handleMessage ignoring msg=" + msg); 297155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 298155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 299155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 300155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 301155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 302155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 303155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiStateMachineHandler mWifiStateMachineHandler; 304155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 305155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private WifiWatchdogStateMachine mWifiWatchdogStateMachine; 306155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 307155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private WifiController mWifiController; 308155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 309155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public WifiServiceImpl(Context context) { 310155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext = context; 311155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 312155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mInterfaceName = SystemProperties.get("wifi.interface", "wlan0"); 313155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 314f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle mTrafficPoller = new WifiTrafficPoller(mContext, mInterfaceName); 315f22d23092ab37286a5ef9d257d5bb32c421d2669vandwalle mWifiStateMachine = new WifiStateMachine(mContext, mInterfaceName, mTrafficPoller); 316155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.enableRssiPolling(true); 317155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBatteryStats = BatteryStatsService.getService(); 31803b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn mPowerManager = context.getSystemService(PowerManager.class); 319155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); 320f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott mUserManager = UserManager.get(mContext); 321155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 322155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mNotificationController = new WifiNotificationController(mContext, mWifiStateMachine); 323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mSettingsStore = new WifiSettingsStore(mContext); 324155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 325155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande HandlerThread wifiThread = new HandlerThread("WifiService"); 326155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande wifiThread.start(); 327155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mClientHandler = new ClientHandler(wifiThread.getLooper()); 328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachineHandler = new WifiStateMachineHandler(wifiThread.getLooper()); 329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController = new WifiController(mContext, this, wifiThread.getLooper()); 3301c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde } 3311c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde 3321c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde 3331c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde /** 3341c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde * Check if Wi-Fi needs to be enabled and start 3351c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde * if needed 3361c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde * 3371c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde * This function is used only at boot time 3381c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde */ 3391c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde public void checkAndStartWifi() { 3401c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde /* Check if wi-fi needs to be enabled */ 3411c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled(); 3421c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde Slog.i(TAG, "WifiService starting up with Wi-Fi " + 3431c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde (wifiEnabled ? "enabled" : "disabled")); 344155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 345155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande registerForScanModeChange(); 346155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.registerReceiver( 347155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande new BroadcastReceiver() { 348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void onReceive(Context context, Intent intent) { 350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mSettingsStore.handleAirplaneModeToggled()) { 351155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_AIRPLANE_TOGGLED); 352155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande }, 355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); 356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Adding optimizations of only receiving broadcasts when wifi is enabled 358155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // can result in race conditions when apps toggle wifi in the background 359155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // without active user involvement. Always receive broadcasts. 360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande registerForBroadcasts(); 361faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee registerForPackageOrUserRemoval(); 36203b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn mInIdleMode = mPowerManager.isDeviceIdleMode(); 363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 3641c28bb29cb19367d5e3bdbe6d8558d0fd4b8f33eVinit Deshapnde mWifiController.start(); 365155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 366155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // If we are already disabled (could be due to airplane mode), avoid changing persist 367155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // state here 368155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (wifiEnabled) setWifiEnabled(wifiEnabled); 369155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 370155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiWatchdogStateMachine = WifiWatchdogStateMachine. 371569b093c4afd30787308032c8259af2680a2874fNavtej Singh Mann makeWifiWatchdogStateMachine(mContext, mWifiStateMachine.getMessenger()); 372155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 373155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 374155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 375155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#pingSupplicant()} 376155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeds, {@code false} otherwise 377155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 378155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean pingSupplicant() { 379155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 380155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 381155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncPingSupplicant(mWifiStateMachineChannel); 382155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 383155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 384155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 385155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 386155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 387155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 388155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 389a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng * see {@link android.net.wifi.WifiManager#getChannelList} 390a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng */ 391a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public List<WifiChannel> getChannelList() { 392a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng enforceAccessPermission(); 393a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (mWifiStateMachineChannel != null) { 394a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return mWifiStateMachine.syncGetChannelList(mWifiStateMachineChannel); 395a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } else { 396a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 397a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return null; 398a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 399a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 400a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng 4019086afccf6938a49eb9a2cd248917c1cb0943942vandwalle // Start a location scan. 4029086afccf6938a49eb9a2cd248917c1cb0943942vandwalle // L release: A location scan is implemented as a normal scan and avoids scanning DFS channels 4031227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande // Deprecated: Will soon remove implementation 4049086afccf6938a49eb9a2cd248917c1cb0943942vandwalle public void startLocationRestrictedScan(WorkSource workSource) { 4059086afccf6938a49eb9a2cd248917c1cb0943942vandwalle enforceChangePermission(); 4069086afccf6938a49eb9a2cd248917c1cb0943942vandwalle enforceLocationHardwarePermission(); 4079086afccf6938a49eb9a2cd248917c1cb0943942vandwalle List<WifiChannel> channels = getChannelList(); 4089086afccf6938a49eb9a2cd248917c1cb0943942vandwalle if (channels == null) { 4099086afccf6938a49eb9a2cd248917c1cb0943942vandwalle Slog.e(TAG, "startLocationRestrictedScan cant get channels"); 4109086afccf6938a49eb9a2cd248917c1cb0943942vandwalle return; 4119086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 4129086afccf6938a49eb9a2cd248917c1cb0943942vandwalle ScanSettings settings = new ScanSettings(); 4139086afccf6938a49eb9a2cd248917c1cb0943942vandwalle for (WifiChannel channel : channels) { 4149086afccf6938a49eb9a2cd248917c1cb0943942vandwalle if (!channel.isDFS) { 4159086afccf6938a49eb9a2cd248917c1cb0943942vandwalle settings.channelSet.add(channel); 4169086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 4179086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 4189086afccf6938a49eb9a2cd248917c1cb0943942vandwalle if (workSource == null) { 4199086afccf6938a49eb9a2cd248917c1cb0943942vandwalle // Make sure we always have a workSource indicating the origin of the scan 4209086afccf6938a49eb9a2cd248917c1cb0943942vandwalle // hence if there is none, pick an internal WifiStateMachine one 4219086afccf6938a49eb9a2cd248917c1cb0943942vandwalle workSource = new WorkSource(WifiStateMachine.DFS_RESTRICTED_SCAN_REQUEST); 4229086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 4239086afccf6938a49eb9a2cd248917c1cb0943942vandwalle startScan(settings, workSource); 4249086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 4259086afccf6938a49eb9a2cd248917c1cb0943942vandwalle 426a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng /** 427a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng * see {@link android.net.wifi.WifiManager#startScan} 428a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng * and {@link android.net.wifi.WifiManager#startCustomizedScan} 429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 430a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng * @param settings If null, use default parameter, i.e. full scan. 431a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng * @param workSource If null, all blame is given to the calling uid. 432155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 433a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng public void startScan(ScanSettings settings, WorkSource workSource) { 434155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 4351227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande synchronized (this) { 43603b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn if (mInIdleMode) { 43749dfc6768889a33eb67102b16faf21667af2a60dVinit Deshpande // Need to send an immediate scan result broadcast in case the 43849dfc6768889a33eb67102b16faf21667af2a60dVinit Deshpande // caller is waiting for a result .. 43949dfc6768889a33eb67102b16faf21667af2a60dVinit Deshpande mWifiStateMachine.sendScanResultsAvailableBroadcast(/* scanSucceeded = */ false); 44003b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn mScanPending = true; 44103b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn return; 44203b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 44303b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 444a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (settings != null) { 445a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng settings = new ScanSettings(settings); 446a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng if (!settings.isValid()) { 447a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng Slog.e(TAG, "invalid scan setting"); 448a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng return; 449a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 450a0009d14075b5345b8f916c3fb3f2260c938cb9dYuhao Zheng } 451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (workSource != null) { 452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceWorkSourcePermission(); 453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // WifiManager currently doesn't use names, so need to clear names out of the 454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // supplied WorkSource to allow future WorkSource combining. 455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande workSource.clearNames(); 456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 457ebb7e0cb4572f73325a749539d589ebdefb8635cvandwalle mWifiStateMachine.startScan(Binder.getCallingUid(), scanRequestCounter++, 458ebb7e0cb4572f73325a749539d589ebdefb8635cvandwalle settings, workSource); 459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean isBatchedScanSupported() { 462ad9984607c007b15b9eb6601facf821cb57e1555Vinit Deshpande return false; 463155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 464155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 465ad9984607c007b15b9eb6601facf821cb57e1555Vinit Deshpande public void pollBatchedScan() { } 466155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 4673f7ef65ab71619040032aee96b5599849881d6fdAndres Morales public String getWpsNfcConfigurationToken(int netId) { 468f3f4029b3ac41da4cc6a1bc22bae47c750a47048Andres Morales enforceConnectivityInternalPermission(); 4693f7ef65ab71619040032aee96b5599849881d6fdAndres Morales return mWifiStateMachine.syncGetWpsNfcConfigurationToken(netId); 4703f7ef65ab71619040032aee96b5599849881d6fdAndres Morales } 4713f7ef65ab71619040032aee96b5599849881d6fdAndres Morales 472155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#requestBatchedScan()} 474155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 475155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean requestBatchedScan(BatchedScanSettings requested, IBinder binder, 476155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WorkSource workSource) { 477ad9984607c007b15b9eb6601facf821cb57e1555Vinit Deshpande return false; 478155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 479155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 480155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public List<BatchedScanResult> getBatchedScanResults(String callingPackage) { 481ad9984607c007b15b9eb6601facf821cb57e1555Vinit Deshpande return null; 482155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 484ad9984607c007b15b9eb6601facf821cb57e1555Vinit Deshpande public void stopBatchedScan(BatchedScanSettings settings) { } 485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 4861227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande boolean mInIdleMode; 4871227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande boolean mScanPending; 4881227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande 48903b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn void handleIdleModeChanged() { 49003b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn boolean doScan = false; 4911227b49a94f33844ad0606b48b591bea4d27b08eVinit Deshpande synchronized (this) { 49203b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn boolean idle = mPowerManager.isDeviceIdleMode(); 49303b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn if (mInIdleMode != idle) { 49403b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn mInIdleMode = idle; 49503b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn if (!idle) { 49603b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn if (mScanPending) { 49703b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn mScanPending = false; 49803b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn doScan = true; 49903b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50003b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50103b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50203b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50303b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn if (doScan) { 50403b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn // Someone requested a scan while we were idle; do a full scan now. 50503b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn startScan(null, null); 50603b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50703b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } 50803b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn 509155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void enforceAccessPermission() { 510155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE, 511a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande "WifiService"); 512155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 513155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 514155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void enforceChangePermission() { 515155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE, 51631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist "WifiService"); 5179086afccf6938a49eb9a2cd248917c1cb0943942vandwalle } 518155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5199086afccf6938a49eb9a2cd248917c1cb0943942vandwalle private void enforceLocationHardwarePermission() { 5209086afccf6938a49eb9a2cd248917c1cb0943942vandwalle mContext.enforceCallingOrSelfPermission(Manifest.permission.LOCATION_HARDWARE, 5219086afccf6938a49eb9a2cd248917c1cb0943942vandwalle "LocationHardware"); 522155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 523155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 5249878c61bbd81176561991be025af44efc67332feWenchao Tong private void enforceReadCredentialPermission() { 5259878c61bbd81176561991be025af44efc67332feWenchao Tong mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_WIFI_CREDENTIAL, 5269878c61bbd81176561991be025af44efc67332feWenchao Tong "WifiService"); 5279878c61bbd81176561991be025af44efc67332feWenchao Tong } 5289878c61bbd81176561991be025af44efc67332feWenchao Tong 529155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void enforceWorkSourcePermission() { 530155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingPermission(android.Manifest.permission.UPDATE_DEVICE_STATS, 531a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande "WifiService"); 532155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 533155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 534155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 535155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void enforceMulticastChangePermission() { 536155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission( 537155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, 538155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande "WifiService"); 539155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 540155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 541155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void enforceConnectivityInternalPermission() { 542155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission( 543155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande android.Manifest.permission.CONNECTIVITY_INTERNAL, 544155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande "ConnectivityService"); 545155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 546155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 547155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 548155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} 549155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param enable {@code true} to enable, {@code false} to disable. 550155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the enable/disable operation was 551155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * started or is already in the queue. 552155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 553155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public synchronized boolean setWifiEnabled(boolean enable) { 554155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 555155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid() 556155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + ", uid=" + Binder.getCallingUid()); 557155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) { 558155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Invoking mWifiStateMachine.setWifiEnabled\n"); 559155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 560155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 561155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 562155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Caller might not have WRITE_SECURE_SETTINGS, 563155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * only CHANGE_WIFI_STATE is enforced 564155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 565155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 566155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande long ident = Binder.clearCallingIdentity(); 567155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 568155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (! mSettingsStore.handleWifiToggled(enable)) { 569155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Nothing to do if wifi cannot be toggled 570155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 571155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 572155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 573155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 574155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 575155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 576155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_WIFI_TOGGLED); 577155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 578155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 579155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 580155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 581155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link WifiManager#getWifiState()} 582155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return One of {@link WifiManager#WIFI_STATE_DISABLED}, 583155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_STATE_DISABLING}, 584155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_STATE_ENABLED}, 585155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_STATE_ENABLING}, 586155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_STATE_UNKNOWN} 587155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 588155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getWifiEnabledState() { 589155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 590155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncGetWifiState(); 591155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 592155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 593155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 594155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#setWifiApEnabled(WifiConfiguration, boolean)} 595155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param wifiConfig SSID, security and channel details as 596155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * part of WifiConfiguration 597155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param enabled true to enable and false to disable 598155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 599155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { 600328fc5407927799843c11f2b767a8cf47b89f366Robert Greenwalt enforceChangePermission(); 60134f173a54307c39ffe5dfab52e7ef8166a00539eRobert Greenwalt ConnectivityManager.enforceTetherChangePermission(mContext); 602f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) { 60313cddb5337418359eb5f9bebd0504fbc5c47fc41Julia Reynolds throw new SecurityException("DISALLOW_CONFIG_TETHERING is enabled for this user."); 60413cddb5337418359eb5f9bebd0504fbc5c47fc41Julia Reynolds } 605155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // null wifiConfig is a meaningful input for CMD_SET_AP 606d03a9283285bb7adef6c687eb3a91fa4a8c4b502Vinit Deshpande if (wifiConfig == null || isValid(wifiConfig)) { 607155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget(); 608155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 609155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Invalid WifiConfiguration"); 610155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 611155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 612155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 613155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 614155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link WifiManager#getWifiApState()} 615155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return One of {@link WifiManager#WIFI_AP_STATE_DISABLED}, 616155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_AP_STATE_DISABLING}, 617155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_AP_STATE_ENABLED}, 618155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_AP_STATE_ENABLING}, 619155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_AP_STATE_FAILED} 620155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 621155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getWifiApEnabledState() { 622155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 623155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncGetWifiApState(); 624155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 625155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 626155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 627155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link WifiManager#getWifiApConfiguration()} 628155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return soft access point configuration 629155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 630155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public WifiConfiguration getWifiApConfiguration() { 631155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 632155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncGetWifiApConfiguration(); 633155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 634155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 635155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 636a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist * see {@link WifiManager#buildWifiConfig()} 637a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist * @return a WifiConfiguration. 638a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist */ 639a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist public WifiConfiguration buildWifiConfig(String uriString, String mimeType, byte[] data) { 6404e940bb499f65b4305dbeb2e01237c43c2b0b42dJan Nordqvist if (mimeType.equals(ConfigBuilder.WifiConfigType)) { 641a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist try { 642a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist return ConfigBuilder.buildConfig(uriString, data, mContext); 643a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist } 644a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist catch (IOException | GeneralSecurityException | SAXException e) { 645a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist Log.e(TAG, "Failed to parse wi-fi configuration: " + e); 646a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist } 647a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist } 648a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist else { 649a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist Log.i(TAG, "Unknown wi-fi config type: " + mimeType); 650a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist } 651a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist return null; 652a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist } 653a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist 654a1edc185d46d85e04930a5e12b465de9fea64afeJan Nordqvist /** 655155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link WifiManager#setWifiApConfiguration(WifiConfiguration)} 656155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param wifiConfig WifiConfiguration details for soft access point 657155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setWifiApConfiguration(WifiConfiguration wifiConfig) { 659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (wifiConfig == null) 661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return; 662d03a9283285bb7adef6c687eb3a91fa4a8c4b502Vinit Deshpande if (isValid(wifiConfig)) { 663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.setWifiApConfiguration(wifiConfig); 664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Invalid WifiConfiguration"); 666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param enable {@code true} to enable, {@code false} to disable. 671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the enable/disable operation was 672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * started or is already in the queue. 673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean isScanAlwaysAvailable() { 675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mSettingsStore.isScanAlwaysAvailable(); 677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#disconnect()} 681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void disconnect() { 683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.disconnectCommand(); 685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#reconnect()} 689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void reconnect() { 691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.reconnectCommand(); 693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#reassociate()} 697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void reassociate() { 699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.reassociateCommand(); 701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 704048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande * see {@link android.net.wifi.WifiManager#getSupportedFeatures} 705a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande */ 706048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande public int getSupportedFeatures() { 707a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande enforceAccessPermission(); 708a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande if (mWifiStateMachineChannel != null) { 709048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande return mWifiStateMachine.syncGetSupportedFeatures(mWifiStateMachineChannel); 710a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } else { 711a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 712048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande return 0; 713a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 714a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 715a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande 716a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande /** 71794a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski * see {@link android.net.wifi.WifiManager#getControllerActivityEnergyInfo(int)} 718200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle */ 719048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande public WifiActivityEnergyInfo reportActivityInfo() { 720200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle enforceAccessPermission(); 721200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle WifiLinkLayerStats stats; 722200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle WifiActivityEnergyInfo energyInfo = null; 723200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (mWifiStateMachineChannel != null) { 724048dc8df2bd9394979dbb090b0cfe8d6627d23e3Vinit Deshpande stats = mWifiStateMachine.syncGetLinkLayerStats(mWifiStateMachineChannel); 725200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (stats != null) { 72694a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final long rxIdleCurrent = mContext.getResources().getInteger( 72794a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski com.android.internal.R.integer.config_wifi_idle_receive_cur_ma); 72894a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final long rxCurrent = mContext.getResources().getInteger( 72994a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski com.android.internal.R.integer.config_wifi_active_rx_cur_ma); 73094a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final long txCurrent = mContext.getResources().getInteger( 73194a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski com.android.internal.R.integer.config_wifi_tx_cur_ma); 73294a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final double voltage = mContext.getResources().getInteger( 73394a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski com.android.internal.R.integer.config_wifi_operating_voltage_mv) 73494a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski / 1000.0; 73594a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski 73694a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final long rxIdleTime = stats.on_time - stats.tx_time - stats.rx_time; 73794a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski final long energyUsed = (long)((stats.tx_time * txCurrent + 73894a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski stats.rx_time * rxCurrent + 73994a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski rxIdleTime * rxIdleCurrent) * voltage); 74070b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle if (VDBG) { 74170b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle StringBuilder sb = new StringBuilder(); 74270b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" rxIdleCur=" + rxIdleCurrent); 74370b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" rxCur=" + rxCurrent); 74470b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" txCur=" + txCurrent); 74570b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" voltage=" + voltage); 74670b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" on_time=" + stats.on_time); 74770b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" tx_time=" + stats.tx_time); 74870b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" rx_time=" + stats.rx_time); 74970b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" rxIdleTime=" + rxIdleTime); 75070b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle sb.append(" energy=" + energyUsed); 75170b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle Log.e(TAG, " reportActivityInfo: " + sb.toString()); 75270b75cda33a05e8b6e6724ed08e4e72f6fee0471Pierre Vandwalle } 75384a11a3d54b7c6f043dcf7a874b7c0d45709677aPierre Vandwalle 754200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle // Convert the LinkLayerStats into EnergyActivity 755186f7513a080eb1a419b6d83286d62961168a5feAdam Lesinski energyInfo = new WifiActivityEnergyInfo(SystemClock.elapsedRealtime(), 756200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle WifiActivityEnergyInfo.STACK_STATE_STATE_IDLE, stats.tx_time, 75794a2dd090b7d3823058b7a69cf4653d5663708cdAdam Lesinski stats.rx_time, rxIdleTime, energyUsed); 758200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } 759200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle return energyInfo; 760200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } else { 761200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 762200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle return null; 763200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } 764200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } 765200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle 766200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle /** 767155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#getConfiguredNetworks()} 768155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the list of configured networks 769155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 770155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public List<WifiConfiguration> getConfiguredNetworks() { 771155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 772155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 77382199a285f4a45a46b44eb8253999aa918534753vandwalle return mWifiStateMachine.syncGetConfiguredNetworks(Binder.getCallingUid(), 77482199a285f4a45a46b44eb8253999aa918534753vandwalle mWifiStateMachineChannel); 775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 7829878c61bbd81176561991be025af44efc67332feWenchao Tong * see {@link android.net.wifi.WifiManager#getPrivilegedConfiguredNetworks()} 7839878c61bbd81176561991be025af44efc67332feWenchao Tong * @return the list of configured networks with real preSharedKey 7849878c61bbd81176561991be025af44efc67332feWenchao Tong */ 7859878c61bbd81176561991be025af44efc67332feWenchao Tong public List<WifiConfiguration> getPrivilegedConfiguredNetworks() { 7869878c61bbd81176561991be025af44efc67332feWenchao Tong enforceReadCredentialPermission(); 7879878c61bbd81176561991be025af44efc67332feWenchao Tong enforceAccessPermission(); 7889878c61bbd81176561991be025af44efc67332feWenchao Tong if (mWifiStateMachineChannel != null) { 7899878c61bbd81176561991be025af44efc67332feWenchao Tong return mWifiStateMachine.syncGetPrivilegedConfiguredNetwork(mWifiStateMachineChannel); 7909878c61bbd81176561991be025af44efc67332feWenchao Tong } else { 7919878c61bbd81176561991be025af44efc67332feWenchao Tong Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 7929878c61bbd81176561991be025af44efc67332feWenchao Tong return null; 7939878c61bbd81176561991be025af44efc67332feWenchao Tong } 7949878c61bbd81176561991be025af44efc67332feWenchao Tong } 7959878c61bbd81176561991be025af44efc67332feWenchao Tong 7969878c61bbd81176561991be025af44efc67332feWenchao Tong /** 797ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande * Returns a WifiConfiguration matching this ScanResult 798ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande * @param scanResult scanResult that represents the BSSID 799ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande * @return {@link WifiConfiguration} that matches this BSSID or null 800ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande */ 801ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande public WifiConfiguration getMatchingWifiConfig(ScanResult scanResult) { 802ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande enforceAccessPermission(); 803ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande return mWifiStateMachine.syncGetMatchingWifiConfig(scanResult, mWifiStateMachineChannel); 804ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande } 805ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande 806ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande 807ccbe820337a230f0827f734aca2c51a244a0837fVinit Deshpande /** 808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#addOrUpdateNetwork(WifiConfiguration)} 809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the supplicant-assigned identifier for the new or updated 810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * network if the operation succeeds, or {@code -1} if it fails 811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int addOrUpdateNetwork(WifiConfiguration config) { 813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 8144d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (isValid(config)) { 815cd0af1c9ddcac881f49c815fb9da45433eb50736Vinit Deshpande 81631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig; 81731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist 81831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist if (config.isPasspoint() && 81931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist (enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS || 82031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TTLS)) { 82131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist try { 82231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist verifyCert(enterpriseConfig.getCaCertificate()); 82331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } catch (CertPathValidatorException cpve) { 82431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist Slog.e(TAG, "CA Cert " + 82531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist enterpriseConfig.getCaCertificate().getSubjectX500Principal() + 82631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist " untrusted: " + cpve.getMessage()); 82731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return -1; 82831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } catch (GeneralSecurityException | IOException e) { 82931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist Slog.e(TAG, "Failed to verify certificate" + 83031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist enterpriseConfig.getCaCertificate().getSubjectX500Principal() + 83131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist ": " + e); 83231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return -1; 83331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 83431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 83531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist 836992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle //TODO: pass the Uid the WifiStateMachine as a message parameter 83731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist Slog.i("addOrUpdateNetwork", " uid = " + Integer.toString(Binder.getCallingUid()) 838992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle + " SSID " + config.SSID 839992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle + " nid=" + Integer.toString(config.networkId)); 840992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle if (config.networkId == WifiConfiguration.INVALID_NETWORK_ID) { 841992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle config.creatorUid = Binder.getCallingUid(); 842992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle } else { 843992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle config.lastUpdateUid = Binder.getCallingUid(); 844992ae00f25a9cc22cf5db3261bd7e72927069cf7vandwalle } 845155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 846155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config); 847155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 848155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 849155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return -1; 850155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 851155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 852155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "bad network configuration"); 853155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return -1; 854155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 855155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 856155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 85731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist public static void verifyCert(X509Certificate caCert) 85831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist throws GeneralSecurityException, IOException { 85931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist CertificateFactory factory = CertificateFactory.getInstance("X.509"); 86031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist CertPathValidator validator = 86131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist CertPathValidator.getInstance(CertPathValidator.getDefaultType()); 86231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist CertPath path = factory.generateCertPath( 86331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist Arrays.asList(caCert)); 86431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist KeyStore ks = KeyStore.getInstance("AndroidCAStore"); 86531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist ks.load(null, null); 86631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist PKIXParameters params = new PKIXParameters(ks); 86731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist params.setRevocationEnabled(false); 86831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist Log.d("HS2J", "CA Cert: " + caCert.getSubjectX500Principal()); 86931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist validator.validate(path, params); 87031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 87131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist 87231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist /** 873155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See {@link android.net.wifi.WifiManager#removeNetwork(int)} 874155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param netId the integer that identifies the network configuration 875155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to the supplicant 876155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded 877155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 878155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean removeNetwork(int netId) { 879155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 880c35d728a15e9270f5642ef79f5245c89d749285fSky Faber 881002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber if (!isOwner(Binder.getCallingUid())) { 882002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber Slog.e(TAG, "Remove is not authorized for user"); 883002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber return false; 884002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 885002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber 886155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 887155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncRemoveNetwork(mWifiStateMachineChannel, netId); 888155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 889155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 890155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 891155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 892155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 893155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 894155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 895155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See {@link android.net.wifi.WifiManager#enableNetwork(int, boolean)} 896155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param netId the integer that identifies the network configuration 897155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to the supplicant 898155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param disableOthers if true, disable all other networks. 899155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded 900155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 901155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean enableNetwork(int netId, boolean disableOthers) { 902155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 903155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 904155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncEnableNetwork(mWifiStateMachineChannel, netId, 905155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande disableOthers); 906155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 907155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 908155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 909155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 910155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 911155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 912155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 913155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See {@link android.net.wifi.WifiManager#disableNetwork(int)} 914155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param netId the integer that identifies the network configuration 915155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * to the supplicant 916155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded 917155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 918155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean disableNetwork(int netId) { 919155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 920155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 921155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncDisableNetwork(mWifiStateMachineChannel, netId); 922155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 923155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 924155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 925155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 926155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 927155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 928155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 929155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See {@link android.net.wifi.WifiManager#getConnectionInfo()} 930155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the Wi-Fi information, contained in {@link WifiInfo}. 931155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 932155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public WifiInfo getConnectionInfo() { 933155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 934155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 935155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Make sure we have the latest information, by sending 936155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * a status request to the supplicant. 937155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 938155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncRequestConnectionInfo(); 939155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 940155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 941155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 942155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Return the results of the most recent access point scan, in the form of 943155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * a list of {@link ScanResult} objects. 944155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the list of results 945155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 946155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public List<ScanResult> getScanResults(String callingPackage) { 947155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 948155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int userId = UserHandle.getCallingUserId(); 949155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int uid = Binder.getCallingUid(); 950f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk boolean hasInteractUsersFull = checkInteractAcrossUsersFull(); 951155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande long ident = Binder.clearCallingIdentity(); 952155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 953155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mAppOps.noteOp(AppOpsManager.OP_WIFI_SCAN, uid, callingPackage) 954155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande != AppOpsManager.MODE_ALLOWED) { 955155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return new ArrayList<ScanResult>(); 956155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 957f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk if (!isCurrentProfile(userId) && !hasInteractUsersFull) { 9581ecb0083490436303cdb89bc4c46b6743ea0afa8Sky Faber return new ArrayList<ScanResult>(); 9591ecb0083490436303cdb89bc4c46b6743ea0afa8Sky Faber } 960e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov if (!checkCallerHasLocationPermission(callingPackage, uid)) { 961e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov return new ArrayList<ScanResult>(); 962e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov } 963fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina return mWifiStateMachine.syncGetScanResultsList(); 964155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 965155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 966155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 967155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 968155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 969155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 970f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL. 971f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk */ 972f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk private boolean checkInteractAcrossUsersFull() { 973f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk return mContext.checkCallingOrSelfPermission( 974f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) 975f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk == PackageManager.PERMISSION_GRANTED; 976f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk } 977f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk 978f8704c368e0fee0c7cf7e294d109dece6b72e832Jason Monk /** 979b59f69faf9e3de740bbe1e55cef70e9e22858c2aKenny Guy * Returns true if the calling user is the current one or a profile of the 980b59f69faf9e3de740bbe1e55cef70e9e22858c2aKenny Guy * current user.. 981fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina */ 9821ecb0083490436303cdb89bc4c46b6743ea0afa8Sky Faber private boolean isCurrentProfile(int userId) { 983fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina int currentUser = ActivityManager.getCurrentUser(); 984fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina if (userId == currentUser) { 985fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina return true; 986fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina } 987f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott List<UserInfo> profiles = mUserManager.getProfiles(currentUser); 988b59f69faf9e3de740bbe1e55cef70e9e22858c2aKenny Guy for (UserInfo user : profiles) { 989b59f69faf9e3de740bbe1e55cef70e9e22858c2aKenny Guy if (userId == user.id) { 990fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina return true; 991fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina } 992fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina } 993fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina return false; 994fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina } 995fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina 996fd5470391e5342daa38d00b68ccbccfeacbe6d33Alexandra Gherghina /** 9972a325cd07d40941adb93c1284abb263ba650c213Sky Faber * Returns true if uid is an application running under the owner or a profile of the owner. 998002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber * 999002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber * Note: Should not be called if identity is cleared. 1000002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber */ 10012a325cd07d40941adb93c1284abb263ba650c213Sky Faber private boolean isOwner(int uid) { 1002002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber long ident = Binder.clearCallingIdentity(); 10032a325cd07d40941adb93c1284abb263ba650c213Sky Faber int userId = UserHandle.getUserId(uid); 1004002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber try { 1005002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber int ownerUser = UserHandle.USER_OWNER; 1006002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber if (userId == ownerUser) { 1007002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber return true; 1008002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1009f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott List<UserInfo> profiles = mUserManager.getProfiles(ownerUser); 1010002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber for (UserInfo profile : profiles) { 1011002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber if (userId == profile.id) { 1012002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber return true; 1013002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1014002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1015002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber return false; 1016002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1017002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber finally { 1018002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber Binder.restoreCallingIdentity(ident); 1019002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1020002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber } 1021002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber 1022002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber 1023002ea67f42b0f69a8c9fa4719391f9476567b762Sky Faber /** 1024155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Tell the supplicant to persist the current list of configured networks. 1025155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return {@code true} if the operation succeeded 1026155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1027155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TODO: deprecate this 1028155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1029155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean saveConfiguration() { 1030155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean result = true; 1031155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 1032155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mWifiStateMachineChannel != null) { 1033155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.syncSaveConfig(mWifiStateMachineChannel); 1034155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1035155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 1036155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1037155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1038155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1039155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1040155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1041155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Set the country code 1042155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param countryCode ISO 3166 country code. 1043155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param persist {@code true} if the setting should be remembered. 1044155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1045155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The persist behavior exists so that wifi can fall back to the last 1046155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * persisted country code on a restart, when the locale information is 1047155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * not available from telephony. 1048155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1049155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setCountryCode(String countryCode, boolean persist) { 1050155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.i(TAG, "WifiService trying to set country code to " + countryCode + 1051155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande " with persist set to " + persist); 10529c22c8ea193360f50ad490368ca6a11af0684362Robert Greenwalt enforceConnectivityInternalPermission(); 1053155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final long token = Binder.clearCallingIdentity(); 1054155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1055155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.setCountryCode(countryCode, persist); 1056155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1057155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(token); 1058155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1059155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1060155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 106180d14d67a956e6c69433470aaa73100898166efaxinhe /** 106280d14d67a956e6c69433470aaa73100898166efaxinhe * Get the country code 106380d14d67a956e6c69433470aaa73100898166efaxinhe * @return ISO 3166 country code. 106480d14d67a956e6c69433470aaa73100898166efaxinhe */ 106580d14d67a956e6c69433470aaa73100898166efaxinhe public String getCountryCode() { 106680d14d67a956e6c69433470aaa73100898166efaxinhe enforceConnectivityInternalPermission(); 106780d14d67a956e6c69433470aaa73100898166efaxinhe String country = mWifiStateMachine.getCountryCode(); 106880d14d67a956e6c69433470aaa73100898166efaxinhe return country; 106980d14d67a956e6c69433470aaa73100898166efaxinhe } 1070155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1071155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Set the operational frequency band 1072155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param band One of 1073155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_FREQUENCY_BAND_AUTO}, 1074155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_FREQUENCY_BAND_5GHZ}, 1075155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * {@link WifiManager#WIFI_FREQUENCY_BAND_2GHZ}, 1076155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @param persist {@code true} if the setting should be remembered. 1077155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1078155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1079155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void setFrequencyBand(int band, boolean persist) { 1080155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 1081155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!isDualBandSupported()) return; 1082155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.i(TAG, "WifiService trying to set frequency band to " + band + 1083155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande " with persist set to " + persist); 1084155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final long token = Binder.clearCallingIdentity(); 1085155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1086155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.setFrequencyBand(band, persist); 1087155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1088155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(token); 1089155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1090155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1091155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1092155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1093155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1094155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Get the operational frequency band 1095155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1096155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getFrequencyBand() { 1097155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 1098155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.getFrequencyBand(); 1099155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean isDualBandSupported() { 1102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande //TODO: Should move towards adding a driver API that checks at runtime 1103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mContext.getResources().getBoolean( 1104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande com.android.internal.R.bool.config_wifi_dual_band_support); 1105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Return the DHCP-assigned addresses from the last successful DHCP request, 1109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * if any. 1110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @return the DHCP information 1111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * @deprecated 1112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public DhcpInfo getDhcpInfo() { 1114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 1115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande DhcpResults dhcpResults = mWifiStateMachine.syncGetDhcpResults(); 1116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande DhcpInfo info = new DhcpInfo(); 11183b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti 11193b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti if (dhcpResults.ipAddress != null && 11203b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti dhcpResults.ipAddress.getAddress() instanceof Inet4Address) { 11213b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address) dhcpResults.ipAddress.getAddress()); 1122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 11233b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti 11243b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti if (dhcpResults.gateway != null) { 11253b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti info.gateway = NetworkUtils.inetAddressToInt((Inet4Address) dhcpResults.gateway); 1126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 11273b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti 1128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int dnsFound = 0; 11293b26801d62a06475b722bbf29cba7f48f376654eLorenzo Colitti for (InetAddress dns : dhcpResults.dnsServers) { 1130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (dns instanceof Inet4Address) { 1131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (dnsFound == 0) { 1132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande info.dns1 = NetworkUtils.inetAddressToInt((Inet4Address)dns); 1133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande info.dns2 = NetworkUtils.inetAddressToInt((Inet4Address)dns); 1135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (++dnsFound > 1) break; 1137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande InetAddress serverAddress = dhcpResults.serverAddress; 1140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (serverAddress instanceof Inet4Address) { 1141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande info.serverAddress = NetworkUtils.inetAddressToInt((Inet4Address)serverAddress); 1142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande info.leaseDuration = dhcpResults.leaseDuration; 1144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return info; 1146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#startWifi} 1150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void startWifi() { 1153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceConnectivityInternalPermission(); 1154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* TODO: may be add permissions for access only to connectivity service 1155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TODO: if a start issued, keep wifi alive until a stop issued irrespective 1156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * of WifiLock & device idle status unless wifi enabled status is toggled 1157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.setDriverStart(true); 1160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.reconnectCommand(); 1161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#stopWifi} 1165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void stopWifi() { 1168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceConnectivityInternalPermission(); 1169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* 1170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * TODO: if a stop is issued, wifi is brought up only by startWifi 1171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * unless wifi enabled status is toggled 1172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.setDriverStart(false); 1174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#addToBlacklist} 1178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void addToBlacklist(String bssid) { 1181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 1182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1183155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.addToBlacklist(bssid); 1184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1185155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * see {@link android.net.wifi.WifiManager#clearBlacklist} 1188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 1189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void clearBlacklist() { 1191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 1192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.clearBlacklist(); 1194155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1195155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1196155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1197155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * enable TDLS for the local NIC to remote NIC 1198155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * The APPs don't know the remote MAC address to identify NIC though, 1199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * so we need to do additional work to find it from remote IP address 1200155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1201155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1202155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande class TdlsTaskParams { 1203155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String remoteIpAddress; 1204155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean enable; 1205155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1206155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1207155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande class TdlsTask extends AsyncTask<TdlsTaskParams, Integer, Integer> { 1208155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 1209155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande protected Integer doInBackground(TdlsTaskParams... params) { 1210155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1211155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Retrieve parameters for the call 1212155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande TdlsTaskParams param = params[0]; 1213155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String remoteIpAddress = param.remoteIpAddress.trim(); 1214155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean enable = param.enable; 1215155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1216155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Get MAC address of Remote IP 1217155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String macAddress = null; 1218155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1219155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande BufferedReader reader = null; 1220155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1221155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1222155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande reader = new BufferedReader(new FileReader("/proc/net/arp")); 1223155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1224155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Skip over the line bearing colum titles 1225155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String line = reader.readLine(); 1226155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1227155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande while ((line = reader.readLine()) != null) { 1228155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String[] tokens = line.split("[ ]+"); 1229155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (tokens.length < 6) { 1230155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande continue; 1231155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1232155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1233155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // ARP column format is 1234155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Address HWType HWAddress Flags Mask IFace 1235155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String ip = tokens[0]; 1236155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String mac = tokens[3]; 1237155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1238155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (remoteIpAddress.equals(ip)) { 1239155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande macAddress = mac; 1240155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1241155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1242155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1243155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1244155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (macAddress == null) { 1245155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.w(TAG, "Did not find remoteAddress {" + remoteIpAddress + "} in " + 1246155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande "/proc/net/arp"); 1247155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1248155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enableTdlsWithMacAddress(macAddress, enable); 1249155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1250155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1251155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (FileNotFoundException e) { 1252155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Could not open /proc/net/arp to lookup mac address"); 1253155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (IOException e) { 1254155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Could not read /proc/net/arp to lookup mac address"); 1255155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1256155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1257155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (reader != null) { 1258155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande reader.close(); 1259155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1260155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1261155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande catch (IOException e) { 1262155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Do nothing 1263155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1264155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1265155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1266155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return 0; 1267155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1268155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1269155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1270155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void enableTdls(String remoteAddress, boolean enable) { 12718e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer if (remoteAddress == null) { 12728e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer throw new IllegalArgumentException("remoteAddress cannot be null"); 12738e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer } 12748e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer 1275155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande TdlsTaskParams params = new TdlsTaskParams(); 1276155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande params.remoteIpAddress = remoteAddress; 1277155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande params.enable = enable; 1278155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande new TdlsTask().execute(params); 1279155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1280155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1281155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1282155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable) { 12838e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer if (remoteMacAddress == null) { 12848e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer throw new IllegalArgumentException("remoteMacAddress cannot be null"); 12858e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer } 12868e6144b4059fc2117be23d7222893bc57a33f64dJon Larimer 1287155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.enableTdls(remoteMacAddress, enable); 1288155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1289155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1290155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1291155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Get a reference to handler. This is used by a client to establish 1292155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * an AsyncChannel communication with WifiService 1293155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1294155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public Messenger getWifiServiceMessenger() { 1295155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 1296155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceChangePermission(); 1297155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return new Messenger(mClientHandler); 1298155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1299155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 13002ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle /** 13012ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle * Disable an ephemeral network, i.e. network that is created thru a WiFi Scorer 13022ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle */ 13032ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle public void disableEphemeralNetwork(String SSID) { 13042ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle enforceAccessPermission(); 13052ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle enforceChangePermission(); 13062ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle mWifiStateMachine.disableEphemeralNetwork(SSID); 13072ce99b40c36ed0352b31aa85d5f9383d5f0506f5vandwalle } 1308155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1309155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1310155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Get the IP and proxy configuration file 1311155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1312155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String getConfigFile() { 1313155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 1314155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mWifiStateMachine.getConfigFile(); 1315155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1316155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1317155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 1318155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 1319155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void onReceive(Context context, Intent intent) { 1320155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String action = intent.getAction(); 1321155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (action.equals(Intent.ACTION_SCREEN_ON)) { 1322155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_SCREEN_ON); 1323155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (action.equals(Intent.ACTION_USER_PRESENT)) { 1324155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_USER_PRESENT); 1325155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { 1326155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_SCREEN_OFF); 1327155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { 1328155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int pluggedType = intent.getIntExtra("plugged", 0); 1329155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_BATTERY_CHANGED, pluggedType, 0, null); 1330155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { 1331155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, 1332155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande BluetoothAdapter.STATE_DISCONNECTED); 1333155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.sendBluetoothAdapterStateChange(state); 1334155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { 1335155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean emergencyMode = intent.getBooleanExtra("phoneinECMState", false); 1336155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_EMERGENCY_MODE_CHANGED, emergencyMode ? 1 : 0, 0); 133703b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn } else if (action.equals(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED)) { 133803b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn handleIdleModeChanged(); 1339155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1340155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1341155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande }; 1342155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1343155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /** 1344155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Observes settings changes to scan always mode. 1345155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1346155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void registerForScanModeChange() { 1347155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ContentObserver contentObserver = new ContentObserver(null) { 1348155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 1349155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void onChange(boolean selfChange) { 1350155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mSettingsStore.handleWifiScanAlwaysAvailableToggled(); 1351155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_SCAN_ALWAYS_MODE_CHANGED); 1352155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1353155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande }; 1354155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1355155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.getContentResolver().registerContentObserver( 1356155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Settings.Global.getUriFor(Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE), 1357155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande false, contentObserver); 1358155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1359155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1360155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void registerForBroadcasts() { 1361155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande IntentFilter intentFilter = new IntentFilter(); 1362155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(Intent.ACTION_SCREEN_ON); 1363155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(Intent.ACTION_USER_PRESENT); 1364155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(Intent.ACTION_SCREEN_OFF); 1365155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); 1366155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); 1367155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); 1368155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); 136903b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); 1370155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.registerReceiver(mReceiver, intentFilter); 1371155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1372155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1373faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee private void registerForPackageOrUserRemoval() { 1374e487a4648dd41881e754f1224aaedead78a0777dSky Faber IntentFilter intentFilter = new IntentFilter(); 1375e487a4648dd41881e754f1224aaedead78a0777dSky Faber intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); 1376faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee intentFilter.addAction(Intent.ACTION_USER_REMOVED); 1377faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee mContext.registerReceiverAsUser(new BroadcastReceiver() { 1378e487a4648dd41881e754f1224aaedead78a0777dSky Faber @Override 1379e487a4648dd41881e754f1224aaedead78a0777dSky Faber public void onReceive(Context context, Intent intent) { 1380faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee switch (intent.getAction()) { 1381faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee case Intent.ACTION_PACKAGE_REMOVED: { 1382faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { 1383faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee return; 1384faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee } 1385faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); 1386faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee Uri uri = intent.getData(); 1387faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee if (uid == -1 || uri == null) { 1388faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee return; 1389faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee } 1390faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee String pkgName = uri.getSchemeSpecificPart(); 1391faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee mWifiStateMachine.removeAppConfigs(pkgName, uid); 1392faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee break; 1393faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee } 1394faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee case Intent.ACTION_USER_REMOVED: { 1395faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); 1396faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee mWifiStateMachine.removeUserConfigs(userHandle); 1397faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee break; 1398e487a4648dd41881e754f1224aaedead78a0777dSky Faber } 1399e487a4648dd41881e754f1224aaedead78a0777dSky Faber } 1400e487a4648dd41881e754f1224aaedead78a0777dSky Faber } 1401faa2ce7f93eef2c436796fb1ea3574e2d1412491Robin Lee }, UserHandle.ALL, intentFilter, null, null); 1402e487a4648dd41881e754f1224aaedead78a0777dSky Faber } 1403e487a4648dd41881e754f1224aaedead78a0777dSky Faber 1404155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande @Override 1405155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1406155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 1407155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande != PackageManager.PERMISSION_GRANTED) { 1408155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Permission Denial: can't dump WifiService from from pid=" 1409155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + Binder.getCallingPid() 1410155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande + ", uid=" + Binder.getCallingUid()); 1411155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return; 1412155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1413155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName()); 1414155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Stay-awake conditions: " + 1415155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Settings.Global.getInt(mContext.getContentResolver(), 1416155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0)); 1417155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("mMulticastEnabled " + mMulticastEnabled); 1418155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("mMulticastDisabled " + mMulticastDisabled); 141903b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn pw.println("mInIdleMode " + mInIdleMode); 142003b70b37a8a20cb92d860b5015f6762dcb5e75ccDianne Hackborn pw.println("mScanPending " + mScanPending); 1421155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.dump(fd, pw, args); 1422155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mSettingsStore.dump(fd, pw, args); 1423155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mNotificationController.dump(fd, pw, args); 1424155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTrafficPoller.dump(fd, pw, args); 1425155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1426155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Latest scan results:"); 1427155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande List<ScanResult> scanResults = mWifiStateMachine.syncGetScanResultsList(); 1428a0708b09ad17b086c008ab100aec7143d7613c80vandwalle long nowMs = System.currentTimeMillis(); 1429155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (scanResults != null && scanResults.size() != 0) { 1430a0708b09ad17b086c008ab100aec7143d7613c80vandwalle pw.println(" BSSID Frequency RSSI Age SSID " + 1431a0708b09ad17b086c008ab100aec7143d7613c80vandwalle " Flags"); 1432155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (ScanResult r : scanResults) { 1433a0708b09ad17b086c008ab100aec7143d7613c80vandwalle long ageSec = 0; 1434a0708b09ad17b086c008ab100aec7143d7613c80vandwalle long ageMilli = 0; 1435a0708b09ad17b086c008ab100aec7143d7613c80vandwalle if (nowMs > r.seen && r.seen > 0) { 1436a0708b09ad17b086c008ab100aec7143d7613c80vandwalle ageSec = (nowMs - r.seen) / 1000; 1437a0708b09ad17b086c008ab100aec7143d7613c80vandwalle ageMilli = (nowMs - r.seen) % 1000; 1438a0708b09ad17b086c008ab100aec7143d7613c80vandwalle } 1439a0708b09ad17b086c008ab100aec7143d7613c80vandwalle String candidate = " "; 1440a0708b09ad17b086c008ab100aec7143d7613c80vandwalle if (r.isAutoJoinCandidate > 0) candidate = "+"; 1441a0708b09ad17b086c008ab100aec7143d7613c80vandwalle pw.printf(" %17s %9d %5d %3d.%03d%s %-32s %s\n", 1442155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande r.BSSID, 1443155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande r.frequency, 1444155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande r.level, 1445a0708b09ad17b086c008ab100aec7143d7613c80vandwalle ageSec, ageMilli, 1446a0708b09ad17b086c008ab100aec7143d7613c80vandwalle candidate, 1447a0708b09ad17b086c008ab100aec7143d7613c80vandwalle r.SSID == null ? "" : r.SSID, 1448a0708b09ad17b086c008ab100aec7143d7613c80vandwalle r.capabilities); 1449155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1450155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1451155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println(); 1452155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Locks acquired: " + mFullLocksAcquired + " full, " + 1453155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mFullHighPerfLocksAcquired + " full high perf, " + 1454155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mScanLocksAcquired + " scan"); 1455155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Locks released: " + mFullLocksReleased + " full, " + 1456155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mFullHighPerfLocksReleased + " full high perf, " + 1457155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mScanLocksReleased + " scan"); 1458155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println(); 1459155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println("Locks held:"); 1460155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mLocks.dump(pw); 1461155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 14627e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande pw.println("Multicast Locks held:"); 14637e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande for (Multicaster l : mMulticasters) { 14647e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande pw.print(" "); 14657e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande pw.println(l); 14667e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande } 14677e6573a1866812a302c1bfd224a2ed2d5633259fVinit Deshpande 1468155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiWatchdogStateMachine.dump(fd, pw, args); 1469155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println(); 1470155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.dump(fd, pw, args); 1471155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println(); 1472155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1473155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1474155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private class WifiLock extends DeathRecipient { 1475155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiLock(int lockMode, String tag, IBinder binder, WorkSource ws) { 1476155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande super(lockMode, tag, binder, ws); 1477155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1478155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1479155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void binderDied() { 1480155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLocks) { 1481155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande releaseWifiLockLocked(mBinder); 1482155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1484155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1485155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String toString() { 1486155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return "WifiLock{" + mTag + " type=" + mMode + " binder=" + mBinder + "}"; 1487155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1488155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1489155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1490155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande class LockList { 1491155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private List<WifiLock> mList; 1492155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1493155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private LockList() { 1494155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mList = new ArrayList<WifiLock>(); 1495155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1496155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1497155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized boolean hasLocks() { 1498155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return !mList.isEmpty(); 1499155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1500155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1501155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized int getStrongestLockMode() { 1502155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mList.isEmpty()) { 1503155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return WifiManager.WIFI_MODE_FULL; 1504155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1505155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1506155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mFullHighPerfLocksAcquired > mFullHighPerfLocksReleased) { 1507155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return WifiManager.WIFI_MODE_FULL_HIGH_PERF; 1508155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1509155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1510155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mFullLocksAcquired > mFullLocksReleased) { 1511155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return WifiManager.WIFI_MODE_FULL; 1512155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1513155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1514155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return WifiManager.WIFI_MODE_SCAN_ONLY; 1515155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1516155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1517155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized void updateWorkSource(WorkSource ws) { 1518155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (int i = 0; i < mLocks.mList.size(); i++) { 1519155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ws.add(mLocks.mList.get(i).mWorkSource); 1520155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1521155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1522155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1523155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void addLock(WifiLock lock) { 1524155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (findLockByBinder(lock.mBinder) < 0) { 1525155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mList.add(lock); 1526155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1527155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1528155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1529155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private WifiLock removeLock(IBinder binder) { 1530155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int index = findLockByBinder(binder); 1531155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (index >= 0) { 1532155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiLock ret = mList.remove(index); 1533155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ret.unlinkDeathRecipient(); 1534155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return ret; 1535155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1536155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return null; 1537155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1538155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1539155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1540155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private int findLockByBinder(IBinder binder) { 1541155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int size = mList.size(); 1542155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (int i = size - 1; i >= 0; i--) { 1543155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mList.get(i).mBinder == binder) 1544155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return i; 1545155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1546155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return -1; 1547155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1548155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1549155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void dump(PrintWriter pw) { 1550155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (WifiLock l : mList) { 1551155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.print(" "); 1552155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pw.println(l); 1553155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1554155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1555155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1556155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1557155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande void enforceWakeSourcePermission(int uid, int pid) { 1558155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (uid == android.os.Process.myUid()) { 1559155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return; 1560155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1561155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS, 1562155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande pid, uid, null); 1563155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1564155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1565155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean acquireWifiLock(IBinder binder, int lockMode, String tag, WorkSource ws) { 1566155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); 1567155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (lockMode != WifiManager.WIFI_MODE_FULL && 1568155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande lockMode != WifiManager.WIFI_MODE_SCAN_ONLY && 1569155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande lockMode != WifiManager.WIFI_MODE_FULL_HIGH_PERF) { 1570155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Illegal argument, lockMode= " + lockMode); 1571155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) throw new IllegalArgumentException("lockMode=" + lockMode); 1572155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1573155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1574155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (ws != null && ws.size() == 0) { 1575155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ws = null; 1576155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1577155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (ws != null) { 1578155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceWakeSourcePermission(Binder.getCallingUid(), Binder.getCallingPid()); 1579155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1580155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (ws == null) { 1581155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ws = new WorkSource(Binder.getCallingUid()); 1582155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1583155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiLock wifiLock = new WifiLock(lockMode, tag, binder, ws); 1584155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLocks) { 1585155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return acquireWifiLockLocked(wifiLock); 1586155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1587155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1588155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1589155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void noteAcquireWifiLock(WifiLock wifiLock) throws RemoteException { 1590155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch(wifiLock.mMode) { 1591155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL: 1592155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL_HIGH_PERF: 1593155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_SCAN_ONLY: 1594155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource); 1595155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1596155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1597155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1598155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1599155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void noteReleaseWifiLock(WifiLock wifiLock) throws RemoteException { 1600155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch(wifiLock.mMode) { 1601155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL: 1602155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL_HIGH_PERF: 1603155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_SCAN_ONLY: 1604155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource); 1605155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1606155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1607155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1608155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1609155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean acquireWifiLockLocked(WifiLock wifiLock) { 1610155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "acquireWifiLockLocked: " + wifiLock); 1611155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1612155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mLocks.addLock(wifiLock); 1613155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1614155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande long ident = Binder.clearCallingIdentity(); 1615155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1616155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande noteAcquireWifiLock(wifiLock); 1617155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch(wifiLock.mMode) { 1618155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL: 1619155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mFullLocksAcquired; 1620155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1621155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL_HIGH_PERF: 1622155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mFullHighPerfLocksAcquired; 1623155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1624155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1625155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_SCAN_ONLY: 1626155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mScanLocksAcquired; 1627155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1628155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1629155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_LOCKS_CHANGED); 1630155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 1631155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1632155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 1633155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1634155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 1635155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1636155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1637155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1638155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void updateWifiLockWorkSource(IBinder lock, WorkSource ws) { 1639155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int uid = Binder.getCallingUid(); 1640155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int pid = Binder.getCallingPid(); 1641155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (ws != null && ws.size() == 0) { 1642155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ws = null; 1643155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1644155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (ws != null) { 1645155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceWakeSourcePermission(uid, pid); 1646155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1647155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande long ident = Binder.clearCallingIdentity(); 1648155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1649155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLocks) { 1650155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int index = mLocks.findLockByBinder(lock); 1651155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (index < 0) { 1652155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande throw new IllegalArgumentException("Wifi lock not active"); 1653155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1654155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiLock wl = mLocks.mList.get(index); 1655155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande noteReleaseWifiLock(wl); 1656155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande wl.mWorkSource = ws != null ? new WorkSource(ws) : new WorkSource(uid); 1657155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande noteAcquireWifiLock(wl); 1658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 1662155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean releaseWifiLock(IBinder lock) { 1666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); 1667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mLocks) { 1668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return releaseWifiLockLocked(lock); 1669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private boolean releaseWifiLockLocked(IBinder lock) { 1673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande boolean hadLock; 1674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WifiLock wifiLock = mLocks.removeLock(lock); 1676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) Slog.d(TAG, "releaseWifiLockLocked: " + wifiLock); 1678155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1679155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande hadLock = (wifiLock != null); 1680155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1681155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande long ident = Binder.clearCallingIdentity(); 1682155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1683155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (hadLock) { 1684155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande noteReleaseWifiLock(wifiLock); 1685155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande switch(wifiLock.mMode) { 1686155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL: 1687155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mFullLocksReleased; 1688155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1689155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_FULL_HIGH_PERF: 1690155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mFullHighPerfLocksReleased; 1691155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1692155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande case WifiManager.WIFI_MODE_SCAN_ONLY: 1693155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ++mScanLocksReleased; 1694155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande break; 1695155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1696155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiController.sendMessage(CMD_LOCKS_CHANGED); 1697155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1698155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1699155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1700155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 1701155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1702155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1703155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return hadLock; 1704155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1705155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1706155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private abstract class DeathRecipient 1707155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande implements IBinder.DeathRecipient { 1708155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande String mTag; 1709155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int mMode; 1710155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande IBinder mBinder; 1711155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande WorkSource mWorkSource; 1712155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1713155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande DeathRecipient(int mode, String tag, IBinder binder, WorkSource ws) { 1714155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande super(); 1715155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mTag = tag; 1716155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mMode = mode; 1717155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBinder = binder; 1718155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWorkSource = ws; 1719155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1720155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBinder.linkToDeath(this, 0); 1721155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1722155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande binderDied(); 1723155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1724155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1725155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1726155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande void unlinkDeathRecipient() { 1727155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBinder.unlinkToDeath(this, 0); 1728155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1729155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1730155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1731155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private class Multicaster extends DeathRecipient { 1732155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Multicaster(String tag, IBinder binder) { 1733155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande super(Binder.getCallingUid(), tag, binder, null); 1734155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1735155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1736155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void binderDied() { 1737155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Slog.e(TAG, "Multicaster binderDied"); 1738155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mMulticasters) { 1739155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int i = mMulticasters.indexOf(this); 1740155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (i != -1) { 1741155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande removeMulticasterLocked(i, mMode); 1742155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1743155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1744155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1745155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1746155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public String toString() { 1747155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return "Multicaster{" + mTag + " binder=" + mBinder + "}"; 1748155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1749155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1750155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public int getUid() { 1751155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return mMode; 1752155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1753155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1754155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1755155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void initializeMulticastFiltering() { 1756155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceMulticastChangePermission(); 1757155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1758155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mMulticasters) { 1759155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // if anybody had requested filters be off, leave off 1760155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mMulticasters.size() != 0) { 1761155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return; 1762155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 1763155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.startFilteringMulticastV4Packets(); 1764155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1765155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1766155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1767155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1768155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void acquireMulticastLock(IBinder binder, String tag) { 1769155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceMulticastChangePermission(); 1770155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1771155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mMulticasters) { 1772155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mMulticastEnabled++; 1773155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mMulticasters.add(new Multicaster(tag, binder)); 1774155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Note that we could call stopFilteringMulticastV4Packets only when 1775155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // our new size == 1 (first call), but this function won't 1776155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // be called often and by making the stopPacket call each 1777155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // time we're less fragile and self-healing. 1778155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.stopFilteringMulticastV4Packets(); 1779155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1780155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1781155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int uid = Binder.getCallingUid(); 1782155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final long ident = Binder.clearCallingIdentity(); 1783155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1784155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBatteryStats.noteWifiMulticastEnabled(uid); 1785155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1786155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1787155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 1788155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1789155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1790155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1791155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public void releaseMulticastLock() { 1792155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceMulticastChangePermission(); 1793155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1794155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int uid = Binder.getCallingUid(); 1795155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mMulticasters) { 1796155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mMulticastDisabled++; 1797155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int size = mMulticasters.size(); 1798155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande for (int i = size - 1; i >= 0; i--) { 1799155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Multicaster m = mMulticasters.get(i); 1800155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if ((m != null) && (m.getUid() == uid)) { 1801155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande removeMulticasterLocked(i, uid); 1802155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1803155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1804155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1805155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1806155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1807155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande private void removeMulticasterLocked(int i, int uid) 1808155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { 1809155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Multicaster removed = mMulticasters.remove(i); 1810155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1811155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (removed != null) { 1812155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande removed.unlinkDeathRecipient(); 1813155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1814155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (mMulticasters.size() == 0) { 1815155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mWifiStateMachine.startFilteringMulticastV4Packets(); 1816155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1817155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1818155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande final long ident = Binder.clearCallingIdentity(); 1819155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande try { 1820155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande mBatteryStats.noteWifiMulticastDisabled(uid); 1821155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } catch (RemoteException e) { 1822155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } finally { 1823155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande Binder.restoreCallingIdentity(ident); 1824155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1825155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1826155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1827155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande public boolean isMulticastEnabled() { 1828155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande enforceAccessPermission(); 1829155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1830155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande synchronized (mMulticasters) { 1831155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (mMulticasters.size() > 0); 1832155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 1833155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 18349ae6b45c038fa74a9e7285ef4834551dd93da332Yuhao Zheng 1835511a412adce5a46c41e61f90c0df6de5fb4e491cYuhao Zheng public WifiMonitor getWifiMonitor() { 1836511a412adce5a46c41e61f90c0df6de5fb4e491cYuhao Zheng return mWifiStateMachine.getWifiMonitor(); 18379ae6b45c038fa74a9e7285ef4834551dd93da332Yuhao Zheng } 1838ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle 1839ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle public void enableVerboseLogging(int verbose) { 1840ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle enforceAccessPermission(); 1841ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle mWifiStateMachine.enableVerboseLogging(verbose); 1842ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 1843ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle 1844ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle public int getVerboseLoggingLevel() { 1845ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle enforceAccessPermission(); 1846ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle return mWifiStateMachine.getVerboseLoggingLevel(); 1847ed9938883ae2dade81c8be6cd6ceaef3febd5239vandwalle } 1848c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle 1849c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle public void enableAggressiveHandover(int enabled) { 1850c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle enforceAccessPermission(); 1851c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle mWifiStateMachine.enableAggressiveHandover(enabled); 1852c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle } 1853c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle 1854c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle public int getAggressiveHandover() { 1855c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle enforceAccessPermission(); 1856c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle return mWifiStateMachine.getAggressiveHandover(); 1857c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle } 1858c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle 1859c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle public void setAllowScansWithTraffic(int enabled) { 1860c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle enforceAccessPermission(); 1861c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle mWifiStateMachine.setAllowScansWithTraffic(enabled); 1862c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle } 1863c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle 1864c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle public int getAllowScansWithTraffic() { 1865c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle enforceAccessPermission(); 1866c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle return mWifiStateMachine.getAllowScansWithTraffic(); 1867c6f06c628ee3583b60ff31a7da442e0ac7b26d97vandwalle } 1868c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle 1869b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public void setAllowScansWhileAssociated(int enabled) { 1870e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle enforceAccessPermission(); 1871e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle mWifiStateMachine.setAllowScansWhileAssociated(enabled); 1872e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle } 1873e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle 1874b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public int getAllowScansWhileAssociated() { 1875e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle enforceAccessPermission(); 1876e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle return mWifiStateMachine.getAllowScansWhileAssociated(); 1877e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle } 1878e2614ba1b774529ee68cc4ac189f7492cff89db3Pierre Vandwalle 1879b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public void setHalBasedAutojoinOffload(int enabled) { 1880b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle enforceAccessPermission(); 1881b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle mWifiStateMachine.setHalBasedAutojoinOffload(enabled); 1882b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle } 1883b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle 1884b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public int getHalBasedAutojoinOffload() { 1885b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle enforceAccessPermission(); 1886b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle return mWifiStateMachine.getHalBasedAutojoinOffload(); 1887b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle } 1888b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle 1889b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public void setAllowNetworkSwitchingWhileAssociated(int enabled) { 1890b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle enforceAccessPermission(); 1891b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle mWifiStateMachine.setAllowNetworkSwitchingWhileAssociated(enabled); 1892b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle } 1893b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle 1894b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle public int getAllowNetworkSwitchingWhileAssociated() { 1895b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle enforceAccessPermission(); 1896b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle return mWifiStateMachine.getAllowNetworkSwitchingWhileAssociated(); 1897b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle } 1898b0b0cc202b7d7aaad7b3f69d73e9b58ea2968b05Pierre Vandwalle 1899c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle /* Return the Wifi Connection statistics object */ 1900c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle public WifiConnectionStatistics getConnectionStatistics() { 1901c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle enforceAccessPermission(); 1902c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle enforceReadCredentialPermission(); 1903c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle if (mWifiStateMachineChannel != null) { 1904c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle return mWifiStateMachine.syncGetConnectionStatistics(mWifiStateMachineChannel); 1905c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle } else { 1906c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); 1907c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle return null; 1908c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle } 1909c298087de50ea56c31a4ade7ee1e83b313bb63c7vandwalle } 1910b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott 1911b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott public void factoryReset() { 1912b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott enforceConnectivityInternalPermission(); 1913b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott 1914f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { 1915f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott return; 1916f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott } 1917b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott 1918f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) { 1919f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott // Turn mobile hotspot off 1920f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott setWifiApEnabled(null, false); 1921f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott } 1922f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott 1923f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) { 1924f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott // Enable wifi 1925f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott setWifiEnabled(true); 1926f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott // Delete all Wifi SSIDs 1927f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott List<WifiConfiguration> networks = getConfiguredNetworks(); 1928f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott if (networks != null) { 1929f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott for (WifiConfiguration config : networks) { 1930f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott removeNetwork(config.networkId); 1931f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott } 1932f9d866f1b4e93593b3411886fd71e729f4a5a205Stuart Scott saveConfiguration(); 1933b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott } 1934b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott } 1935b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott } 1936cd0af1c9ddcac881f49c815fb9da45433eb50736Vinit Deshpande 19374d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande /* private methods */ 193831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist static boolean logAndReturnFalse(String s) { 19394d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande Log.d(TAG, s); 19404d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande return false; 19414d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19424d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande 194331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist public static boolean isValid(WifiConfiguration config) { 194431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist String validity = checkValidity(config); 194531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return validity == null || logAndReturnFalse(validity); 194631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 19474d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande 194831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist public static String checkValidity(WifiConfiguration config) { 194931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist if (config.allowedKeyManagement == null) 195031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "allowed kmgmt"; 19514d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande 19524d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (config.allowedKeyManagement.cardinality() > 1) { 19534d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (config.allowedKeyManagement.cardinality() != 2) { 195431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "cardinality != 2"; 19554d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19564d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (!config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) { 195731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "not WPA_EAP"; 19584d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19594d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if ((!config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) 19604d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande && (!config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK))) { 196131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "not PSK or 8021X"; 19624d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19634d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19644d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande 19654d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (!TextUtils.isEmpty(config.FQDN)) { 19664d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande /* this is passpoint configuration; it must not have an SSID */ 19674d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (!TextUtils.isEmpty(config.SSID)) { 196831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "SSID not expected for Passpoint: '" + config.SSID + 196931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist "' FQDN " + toHexString(config.FQDN); 19704d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19714d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande /* this is passpoint configuration; it must have a providerFriendlyName */ 19724d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (TextUtils.isEmpty(config.providerFriendlyName)) { 197331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "no provider friendly name"; 19744d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19754d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande /* this is passpoint configuration; it must have enterprise config */ 19764d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (config.enterpriseConfig == null 197731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist ||config. enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.NONE ) { 197831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "no enterprise config"; 19794d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19804d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande if (config.enterpriseConfig.getCaCertificate() == null) { 198131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "no CA certificate"; 19824d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19834d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 19844d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande 198531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist // TODO: Add more checks 198631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return null; 1987cd0af1c9ddcac881f49c815fb9da45433eb50736Vinit Deshpande } 1988b8671cfafc2830ebddeafcfb2d91f2b39b19019bStuart Scott 19899846078598c3468f8813dbfa58238a1846bd81efSanket Padawe public Network getCurrentNetwork() { 19909846078598c3468f8813dbfa58238a1846bd81efSanket Padawe enforceAccessPermission(); 19919846078598c3468f8813dbfa58238a1846bd81efSanket Padawe return mWifiStateMachine.getCurrentNetwork(); 19929846078598c3468f8813dbfa58238a1846bd81efSanket Padawe } 19939846078598c3468f8813dbfa58238a1846bd81efSanket Padawe 199431891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist public static String toHexString(String s) { 199531891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist if (s == null) { 199631891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return "null"; 199731891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 199831891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist StringBuilder sb = new StringBuilder(); 199931891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist sb.append('\'').append(s).append('\''); 200031891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist for (int n = 0; n < s.length(); n++) { 200131891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist sb.append(String.format(" %02x", s.charAt(n) & 0xffff)); 200231891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist } 200331891afce40b903ada9b24ec12e3648ae6aa27b2Jan Nordqvist return sb.toString(); 20044d381bc39f5263effdae73ec99065eb299b806caVinit Deshpande } 2005cd0af1c9ddcac881f49c815fb9da45433eb50736Vinit Deshpande 2006e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov /** 2007e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov * Checks that calling process has android.Manifest.permission.ACCESS_COARSE_LOCATION or 2008e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov * android.Manifest.permission.ACCESS_FINE_LOCATION and a corresponding app op is allowed 2009e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov */ 2010e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov private boolean checkCallerHasLocationPermission(String callingPackage, int uid) { 2011e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov if (mContext.checkCallingOrSelfPermission( 2012e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED 2013e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov && isAppOppAllowed(AppOpsManager.OP_FINE_LOCATION, callingPackage, uid)) { 2014e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov return true; 2015e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov } 2016e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov 2017e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov return mContext.checkCallingOrSelfPermission( 2018e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED 2019e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov && isAppOppAllowed(AppOpsManager.OP_COARSE_LOCATION, callingPackage, uid); 2020e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov } 2021e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov 2022e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov private boolean isAppOppAllowed(int op, String callingPackage, int uid) { 2023e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov return mAppOps.noteOp(op, uid, callingPackage) == AppOpsManager.MODE_ALLOWED; 2024e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov } 2025e87a8da7bb513ca720b0160e3bff8c9f355faabbFyodor Kupolov 2026155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 2027