WifiInjector.java revision 3204fb9682242a7b5a749489076c66d448c42577
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
17package com.android.server.wifi;
18
19import 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 */
25public 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
31    public static WifiInjector getInstance() {
32        return LazyHolder.sInstance;
33    }
34
35    private final WifiMetrics mWifiMetrics = new WifiMetrics();
36    private final WifiLastResortWatchdog mWifiLastResortWatchdog =
37            new WifiLastResortWatchdog(mWifiMetrics);
38    private final Clock mClock = new Clock();
39    private final PropertyService mPropertyService = new SystemPropertyService();
40    private final BuildProperties mBuildProperties = new SystemBuildProperties();
41    private final KeyStore mKeyStore = KeyStore.getInstance();
42    private final WifiBackupRestore mWifiBackupRestore = new WifiBackupRestore();
43
44    public WifiMetrics getWifiMetrics() {
45        return mWifiMetrics;
46    }
47
48    public WifiLastResortWatchdog getWifiLastResortWatchdog() {
49        return mWifiLastResortWatchdog;
50    }
51
52    public Clock getClock() {
53        return mClock;
54    }
55
56    public PropertyService getPropertyService() {
57        return mPropertyService;
58    }
59
60    public BuildProperties getBuildProperties() { return mBuildProperties; }
61
62    public KeyStore getKeyStore() {
63        return mKeyStore;
64    }
65
66    public WifiBackupRestore getWifiBackupRestore() {
67        return mWifiBackupRestore;
68    }
69}
70