WifiInjector.java revision 107f6ce4a5f6017ce336d9b60650ddbe28bee965
17cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj/*
27cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * Copyright (C) 2016 The Android Open Source Project
37cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *
47cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * Licensed under the Apache License, Version 2.0 (the "License");
57cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * you may not use this file except in compliance with the License.
67cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * You may obtain a copy of the License at
77cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *
87cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *      http://www.apache.org/licenses/LICENSE-2.0
97cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *
107cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * Unless required by applicable law or agreed to in writing, software
117cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * distributed under the License is distributed on an "AS IS" BASIS,
127cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * See the License for the specific language governing permissions and
147cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj * limitations under the License.
157cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj */
167cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
177cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardjpackage com.android.server.wifi;
187cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
197cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardjimport android.security.KeyStore;
207cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
217cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj/**
227cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *  WiFi dependency injector using thread-safe lazy singleton pattern. To be used for accessing
237cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj *  various wifi class instances and as a handle for mock injection.
247cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj */
257cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardjpublic class WifiInjector {
267cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    // see: https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom
277cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private static class LazyHolder {
287cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        public static final WifiInjector sInstance = new WifiInjector();
297cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
307cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
317cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public static WifiInjector getInstance() {
327cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return LazyHolder.sInstance;
337cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
347cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
357cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final Clock mClock = new Clock();
367cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final WifiMetrics mWifiMetrics = new WifiMetrics(mClock);
377cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final WifiLastResortWatchdog mWifiLastResortWatchdog =
387cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj            new WifiLastResortWatchdog(mWifiMetrics);
397cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final PropertyService mPropertyService = new SystemPropertyService();
407cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final BuildProperties mBuildProperties = new SystemBuildProperties();
417cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    private final KeyStore mKeyStore = KeyStore.getInstance();
427cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
437cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public WifiMetrics getWifiMetrics() {
447cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return mWifiMetrics;
457cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
467cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
477cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public WifiLastResortWatchdog getWifiLastResortWatchdog() {
487cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return mWifiLastResortWatchdog;
497cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
507cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
517cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public Clock getClock() {
527cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return mClock;
537cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
547cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
557cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public PropertyService getPropertyService() {
567cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return mPropertyService;
577cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
587cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
597cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public BuildProperties getBuildProperties() { return mBuildProperties; }
607cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj
617cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    public KeyStore getKeyStore() {
627cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj        return mKeyStore;
637cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj    }
647cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj}
657cf4e6b6aed533af53339f36099ed244dc4a5b7fsewardj