WifiInjector.java revision 5f001750a0ce82a8b3a47ac566117d4de27f3e23
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 38 public WifiMetrics getWifiMetrics() { 39 return mWifiMetrics; 40 } 41 42 public WifiLastResortWatchdog getWifiLastResortWatchdog() { 43 return mWifiLastResortWatchdog; 44 } 45 46 public Clock getClock() { 47 return mClock; 48 } 49} 50