blob: 55552850890f46f9dc15173a65dd075ee618cbb5 [file] [log] [blame]
Dave Mankoff898e1bb2019-09-25 17:54:19 -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.recents;
18
19import android.content.Context;
20
21import com.android.systemui.R;
22
23import dagger.Module;
24import dagger.Provides;
25
26/**
27 * Dagger injection module for {@link RecentsImplementation}
28 */
29@Module
30public class RecentsModule {
31 /**
32 * @return The {@link RecentsImplementation} from the config.
33 */
34 @Provides
35 public RecentsImplementation provideRecentsImpl(Context context) {
36 final String clsName = context.getString(R.string.config_recentsComponent);
37 if (clsName == null || clsName.length() == 0) {
38 throw new RuntimeException("No recents component configured", null);
39 }
40 Class<?> cls = null;
41 try {
42 cls = context.getClassLoader().loadClass(clsName);
43 } catch (Throwable t) {
44 throw new RuntimeException("Error loading recents component: " + clsName, t);
45 }
46 try {
47 RecentsImplementation impl = (RecentsImplementation) cls.newInstance();
48 return impl;
49 } catch (Throwable t) {
50 throw new RuntimeException("Error creating recents component: " + clsName, t);
51 }
52 }
53}