• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.wifi;
18 
19 import android.annotation.NonNull;
20 import android.app.ActivityManager;
21 import android.app.AlarmManager;
22 import android.app.AppOpsManager;
23 import android.content.Context;
24 import android.content.pm.PackageManager;
25 import android.hardware.SystemSensorManager;
26 import android.net.IpMemoryStore;
27 import android.net.NetworkCapabilities;
28 import android.net.NetworkKey;
29 import android.net.NetworkScoreManager;
30 import android.net.wifi.IWifiScanner;
31 import android.net.wifi.IWificond;
32 import android.net.wifi.WifiManager;
33 import android.net.wifi.WifiNetworkScoreCache;
34 import android.net.wifi.WifiScanner;
35 import android.os.BatteryStats;
36 import android.os.Handler;
37 import android.os.HandlerThread;
38 import android.os.IBinder;
39 import android.os.INetworkManagementService;
40 import android.os.Looper;
41 import android.os.ServiceManager;
42 import android.os.SystemProperties;
43 import android.os.UserManager;
44 import android.provider.Settings.Secure;
45 import android.security.KeyStore;
46 import android.telephony.SubscriptionManager;
47 import android.telephony.TelephonyManager;
48 import android.util.LocalLog;
49 
50 import com.android.internal.R;
51 import com.android.internal.app.IBatteryStats;
52 import com.android.internal.os.PowerProfile;
53 import com.android.server.am.ActivityManagerService;
54 import com.android.server.am.BatteryStatsService;
55 import com.android.server.wifi.aware.WifiAwareMetrics;
56 import com.android.server.wifi.hotspot2.PasspointManager;
57 import com.android.server.wifi.hotspot2.PasspointNetworkEvaluator;
58 import com.android.server.wifi.hotspot2.PasspointObjectFactory;
59 import com.android.server.wifi.p2p.SupplicantP2pIfaceHal;
60 import com.android.server.wifi.p2p.WifiP2pMetrics;
61 import com.android.server.wifi.p2p.WifiP2pMonitor;
62 import com.android.server.wifi.p2p.WifiP2pNative;
63 import com.android.server.wifi.rtt.RttMetrics;
64 import com.android.server.wifi.util.WifiPermissionsUtil;
65 import com.android.server.wifi.util.WifiPermissionsWrapper;
66 
67 import java.util.Random;
68 
69 /**
70  *  WiFi dependency injector. To be used for accessing various WiFi class instances and as a
71  *  handle for mock injection.
72  *
73  *  Some WiFi class instances currently depend on having a Looper from a HandlerThread that has
74  *  been started. To accommodate this, we have a two-phased approach to initialize and retrieve
75  *  an instance of the WifiInjector.
76  */
77 public class WifiInjector {
78     private static final String BOOT_DEFAULT_WIFI_COUNTRY_CODE = "ro.boot.wificountrycode";
79     private static final String WIFICOND_SERVICE_NAME = "wificond";
80 
81     static WifiInjector sWifiInjector = null;
82 
83     private final Context mContext;
84     private final FrameworkFacade mFrameworkFacade = new FrameworkFacade();
85     private final HandlerThread mWifiServiceHandlerThread;
86     private final HandlerThread mWifiCoreHandlerThread;
87     private final HandlerThread mWifiP2pServiceHandlerThread;
88     private final WifiTrafficPoller mWifiTrafficPoller;
89     private final WifiCountryCode mCountryCode;
90     private final BackupManagerProxy mBackupManagerProxy = new BackupManagerProxy();
91     private final WifiApConfigStore mWifiApConfigStore;
92     private final WifiNative mWifiNative;
93     private final WifiMonitor mWifiMonitor;
94     private final WifiP2pNative mWifiP2pNative;
95     private final WifiP2pMonitor mWifiP2pMonitor;
96     private final SupplicantStaIfaceHal mSupplicantStaIfaceHal;
97     private final SupplicantP2pIfaceHal mSupplicantP2pIfaceHal;
98     private final HostapdHal mHostapdHal;
99     private final WifiVendorHal mWifiVendorHal;
100     private final ScoringParams mScoringParams;
101     private final ClientModeImpl mClientModeImpl;
102     private final ActiveModeWarden mActiveModeWarden;
103     private final WifiSettingsStore mSettingsStore;
104     private OpenNetworkNotifier mOpenNetworkNotifier;
105     private CarrierNetworkNotifier mCarrierNetworkNotifier;
106     private final CarrierNetworkConfig mCarrierNetworkConfig;
107     private final WifiLockManager mLockManager;
108     private final WifiController mWifiController;
109     private final WificondControl mWificondControl;
110     private final Clock mClock = new Clock();
111     private final WifiMetrics mWifiMetrics;
112     private final WifiP2pMetrics mWifiP2pMetrics;
113     private WifiLastResortWatchdog mWifiLastResortWatchdog;
114     private final PropertyService mPropertyService = new SystemPropertyService();
115     private final BuildProperties mBuildProperties = new SystemBuildProperties();
116     private final KeyStore mKeyStore = KeyStore.getInstance();
117     private final WifiBackupRestore mWifiBackupRestore;
118     private final WifiMulticastLockManager mWifiMulticastLockManager;
119     private final WifiConfigStore mWifiConfigStore;
120     private final WifiKeyStore mWifiKeyStore;
121     private final WifiConfigManager mWifiConfigManager;
122     private final WifiConnectivityHelper mWifiConnectivityHelper;
123     private final LocalLog mConnectivityLocalLog;
124     private final WifiNetworkSelector mWifiNetworkSelector;
125     private final SavedNetworkEvaluator mSavedNetworkEvaluator;
126     private final NetworkSuggestionEvaluator mNetworkSuggestionEvaluator;
127     private final PasspointNetworkEvaluator mPasspointNetworkEvaluator;
128     private final ScoredNetworkEvaluator mScoredNetworkEvaluator;
129     private final CarrierNetworkEvaluator mCarrierNetworkEvaluator;
130     private final WifiNetworkScoreCache mWifiNetworkScoreCache;
131     private final NetworkScoreManager mNetworkScoreManager;
132     private WifiScanner mWifiScanner;
133     private final WifiPermissionsWrapper mWifiPermissionsWrapper;
134     private final WifiPermissionsUtil mWifiPermissionsUtil;
135     private final PasspointManager mPasspointManager;
136     private final SIMAccessor mSimAccessor;
137     private HandlerThread mWifiAwareHandlerThread;
138     private HandlerThread mRttHandlerThread;
139     private HalDeviceManager mHalDeviceManager;
140     private final IBatteryStats mBatteryStats;
141     private final WifiStateTracker mWifiStateTracker;
142     private final SelfRecovery mSelfRecovery;
143     private final WakeupController mWakeupController;
144     private final INetworkManagementService mNwManagementService;
145     private final ScanRequestProxy mScanRequestProxy;
146     private final SarManager mSarManager;
147     private final BaseWifiDiagnostics mWifiDiagnostics;
148     private final WifiDataStall mWifiDataStall;
149     private final WifiScoreCard mWifiScoreCard;
150     private final WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
151     private final DppMetrics mDppMetrics;
152     private final DppManager mDppManager;
153     private final LinkProbeManager mLinkProbeManager;
154     private final IpMemoryStore mIpMemoryStore;
155     private final CellularLinkLayerStatsCollector mCellularLinkLayerStatsCollector;
156 
WifiInjector(Context context)157     public WifiInjector(Context context) {
158         if (context == null) {
159             throw new IllegalStateException(
160                     "WifiInjector should not be initialized with a null Context.");
161         }
162 
163         if (sWifiInjector != null) {
164             throw new IllegalStateException(
165                     "WifiInjector was already created, use getInstance instead.");
166         }
167 
168         sWifiInjector = this;
169 
170         mContext = context;
171         mWifiScoreCard = new WifiScoreCard(mClock,
172                 Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID));
173         mSettingsStore = new WifiSettingsStore(mContext);
174         mWifiPermissionsWrapper = new WifiPermissionsWrapper(mContext);
175         mNetworkScoreManager = mContext.getSystemService(NetworkScoreManager.class);
176         mWifiNetworkScoreCache = new WifiNetworkScoreCache(mContext);
177         mNetworkScoreManager.registerNetworkScoreCache(NetworkKey.TYPE_WIFI,
178                 mWifiNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_NONE);
179         mWifiPermissionsUtil = new WifiPermissionsUtil(mWifiPermissionsWrapper, mContext,
180                 UserManager.get(mContext), this);
181         mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil);
182         mBatteryStats = IBatteryStats.Stub.asInterface(mFrameworkFacade.getService(
183                 BatteryStats.SERVICE_NAME));
184         mWifiStateTracker = new WifiStateTracker(mBatteryStats);
185         // Now create and start handler threads
186         mWifiServiceHandlerThread = new HandlerThread("WifiService");
187         mWifiServiceHandlerThread.start();
188         mWifiCoreHandlerThread = new HandlerThread("ClientModeImpl");
189         mWifiCoreHandlerThread.start();
190         mWifiP2pServiceHandlerThread = new HandlerThread("WifiP2pService");
191         mWifiP2pServiceHandlerThread.start();
192         Looper clientModeImplLooper = mWifiCoreHandlerThread.getLooper();
193         mCarrierNetworkConfig = new CarrierNetworkConfig(mContext,
194                 clientModeImplLooper, mFrameworkFacade);
195         WifiAwareMetrics awareMetrics = new WifiAwareMetrics(mClock);
196         RttMetrics rttMetrics = new RttMetrics(mClock);
197         mWifiP2pMetrics = new WifiP2pMetrics(mClock);
198         mDppMetrics = new DppMetrics();
199         mCellularLinkLayerStatsCollector = new CellularLinkLayerStatsCollector(mContext);
200         mWifiMetrics = new WifiMetrics(mContext, mFrameworkFacade, mClock, clientModeImplLooper,
201                 awareMetrics, rttMetrics, new WifiPowerMetrics(), mWifiP2pMetrics, mDppMetrics,
202                 mCellularLinkLayerStatsCollector);
203         // Modules interacting with Native.
204         mWifiMonitor = new WifiMonitor(this);
205         mHalDeviceManager = new HalDeviceManager(mClock);
206         mWifiVendorHal =
207                 new WifiVendorHal(mHalDeviceManager, mWifiCoreHandlerThread.getLooper());
208         mSupplicantStaIfaceHal =
209                 new SupplicantStaIfaceHal(mContext, mWifiMonitor, mPropertyService,
210                         clientModeImplLooper);
211         mHostapdHal = new HostapdHal(mContext, clientModeImplLooper);
212         mWificondControl = new WificondControl(this, mWifiMonitor, mCarrierNetworkConfig,
213                 (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE),
214                 clientModeImplLooper, mClock);
215         mNwManagementService = INetworkManagementService.Stub.asInterface(
216                 ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
217         mWifiNative = new WifiNative(
218                 mWifiVendorHal, mSupplicantStaIfaceHal, mHostapdHal, mWificondControl,
219                 mWifiMonitor, mNwManagementService, mPropertyService, mWifiMetrics,
220                 new Handler(mWifiCoreHandlerThread.getLooper()), new Random());
221         mWifiP2pMonitor = new WifiP2pMonitor(this);
222         mSupplicantP2pIfaceHal = new SupplicantP2pIfaceHal(mWifiP2pMonitor);
223         mWifiP2pNative = new WifiP2pNative(
224                 mWifiVendorHal, mSupplicantP2pIfaceHal, mHalDeviceManager,
225                 mPropertyService);
226 
227         // Now get instances of all the objects that depend on the HandlerThreads
228         mWifiTrafficPoller = new WifiTrafficPoller(clientModeImplLooper);
229         mCountryCode = new WifiCountryCode(mWifiNative,
230                 SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE),
231                 mContext.getResources()
232                         .getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss));
233         mWifiApConfigStore = new WifiApConfigStore(
234                 mContext, mWifiCoreHandlerThread.getLooper(), mBackupManagerProxy,
235                 mFrameworkFacade);
236 
237         // WifiConfigManager/Store objects and their dependencies.
238         // New config store
239         mWifiKeyStore = new WifiKeyStore(mKeyStore);
240         mWifiConfigStore = new WifiConfigStore(
241                 mContext, clientModeImplLooper, mClock, mWifiMetrics,
242                 WifiConfigStore.createSharedFile());
243         SubscriptionManager subscriptionManager =
244                 mContext.getSystemService(SubscriptionManager.class);
245         // Config Manager
246         mWifiConfigManager = new WifiConfigManager(mContext, mClock,
247                 UserManager.get(mContext), makeTelephonyManager(),
248                 mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil,
249                 mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext),
250                 new NetworkListUserStoreData(mContext),
251                 new DeletedEphemeralSsidsStoreData(mClock), new RandomizedMacStoreData(),
252                 mFrameworkFacade, mWifiCoreHandlerThread.getLooper());
253         mWifiMetrics.setWifiConfigManager(mWifiConfigManager);
254         mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative);
255         mConnectivityLocalLog = new LocalLog(ActivityManager.isLowRamDeviceStatic() ? 256 : 512);
256         mScoringParams = new ScoringParams(mContext, mFrameworkFacade,
257                 new Handler(clientModeImplLooper));
258         mWifiMetrics.setScoringParams(mScoringParams);
259         mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiScoreCard, mScoringParams,
260                 mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiMetrics, mWifiNative);
261         CompatibilityScorer compatibilityScorer = new CompatibilityScorer(mScoringParams);
262         mWifiNetworkSelector.registerCandidateScorer(compatibilityScorer);
263         ScoreCardBasedScorer scoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams);
264         mWifiNetworkSelector.registerCandidateScorer(scoreCardBasedScorer);
265         BubbleFunScorer bubbleFunScorer = new BubbleFunScorer(mScoringParams);
266         mWifiNetworkSelector.registerCandidateScorer(bubbleFunScorer);
267         mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector);
268         mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mScoringParams,
269                 mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiConnectivityHelper,
270                 subscriptionManager);
271         mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext,
272                 new Handler(mWifiCoreHandlerThread.getLooper()), this, mWifiPermissionsUtil,
273                 mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiKeyStore);
274         mNetworkSuggestionEvaluator = new NetworkSuggestionEvaluator(mWifiNetworkSuggestionsManager,
275                 mWifiConfigManager, mConnectivityLocalLog);
276         mScoredNetworkEvaluator = new ScoredNetworkEvaluator(context, clientModeImplLooper,
277                 mFrameworkFacade, mNetworkScoreManager, mWifiConfigManager, mConnectivityLocalLog,
278                 mWifiNetworkScoreCache, mWifiPermissionsUtil);
279         mCarrierNetworkEvaluator = new CarrierNetworkEvaluator(mWifiConfigManager,
280                 mCarrierNetworkConfig, mConnectivityLocalLog, this);
281         mSimAccessor = new SIMAccessor(mContext);
282         mPasspointManager = new PasspointManager(mContext, this,
283                 new Handler(mWifiCoreHandlerThread.getLooper()), mWifiNative, mWifiKeyStore, mClock,
284                 mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore,
285                 mWifiMetrics, makeTelephonyManager(), subscriptionManager);
286         mPasspointNetworkEvaluator = new PasspointNetworkEvaluator(
287                 mPasspointManager, mWifiConfigManager, mConnectivityLocalLog,
288                 mCarrierNetworkConfig, this, subscriptionManager);
289         mWifiMetrics.setPasspointManager(mPasspointManager);
290         mScanRequestProxy = new ScanRequestProxy(mContext,
291                 (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE),
292                 (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE),
293                 this, mWifiConfigManager,
294                 mWifiPermissionsUtil, mWifiMetrics, mClock, mFrameworkFacade,
295                 new Handler(clientModeImplLooper));
296         mSarManager = new SarManager(mContext, makeTelephonyManager(), clientModeImplLooper,
297                 mWifiNative, new SystemSensorManager(mContext, clientModeImplLooper),
298                 mWifiMetrics);
299         mWifiDiagnostics = new WifiDiagnostics(
300                 mContext, this, mWifiNative, mBuildProperties,
301                 new LastMileLogger(this), mClock);
302         mWifiDataStall = new WifiDataStall(mContext, mFrameworkFacade, mWifiMetrics);
303         mWifiMetrics.setWifiDataStall(mWifiDataStall);
304         mLinkProbeManager = new LinkProbeManager(mClock, mWifiNative, mWifiMetrics,
305                 mFrameworkFacade, mWifiCoreHandlerThread.getLooper(), mContext);
306         mClientModeImpl = new ClientModeImpl(mContext, mFrameworkFacade,
307                 clientModeImplLooper, UserManager.get(mContext),
308                 this, mBackupManagerProxy, mCountryCode, mWifiNative,
309                 new WrongPasswordNotifier(mContext, mFrameworkFacade),
310                 mSarManager, mWifiTrafficPoller, mLinkProbeManager);
311         mActiveModeWarden = new ActiveModeWarden(this, mContext, clientModeImplLooper,
312                 mWifiNative, new DefaultModeManager(mContext, clientModeImplLooper),
313                 mBatteryStats);
314 
315         WakeupNotificationFactory wakeupNotificationFactory =
316                 new WakeupNotificationFactory(mContext, mFrameworkFacade);
317         WakeupOnboarding wakeupOnboarding = new WakeupOnboarding(mContext, mWifiConfigManager,
318                 mWifiCoreHandlerThread.getLooper(), mFrameworkFacade,
319                 wakeupNotificationFactory);
320         mWakeupController = new WakeupController(mContext,
321                 mWifiCoreHandlerThread.getLooper(),
322                 new WakeupLock(mWifiConfigManager, mWifiMetrics.getWakeupMetrics(), mClock),
323                 new WakeupEvaluator(mScoringParams), wakeupOnboarding, mWifiConfigManager,
324                 mWifiConfigStore, mWifiNetworkSuggestionsManager, mWifiMetrics.getWakeupMetrics(),
325                 this, mFrameworkFacade, mClock);
326         mLockManager = new WifiLockManager(mContext, BatteryStatsService.getService(),
327                 mClientModeImpl, mFrameworkFacade, new Handler(clientModeImplLooper), mWifiNative,
328                 mClock, mWifiMetrics);
329         mWifiController = new WifiController(mContext, mClientModeImpl, clientModeImplLooper,
330                 mSettingsStore, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade,
331                 mActiveModeWarden, mWifiPermissionsUtil);
332         mSelfRecovery = new SelfRecovery(mWifiController, mClock);
333         mWifiMulticastLockManager = new WifiMulticastLockManager(
334                 mClientModeImpl.getMcastLockManagerFilterController(),
335                 BatteryStatsService.getService());
336         mDppManager = new DppManager(mWifiCoreHandlerThread.getLooper(), mWifiNative,
337                 mWifiConfigManager, mContext, mDppMetrics);
338         mIpMemoryStore = IpMemoryStore.getMemoryStore(mContext);
339 
340         // Register the various network evaluators with the network selector.
341         mWifiNetworkSelector.registerNetworkEvaluator(mSavedNetworkEvaluator);
342         mWifiNetworkSelector.registerNetworkEvaluator(mNetworkSuggestionEvaluator);
343         if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_PASSPOINT)) {
344             mWifiNetworkSelector.registerNetworkEvaluator(mPasspointNetworkEvaluator);
345         }
346         mWifiNetworkSelector.registerNetworkEvaluator(mCarrierNetworkEvaluator);
347         mWifiNetworkSelector.registerNetworkEvaluator(mScoredNetworkEvaluator);
348 
349         mClientModeImpl.start();
350     }
351 
352     /**
353      *  Obtain an instance of the WifiInjector class.
354      *
355      *  This is the generic method to get an instance of the class. The first instance should be
356      *  retrieved using the getInstanceWithContext method.
357      */
getInstance()358     public static WifiInjector getInstance() {
359         if (sWifiInjector == null) {
360             throw new IllegalStateException(
361                     "Attempted to retrieve a WifiInjector instance before constructor was called.");
362         }
363         return sWifiInjector;
364     }
365 
366     /**
367      * Enable verbose logging in Injector objects. Called from the WifiServiceImpl (based on
368      * binder call).
369      */
enableVerboseLogging(int verbose)370     public void enableVerboseLogging(int verbose) {
371         mWifiLastResortWatchdog.enableVerboseLogging(verbose);
372         mWifiBackupRestore.enableVerboseLogging(verbose);
373         mHalDeviceManager.enableVerboseLogging(verbose);
374         mScanRequestProxy.enableVerboseLogging(verbose);
375         mWakeupController.enableVerboseLogging(verbose);
376         mCarrierNetworkConfig.enableVerboseLogging(verbose);
377         mWifiNetworkSuggestionsManager.enableVerboseLogging(verbose);
378         LogcatLog.enableVerboseLogging(verbose);
379         mDppManager.enableVerboseLogging(verbose);
380     }
381 
getUserManager()382     public UserManager getUserManager() {
383         return UserManager.get(mContext);
384     }
385 
getWifiMetrics()386     public WifiMetrics getWifiMetrics() {
387         return mWifiMetrics;
388     }
389 
getWifiP2pMetrics()390     public WifiP2pMetrics getWifiP2pMetrics() {
391         return mWifiP2pMetrics;
392     }
393 
getSupplicantStaIfaceHal()394     public SupplicantStaIfaceHal getSupplicantStaIfaceHal() {
395         return mSupplicantStaIfaceHal;
396     }
397 
getBackupManagerProxy()398     public BackupManagerProxy getBackupManagerProxy() {
399         return mBackupManagerProxy;
400     }
401 
getFrameworkFacade()402     public FrameworkFacade getFrameworkFacade() {
403         return mFrameworkFacade;
404     }
405 
getWifiServiceHandlerThread()406     public HandlerThread getWifiServiceHandlerThread() {
407         return mWifiServiceHandlerThread;
408     }
409 
getWifiP2pServiceHandlerThread()410     public HandlerThread getWifiP2pServiceHandlerThread() {
411         return mWifiP2pServiceHandlerThread;
412     }
413 
getWifiCoreHandlerThread()414     public HandlerThread getWifiCoreHandlerThread() {
415         return mWifiCoreHandlerThread;
416     }
417 
getWifiTrafficPoller()418     public WifiTrafficPoller getWifiTrafficPoller() {
419         return mWifiTrafficPoller;
420     }
421 
getWifiCountryCode()422     public WifiCountryCode getWifiCountryCode() {
423         return mCountryCode;
424     }
425 
getWifiApConfigStore()426     public WifiApConfigStore getWifiApConfigStore() {
427         return mWifiApConfigStore;
428     }
429 
getSarManager()430     public SarManager getSarManager() {
431         return mSarManager;
432     }
433 
getClientModeImpl()434     public ClientModeImpl getClientModeImpl() {
435         return mClientModeImpl;
436     }
437 
getClientModeImplHandler()438     public Handler getClientModeImplHandler() {
439         return mClientModeImpl.getHandler();
440     }
441 
getActiveModeWarden()442     public ActiveModeWarden getActiveModeWarden() {
443         return mActiveModeWarden;
444     }
445 
getWifiSettingsStore()446     public WifiSettingsStore getWifiSettingsStore() {
447         return mSettingsStore;
448     }
449 
getWifiLockManager()450     public WifiLockManager getWifiLockManager() {
451         return mLockManager;
452     }
453 
getWifiController()454     public WifiController getWifiController() {
455         return mWifiController;
456     }
457 
getWifiLastResortWatchdog()458     public WifiLastResortWatchdog getWifiLastResortWatchdog() {
459         return mWifiLastResortWatchdog;
460     }
461 
getClock()462     public Clock getClock() {
463         return mClock;
464     }
465 
getPropertyService()466     public PropertyService getPropertyService() {
467         return mPropertyService;
468     }
469 
getBuildProperties()470     public BuildProperties getBuildProperties() {
471         return mBuildProperties;
472     }
473 
getKeyStore()474     public KeyStore getKeyStore() {
475         return mKeyStore;
476     }
477 
getWifiBackupRestore()478     public WifiBackupRestore getWifiBackupRestore() {
479         return mWifiBackupRestore;
480     }
481 
getWifiMulticastLockManager()482     public WifiMulticastLockManager getWifiMulticastLockManager() {
483         return mWifiMulticastLockManager;
484     }
485 
getWifiConfigManager()486     public WifiConfigManager getWifiConfigManager() {
487         return mWifiConfigManager;
488     }
489 
getPasspointManager()490     public PasspointManager getPasspointManager() {
491         return mPasspointManager;
492     }
493 
getCarrierNetworkConfig()494     public CarrierNetworkConfig getCarrierNetworkConfig() {
495         return mCarrierNetworkConfig;
496     }
497 
getWakeupController()498     public WakeupController getWakeupController() {
499         return mWakeupController;
500     }
501 
getScoringParams()502     public ScoringParams getScoringParams() {
503         return mScoringParams;
504     }
505 
getWifiScoreCard()506     public WifiScoreCard getWifiScoreCard() {
507         return mWifiScoreCard;
508     }
509 
makeTelephonyManager()510     public TelephonyManager makeTelephonyManager() {
511         return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
512     }
513 
getWifiStateTracker()514     public WifiStateTracker getWifiStateTracker() {
515         return mWifiStateTracker;
516     }
517 
getDppManager()518     public DppManager getDppManager() {
519         return mDppManager;
520     }
521 
522     /** Gets IWificond without caching. */
makeWificond()523     public IWificond makeWificond() {
524         // We depend on being able to refresh our binder in ClientModeImpl, so don't cache it.
525         IBinder binder = ServiceManager.getService(WIFICOND_SERVICE_NAME);
526         return IWificond.Stub.asInterface(binder);
527     }
528 
529     /**
530      * Create a SoftApManager.
531      * @param config SoftApModeConfiguration object holding the config and mode
532      * @return an instance of SoftApManager
533      */
makeSoftApManager(@onNull WifiManager.SoftApCallback callback, @NonNull SoftApModeConfiguration config)534     public SoftApManager makeSoftApManager(@NonNull WifiManager.SoftApCallback callback,
535                                            @NonNull SoftApModeConfiguration config) {
536         return new SoftApManager(mContext, mWifiCoreHandlerThread.getLooper(),
537                 mFrameworkFacade, mWifiNative, mCountryCode.getCountryCode(), callback,
538                 mWifiApConfigStore, config, mWifiMetrics, mSarManager);
539     }
540 
541     /**
542      * Create a ScanOnlyModeManager
543      *
544      * @param listener listener for ScanOnlyModeManager state changes
545      * @return a new instance of ScanOnlyModeManager
546      */
makeScanOnlyModeManager( @onNull ScanOnlyModeManager.Listener listener)547     public ScanOnlyModeManager makeScanOnlyModeManager(
548             @NonNull ScanOnlyModeManager.Listener listener) {
549         return new ScanOnlyModeManager(mContext, mWifiCoreHandlerThread.getLooper(),
550                 mWifiNative, listener, mWifiMetrics, mWakeupController,
551                 mSarManager);
552     }
553 
554     /**
555      * Create a ClientModeManager
556      *
557      * @param listener listener for ClientModeManager state changes
558      * @return a new instance of ClientModeManager
559      */
makeClientModeManager(ClientModeManager.Listener listener)560     public ClientModeManager makeClientModeManager(ClientModeManager.Listener listener) {
561         return new ClientModeManager(mContext, mWifiCoreHandlerThread.getLooper(),
562                 mWifiNative, listener, mWifiMetrics, mClientModeImpl);
563     }
564 
565     /**
566      * Create a WifiLog instance.
567      * @param tag module name to include in all log messages
568      */
makeLog(String tag)569     public WifiLog makeLog(String tag) {
570         return new LogcatLog(tag);
571     }
572 
getWifiDiagnostics()573     public BaseWifiDiagnostics getWifiDiagnostics() {
574         return mWifiDiagnostics;
575     }
576 
577     /**
578      * Obtain an instance of WifiScanner.
579      * If it was not already created, then obtain an instance.  Note, this must be done lazily since
580      * WifiScannerService is separate and created later.
581      */
getWifiScanner()582     public synchronized WifiScanner getWifiScanner() {
583         if (mWifiScanner == null) {
584             mWifiScanner = new WifiScanner(mContext,
585                     IWifiScanner.Stub.asInterface(ServiceManager.getService(
586                             Context.WIFI_SCANNING_SERVICE)),
587                     mWifiCoreHandlerThread.getLooper());
588         }
589         return mWifiScanner;
590     }
591 
592     /**
593      * Construct a new instance of WifiConnectivityManager & its dependencies.
594      *
595      * Create and return a new WifiConnectivityManager.
596      * @param clientModeImpl Instance of client mode impl.
597      * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl.
598      */
makeWifiConnectivityManager(ClientModeImpl clientModeImpl)599     public WifiConnectivityManager makeWifiConnectivityManager(ClientModeImpl clientModeImpl) {
600         mOpenNetworkNotifier = new OpenNetworkNotifier(mContext,
601                 mWifiCoreHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics,
602                 mWifiConfigManager, mWifiConfigStore, clientModeImpl,
603                 new ConnectToNetworkNotificationBuilder(mContext, mFrameworkFacade));
604         mCarrierNetworkNotifier = new CarrierNetworkNotifier(mContext,
605                 mWifiCoreHandlerThread.getLooper(), mFrameworkFacade, mClock, mWifiMetrics,
606                 mWifiConfigManager, mWifiConfigStore, clientModeImpl,
607                 new ConnectToNetworkNotificationBuilder(mContext, mFrameworkFacade));
608         mWifiLastResortWatchdog = new WifiLastResortWatchdog(this, mClock,
609                 mWifiMetrics, clientModeImpl, clientModeImpl.getHandler().getLooper());
610         return new WifiConnectivityManager(mContext, getScoringParams(),
611                 clientModeImpl, this,
612                 mWifiConfigManager, clientModeImpl.getWifiInfo(),
613                 mWifiNetworkSelector, mWifiConnectivityHelper,
614                 mWifiLastResortWatchdog, mOpenNetworkNotifier, mCarrierNetworkNotifier,
615                 mCarrierNetworkConfig, mWifiMetrics, mWifiCoreHandlerThread.getLooper(),
616                 mClock, mConnectivityLocalLog);
617     }
618 
619     /**
620      * Construct a new instance of {@link WifiNetworkFactory}.
621      * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl.
622      */
makeWifiNetworkFactory( NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager)623     public WifiNetworkFactory makeWifiNetworkFactory(
624             NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager) {
625         return new WifiNetworkFactory(
626                 mWifiCoreHandlerThread.getLooper(), mContext, nc,
627                 (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE),
628                 (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE),
629                 (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE),
630                 mClock, this, wifiConnectivityManager, mWifiConfigManager,
631                 mWifiConfigStore, mWifiPermissionsUtil, mWifiMetrics);
632     }
633 
634     /**
635      * Construct an instance of {@link NetworkRequestStoreData}.
636      */
makeNetworkRequestStoreData( NetworkRequestStoreData.DataSource dataSource)637     public NetworkRequestStoreData makeNetworkRequestStoreData(
638             NetworkRequestStoreData.DataSource dataSource) {
639         return new NetworkRequestStoreData(dataSource);
640     }
641 
642     /**
643      * Construct a new instance of {@link UntrustedWifiNetworkFactory}.
644      * TODO(b/116233964): Remove cyclic dependency between WifiConnectivityManager & ClientModeImpl.
645      */
makeUntrustedWifiNetworkFactory( NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager)646     public UntrustedWifiNetworkFactory makeUntrustedWifiNetworkFactory(
647             NetworkCapabilities nc, WifiConnectivityManager wifiConnectivityManager) {
648         return new UntrustedWifiNetworkFactory(
649                 mWifiCoreHandlerThread.getLooper(), mContext, nc, wifiConnectivityManager);
650     }
651 
652     /**
653      * Construct an instance of {@link NetworkSuggestionStoreData}.
654      */
makeNetworkSuggestionStoreData( NetworkSuggestionStoreData.DataSource dataSource)655     public NetworkSuggestionStoreData makeNetworkSuggestionStoreData(
656             NetworkSuggestionStoreData.DataSource dataSource) {
657         return new NetworkSuggestionStoreData(dataSource);
658     }
659 
getWifiPermissionsUtil()660     public WifiPermissionsUtil getWifiPermissionsUtil() {
661         return mWifiPermissionsUtil;
662     }
663 
getWifiPermissionsWrapper()664     public WifiPermissionsWrapper getWifiPermissionsWrapper() {
665         return mWifiPermissionsWrapper;
666     }
667 
668     /**
669      * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization.
670      *
671      * TODO: share worker thread with other Wi-Fi handlers (b/27924886)
672      */
getWifiAwareHandlerThread()673     public HandlerThread getWifiAwareHandlerThread() {
674         if (mWifiAwareHandlerThread == null) { // lazy initialization
675             mWifiAwareHandlerThread = new HandlerThread("wifiAwareService");
676             mWifiAwareHandlerThread.start();
677         }
678         return mWifiAwareHandlerThread;
679     }
680 
681     /**
682      * Returns a singleton instance of a HandlerThread for injection. Uses lazy initialization.
683      *
684      * TODO: share worker thread with other Wi-Fi handlers (b/27924886)
685      */
getRttHandlerThread()686     public HandlerThread getRttHandlerThread() {
687         if (mRttHandlerThread == null) { // lazy initialization
688             mRttHandlerThread = new HandlerThread("wifiRttService");
689             mRttHandlerThread.start();
690         }
691         return mRttHandlerThread;
692     }
693 
694     /**
695      * Returns a single instance of HalDeviceManager for injection.
696      */
getHalDeviceManager()697     public HalDeviceManager getHalDeviceManager() {
698         return mHalDeviceManager;
699     }
700 
getWifiNative()701     public WifiNative getWifiNative() {
702         return mWifiNative;
703     }
704 
getWifiMonitor()705     public WifiMonitor getWifiMonitor() {
706         return mWifiMonitor;
707     }
708 
getWifiP2pNative()709     public WifiP2pNative getWifiP2pNative() {
710         return mWifiP2pNative;
711     }
712 
getWifiP2pMonitor()713     public WifiP2pMonitor getWifiP2pMonitor() {
714         return mWifiP2pMonitor;
715     }
716 
getSelfRecovery()717     public SelfRecovery getSelfRecovery() {
718         return mSelfRecovery;
719     }
720 
getPowerProfile()721     public PowerProfile getPowerProfile() {
722         return new PowerProfile(mContext, false);
723     }
724 
getScanRequestProxy()725     public ScanRequestProxy getScanRequestProxy() {
726         return mScanRequestProxy;
727     }
728 
getJavaRuntime()729     public Runtime getJavaRuntime() {
730         return Runtime.getRuntime();
731     }
732 
getActivityManagerService()733     public ActivityManagerService getActivityManagerService() {
734         return (ActivityManagerService) ActivityManager.getService();
735     }
736 
getWifiDataStall()737     public WifiDataStall getWifiDataStall() {
738         return mWifiDataStall;
739     }
740 
getWifiNetworkSuggestionsManager()741     public WifiNetworkSuggestionsManager getWifiNetworkSuggestionsManager() {
742         return mWifiNetworkSuggestionsManager;
743     }
744 
getIpMemoryStore()745     public IpMemoryStore getIpMemoryStore() {
746         return mIpMemoryStore;
747     }
748 }
749