blob: 09bccd993f39e41f1d6161c61defa3ad3bfcb6e3 [file] [log] [blame]
Dave Mankoff1a0e3822019-07-03 13:26:55 -04001/*
2 * Copyright (C) 2019 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.systemui;
18
19import java.util.Map;
20
21import javax.inject.Inject;
22import javax.inject.Provider;
23
24/**
25 * Used during Service and Activity instantiation to make them injectable.
26 */
27public class ContextComponentResolver implements ContextComponentHelper {
28 private final Map<Class<?>, Provider<Object>> mCreators;
29
30 @Inject
31 ContextComponentResolver(Map<Class<?>, Provider<Object>> creators) {
32 mCreators = creators;
33 }
34
35 /**
36 * Looks up the class name to see if Dagger has an instance of it.
37 */
38 @Override
39 public <T> T resolve(String className) {
40 for (Map.Entry<Class<?>, Provider<Object>> p : mCreators.entrySet()) {
41 if (p.getKey().getName().equals(className)) {
42 return (T) p.getValue().get();
43 }
44 }
45
46 return null;
47 }
48}