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