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.annotation.Nullable; 21 import android.app.ActivityManager; 22 import android.app.AlarmManager; 23 import android.app.AppOpsManager; 24 import android.content.Context; 25 import android.net.IpMemoryStore; 26 import android.net.LinkProperties; 27 import android.net.MatchAllNetworkSpecifier; 28 import android.net.NetworkAgentConfig; 29 import android.net.NetworkCapabilities; 30 import android.net.NetworkKey; 31 import android.net.NetworkProvider; 32 import android.net.NetworkScoreManager; 33 import android.net.wifi.WifiScanner; 34 import android.net.wifi.nl80211.WifiNl80211Manager; 35 import android.os.BatteryStatsManager; 36 import android.os.Handler; 37 import android.os.HandlerExecutor; 38 import android.os.HandlerThread; 39 import android.os.Looper; 40 import android.os.Process; 41 import android.os.UserManager; 42 import android.os.WorkSource; 43 import android.provider.Settings.Secure; 44 import android.security.keystore.AndroidKeyStoreProvider; 45 import android.telephony.CarrierConfigManager; 46 import android.telephony.SubscriptionManager; 47 import android.telephony.TelephonyManager; 48 import android.util.LocalLog; 49 import android.util.Log; 50 51 import com.android.internal.annotations.VisibleForTesting; 52 import com.android.modules.utils.build.SdkLevel; 53 import com.android.server.wifi.aware.WifiAwareMetrics; 54 import com.android.server.wifi.coex.CoexManager; 55 import com.android.server.wifi.hotspot2.PasspointManager; 56 import com.android.server.wifi.hotspot2.PasspointNetworkNominateHelper; 57 import com.android.server.wifi.hotspot2.PasspointObjectFactory; 58 import com.android.server.wifi.p2p.SupplicantP2pIfaceHal; 59 import com.android.server.wifi.p2p.WifiP2pMetrics; 60 import com.android.server.wifi.p2p.WifiP2pMonitor; 61 import com.android.server.wifi.p2p.WifiP2pNative; 62 import com.android.server.wifi.rtt.RttMetrics; 63 import com.android.server.wifi.util.LastCallerInfoManager; 64 import com.android.server.wifi.util.LruConnectionTracker; 65 import com.android.server.wifi.util.NetdWrapper; 66 import com.android.server.wifi.util.SettingsMigrationDataHolder; 67 import com.android.server.wifi.util.WifiPermissionsUtil; 68 import com.android.server.wifi.util.WifiPermissionsWrapper; 69 import com.android.server.wifi.util.WorkSourceHelper; 70 import com.android.wifi.resources.R; 71 72 import java.security.KeyStore; 73 import java.security.KeyStoreException; 74 import java.security.NoSuchProviderException; 75 import java.util.Random; 76 77 /** 78 * WiFi dependency injector. To be used for accessing various WiFi class instances and as a 79 * handle for mock injection. 80 * 81 * Some WiFi class instances currently depend on having a Looper from a HandlerThread that has 82 * been started. To accommodate this, we have a two-phased approach to initialize and retrieve 83 * an instance of the WifiInjector. 84 */ 85 public class WifiInjector { 86 private static final String TAG = "WifiInjector"; 87 private static final String BOOT_DEFAULT_WIFI_COUNTRY_CODE = "ro.boot.wificountrycode"; 88 /** 89 * Maximum number in-memory store network connection order; 90 */ 91 private static final int MAX_RECENTLY_CONNECTED_NETWORK = 100; 92 makeBaseNetworkCapatibilitiesFilterBuilder()93 private static NetworkCapabilities.Builder makeBaseNetworkCapatibilitiesFilterBuilder() { 94 NetworkCapabilities.Builder builder = new NetworkCapabilities.Builder() 95 .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) 96 .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) 97 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) 98 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING) 99 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED) 100 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED) 101 .setLinkUpstreamBandwidthKbps(1024 * 1024) 102 .setLinkDownstreamBandwidthKbps(1024 * 1024) 103 .setNetworkSpecifier(new MatchAllNetworkSpecifier()); 104 if (SdkLevel.isAtLeastS()) { 105 builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED); 106 } 107 return builder; 108 } 109 110 @VisibleForTesting 111 public static final NetworkCapabilities REGULAR_NETWORK_CAPABILITIES_FILTER = 112 makeBaseNetworkCapatibilitiesFilterBuilder() 113 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) 114 .build(); 115 makeOemNetworkCapatibilitiesFilter()116 private static NetworkCapabilities makeOemNetworkCapatibilitiesFilter() { 117 NetworkCapabilities.Builder builder = 118 makeBaseNetworkCapatibilitiesFilterBuilder() 119 .addCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID); 120 if (SdkLevel.isAtLeastS()) { 121 // OEM_PRIVATE capability was only added in Android S. 122 builder.addCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE); 123 } 124 return builder.build(); 125 } 126 127 private static final NetworkCapabilities OEM_NETWORK_CAPABILITIES_FILTER = 128 makeOemNetworkCapatibilitiesFilter(); 129 130 131 static WifiInjector sWifiInjector = null; 132 133 private final WifiContext mContext; 134 private final BatteryStatsManager mBatteryStats; 135 private final FrameworkFacade mFrameworkFacade = new FrameworkFacade(); 136 private final DeviceConfigFacade mDeviceConfigFacade; 137 private final UserManager mUserManager; 138 private final HandlerThread mWifiHandlerThread; 139 private final HandlerThread mWifiP2pServiceHandlerThread; 140 private final HandlerThread mPasspointProvisionerHandlerThread; 141 private final HandlerThread mWifiDiagnosticsHandlerThread; 142 private final WifiTrafficPoller mWifiTrafficPoller; 143 private final WifiCountryCode mCountryCode; 144 private final BackupManagerProxy mBackupManagerProxy = new BackupManagerProxy(); 145 private final WifiApConfigStore mWifiApConfigStore; 146 private final WifiNative mWifiNative; 147 private final WifiMonitor mWifiMonitor; 148 private final WifiP2pNative mWifiP2pNative; 149 private final WifiP2pMonitor mWifiP2pMonitor; 150 private final SupplicantStaIfaceHal mSupplicantStaIfaceHal; 151 private final SupplicantP2pIfaceHal mSupplicantP2pIfaceHal; 152 private final HostapdHal mHostapdHal; 153 private final WifiVendorHal mWifiVendorHal; 154 private final ScoringParams mScoringParams; 155 private final ActiveModeWarden mActiveModeWarden; 156 private final WifiSettingsStore mSettingsStore; 157 private final OpenNetworkNotifier mOpenNetworkNotifier; 158 private final WifiLockManager mLockManager; 159 private final WifiNl80211Manager mWifiCondManager; 160 private final Clock mClock = new Clock(); 161 private final WifiMetrics mWifiMetrics; 162 private final WifiP2pMetrics mWifiP2pMetrics; 163 private final WifiLastResortWatchdog mWifiLastResortWatchdog; 164 private final PropertyService mPropertyService = new SystemPropertyService(); 165 private final BuildProperties mBuildProperties = new SystemBuildProperties(); 166 private final WifiBackupRestore mWifiBackupRestore; 167 // This will only be null if SdkLevel is not at least S 168 @Nullable private final CoexManager mCoexManager; 169 private final SoftApBackupRestore mSoftApBackupRestore; 170 private final WifiMulticastLockManager mWifiMulticastLockManager; 171 private final WifiConfigStore mWifiConfigStore; 172 private final WifiKeyStore mWifiKeyStore; 173 private final WifiConfigManager mWifiConfigManager; 174 private final WifiConnectivityHelper mWifiConnectivityHelper; 175 private final LocalLog mConnectivityLocalLog; 176 private final WifiNetworkSelector mWifiNetworkSelector; 177 private final SavedNetworkNominator mSavedNetworkNominator; 178 private final NetworkSuggestionNominator mNetworkSuggestionNominator; 179 private final ScoredNetworkNominator mScoredNetworkNominator; 180 private final WifiNetworkScoreCache mWifiNetworkScoreCache; 181 private final NetworkScoreManager mNetworkScoreManager; 182 private final ClientModeManagerBroadcastQueue mBroadcastQueue; 183 private WifiScanner mWifiScanner; 184 private final WifiPermissionsWrapper mWifiPermissionsWrapper; 185 private final WifiPermissionsUtil mWifiPermissionsUtil; 186 private final PasspointManager mPasspointManager; 187 private HandlerThread mWifiAwareHandlerThread; 188 private HandlerThread mRttHandlerThread; 189 private final HalDeviceManager mHalDeviceManager; 190 private final WifiStateTracker mWifiStateTracker; 191 private final SelfRecovery mSelfRecovery; 192 private final WakeupController mWakeupController; 193 private final ScanRequestProxy mScanRequestProxy; 194 private final SarManager mSarManager; 195 private final WifiDiagnostics mWifiDiagnostics; 196 private final WifiDataStall mWifiDataStall; 197 private final WifiScoreCard mWifiScoreCard; 198 private final WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; 199 private final DppMetrics mDppMetrics; 200 private final DppManager mDppManager; 201 private final LinkProbeManager mLinkProbeManager; 202 private IpMemoryStore mIpMemoryStore; 203 private final WifiThreadRunner mWifiThreadRunner; 204 private final WifiBlocklistMonitor mWifiBlocklistMonitor; 205 private final MacAddressUtil mMacAddressUtil = new MacAddressUtil(); 206 private final MboOceController mMboOceController; 207 private final WifiCarrierInfoManager mWifiCarrierInfoManager; 208 private final WifiChannelUtilization mWifiChannelUtilizationScan; 209 private final KeyStore mKeyStore; 210 private final ConnectionFailureNotificationBuilder mConnectionFailureNotificationBuilder; 211 private final ThroughputPredictor mThroughputPredictor; 212 private NetdWrapper mNetdWrapper; 213 private final WifiHealthMonitor mWifiHealthMonitor; 214 private final WifiSettingsConfigStore mSettingsConfigStore; 215 private final WifiScanAlwaysAvailableSettingsCompatibility 216 mWifiScanAlwaysAvailableSettingsCompatibility; 217 private final SettingsMigrationDataHolder mSettingsMigrationDataHolder; 218 private final LruConnectionTracker mLruConnectionTracker; 219 private final WifiConnectivityManager mWifiConnectivityManager; 220 private final ConnectHelper mConnectHelper; 221 private final ConnectionFailureNotifier mConnectionFailureNotifier; 222 private final WifiNetworkFactory mWifiNetworkFactory; 223 private final UntrustedWifiNetworkFactory mUntrustedWifiNetworkFactory; 224 private final OemWifiNetworkFactory mOemWifiNetworkFactory; 225 private final WifiP2pConnection mWifiP2pConnection; 226 private final WifiGlobals mWifiGlobals; 227 private final SimRequiredNotifier mSimRequiredNotifier; 228 private final DefaultClientModeManager mDefaultClientModeManager; 229 private final AdaptiveConnectivityEnabledSettingObserver 230 mAdaptiveConnectivityEnabledSettingObserver; 231 private final MakeBeforeBreakManager mMakeBeforeBreakManager; 232 private final ClientModeImplMonitor mCmiMonitor = new ClientModeImplMonitor(); 233 private final ExternalScoreUpdateObserverProxy mExternalScoreUpdateObserverProxy; 234 private final WifiNotificationManager mWifiNotificationManager; 235 private final LastCallerInfoManager mLastCallerInfoManager; 236 WifiInjector(WifiContext context)237 public WifiInjector(WifiContext context) { 238 if (context == null) { 239 throw new IllegalStateException( 240 "WifiInjector should not be initialized with a null Context."); 241 } 242 243 if (sWifiInjector != null) { 244 throw new IllegalStateException( 245 "WifiInjector was already created, use getInstance instead."); 246 } 247 248 sWifiInjector = this; 249 250 // Now create and start handler threads 251 mWifiHandlerThread = new HandlerThread("WifiHandlerThread"); 252 mWifiHandlerThread.start(); 253 Looper wifiLooper = mWifiHandlerThread.getLooper(); 254 Handler wifiHandler = new Handler(wifiLooper); 255 mWifiDiagnosticsHandlerThread = new HandlerThread("WifiDiagnostics"); 256 mWifiDiagnosticsHandlerThread.start(); 257 258 mContext = context; 259 mWifiNotificationManager = new WifiNotificationManager(mContext); 260 mWifiGlobals = new WifiGlobals(mContext); 261 mScoringParams = new ScoringParams(mContext); 262 mWifiChannelUtilizationScan = new WifiChannelUtilization(mClock, mContext); 263 mSettingsMigrationDataHolder = new SettingsMigrationDataHolder(mContext); 264 mConnectionFailureNotificationBuilder = new ConnectionFailureNotificationBuilder( 265 mContext, mFrameworkFacade); 266 mBatteryStats = context.getSystemService(BatteryStatsManager.class); 267 mWifiPermissionsWrapper = new WifiPermissionsWrapper(mContext); 268 mNetworkScoreManager = mContext.getSystemService(NetworkScoreManager.class); 269 mWifiNetworkScoreCache = new WifiNetworkScoreCache(mContext); 270 mNetworkScoreManager.registerNetworkScoreCallback(NetworkKey.TYPE_WIFI, 271 NetworkScoreManager.SCORE_FILTER_NONE, 272 new HandlerExecutor(wifiHandler), mWifiNetworkScoreCache); 273 mUserManager = mContext.getSystemService(UserManager.class); 274 mWifiPermissionsUtil = new WifiPermissionsUtil(mWifiPermissionsWrapper, mContext, 275 mUserManager, this); 276 mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil); 277 mSoftApBackupRestore = new SoftApBackupRestore(mContext, mSettingsMigrationDataHolder); 278 mWifiStateTracker = new WifiStateTracker(mBatteryStats); 279 mWifiThreadRunner = new WifiThreadRunner(wifiHandler); 280 mWifiP2pServiceHandlerThread = new HandlerThread("WifiP2pService"); 281 mWifiP2pServiceHandlerThread.start(); 282 mPasspointProvisionerHandlerThread = 283 new HandlerThread("PasspointProvisionerHandlerThread"); 284 mPasspointProvisionerHandlerThread.start(); 285 WifiAwareMetrics awareMetrics = new WifiAwareMetrics(mClock); 286 RttMetrics rttMetrics = new RttMetrics(mClock); 287 mWifiP2pMetrics = new WifiP2pMetrics(mClock); 288 mDppMetrics = new DppMetrics(); 289 mWifiMonitor = new WifiMonitor(); 290 mWifiMetrics = new WifiMetrics(mContext, mFrameworkFacade, mClock, wifiLooper, 291 awareMetrics, rttMetrics, new WifiPowerMetrics(mBatteryStats), mWifiP2pMetrics, 292 mDppMetrics, mWifiMonitor); 293 mDeviceConfigFacade = new DeviceConfigFacade(mContext, wifiHandler, mWifiMetrics); 294 mAdaptiveConnectivityEnabledSettingObserver = 295 new AdaptiveConnectivityEnabledSettingObserver(wifiHandler, mWifiMetrics, 296 mFrameworkFacade, mContext); 297 // Modules interacting with Native. 298 mHalDeviceManager = new HalDeviceManager(mClock, this, wifiHandler); 299 mWifiVendorHal = new WifiVendorHal(mContext, mHalDeviceManager, wifiHandler, mWifiGlobals); 300 mSupplicantStaIfaceHal = new SupplicantStaIfaceHal( 301 mContext, mWifiMonitor, mFrameworkFacade, wifiHandler, mClock, mWifiMetrics, 302 mWifiGlobals); 303 mHostapdHal = new HostapdHal(mContext, wifiHandler); 304 mWifiCondManager = (WifiNl80211Manager) mContext.getSystemService( 305 Context.WIFI_NL80211_SERVICE); 306 mWifiNative = new WifiNative( 307 mWifiVendorHal, mSupplicantStaIfaceHal, mHostapdHal, mWifiCondManager, 308 mWifiMonitor, mPropertyService, mWifiMetrics, 309 wifiHandler, new Random(), mBuildProperties, this); 310 mWifiP2pMonitor = new WifiP2pMonitor(); 311 mSupplicantP2pIfaceHal = new SupplicantP2pIfaceHal(mWifiP2pMonitor); 312 mWifiP2pNative = new WifiP2pNative(mWifiCondManager, mWifiNative, 313 mWifiVendorHal, mSupplicantP2pIfaceHal, mHalDeviceManager, mPropertyService); 314 SubscriptionManager subscriptionManager = 315 mContext.getSystemService(SubscriptionManager.class); 316 if (SdkLevel.isAtLeastS()) { 317 mCoexManager = new CoexManager(mContext, mWifiNative, makeTelephonyManager(), 318 subscriptionManager, mContext.getSystemService(CarrierConfigManager.class), 319 wifiHandler); 320 } else { 321 mCoexManager = null; 322 } 323 324 // Now get instances of all the objects that depend on the HandlerThreads 325 mWifiTrafficPoller = new WifiTrafficPoller(mContext); 326 // WifiConfigManager/Store objects and their dependencies. 327 KeyStore keyStore = null; 328 try { 329 keyStore = AndroidKeyStoreProvider.getKeyStoreForUid(Process.WIFI_UID); 330 } catch (KeyStoreException | NoSuchProviderException e) { 331 Log.wtf(TAG, "Failed to load keystore", e); 332 } 333 mKeyStore = keyStore; 334 mWifiKeyStore = new WifiKeyStore(mContext, mKeyStore, mFrameworkFacade); 335 // New config store 336 mWifiConfigStore = new WifiConfigStore(mContext, wifiHandler, mClock, mWifiMetrics, 337 WifiConfigStore.createSharedFiles(mFrameworkFacade.isNiapModeOn(mContext))); 338 mWifiCarrierInfoManager = new WifiCarrierInfoManager(makeTelephonyManager(), 339 subscriptionManager, this, mFrameworkFacade, mContext, 340 mWifiConfigStore, wifiHandler, mWifiMetrics, mClock); 341 String l2KeySeed = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID); 342 mWifiScoreCard = new WifiScoreCard(mClock, l2KeySeed, mDeviceConfigFacade, 343 mFrameworkFacade, mContext); 344 mWifiMetrics.setWifiScoreCard(mWifiScoreCard); 345 mLruConnectionTracker = new LruConnectionTracker(MAX_RECENTLY_CONNECTED_NETWORK, 346 mContext); 347 mWifiConnectivityHelper = new WifiConnectivityHelper(this); 348 int maxLinesLowRam = mContext.getResources().getInteger( 349 R.integer.config_wifiConnectivityLocalLogMaxLinesLowRam); 350 int maxLinesHighRam = mContext.getResources().getInteger( 351 R.integer.config_wifiConnectivityLocalLogMaxLinesHighRam); 352 mConnectivityLocalLog = new LocalLog( 353 mContext.getSystemService(ActivityManager.class).isLowRamDevice() ? maxLinesLowRam 354 : maxLinesHighRam); 355 mWifiDiagnostics = new WifiDiagnostics( 356 mContext, this, mWifiNative, mBuildProperties, 357 new LastMileLogger(this), mClock, mWifiDiagnosticsHandlerThread.getLooper()); 358 mWifiLastResortWatchdog = new WifiLastResortWatchdog(this, mContext, mClock, 359 mWifiMetrics, mWifiDiagnostics, wifiLooper, 360 mDeviceConfigFacade, mWifiThreadRunner, mWifiMonitor); 361 mWifiBlocklistMonitor = new WifiBlocklistMonitor(mContext, mWifiConnectivityHelper, 362 mWifiLastResortWatchdog, mClock, new LocalLog( 363 mContext.getSystemService(ActivityManager.class).isLowRamDevice() ? 128 : 256), 364 mWifiScoreCard, mScoringParams, mWifiMetrics); 365 mWifiMetrics.setWifiBlocklistMonitor(mWifiBlocklistMonitor); 366 // Config Manager 367 mWifiConfigManager = new WifiConfigManager(mContext, mClock, 368 mUserManager, mWifiCarrierInfoManager, 369 mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, 370 mMacAddressUtil, mWifiMetrics, mWifiBlocklistMonitor, mWifiLastResortWatchdog, 371 new NetworkListSharedStoreData(mContext), 372 new NetworkListUserStoreData(mContext), 373 new RandomizedMacStoreData(), mFrameworkFacade, mDeviceConfigFacade, 374 mWifiScoreCard, mLruConnectionTracker, mBuildProperties); 375 mSettingsConfigStore = new WifiSettingsConfigStore(context, wifiHandler, 376 mSettingsMigrationDataHolder, mWifiConfigManager, mWifiConfigStore); 377 mSettingsStore = new WifiSettingsStore(mContext, mSettingsConfigStore); 378 mWifiMetrics.setWifiConfigManager(mWifiConfigManager); 379 mWifiMetrics.setWifiSettingsStore(mSettingsStore); 380 381 mWifiMetrics.setScoringParams(mScoringParams); 382 mThroughputPredictor = new ThroughputPredictor(mContext); 383 mScanRequestProxy = new ScanRequestProxy(mContext, 384 mContext.getSystemService(AppOpsManager.class), 385 mContext.getSystemService(ActivityManager.class), 386 this, mWifiConfigManager, 387 mWifiPermissionsUtil, mWifiMetrics, mClock, wifiHandler, mSettingsConfigStore); 388 mSarManager = new SarManager(mContext, makeTelephonyManager(), wifiLooper, 389 mWifiNative); 390 mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiScoreCard, mScoringParams, 391 mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiMetrics, this, 392 mThroughputPredictor, mWifiChannelUtilizationScan, mWifiGlobals, 393 mScanRequestProxy); 394 CompatibilityScorer compatibilityScorer = new CompatibilityScorer(mScoringParams); 395 mWifiNetworkSelector.registerCandidateScorer(compatibilityScorer); 396 ScoreCardBasedScorer scoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams); 397 mWifiNetworkSelector.registerCandidateScorer(scoreCardBasedScorer); 398 BubbleFunScorer bubbleFunScorer = new BubbleFunScorer(mScoringParams); 399 mWifiNetworkSelector.registerCandidateScorer(bubbleFunScorer); 400 ThroughputScorer throughputScorer = new ThroughputScorer(mScoringParams); 401 mWifiNetworkSelector.registerCandidateScorer(throughputScorer); 402 mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector); 403 mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, wifiHandler, 404 this, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, mWifiMetrics, 405 mWifiCarrierInfoManager, mWifiKeyStore, mLruConnectionTracker, 406 mClock); 407 mPasspointManager = new PasspointManager(mContext, this, 408 wifiHandler, mWifiNative, mWifiKeyStore, mClock, new PasspointObjectFactory(), 409 mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, 410 mMacAddressUtil, mWifiPermissionsUtil); 411 PasspointNetworkNominateHelper nominateHelper = 412 new PasspointNetworkNominateHelper(mPasspointManager, mWifiConfigManager, 413 mConnectivityLocalLog); 414 mSavedNetworkNominator = new SavedNetworkNominator( 415 mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager, 416 mWifiPermissionsUtil, mWifiNetworkSuggestionsManager); 417 mNetworkSuggestionNominator = new NetworkSuggestionNominator(mWifiNetworkSuggestionsManager, 418 mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager, 419 mWifiMetrics); 420 mScoredNetworkNominator = new ScoredNetworkNominator(mContext, wifiHandler, 421 mFrameworkFacade, mNetworkScoreManager, mContext.getPackageManager(), 422 mWifiConfigManager, mConnectivityLocalLog, 423 mWifiNetworkScoreCache, mWifiPermissionsUtil); 424 425 mWifiMetrics.setPasspointManager(mPasspointManager); 426 WifiChannelUtilization wifiChannelUtilizationConnected = 427 new WifiChannelUtilization(mClock, mContext); 428 mWifiMetrics.setWifiChannelUtilization(wifiChannelUtilizationConnected); 429 mLinkProbeManager = new LinkProbeManager(mClock, mWifiNative, mWifiMetrics, 430 mFrameworkFacade, wifiHandler, mContext); 431 mDefaultClientModeManager = new DefaultClientModeManager(); 432 mExternalScoreUpdateObserverProxy = 433 new ExternalScoreUpdateObserverProxy(mWifiThreadRunner); 434 mDppManager = new DppManager(wifiHandler, mWifiNative, 435 mWifiConfigManager, mContext, mDppMetrics, mScanRequestProxy, mWifiPermissionsUtil); 436 mActiveModeWarden = new ActiveModeWarden(this, wifiLooper, 437 mWifiNative, mDefaultClientModeManager, mBatteryStats, mWifiDiagnostics, 438 mContext, mSettingsStore, mFrameworkFacade, mWifiPermissionsUtil, mWifiMetrics, 439 mExternalScoreUpdateObserverProxy, mDppManager); 440 mWifiMetrics.setActiveModeWarden(mActiveModeWarden); 441 mWifiHealthMonitor = new WifiHealthMonitor(mContext, this, mClock, mWifiConfigManager, 442 mWifiScoreCard, wifiHandler, mWifiNative, l2KeySeed, mDeviceConfigFacade, 443 mActiveModeWarden); 444 mWifiDataStall = new WifiDataStall(mFrameworkFacade, mWifiMetrics, mContext, 445 mDeviceConfigFacade, wifiChannelUtilizationConnected, mClock, wifiHandler, 446 mThroughputPredictor, mActiveModeWarden, mCmiMonitor); 447 mWifiMetrics.setWifiDataStall(mWifiDataStall); 448 mWifiMetrics.setWifiHealthMonitor(mWifiHealthMonitor); 449 mWifiP2pConnection = new WifiP2pConnection(mContext, wifiLooper, mActiveModeWarden); 450 mConnectHelper = new ConnectHelper(mActiveModeWarden, mWifiConfigManager); 451 mBroadcastQueue = new ClientModeManagerBroadcastQueue(mActiveModeWarden, mContext); 452 mMakeBeforeBreakManager = new MakeBeforeBreakManager(mActiveModeWarden, mFrameworkFacade, 453 mContext, mCmiMonitor, mBroadcastQueue, mWifiMetrics); 454 mOpenNetworkNotifier = new OpenNetworkNotifier(mContext, 455 wifiLooper, mFrameworkFacade, mClock, mWifiMetrics, 456 mWifiConfigManager, mWifiConfigStore, mConnectHelper, 457 new ConnectToNetworkNotificationBuilder(mContext, mFrameworkFacade), 458 mMakeBeforeBreakManager, mWifiNotificationManager); 459 mWifiConnectivityManager = new WifiConnectivityManager( 460 mContext, mScoringParams, mWifiConfigManager, 461 mWifiNetworkSuggestionsManager, mWifiNetworkSelector, 462 mWifiConnectivityHelper, mWifiLastResortWatchdog, mOpenNetworkNotifier, 463 mWifiMetrics, wifiHandler, 464 mClock, mConnectivityLocalLog, mWifiScoreCard, mWifiBlocklistMonitor, 465 mWifiChannelUtilizationScan, mPasspointManager, mDeviceConfigFacade, 466 mActiveModeWarden, mWifiGlobals); 467 mMboOceController = new MboOceController(makeTelephonyManager(), mActiveModeWarden); 468 mCountryCode = new WifiCountryCode(mContext, mActiveModeWarden, 469 mCmiMonitor, mWifiNative, mSettingsConfigStore); 470 mConnectionFailureNotifier = new ConnectionFailureNotifier( 471 mContext, mFrameworkFacade, mWifiConfigManager, 472 mWifiConnectivityManager, wifiHandler, 473 mWifiNotificationManager, mConnectionFailureNotificationBuilder); 474 mWifiNetworkFactory = new WifiNetworkFactory( 475 wifiLooper, mContext, REGULAR_NETWORK_CAPABILITIES_FILTER, 476 (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE), 477 (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE), 478 (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE), 479 mClock, this, mWifiConnectivityManager, mWifiConfigManager, 480 mWifiConfigStore, mWifiPermissionsUtil, mWifiMetrics, mActiveModeWarden, 481 mConnectHelper, mCmiMonitor); 482 // We can't filter untrusted network in the capabilities filter because a trusted 483 // network would still satisfy a request that accepts untrusted ones. 484 // We need a second network factory for untrusted network requests because we need a 485 // different score filter for these requests. 486 mUntrustedWifiNetworkFactory = new UntrustedWifiNetworkFactory( 487 wifiLooper, mContext, REGULAR_NETWORK_CAPABILITIES_FILTER, 488 mWifiConnectivityManager); 489 mOemWifiNetworkFactory = new OemWifiNetworkFactory( 490 wifiLooper, mContext, OEM_NETWORK_CAPABILITIES_FILTER, 491 mWifiConnectivityManager); 492 mWifiScanAlwaysAvailableSettingsCompatibility = 493 new WifiScanAlwaysAvailableSettingsCompatibility(mContext, wifiHandler, 494 mSettingsStore, mActiveModeWarden, mFrameworkFacade); 495 mWifiApConfigStore = new WifiApConfigStore( 496 mContext, this, wifiHandler, mBackupManagerProxy, 497 mWifiConfigStore, mWifiConfigManager, mActiveModeWarden, mWifiMetrics); 498 WakeupNotificationFactory wakeupNotificationFactory = 499 new WakeupNotificationFactory(mContext, mFrameworkFacade); 500 WakeupOnboarding wakeupOnboarding = new WakeupOnboarding(mContext, mWifiConfigManager, 501 wifiHandler, mFrameworkFacade, wakeupNotificationFactory, mWifiNotificationManager); 502 mWakeupController = new WakeupController(mContext, wifiHandler, 503 new WakeupLock(mWifiConfigManager, mWifiMetrics.getWakeupMetrics(), mClock), 504 new WakeupEvaluator(mScoringParams), wakeupOnboarding, mWifiConfigManager, 505 mWifiConfigStore, mWifiNetworkSuggestionsManager, mWifiMetrics.getWakeupMetrics(), 506 this, mFrameworkFacade, mClock, mActiveModeWarden); 507 mLockManager = new WifiLockManager(mContext, mBatteryStats, mActiveModeWarden, 508 mFrameworkFacade, wifiHandler, mClock, mWifiMetrics); 509 mSelfRecovery = new SelfRecovery(mContext, mActiveModeWarden, mClock, mWifiNative); 510 mWifiMulticastLockManager = new WifiMulticastLockManager(mActiveModeWarden, mBatteryStats); 511 512 // Register the various network Nominators with the network selector. 513 mWifiNetworkSelector.registerNetworkNominator(mSavedNetworkNominator); 514 mWifiNetworkSelector.registerNetworkNominator(mNetworkSuggestionNominator); 515 mWifiNetworkSelector.registerNetworkNominator(mScoredNetworkNominator); 516 517 mSimRequiredNotifier = new SimRequiredNotifier(mContext, mFrameworkFacade, 518 mWifiNotificationManager); 519 mLastCallerInfoManager = new LastCallerInfoManager(); 520 } 521 522 /** 523 * Obtain an instance of the WifiInjector class. 524 * 525 * This is the generic method to get an instance of the class. The first instance should be 526 * retrieved using the getInstanceWithContext method. 527 */ getInstance()528 public static WifiInjector getInstance() { 529 if (sWifiInjector == null) { 530 throw new IllegalStateException( 531 "Attempted to retrieve a WifiInjector instance before constructor was called."); 532 } 533 return sWifiInjector; 534 } 535 536 /** 537 * Enable verbose logging in Injector objects. Called from the WifiServiceImpl (based on 538 * binder call). 539 */ enableVerboseLogging(int verbose)540 public void enableVerboseLogging(int verbose) { 541 mWifiLastResortWatchdog.enableVerboseLogging(verbose); 542 mWifiBackupRestore.enableVerboseLogging(verbose); 543 mHalDeviceManager.enableVerboseLogging(verbose); 544 mScanRequestProxy.enableVerboseLogging(verbose); 545 mWakeupController.enableVerboseLogging(verbose); 546 mWifiNetworkSuggestionsManager.enableVerboseLogging(verbose); 547 LogcatLog.enableVerboseLogging(verbose); 548 mDppManager.enableVerboseLogging(verbose); 549 mWifiCarrierInfoManager.enableVerboseLogging(verbose); 550 551 boolean verboseBool = verbose > 0; 552 Log.i(TAG, "enableVerboseLogging(" + verbose + "): " + verboseBool); 553 mCountryCode.enableVerboseLogging(verboseBool); 554 mWifiDiagnostics.enableVerboseLogging(verboseBool); 555 mWifiMonitor.enableVerboseLogging(verboseBool); 556 mWifiNative.enableVerboseLogging(verboseBool); 557 mWifiConfigManager.enableVerboseLogging(verboseBool); 558 mPasspointManager.enableVerboseLogging(verboseBool); 559 mWifiNetworkFactory.enableVerboseLogging(verboseBool); 560 mLinkProbeManager.enableVerboseLogging(verboseBool); 561 mMboOceController.enableVerboseLogging(verboseBool); 562 mWifiScoreCard.enableVerboseLogging(verboseBool); 563 mWifiHealthMonitor.enableVerboseLogging(verboseBool); 564 mThroughputPredictor.enableVerboseLogging(verboseBool); 565 mWifiDataStall.enableVerboseLogging(verboseBool); 566 mWifiConnectivityManager.enableVerboseLogging(verboseBool); 567 mWifiNetworkSelector.enableVerboseLogging(verboseBool); 568 mMakeBeforeBreakManager.setVerboseLoggingEnabled(verboseBool); 569 mBroadcastQueue.setVerboseLoggingEnabled(verboseBool); 570 if (SdkLevel.isAtLeastS()) { 571 mCoexManager.enableVerboseLogging(verboseBool); 572 } 573 mWifiPermissionsWrapper.enableVerboseLogging(verboseBool); 574 mWifiPermissionsUtil.enableVerboseLogging(verboseBool); 575 } 576 getUserManager()577 public UserManager getUserManager() { 578 return mUserManager; 579 } 580 getWifiMetrics()581 public WifiMetrics getWifiMetrics() { 582 return mWifiMetrics; 583 } 584 getWifiP2pMetrics()585 public WifiP2pMetrics getWifiP2pMetrics() { 586 return mWifiP2pMetrics; 587 } 588 getSupplicantStaIfaceHal()589 public SupplicantStaIfaceHal getSupplicantStaIfaceHal() { 590 return mSupplicantStaIfaceHal; 591 } 592 getBackupManagerProxy()593 public BackupManagerProxy getBackupManagerProxy() { 594 return mBackupManagerProxy; 595 } 596 getFrameworkFacade()597 public FrameworkFacade getFrameworkFacade() { 598 return mFrameworkFacade; 599 } 600 getWifiP2pServiceHandlerThread()601 public HandlerThread getWifiP2pServiceHandlerThread() { 602 return mWifiP2pServiceHandlerThread; 603 } 604 getPasspointProvisionerHandlerThread()605 public HandlerThread getPasspointProvisionerHandlerThread() { 606 return mPasspointProvisionerHandlerThread; 607 } 608 getWifiHandlerThread()609 public HandlerThread getWifiHandlerThread() { 610 return mWifiHandlerThread; 611 } 612 getWifiTrafficPoller()613 public WifiTrafficPoller getWifiTrafficPoller() { 614 return mWifiTrafficPoller; 615 } 616 getWifiCountryCode()617 public WifiCountryCode getWifiCountryCode() { 618 return mCountryCode; 619 } 620 getWifiApConfigStore()621 public WifiApConfigStore getWifiApConfigStore() { 622 return mWifiApConfigStore; 623 } 624 getSarManager()625 public SarManager getSarManager() { 626 return mSarManager; 627 } 628 getActiveModeWarden()629 public ActiveModeWarden getActiveModeWarden() { 630 return mActiveModeWarden; 631 } 632 getWifiSettingsStore()633 public WifiSettingsStore getWifiSettingsStore() { 634 return mSettingsStore; 635 } 636 getWifiLockManager()637 public WifiLockManager getWifiLockManager() { 638 return mLockManager; 639 } 640 getWifiLastResortWatchdog()641 public WifiLastResortWatchdog getWifiLastResortWatchdog() { 642 return mWifiLastResortWatchdog; 643 } 644 getClock()645 public Clock getClock() { 646 return mClock; 647 } 648 getWifiBackupRestore()649 public WifiBackupRestore getWifiBackupRestore() { 650 return mWifiBackupRestore; 651 } 652 getSoftApBackupRestore()653 public SoftApBackupRestore getSoftApBackupRestore() { 654 return mSoftApBackupRestore; 655 } 656 getWifiMulticastLockManager()657 public WifiMulticastLockManager getWifiMulticastLockManager() { 658 return mWifiMulticastLockManager; 659 } 660 getWifiConfigManager()661 public WifiConfigManager getWifiConfigManager() { 662 return mWifiConfigManager; 663 } 664 getPasspointManager()665 public PasspointManager getPasspointManager() { 666 return mPasspointManager; 667 } 668 getWakeupController()669 public WakeupController getWakeupController() { 670 return mWakeupController; 671 } 672 getScoringParams()673 public ScoringParams getScoringParams() { 674 return mScoringParams; 675 } 676 getWifiScoreCard()677 public WifiScoreCard getWifiScoreCard() { 678 return mWifiScoreCard; 679 } 680 makeTelephonyManager()681 public TelephonyManager makeTelephonyManager() { 682 return mContext.getSystemService(TelephonyManager.class); 683 } 684 getWifiCarrierInfoManager()685 public WifiCarrierInfoManager getWifiCarrierInfoManager() { 686 return mWifiCarrierInfoManager; 687 } 688 getDppManager()689 public DppManager getDppManager() { 690 return mDppManager; 691 } 692 693 /** 694 * Create a SoftApManager. 695 * 696 * @param config SoftApModeConfiguration object holding the config and mode 697 * @return an instance of SoftApManager 698 */ makeSoftApManager( @onNull ActiveModeManager.Listener<SoftApManager> listener, @NonNull WifiServiceImpl.SoftApCallbackInternal callback, @NonNull SoftApModeConfiguration config, @NonNull WorkSource requestorWs, @NonNull ActiveModeManager.SoftApRole role, boolean verboseLoggingEnabled)699 public SoftApManager makeSoftApManager( 700 @NonNull ActiveModeManager.Listener<SoftApManager> listener, 701 @NonNull WifiServiceImpl.SoftApCallbackInternal callback, 702 @NonNull SoftApModeConfiguration config, 703 @NonNull WorkSource requestorWs, 704 @NonNull ActiveModeManager.SoftApRole role, 705 boolean verboseLoggingEnabled) { 706 return new SoftApManager(mContext, mWifiHandlerThread.getLooper(), 707 mFrameworkFacade, mWifiNative, mCoexManager, mCountryCode.getCountryCode(), 708 listener, callback, mWifiApConfigStore, config, mWifiMetrics, mSarManager, 709 mWifiDiagnostics, new SoftApNotifier(mContext, mFrameworkFacade, 710 mWifiNotificationManager), mCmiMonitor, mActiveModeWarden, 711 mClock.getElapsedSinceBootMillis(), requestorWs, role, verboseLoggingEnabled); 712 } 713 714 /** 715 * Create a ClientModeImpl 716 * @param ifaceName interface name for the ClientModeImpl 717 * @param clientModeManager ClientModeManager that will own the ClientModeImpl 718 */ makeClientModeImpl( @onNull String ifaceName, @NonNull ConcreteClientModeManager clientModeManager, boolean verboseLoggingEnabled)719 public ClientModeImpl makeClientModeImpl( 720 @NonNull String ifaceName, 721 @NonNull ConcreteClientModeManager clientModeManager, 722 boolean verboseLoggingEnabled) { 723 ExtendedWifiInfo wifiInfo = new ExtendedWifiInfo(mWifiGlobals, ifaceName); 724 SupplicantStateTracker supplicantStateTracker = new SupplicantStateTracker( 725 mContext, mWifiConfigManager, mBatteryStats, mWifiHandlerThread.getLooper(), 726 mWifiMonitor, ifaceName, clientModeManager, mBroadcastQueue); 727 supplicantStateTracker.enableVerboseLogging(verboseLoggingEnabled); 728 return new ClientModeImpl(mContext, mWifiMetrics, mClock, 729 mWifiScoreCard, mWifiStateTracker, mWifiPermissionsUtil, mWifiConfigManager, 730 mPasspointManager, mWifiMonitor, mWifiDiagnostics, 731 mWifiDataStall, mScoringParams, mWifiThreadRunner, 732 mWifiNetworkSuggestionsManager, mWifiHealthMonitor, mThroughputPredictor, 733 mDeviceConfigFacade, mScanRequestProxy, wifiInfo, mWifiConnectivityManager, 734 mWifiBlocklistMonitor, mConnectionFailureNotifier, 735 REGULAR_NETWORK_CAPABILITIES_FILTER, mWifiNetworkFactory, 736 mUntrustedWifiNetworkFactory, mOemWifiNetworkFactory, 737 mWifiLastResortWatchdog, mWakeupController, 738 mLockManager, mFrameworkFacade, mWifiHandlerThread.getLooper(), 739 mWifiNative, new WrongPasswordNotifier(mContext, mFrameworkFacade, 740 mWifiNotificationManager), 741 mWifiTrafficPoller, mLinkProbeManager, mClock.getElapsedSinceBootMillis(), 742 mBatteryStats, supplicantStateTracker, mMboOceController, mWifiCarrierInfoManager, 743 new EapFailureNotifier(mContext, mFrameworkFacade, mWifiCarrierInfoManager, 744 mWifiNotificationManager), 745 mSimRequiredNotifier, 746 new WifiScoreReport(mScoringParams, mClock, mWifiMetrics, wifiInfo, 747 mWifiNative, mWifiBlocklistMonitor, mWifiThreadRunner, mWifiScoreCard, 748 mDeviceConfigFacade, mContext, mAdaptiveConnectivityEnabledSettingObserver, 749 ifaceName, mExternalScoreUpdateObserverProxy, mSettingsStore), 750 mWifiP2pConnection, mWifiGlobals, ifaceName, clientModeManager, 751 mCmiMonitor, mBroadcastQueue, mWifiNetworkSelector, makeTelephonyManager(), 752 this, mSettingsConfigStore, verboseLoggingEnabled); 753 } 754 makeWifiNetworkAgent( @onNull NetworkCapabilities nc, @NonNull LinkProperties linkProperties, @NonNull NetworkAgentConfig naConfig, @Nullable NetworkProvider provider, @NonNull WifiNetworkAgent.Callback callback)755 public WifiNetworkAgent makeWifiNetworkAgent( 756 @NonNull NetworkCapabilities nc, 757 @NonNull LinkProperties linkProperties, 758 @NonNull NetworkAgentConfig naConfig, 759 @Nullable NetworkProvider provider, 760 @NonNull WifiNetworkAgent.Callback callback) { 761 return new WifiNetworkAgent(mContext, mWifiHandlerThread.getLooper(), 762 nc, linkProperties, naConfig, provider, callback); 763 } 764 765 /** 766 * Create a ClientModeManager 767 * 768 * @param listener listener for ClientModeManager state changes 769 * @return a new instance of ClientModeManager 770 */ makeClientModeManager( @onNull ClientModeManager.Listener<ConcreteClientModeManager> listener, @NonNull WorkSource requestorWs, @NonNull ActiveModeManager.ClientRole role, boolean verboseLoggingEnabled)771 public ConcreteClientModeManager makeClientModeManager( 772 @NonNull ClientModeManager.Listener<ConcreteClientModeManager> listener, 773 @NonNull WorkSource requestorWs, 774 @NonNull ActiveModeManager.ClientRole role, 775 boolean verboseLoggingEnabled) { 776 return new ConcreteClientModeManager( 777 mContext, mWifiHandlerThread.getLooper(), mClock, 778 mWifiNative, listener, mWifiMetrics, mWakeupController, 779 this, mSelfRecovery, mWifiGlobals, mDefaultClientModeManager, 780 mClock.getElapsedSinceBootMillis(), requestorWs, role, mBroadcastQueue, 781 verboseLoggingEnabled); 782 } 783 makeScanOnlyModeImpl(@onNull String ifaceName)784 public ScanOnlyModeImpl makeScanOnlyModeImpl(@NonNull String ifaceName) { 785 return new ScanOnlyModeImpl(mClock.getElapsedSinceBootMillis(), mWifiNative, ifaceName); 786 } 787 788 /** 789 * Create a WifiLog instance. 790 * 791 * @param tag module name to include in all log messages 792 */ makeLog(String tag)793 public WifiLog makeLog(String tag) { 794 return new LogcatLog(tag); 795 } 796 797 /** 798 * Obtain an instance of WifiScanner. 799 * If it was not already created, then obtain an instance. Note, this must be done lazily since 800 * WifiScannerService is separate and created later. 801 */ getWifiScanner()802 public synchronized WifiScanner getWifiScanner() { 803 if (mWifiScanner == null) { 804 mWifiScanner = mContext.getSystemService(WifiScanner.class); 805 } 806 return mWifiScanner; 807 } 808 809 /** 810 * Construct an instance of {@link NetworkRequestStoreData}. 811 */ makeNetworkRequestStoreData( NetworkRequestStoreData.DataSource dataSource)812 public NetworkRequestStoreData makeNetworkRequestStoreData( 813 NetworkRequestStoreData.DataSource dataSource) { 814 return new NetworkRequestStoreData(dataSource); 815 } 816 817 /** 818 * Construct an instance of {@link NetworkSuggestionStoreData}. 819 */ makeNetworkSuggestionStoreData( NetworkSuggestionStoreData.DataSource dataSource)820 public NetworkSuggestionStoreData makeNetworkSuggestionStoreData( 821 NetworkSuggestionStoreData.DataSource dataSource) { 822 return new NetworkSuggestionStoreData(dataSource); 823 } 824 825 /** 826 * Construct an instance of {@link WifiCarrierInfoStoreManagerData} 827 */ makeWifiCarrierInfoStoreManagerData( WifiCarrierInfoStoreManagerData.DataSource dataSource)828 public WifiCarrierInfoStoreManagerData makeWifiCarrierInfoStoreManagerData( 829 WifiCarrierInfoStoreManagerData.DataSource dataSource) { 830 return new WifiCarrierInfoStoreManagerData(dataSource); 831 } 832 833 /** 834 * Construct an instance of {@link ImsiPrivacyProtectionExemptionStoreData} 835 */ makeImsiPrivacyProtectionExemptionStoreData( ImsiPrivacyProtectionExemptionStoreData.DataSource dataSource)836 public ImsiPrivacyProtectionExemptionStoreData makeImsiPrivacyProtectionExemptionStoreData( 837 ImsiPrivacyProtectionExemptionStoreData.DataSource dataSource) { 838 return new ImsiPrivacyProtectionExemptionStoreData(dataSource); 839 } 840 841 /** 842 * Construct an instance of {@link SoftApStoreData}. 843 */ makeSoftApStoreData( SoftApStoreData.DataSource dataSource)844 public SoftApStoreData makeSoftApStoreData( 845 SoftApStoreData.DataSource dataSource) { 846 return new SoftApStoreData(mContext, mSettingsMigrationDataHolder, dataSource); 847 } 848 getWifiPermissionsUtil()849 public WifiPermissionsUtil getWifiPermissionsUtil() { 850 return mWifiPermissionsUtil; 851 } 852 getWifiPermissionsWrapper()853 public WifiPermissionsWrapper getWifiPermissionsWrapper() { 854 return mWifiPermissionsWrapper; 855 } 856 857 /** 858 * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization. 859 * 860 * TODO: share worker thread with other Wi-Fi handlers (b/27924886) 861 */ getWifiAwareHandlerThread()862 public HandlerThread getWifiAwareHandlerThread() { 863 if (mWifiAwareHandlerThread == null) { // lazy initialization 864 mWifiAwareHandlerThread = new HandlerThread("wifiAwareService"); 865 mWifiAwareHandlerThread.start(); 866 } 867 return mWifiAwareHandlerThread; 868 } 869 870 /** 871 * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization. 872 * 873 * TODO: share worker thread with other Wi-Fi handlers (b/27924886) 874 */ getRttHandlerThread()875 public HandlerThread getRttHandlerThread() { 876 if (mRttHandlerThread == null) { // lazy initialization 877 mRttHandlerThread = new HandlerThread("wifiRttService"); 878 mRttHandlerThread.start(); 879 } 880 return mRttHandlerThread; 881 } 882 getMacAddressUtil()883 public MacAddressUtil getMacAddressUtil() { 884 return mMacAddressUtil; 885 } 886 887 /** 888 * Returns a single instance of HalDeviceManager for injection. 889 */ getHalDeviceManager()890 public HalDeviceManager getHalDeviceManager() { 891 return mHalDeviceManager; 892 } 893 getWifiNative()894 public WifiNative getWifiNative() { 895 return mWifiNative; 896 } 897 getWifiMonitor()898 public WifiMonitor getWifiMonitor() { 899 return mWifiMonitor; 900 } 901 getWifiP2pNative()902 public WifiP2pNative getWifiP2pNative() { 903 return mWifiP2pNative; 904 } 905 906 /** 907 * Returns a single instance of CoexManager for injection. 908 * This will be null if SdkLevel is not at least S. 909 */ getCoexManager()910 @Nullable public CoexManager getCoexManager() { 911 return mCoexManager; 912 } 913 getWifiP2pMonitor()914 public WifiP2pMonitor getWifiP2pMonitor() { 915 return mWifiP2pMonitor; 916 } 917 getSelfRecovery()918 public SelfRecovery getSelfRecovery() { 919 return mSelfRecovery; 920 } 921 getScanRequestProxy()922 public ScanRequestProxy getScanRequestProxy() { 923 return mScanRequestProxy; 924 } 925 getJavaRuntime()926 public Runtime getJavaRuntime() { 927 return Runtime.getRuntime(); 928 } 929 getWifiDataStall()930 public WifiDataStall getWifiDataStall() { 931 return mWifiDataStall; 932 } 933 getWifiNetworkSuggestionsManager()934 public WifiNetworkSuggestionsManager getWifiNetworkSuggestionsManager() { 935 return mWifiNetworkSuggestionsManager; 936 } 937 getIpMemoryStore()938 public IpMemoryStore getIpMemoryStore() { 939 if (mIpMemoryStore == null) { 940 mIpMemoryStore = IpMemoryStore.getMemoryStore(mContext); 941 } 942 return mIpMemoryStore; 943 } 944 getWifiBlocklistMonitor()945 public WifiBlocklistMonitor getWifiBlocklistMonitor() { 946 return mWifiBlocklistMonitor; 947 } 948 getHostapdHal()949 public HostapdHal getHostapdHal() { 950 return mHostapdHal; 951 } 952 getWifiThreadRunner()953 public WifiThreadRunner getWifiThreadRunner() { 954 return mWifiThreadRunner; 955 } 956 getWifiNetworkScoreCache()957 public WifiNetworkScoreCache getWifiNetworkScoreCache() { 958 return mWifiNetworkScoreCache; 959 } 960 makeNetdWrapper()961 public NetdWrapper makeNetdWrapper() { 962 if (mNetdWrapper == null) { 963 mNetdWrapper = new NetdWrapper(mContext, new Handler(mWifiHandlerThread.getLooper())); 964 } 965 return mNetdWrapper; 966 } 967 getWifiCondManager()968 public WifiNl80211Manager getWifiCondManager() { 969 return mWifiCondManager; 970 } 971 getWifiHealthMonitor()972 public WifiHealthMonitor getWifiHealthMonitor() { 973 return mWifiHealthMonitor; 974 } 975 getSettingsConfigStore()976 public WifiSettingsConfigStore getSettingsConfigStore() { 977 return mSettingsConfigStore; 978 } 979 980 public WifiScanAlwaysAvailableSettingsCompatibility getWifiScanAlwaysAvailableSettingsCompatibility()981 getWifiScanAlwaysAvailableSettingsCompatibility() { 982 return mWifiScanAlwaysAvailableSettingsCompatibility; 983 } 984 getDeviceConfigFacade()985 public DeviceConfigFacade getDeviceConfigFacade() { 986 return mDeviceConfigFacade; 987 } 988 getWifiConnectivityManager()989 public WifiConnectivityManager getWifiConnectivityManager() { 990 return mWifiConnectivityManager; 991 } 992 getConnectHelper()993 public ConnectHelper getConnectHelper() { 994 return mConnectHelper; 995 } 996 getWifiNetworkFactory()997 public WifiNetworkFactory getWifiNetworkFactory() { 998 return mWifiNetworkFactory; 999 } 1000 getUntrustedWifiNetworkFactory()1001 public UntrustedWifiNetworkFactory getUntrustedWifiNetworkFactory() { 1002 return mUntrustedWifiNetworkFactory; 1003 } 1004 getOemWifiNetworkFactory()1005 public OemWifiNetworkFactory getOemWifiNetworkFactory() { 1006 return mOemWifiNetworkFactory; 1007 } 1008 getWifiDiagnostics()1009 public WifiDiagnostics getWifiDiagnostics() { 1010 return mWifiDiagnostics; 1011 } 1012 getWifiP2pConnection()1013 public WifiP2pConnection getWifiP2pConnection() { 1014 return mWifiP2pConnection; 1015 } 1016 getWifiGlobals()1017 public WifiGlobals getWifiGlobals() { 1018 return mWifiGlobals; 1019 } 1020 getSimRequiredNotifier()1021 public SimRequiredNotifier getSimRequiredNotifier() { 1022 return mSimRequiredNotifier; 1023 } 1024 1025 /** 1026 * Useful for mocking {@link WorkSourceHelper} instance in {@link HalDeviceManager} unit tests. 1027 */ makeWsHelper(@onNull WorkSource ws)1028 public WorkSourceHelper makeWsHelper(@NonNull WorkSource ws) { 1029 return new WorkSourceHelper(ws, mWifiPermissionsUtil, 1030 mContext.getSystemService(ActivityManager.class), mContext.getPackageManager()); 1031 } 1032 1033 public AdaptiveConnectivityEnabledSettingObserver getAdaptiveConnectivityEnabledSettingObserver()1034 getAdaptiveConnectivityEnabledSettingObserver() { 1035 return mAdaptiveConnectivityEnabledSettingObserver; 1036 } 1037 getMakeBeforeBreakManager()1038 public MakeBeforeBreakManager getMakeBeforeBreakManager() { 1039 return mMakeBeforeBreakManager; 1040 } 1041 getOpenNetworkNotifier()1042 public OpenNetworkNotifier getOpenNetworkNotifier() { 1043 return mOpenNetworkNotifier; 1044 } 1045 getWifiNotificationManager()1046 public WifiNotificationManager getWifiNotificationManager() { 1047 return mWifiNotificationManager; 1048 } 1049 getLastCallerInfoManager()1050 public LastCallerInfoManager getLastCallerInfoManager() { 1051 return mLastCallerInfoManager; 1052 } 1053 getBuildProperties()1054 public BuildProperties getBuildProperties() { 1055 return mBuildProperties; 1056 } 1057 getDefaultClientModeManager()1058 public DefaultClientModeManager getDefaultClientModeManager() { 1059 return mDefaultClientModeManager; 1060 } 1061 getLinkProbeManager()1062 public LinkProbeManager getLinkProbeManager() { 1063 return mLinkProbeManager; 1064 } 1065 } 1066