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.security.KeyStore;
20 
21 /**
22  *  WiFi dependency injector using thread-safe lazy singleton pattern. To be used for accessing
23  *  various wifi class instances and as a handle for mock injection.
24  */
25 public class WifiInjector {
26     // see: https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom
27     private static class LazyHolder {
28         public static final WifiInjector sInstance = new WifiInjector();
29     }
30 
getInstance()31     public static WifiInjector getInstance() {
32         return LazyHolder.sInstance;
33     }
34 
35     private final Clock mClock = new Clock();
36     private final WifiMetrics mWifiMetrics = new WifiMetrics(mClock);
37     private final WifiLastResortWatchdog mWifiLastResortWatchdog =
38             new WifiLastResortWatchdog(mWifiMetrics);
39     private final PropertyService mPropertyService = new SystemPropertyService();
40     private final BuildProperties mBuildProperties = new SystemBuildProperties();
41     private final KeyStore mKeyStore = KeyStore.getInstance();
42 
getWifiMetrics()43     public WifiMetrics getWifiMetrics() {
44         return mWifiMetrics;
45     }
46 
getWifiLastResortWatchdog()47     public WifiLastResortWatchdog getWifiLastResortWatchdog() {
48         return mWifiLastResortWatchdog;
49     }
50 
getClock()51     public Clock getClock() {
52         return mClock;
53     }
54 
getPropertyService()55     public PropertyService getPropertyService() {
56         return mPropertyService;
57     }
58 
getBuildProperties()59     public BuildProperties getBuildProperties() { return mBuildProperties; }
60 
getKeyStore()61     public KeyStore getKeyStore() {
62         return mKeyStore;
63     }
64 }
65