• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 package com.android.bluetooth.gatt;
18 
19 import android.os.Looper;
20 import android.util.Log;
21 
22 import com.android.bluetooth.Utils;
23 import com.android.bluetooth.btservice.AdapterService;
24 
25 /** Factory class for object initialization to help with unit testing */
26 public class GattObjectsFactory {
27     private static final String TAG = GattObjectsFactory.class.getSimpleName();
28 
29     private static GattObjectsFactory sInstance;
30     private static final Object INSTANCE_LOCK = new Object();
31 
GattObjectsFactory()32     private GattObjectsFactory() {}
33 
34     /**
35      * Get the singleton instance of object factory
36      *
37      * @return the singleton instance, guaranteed not null
38      */
getInstance()39     public static GattObjectsFactory getInstance() {
40         synchronized (INSTANCE_LOCK) {
41             if (sInstance == null) {
42                 sInstance = new GattObjectsFactory();
43             }
44         }
45         return sInstance;
46     }
47 
48     /**
49      * Allow unit tests to substitute GattObjectsFactory with a test instance
50      *
51      * @param objectsFactory a test instance of the GattObjectsFactory
52      */
setInstanceForTesting(GattObjectsFactory objectsFactory)53     public static void setInstanceForTesting(GattObjectsFactory objectsFactory) {
54         Utils.enforceInstrumentationTestMode();
55         synchronized (INSTANCE_LOCK) {
56             Log.d(TAG, "setInstanceForTesting(), set to " + objectsFactory);
57             sInstance = objectsFactory;
58         }
59     }
60 
getNativeInterface()61     public GattNativeInterface getNativeInterface() {
62         return GattNativeInterface.getInstance();
63     }
64 
createDistanceMeasurementManager( AdapterService adapterService, Looper looper)65     public DistanceMeasurementManager createDistanceMeasurementManager(
66             AdapterService adapterService, Looper looper) {
67         return new DistanceMeasurementManager(adapterService, looper);
68     }
69 }
70