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