• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.server.nearby.fastpair;
18 
19 import android.content.Context;
20 
21 import com.android.server.nearby.common.eventloop.EventLoop;
22 import com.android.server.nearby.common.locator.Locator;
23 import com.android.server.nearby.common.locator.Module;
24 import com.android.server.nearby.fastpair.cache.FastPairCacheManager;
25 import com.android.server.nearby.fastpair.footprint.FootprintsDeviceManager;
26 import com.android.server.nearby.fastpair.halfsheet.FastPairHalfSheetManager;
27 
28 import java.time.Clock;
29 import java.time.Instant;
30 import java.time.ZoneId;
31 
32 /**
33  * Module that associates all of the fast pair related singleton class
34  */
35 public class FastPairModule extends Module {
36     /**
37      * Initiate the class that needs to be singleton.
38      */
39     @Override
configure(Context context, Class<?> type, Locator locator)40     public void configure(Context context, Class<?> type, Locator locator) {
41         if (type.equals(FastPairCacheManager.class)) {
42             locator.bind(FastPairCacheManager.class, new FastPairCacheManager(context));
43         } else if (type.equals(FootprintsDeviceManager.class)) {
44             locator.bind(FootprintsDeviceManager.class, new FootprintsDeviceManager());
45         } else if (type.equals(EventLoop.class)) {
46             locator.bind(EventLoop.class, EventLoop.newInstance("NearbyFastPair"));
47         } else if (type.equals(FastPairController.class)) {
48             locator.bind(FastPairController.class, new FastPairController(context));
49         } else if (type.equals(FastPairCacheManager.class)) {
50             locator.bind(FastPairCacheManager.class, new FastPairCacheManager(context));
51         } else if (type.equals(FastPairHalfSheetManager.class)) {
52             locator.bind(FastPairHalfSheetManager.class, new FastPairHalfSheetManager(context));
53         } else if (type.equals(FastPairAdvHandler.class)) {
54             locator.bind(FastPairAdvHandler.class, new FastPairAdvHandler(context));
55         } else if (type.equals(Clock.class)) {
56             locator.bind(Clock.class, new Clock() {
57                 @Override
58                 public ZoneId getZone() {
59                     return null;
60                 }
61 
62                 @Override
63                 public Clock withZone(ZoneId zone) {
64                     return null;
65                 }
66 
67                 @Override
68                 public Instant instant() {
69                     return null;
70                 }
71             });
72         }
73 
74     }
75 
76     /**
77      * Clean up the singleton classes.
78      */
79     @Override
destroy(Context context, Class<?> type, Object instance)80     public void destroy(Context context, Class<?> type, Object instance) {
81         super.destroy(context, type, instance);
82     }
83 }
84