WifiInjector.java revision 637a86ffb3a036a4f26a471378b57d8817f35c25
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 35 public WifiMetrics getWifiMetrics() { 36 return mWifiMetrics; 37 } 38} 39