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