1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wifi; 18 19 import android.annotation.NonNull; 20 import android.app.ActivityManager; 21 import android.app.AlarmManager; 22 import android.app.AppOpsManager; 23 import android.app.NotificationManager; 24 import android.content.Context; 25 import android.net.IpMemoryStore; 26 import android.net.NetworkCapabilities; 27 import android.net.NetworkKey; 28 import android.net.NetworkScoreManager; 29 import android.net.wifi.WifiManager; 30 import android.net.wifi.WifiScanner; 31 import android.net.wifi.nl80211.WifiNl80211Manager; 32 import android.os.BatteryStatsManager; 33 import android.os.Handler; 34 import android.os.HandlerExecutor; 35 import android.os.HandlerThread; 36 import android.os.Looper; 37 import android.os.Process; 38 import android.os.SystemProperties; 39 import android.os.UserManager; 40 import android.provider.Settings.Secure; 41 import android.security.keystore.AndroidKeyStoreProvider; 42 import android.telephony.SubscriptionManager; 43 import android.telephony.TelephonyManager; 44 import android.util.LocalLog; 45 import android.util.Log; 46 47 import com.android.server.wifi.aware.WifiAwareMetrics; 48 import com.android.server.wifi.hotspot2.PasspointManager; 49 import com.android.server.wifi.hotspot2.PasspointNetworkNominateHelper; 50 import com.android.server.wifi.hotspot2.PasspointObjectFactory; 51 import com.android.server.wifi.p2p.SupplicantP2pIfaceHal; 52 import com.android.server.wifi.p2p.WifiP2pMetrics; 53 import com.android.server.wifi.p2p.WifiP2pMonitor; 54 import com.android.server.wifi.p2p.WifiP2pNative; 55 import com.android.server.wifi.rtt.RttMetrics; 56 import com.android.server.wifi.util.LruConnectionTracker; 57 import com.android.server.wifi.util.NetdWrapper; 58 import com.android.server.wifi.util.SettingsMigrationDataHolder; 59 import com.android.server.wifi.util.WifiPermissionsUtil; 60 import com.android.server.wifi.util.WifiPermissionsWrapper; 61 62 import java.security.KeyStore; 63 import java.security.KeyStoreException; 64 import java.security.NoSuchProviderException; 65 import java.util.Random; 66 67 /** 68 * WiFi dependency injector. To be used for accessing various WiFi class instances and as a 69 * handle for mock injection. 70 * 71 * Some WiFi class instances currently depend on having a Looper from a HandlerThread that has 72 * been started. To accommodate this, we have a two-phased approach to initialize and retrieve 73 * an instance of the WifiInjector. 74 */ 75 public class WifiInjector { 76 private static final String TAG = "WifiInjector"; 77 private static final String BOOT_DEFAULT_WIFI_COUNTRY_CODE = "ro.boot.wificountrycode"; 78 /** 79 * Maximum number in-memory store network connection order; 80 */ 81 private static final int MAX_RECENTLY_CONNECTED_NETWORK = 100; 82 83 static WifiInjector sWifiInjector = null; 84 85 private final WifiContext mContext; 86 private final BatteryStatsManager mBatteryStats; 87 private final FrameworkFacade mFrameworkFacade; 88 private final DeviceConfigFacade mDeviceConfigFacade; 89 private final UserManager mUserManager; 90 private final HandlerThread mAsyncChannelHandlerThread; 91 private final HandlerThread mWifiHandlerThread; 92 private final HandlerThread mWifiP2pServiceHandlerThread; 93 private final HandlerThread mPasspointProvisionerHandlerThread; 94 private final WifiTrafficPoller mWifiTrafficPoller; 95 private final WifiCountryCode mCountryCode; 96 private final BackupManagerProxy mBackupManagerProxy = new BackupManagerProxy(); 97 private final WifiApConfigStore mWifiApConfigStore; 98 private final WifiNative mWifiNative; 99 private final WifiMonitor mWifiMonitor; 100 private final WifiP2pNative mWifiP2pNative; 101 private final WifiP2pMonitor mWifiP2pMonitor; 102 private final SupplicantStaIfaceHal mSupplicantStaIfaceHal; 103 private final SupplicantP2pIfaceHal mSupplicantP2pIfaceHal; 104 private final HostapdHal mHostapdHal; 105 private final WifiVendorHal mWifiVendorHal; 106 private final ScoringParams mScoringParams; 107 private final ClientModeImpl mClientModeImpl; 108 private final ActiveModeWarden mActiveModeWarden; 109 private final WifiSettingsStore mSettingsStore; 110 private OpenNetworkNotifier mOpenNetworkNotifier; 111 private final WifiLockManager mLockManager; 112 private final WifiNl80211Manager mWifiCondManager; 113 private final Clock mClock = new Clock(); 114 private final WifiMetrics mWifiMetrics; 115 private final WifiP2pMetrics mWifiP2pMetrics; 116 private WifiLastResortWatchdog mWifiLastResortWatchdog; 117 private final PropertyService mPropertyService = new SystemPropertyService(); 118 private final BuildProperties mBuildProperties = new SystemBuildProperties(); 119 private final WifiBackupRestore mWifiBackupRestore; 120 private final SoftApBackupRestore mSoftApBackupRestore; 121 private final WifiMulticastLockManager mWifiMulticastLockManager; 122 private final WifiConfigStore mWifiConfigStore; 123 private final WifiKeyStore mWifiKeyStore; 124 private final WifiConfigManager mWifiConfigManager; 125 private final WifiConnectivityHelper mWifiConnectivityHelper; 126 private final LocalLog mConnectivityLocalLog; 127 private final WifiNetworkSelector mWifiNetworkSelector; 128 private final SavedNetworkNominator mSavedNetworkNominator; 129 private final NetworkSuggestionNominator mNetworkSuggestionNominator; 130 private final ScoredNetworkNominator mScoredNetworkNominator; 131 private final WifiNetworkScoreCache mWifiNetworkScoreCache; 132 private final NetworkScoreManager mNetworkScoreManager; 133 private WifiScanner mWifiScanner; 134 private final WifiPermissionsWrapper mWifiPermissionsWrapper; 135 private final WifiPermissionsUtil mWifiPermissionsUtil; 136 private final PasspointManager mPasspointManager; 137 private HandlerThread mWifiAwareHandlerThread; 138 private HandlerThread mRttHandlerThread; 139 private HalDeviceManager mHalDeviceManager; 140 private final WifiStateTracker mWifiStateTracker; 141 private final SelfRecovery mSelfRecovery; 142 private final WakeupController mWakeupController; 143 private final ScanRequestProxy mScanRequestProxy; 144 private final SarManager mSarManager; 145 private final BaseWifiDiagnostics mWifiDiagnostics; 146 private final WifiDataStall mWifiDataStall; 147 private final WifiScoreCard mWifiScoreCard; 148 private final WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; 149 private final DppMetrics mDppMetrics; 150 private final DppManager mDppManager; 151 private final LinkProbeManager mLinkProbeManager; 152 private IpMemoryStore mIpMemoryStore; 153 private final WifiThreadRunner mWifiThreadRunner; 154 private BssidBlocklistMonitor mBssidBlocklistMonitor; 155 private final MacAddressUtil mMacAddressUtil; 156 private final MboOceController mMboOceController; 157 private final WifiCarrierInfoManager mWifiCarrierInfoManager; 158 private WifiChannelUtilization mWifiChannelUtilizationScan; 159 private WifiChannelUtilization mWifiChannelUtilizationConnected; 160 private final KeyStore mKeyStore; 161 private final ConnectionFailureNotificationBuilder mConnectionFailureNotificationBuilder; 162 private final ThroughputPredictor mThroughputPredictor; 163 private NetdWrapper mNetdWrapper; 164 private final WifiHealthMonitor mWifiHealthMonitor; 165 private final WifiSettingsConfigStore mSettingsConfigStore; 166 private final WifiScanAlwaysAvailableSettingsCompatibility 167 mWifiScanAlwaysAvailableSettingsCompatibility; 168 private final SettingsMigrationDataHolder mSettingsMigrationDataHolder; 169 private final LruConnectionTracker mLruConnectionTracker; 170 WifiInjector(WifiContext context)171 public WifiInjector(WifiContext context) { 172 if (context == null) { 173 throw new IllegalStateException( 174 "WifiInjector should not be initialized with a null Context."); 175 } 176 177 if (sWifiInjector != null) { 178 throw new IllegalStateException( 179 "WifiInjector was already created, use getInstance instead."); 180 } 181 182 sWifiInjector = this; 183 184 // Now create and start handler threads 185 mAsyncChannelHandlerThread = new HandlerThread("AsyncChannelHandlerThread"); 186 mAsyncChannelHandlerThread.start(); 187 mWifiHandlerThread = new HandlerThread("WifiHandlerThread"); 188 mWifiHandlerThread.start(); 189 Looper wifiLooper = mWifiHandlerThread.getLooper(); 190 Handler wifiHandler = new Handler(wifiLooper); 191 192 mFrameworkFacade = new FrameworkFacade(); 193 mMacAddressUtil = new MacAddressUtil(); 194 mContext = context; 195 mSettingsMigrationDataHolder = new SettingsMigrationDataHolder(mContext); 196 mConnectionFailureNotificationBuilder = new ConnectionFailureNotificationBuilder( 197 mContext, getWifiStackPackageName(), mFrameworkFacade); 198 mBatteryStats = context.getSystemService(BatteryStatsManager.class); 199 mWifiPermissionsWrapper = new WifiPermissionsWrapper(mContext); 200 mNetworkScoreManager = mContext.getSystemService(NetworkScoreManager.class); 201 mWifiNetworkScoreCache = new WifiNetworkScoreCache(mContext); 202 mNetworkScoreManager.registerNetworkScoreCallback(NetworkKey.TYPE_WIFI, 203 NetworkScoreManager.SCORE_FILTER_NONE, 204 new HandlerExecutor(wifiHandler), mWifiNetworkScoreCache); 205 mUserManager = mContext.getSystemService(UserManager.class); 206 mWifiPermissionsUtil = new WifiPermissionsUtil(mWifiPermissionsWrapper, mContext, 207 mUserManager, this); 208 mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil); 209 mSoftApBackupRestore = new SoftApBackupRestore(mContext, mSettingsMigrationDataHolder); 210 mWifiStateTracker = new WifiStateTracker(mBatteryStats); 211 mWifiThreadRunner = new WifiThreadRunner(wifiHandler); 212 mWifiP2pServiceHandlerThread = new HandlerThread("WifiP2pService"); 213 mWifiP2pServiceHandlerThread.start(); 214 mPasspointProvisionerHandlerThread = 215 new HandlerThread("PasspointProvisionerHandlerThread"); 216 mPasspointProvisionerHandlerThread.start(); 217 WifiAwareMetrics awareMetrics = new WifiAwareMetrics(mClock); 218 RttMetrics rttMetrics = new RttMetrics(mClock); 219 mWifiP2pMetrics = new WifiP2pMetrics(mClock); 220 mDppMetrics = new DppMetrics(); 221 mWifiMetrics = new WifiMetrics(mContext, mFrameworkFacade, mClock, wifiLooper, 222 awareMetrics, rttMetrics, new WifiPowerMetrics(mBatteryStats), mWifiP2pMetrics, 223 mDppMetrics); 224 mDeviceConfigFacade = new DeviceConfigFacade(mContext, wifiHandler, mWifiMetrics); 225 // Modules interacting with Native. 226 mWifiMonitor = new WifiMonitor(this); 227 mHalDeviceManager = new HalDeviceManager(mClock, wifiHandler); 228 mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, wifiHandler); 229 mSupplicantStaIfaceHal = new SupplicantStaIfaceHal( 230 mContext, mWifiMonitor, mFrameworkFacade, wifiHandler, mClock, mWifiMetrics); 231 mHostapdHal = new HostapdHal(mContext, wifiHandler); 232 mWifiCondManager = (WifiNl80211Manager) mContext.getSystemService( 233 Context.WIFI_NL80211_SERVICE); 234 mWifiNative = new WifiNative( 235 mWifiVendorHal, mSupplicantStaIfaceHal, mHostapdHal, mWifiCondManager, 236 mWifiMonitor, mPropertyService, mWifiMetrics, 237 wifiHandler, new Random(), this); 238 mWifiP2pMonitor = new WifiP2pMonitor(this); 239 mSupplicantP2pIfaceHal = new SupplicantP2pIfaceHal(mWifiP2pMonitor); 240 mWifiP2pNative = new WifiP2pNative(this, 241 mWifiVendorHal, mSupplicantP2pIfaceHal, mHalDeviceManager, 242 mPropertyService); 243 244 // Now get instances of all the objects that depend on the HandlerThreads 245 mWifiTrafficPoller = new WifiTrafficPoller(wifiHandler); 246 mCountryCode = new WifiCountryCode(mContext, wifiHandler, mWifiNative, 247 SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE)); 248 // WifiConfigManager/Store objects and their dependencies. 249 KeyStore keyStore = null; 250 try { 251 keyStore = AndroidKeyStoreProvider.getKeyStoreForUid(Process.WIFI_UID); 252 } catch (KeyStoreException | NoSuchProviderException e) { 253 Log.wtf(TAG, "Failed to load keystore", e); 254 } 255 mKeyStore = keyStore; 256 mWifiKeyStore = new WifiKeyStore(mKeyStore); 257 // New config store 258 mWifiConfigStore = new WifiConfigStore(mContext, wifiHandler, mClock, mWifiMetrics, 259 WifiConfigStore.createSharedFiles(mFrameworkFacade.isNiapModeOn(mContext))); 260 SubscriptionManager subscriptionManager = 261 mContext.getSystemService(SubscriptionManager.class); 262 mWifiCarrierInfoManager = new WifiCarrierInfoManager(makeTelephonyManager(), 263 subscriptionManager, this, mFrameworkFacade, mContext, 264 mWifiConfigStore, wifiHandler, mWifiMetrics); 265 String l2KeySeed = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID); 266 mWifiScoreCard = new WifiScoreCard(mClock, l2KeySeed, mDeviceConfigFacade); 267 mWifiMetrics.setWifiScoreCard(mWifiScoreCard); 268 mLruConnectionTracker = new LruConnectionTracker(MAX_RECENTLY_CONNECTED_NETWORK, 269 mContext); 270 // Config Manager 271 mWifiConfigManager = new WifiConfigManager(mContext, mClock, 272 mUserManager, mWifiCarrierInfoManager, 273 mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, 274 mWifiPermissionsWrapper, this, 275 new NetworkListSharedStoreData(mContext), 276 new NetworkListUserStoreData(mContext), 277 new RandomizedMacStoreData(), mFrameworkFacade, wifiHandler, mDeviceConfigFacade, 278 mWifiScoreCard, mLruConnectionTracker); 279 mSettingsConfigStore = new WifiSettingsConfigStore(context, wifiHandler, 280 mSettingsMigrationDataHolder, mWifiConfigManager, mWifiConfigStore); 281 mSettingsStore = new WifiSettingsStore(mContext, mSettingsConfigStore); 282 mWifiMetrics.setWifiConfigManager(mWifiConfigManager); 283 284 mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative); 285 mConnectivityLocalLog = new LocalLog( 286 mContext.getSystemService(ActivityManager.class).isLowRamDevice() ? 256 : 512); 287 mScoringParams = new ScoringParams(mContext); 288 mWifiMetrics.setScoringParams(mScoringParams); 289 mThroughputPredictor = new ThroughputPredictor(mContext); 290 mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiScoreCard, mScoringParams, 291 mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiMetrics, mWifiNative, 292 mThroughputPredictor); 293 CompatibilityScorer compatibilityScorer = new CompatibilityScorer(mScoringParams); 294 mWifiNetworkSelector.registerCandidateScorer(compatibilityScorer); 295 ScoreCardBasedScorer scoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams); 296 mWifiNetworkSelector.registerCandidateScorer(scoreCardBasedScorer); 297 BubbleFunScorer bubbleFunScorer = new BubbleFunScorer(mScoringParams); 298 mWifiNetworkSelector.registerCandidateScorer(bubbleFunScorer); 299 ThroughputScorer throughputScorer = new ThroughputScorer(mScoringParams); 300 mWifiNetworkSelector.registerCandidateScorer(throughputScorer); 301 mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector); 302 mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, wifiHandler, 303 this, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, mWifiMetrics, 304 mWifiCarrierInfoManager, mWifiKeyStore, mLruConnectionTracker); 305 mPasspointManager = new PasspointManager(mContext, this, 306 wifiHandler, mWifiNative, mWifiKeyStore, mClock, new PasspointObjectFactory(), 307 mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager); 308 PasspointNetworkNominateHelper nominateHelper = 309 new PasspointNetworkNominateHelper(mPasspointManager, mWifiConfigManager, 310 mConnectivityLocalLog); 311 mSavedNetworkNominator = new SavedNetworkNominator( 312 mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager, 313 mWifiPermissionsUtil, mWifiNetworkSuggestionsManager); 314 mNetworkSuggestionNominator = new NetworkSuggestionNominator(mWifiNetworkSuggestionsManager, 315 mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager); 316 mScoredNetworkNominator = new ScoredNetworkNominator(mContext, wifiHandler, 317 mFrameworkFacade, mNetworkScoreManager, mContext.getPackageManager(), 318 mWifiConfigManager, mConnectivityLocalLog, 319 mWifiNetworkScoreCache, mWifiPermissionsUtil); 320 321 mWifiMetrics.setPasspointManager(mPasspointManager); 322 mScanRequestProxy = new ScanRequestProxy(mContext, 323 (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE), 324 (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE), 325 this, mWifiConfigManager, 326 mWifiPermissionsUtil, mWifiMetrics, mClock, wifiHandler, mSettingsConfigStore); 327 mSarManager = new SarManager(mContext, makeTelephonyManager(), wifiLooper, 328 mWifiNative); 329 mWifiDiagnostics = new WifiDiagnostics( 330 mContext, this, mWifiNative, mBuildProperties, 331 new LastMileLogger(this), mClock); 332 mWifiChannelUtilizationConnected = new WifiChannelUtilization(mClock, mContext); 333 mWifiDataStall = new WifiDataStall(mFrameworkFacade, mWifiMetrics, mContext, 334 mDeviceConfigFacade, mWifiChannelUtilizationConnected, mClock, wifiHandler, 335 mThroughputPredictor); 336 mWifiMetrics.setWifiDataStall(mWifiDataStall); 337 mLinkProbeManager = new LinkProbeManager(mClock, mWifiNative, mWifiMetrics, 338 mFrameworkFacade, wifiHandler, mContext); 339 SupplicantStateTracker supplicantStateTracker = new SupplicantStateTracker( 340 mContext, mWifiConfigManager, mBatteryStats, wifiHandler); 341 mMboOceController = new MboOceController(makeTelephonyManager(), mWifiNative); 342 mWifiHealthMonitor = new WifiHealthMonitor(mContext, this, mClock, mWifiConfigManager, 343 mWifiScoreCard, wifiHandler, mWifiNative, l2KeySeed, mDeviceConfigFacade); 344 mWifiMetrics.setWifiHealthMonitor(mWifiHealthMonitor); 345 mClientModeImpl = new ClientModeImpl(mContext, mFrameworkFacade, 346 wifiLooper, mUserManager, 347 this, mBackupManagerProxy, mCountryCode, mWifiNative, 348 new WrongPasswordNotifier(mContext, mFrameworkFacade), 349 mSarManager, mWifiTrafficPoller, mLinkProbeManager, mBatteryStats, 350 supplicantStateTracker, mMboOceController, mWifiCarrierInfoManager, 351 new EapFailureNotifier(mContext, mFrameworkFacade, mWifiCarrierInfoManager), 352 new SimRequiredNotifier(mContext, mFrameworkFacade)); 353 mActiveModeWarden = new ActiveModeWarden(this, wifiLooper, 354 mWifiNative, new DefaultModeManager(mContext), mBatteryStats, mWifiDiagnostics, 355 mContext, mClientModeImpl, mSettingsStore, mFrameworkFacade, mWifiPermissionsUtil); 356 mWifiScanAlwaysAvailableSettingsCompatibility = 357 new WifiScanAlwaysAvailableSettingsCompatibility(mContext, wifiHandler, 358 mSettingsStore, mActiveModeWarden, mFrameworkFacade); 359 mWifiApConfigStore = new WifiApConfigStore( 360 mContext, this, wifiHandler, mBackupManagerProxy, 361 mWifiConfigStore, mWifiConfigManager, mActiveModeWarden, mWifiMetrics); 362 WakeupNotificationFactory wakeupNotificationFactory = 363 new WakeupNotificationFactory(mContext, this, mFrameworkFacade); 364 WakeupOnboarding wakeupOnboarding = new WakeupOnboarding(mContext, mWifiConfigManager, 365 wifiHandler, mFrameworkFacade, wakeupNotificationFactory); 366 mWakeupController = new WakeupController(mContext, wifiHandler, 367 new WakeupLock(mWifiConfigManager, mWifiMetrics.getWakeupMetrics(), mClock), 368 new WakeupEvaluator(mScoringParams), wakeupOnboarding, mWifiConfigManager, 369 mWifiConfigStore, mWifiNetworkSuggestionsManager, mWifiMetrics.getWakeupMetrics(), 370 this, mFrameworkFacade, mClock); 371 mLockManager = new WifiLockManager(mContext, mBatteryStats, 372 mClientModeImpl, mFrameworkFacade, wifiHandler, mWifiNative, mClock, mWifiMetrics); 373 mSelfRecovery = new SelfRecovery(mContext, mActiveModeWarden, mClock); 374 mWifiMulticastLockManager = new WifiMulticastLockManager( 375 mClientModeImpl.getMcastLockManagerFilterController(), mBatteryStats); 376 mDppManager = new DppManager(wifiHandler, mWifiNative, 377 mWifiConfigManager, mContext, mDppMetrics, mScanRequestProxy); 378 379 // Register the various network Nominators with the network selector. 380 mWifiNetworkSelector.registerNetworkNominator(mSavedNetworkNominator); 381 mWifiNetworkSelector.registerNetworkNominator(mNetworkSuggestionNominator); 382 mWifiNetworkSelector.registerNetworkNominator(mScoredNetworkNominator); 383 384 mClientModeImpl.start(); 385 } 386 387 /** 388 * Obtain an instance of the WifiInjector class. 389 * 390 * This is the generic method to get an instance of the class. The first instance should be 391 * retrieved using the getInstanceWithContext method. 392 */ getInstance()393 public static WifiInjector getInstance() { 394 if (sWifiInjector == null) { 395 throw new IllegalStateException( 396 "Attempted to retrieve a WifiInjector instance before constructor was called."); 397 } 398 return sWifiInjector; 399 } 400 401 /** 402 * Enable verbose logging in Injector objects. Called from the WifiServiceImpl (based on 403 * binder call). 404 */ enableVerboseLogging(int verbose)405 public void enableVerboseLogging(int verbose) { 406 mWifiLastResortWatchdog.enableVerboseLogging(verbose); 407 mWifiBackupRestore.enableVerboseLogging(verbose); 408 mHalDeviceManager.enableVerboseLogging(verbose); 409 mScanRequestProxy.enableVerboseLogging(verbose); 410 mWakeupController.enableVerboseLogging(verbose); 411 mWifiNetworkSuggestionsManager.enableVerboseLogging(verbose); 412 LogcatLog.enableVerboseLogging(verbose); 413 mDppManager.enableVerboseLogging(verbose); 414 mWifiCarrierInfoManager.enableVerboseLogging(verbose); 415 } 416 getUserManager()417 public UserManager getUserManager() { 418 return mUserManager; 419 } 420 getWifiMetrics()421 public WifiMetrics getWifiMetrics() { 422 return mWifiMetrics; 423 } 424 getWifiP2pMetrics()425 public WifiP2pMetrics getWifiP2pMetrics() { 426 return mWifiP2pMetrics; 427 } 428 getSupplicantStaIfaceHal()429 public SupplicantStaIfaceHal getSupplicantStaIfaceHal() { 430 return mSupplicantStaIfaceHal; 431 } 432 getBackupManagerProxy()433 public BackupManagerProxy getBackupManagerProxy() { 434 return mBackupManagerProxy; 435 } 436 getFrameworkFacade()437 public FrameworkFacade getFrameworkFacade() { 438 return mFrameworkFacade; 439 } 440 getAsyncChannelHandlerThread()441 public HandlerThread getAsyncChannelHandlerThread() { 442 return mAsyncChannelHandlerThread; 443 } 444 getWifiP2pServiceHandlerThread()445 public HandlerThread getWifiP2pServiceHandlerThread() { 446 return mWifiP2pServiceHandlerThread; 447 } 448 getPasspointProvisionerHandlerThread()449 public HandlerThread getPasspointProvisionerHandlerThread() { 450 return mPasspointProvisionerHandlerThread; 451 } 452 getWifiHandlerThread()453 public HandlerThread getWifiHandlerThread() { 454 return mWifiHandlerThread; 455 } 456 getWifiTrafficPoller()457 public WifiTrafficPoller getWifiTrafficPoller() { 458 return mWifiTrafficPoller; 459 } 460 getWifiCountryCode()461 public WifiCountryCode getWifiCountryCode() { 462 return mCountryCode; 463 } 464 getWifiApConfigStore()465 public WifiApConfigStore getWifiApConfigStore() { 466 return mWifiApConfigStore; 467 } 468 getSarManager()469 public SarManager getSarManager() { 470 return mSarManager; 471 } 472 getClientModeImpl()473 public ClientModeImpl getClientModeImpl() { 474 return mClientModeImpl; 475 } 476 getActiveModeWarden()477 public ActiveModeWarden getActiveModeWarden() { 478 return mActiveModeWarden; 479 } 480 getWifiSettingsStore()481 public WifiSettingsStore getWifiSettingsStore() { 482 return mSettingsStore; 483 } 484 getWifiLockManager()485 public WifiLockManager getWifiLockManager() { 486 return mLockManager; 487 } 488 getWifiLastResortWatchdog()489 public WifiLastResortWatchdog getWifiLastResortWatchdog() { 490 return mWifiLastResortWatchdog; 491 } 492 getClock()493 public Clock getClock() { 494 return mClock; 495 } 496 getPropertyService()497 public PropertyService getPropertyService() { 498 return mPropertyService; 499 } 500 getBuildProperties()501 public BuildProperties getBuildProperties() { 502 return mBuildProperties; 503 } 504 getWifiBackupRestore()505 public WifiBackupRestore getWifiBackupRestore() { 506 return mWifiBackupRestore; 507 } 508 getSoftApBackupRestore()509 public SoftApBackupRestore getSoftApBackupRestore() { 510 return mSoftApBackupRestore; 511 } 512 getWifiMulticastLockManager()513 public WifiMulticastLockManager getWifiMulticastLockManager() { 514 return mWifiMulticastLockManager; 515 } 516 getWifiConfigManager()517 public WifiConfigManager getWifiConfigManager() { 518 return mWifiConfigManager; 519 } 520 getPasspointManager()521 public PasspointManager getPasspointManager() { 522 return mPasspointManager; 523 } 524 getWakeupController()525 public WakeupController getWakeupController() { 526 return mWakeupController; 527 } 528 getScoringParams()529 public ScoringParams getScoringParams() { 530 return mScoringParams; 531 } 532 getWifiScoreCard()533 public WifiScoreCard getWifiScoreCard() { 534 return mWifiScoreCard; 535 } 536 makeTelephonyManager()537 public TelephonyManager makeTelephonyManager() { 538 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); 539 } 540 getWifiCarrierInfoManager()541 public WifiCarrierInfoManager getWifiCarrierInfoManager() { 542 return mWifiCarrierInfoManager; 543 } 544 getWifiStateTracker()545 public WifiStateTracker getWifiStateTracker() { 546 return mWifiStateTracker; 547 } 548 getDppManager()549 public DppManager getDppManager() { 550 return mDppManager; 551 } 552 553 /** 554 * Create a SoftApManager. 555 * @param config SoftApModeConfiguration object holding the config and mode 556 * @return an instance of SoftApManager 557 */ makeSoftApManager(@onNull ActiveModeManager.Listener listener, @NonNull WifiManager.SoftApCallback callback, @NonNull SoftApModeConfiguration config)558 public SoftApManager makeSoftApManager(@NonNull ActiveModeManager.Listener listener, 559 @NonNull WifiManager.SoftApCallback callback, 560 @NonNull SoftApModeConfiguration config) { 561 return new SoftApManager(mContext, mWifiHandlerThread.getLooper(), 562 mFrameworkFacade, mWifiNative, mCountryCode.getCountryCode(), listener, callback, 563 mWifiApConfigStore, config, mWifiMetrics, mSarManager, mWifiDiagnostics); 564 } 565 566 /** 567 * Create a ClientModeManager 568 * 569 * @param listener listener for ClientModeManager state changes 570 * @return a new instance of ClientModeManager 571 */ makeClientModeManager(ClientModeManager.Listener listener)572 public ClientModeManager makeClientModeManager(ClientModeManager.Listener listener) { 573 return new ClientModeManager(mContext, mWifiHandlerThread.getLooper(), mClock, 574 mWifiNative, listener, mWifiMetrics, mSarManager, mWakeupController, 575 mClientModeImpl); 576 } 577 578 /** 579 * Create a WifiLog instance. 580 * @param tag module name to include in all log messages 581 */ makeLog(String tag)582 public WifiLog makeLog(String tag) { 583 return new LogcatLog(tag); 584 } 585 getWifiDiagnostics()586 public BaseWifiDiagnostics getWifiDiagnostics() { 587 return mWifiDiagnostics; 588 } 589 590 /** 591 * Obtain an instance of WifiScanner. 592 * If it was not already created, then obtain an instance. Note, this must be done lazily since 593 * WifiScannerService is separate and created later. 594 */ getWifiScanner()595 public synchronized WifiScanner getWifiScanner() { 596 if (mWifiScanner == null) { 597 mWifiScanner = mContext.getSystemService(WifiScanner.class); 598 } 599 return mWifiScanner; 600 } 601 602 /** 603 * Construct a new instance of WifiConnectivityManager & its dependencies. 604 * 605 * Create and return a new WifiConnectivityManager. 606 * @param clientModeImpl Instance of client mode impl. 607 * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl. 608 */ makeWifiConnectivityManager(ClientModeImpl clientModeImpl)609 public WifiConnectivityManager makeWifiConnectivityManager(ClientModeImpl clientModeImpl) { 610 mOpenNetworkNotifier = new OpenNetworkNotifier(mContext, 611 mWifiHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics, 612 mWifiConfigManager, mWifiConfigStore, clientModeImpl, 613 new ConnectToNetworkNotificationBuilder(mContext, this, mFrameworkFacade)); 614 mWifiLastResortWatchdog = new WifiLastResortWatchdog(this, mContext, mClock, 615 mWifiMetrics, clientModeImpl, mWifiHandlerThread.getLooper(), mDeviceConfigFacade, 616 mWifiThreadRunner); 617 mBssidBlocklistMonitor = new BssidBlocklistMonitor(mContext, mWifiConnectivityHelper, 618 mWifiLastResortWatchdog, mClock, mConnectivityLocalLog, mWifiScoreCard); 619 mWifiMetrics.setBssidBlocklistMonitor(mBssidBlocklistMonitor); 620 mWifiChannelUtilizationScan = new WifiChannelUtilization(mClock, mContext); 621 return new WifiConnectivityManager(mContext, getScoringParams(), 622 clientModeImpl, this, 623 mWifiConfigManager, mWifiNetworkSuggestionsManager, clientModeImpl.getWifiInfo(), 624 mWifiNetworkSelector, mWifiConnectivityHelper, 625 mWifiLastResortWatchdog, mOpenNetworkNotifier, 626 mWifiMetrics, new Handler(mWifiHandlerThread.getLooper()), 627 mClock, mConnectivityLocalLog, mWifiScoreCard); 628 } 629 630 /** 631 * Construct a new instance of ConnectionFailureNotifier. 632 * @param wifiConnectivityManager 633 * @return the created instance 634 */ makeConnectionFailureNotifier( WifiConnectivityManager wifiConnectivityManager)635 public ConnectionFailureNotifier makeConnectionFailureNotifier( 636 WifiConnectivityManager wifiConnectivityManager) { 637 return new ConnectionFailureNotifier(mContext, this, mFrameworkFacade, mWifiConfigManager, 638 wifiConnectivityManager, new Handler(mWifiHandlerThread.getLooper())); 639 } 640 641 /** 642 * Construct a new instance of {@link WifiNetworkFactory}. 643 * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl. 644 */ makeWifiNetworkFactory( NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager)645 public WifiNetworkFactory makeWifiNetworkFactory( 646 NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager) { 647 return new WifiNetworkFactory( 648 mWifiHandlerThread.getLooper(), mContext, nc, 649 (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE), 650 (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE), 651 (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE), 652 mClock, this, wifiConnectivityManager, mWifiConfigManager, 653 mWifiConfigStore, mWifiPermissionsUtil, mWifiMetrics); 654 } 655 656 /** 657 * Construct an instance of {@link NetworkRequestStoreData}. 658 */ makeNetworkRequestStoreData( NetworkRequestStoreData.DataSource dataSource)659 public NetworkRequestStoreData makeNetworkRequestStoreData( 660 NetworkRequestStoreData.DataSource dataSource) { 661 return new NetworkRequestStoreData(dataSource); 662 } 663 664 /** 665 * Construct a new instance of {@link UntrustedWifiNetworkFactory}. 666 * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl. 667 */ makeUntrustedWifiNetworkFactory( NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager)668 public UntrustedWifiNetworkFactory makeUntrustedWifiNetworkFactory( 669 NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager) { 670 return new UntrustedWifiNetworkFactory( 671 mWifiHandlerThread.getLooper(), mContext, nc, wifiConnectivityManager); 672 } 673 674 /** 675 * Construct an instance of {@link NetworkSuggestionStoreData}. 676 */ makeNetworkSuggestionStoreData( NetworkSuggestionStoreData.DataSource dataSource)677 public NetworkSuggestionStoreData makeNetworkSuggestionStoreData( 678 NetworkSuggestionStoreData.DataSource dataSource) { 679 return new NetworkSuggestionStoreData(dataSource); 680 } 681 682 /** 683 * 684 */ makeImsiProtectionExemptionStoreData( ImsiPrivacyProtectionExemptionStoreData.DataSource dataSource)685 public ImsiPrivacyProtectionExemptionStoreData makeImsiProtectionExemptionStoreData( 686 ImsiPrivacyProtectionExemptionStoreData.DataSource dataSource) { 687 return new ImsiPrivacyProtectionExemptionStoreData(dataSource); 688 } 689 690 /** 691 * Construct an instance of {@link SoftApStoreData}. 692 */ makeSoftApStoreData( SoftApStoreData.DataSource dataSource)693 public SoftApStoreData makeSoftApStoreData( 694 SoftApStoreData.DataSource dataSource) { 695 return new SoftApStoreData(mContext, mSettingsMigrationDataHolder, dataSource); 696 } 697 getWifiPermissionsUtil()698 public WifiPermissionsUtil getWifiPermissionsUtil() { 699 return mWifiPermissionsUtil; 700 } 701 getWifiPermissionsWrapper()702 public WifiPermissionsWrapper getWifiPermissionsWrapper() { 703 return mWifiPermissionsWrapper; 704 } 705 706 /** 707 * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization. 708 * 709 * TODO: share worker thread with other Wi-Fi handlers (b/27924886) 710 */ getWifiAwareHandlerThread()711 public HandlerThread getWifiAwareHandlerThread() { 712 if (mWifiAwareHandlerThread == null) { // lazy initialization 713 mWifiAwareHandlerThread = new HandlerThread("wifiAwareService"); 714 mWifiAwareHandlerThread.start(); 715 } 716 return mWifiAwareHandlerThread; 717 } 718 719 /** 720 * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization. 721 * 722 * TODO: share worker thread with other Wi-Fi handlers (b/27924886) 723 */ getRttHandlerThread()724 public HandlerThread getRttHandlerThread() { 725 if (mRttHandlerThread == null) { // lazy initialization 726 mRttHandlerThread = new HandlerThread("wifiRttService"); 727 mRttHandlerThread.start(); 728 } 729 return mRttHandlerThread; 730 } 731 getMacAddressUtil()732 public MacAddressUtil getMacAddressUtil() { 733 return mMacAddressUtil; 734 } 735 getNotificationManager()736 public NotificationManager getNotificationManager() { 737 return (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); 738 } 739 getConnectionFailureNotificationBuilder()740 public ConnectionFailureNotificationBuilder getConnectionFailureNotificationBuilder() { 741 return mConnectionFailureNotificationBuilder; 742 } 743 744 /** 745 * Returns a single instance of HalDeviceManager for injection. 746 */ getHalDeviceManager()747 public HalDeviceManager getHalDeviceManager() { 748 return mHalDeviceManager; 749 } 750 getWifiNative()751 public WifiNative getWifiNative() { 752 return mWifiNative; 753 } 754 getWifiMonitor()755 public WifiMonitor getWifiMonitor() { 756 return mWifiMonitor; 757 } 758 getWifiP2pNative()759 public WifiP2pNative getWifiP2pNative() { 760 return mWifiP2pNative; 761 } 762 getWifiP2pMonitor()763 public WifiP2pMonitor getWifiP2pMonitor() { 764 return mWifiP2pMonitor; 765 } 766 getSelfRecovery()767 public SelfRecovery getSelfRecovery() { 768 return mSelfRecovery; 769 } 770 getScanRequestProxy()771 public ScanRequestProxy getScanRequestProxy() { 772 return mScanRequestProxy; 773 } 774 getJavaRuntime()775 public Runtime getJavaRuntime() { 776 return Runtime.getRuntime(); 777 } 778 getWifiDataStall()779 public WifiDataStall getWifiDataStall() { 780 return mWifiDataStall; 781 } 782 getWifiNetworkSuggestionsManager()783 public WifiNetworkSuggestionsManager getWifiNetworkSuggestionsManager() { 784 return mWifiNetworkSuggestionsManager; 785 } 786 getIpMemoryStore()787 public IpMemoryStore getIpMemoryStore() { 788 if (mIpMemoryStore == null) { 789 mIpMemoryStore = IpMemoryStore.getMemoryStore(mContext); 790 } 791 return mIpMemoryStore; 792 } 793 getBssidBlocklistMonitor()794 public BssidBlocklistMonitor getBssidBlocklistMonitor() { 795 return mBssidBlocklistMonitor; 796 } 797 getHostapdHal()798 public HostapdHal getHostapdHal() { 799 return mHostapdHal; 800 } 801 getWifiStackPackageName()802 public String getWifiStackPackageName() { 803 return mContext.getPackageName(); 804 } 805 getWifiThreadRunner()806 public WifiThreadRunner getWifiThreadRunner() { 807 return mWifiThreadRunner; 808 } 809 getWifiChannelUtilizationScan()810 public WifiChannelUtilization getWifiChannelUtilizationScan() { 811 return mWifiChannelUtilizationScan; 812 } 813 getWifiNetworkScoreCache()814 public WifiNetworkScoreCache getWifiNetworkScoreCache() { 815 return mWifiNetworkScoreCache; 816 } 817 makeNetdWrapper()818 public NetdWrapper makeNetdWrapper() { 819 if (mNetdWrapper == null) { 820 mNetdWrapper = new NetdWrapper(mContext, new Handler(mWifiHandlerThread.getLooper())); 821 } 822 return mNetdWrapper; 823 } 824 getWifiCondManager()825 public WifiNl80211Manager getWifiCondManager() { 826 return mWifiCondManager; 827 } 828 getWifiHealthMonitor()829 public WifiHealthMonitor getWifiHealthMonitor() { 830 return mWifiHealthMonitor; 831 } 832 getThroughputPredictor()833 public ThroughputPredictor getThroughputPredictor() { 834 return mThroughputPredictor; 835 } 836 getSettingsConfigStore()837 public WifiSettingsConfigStore getSettingsConfigStore() { 838 return mSettingsConfigStore; 839 } 840 841 public WifiScanAlwaysAvailableSettingsCompatibility getWifiScanAlwaysAvailableSettingsCompatibility()842 getWifiScanAlwaysAvailableSettingsCompatibility() { 843 return mWifiScanAlwaysAvailableSettingsCompatibility; 844 } 845 getDeviceConfigFacade()846 public DeviceConfigFacade getDeviceConfigFacade() { 847 return mDeviceConfigFacade; 848 } 849 } 850