1 /* 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 17 package com.android.systemui.recents; 18 19 import android.content.Context; 20 21 import com.android.systemui.CoreStartable; 22 import com.android.systemui.dagger.ContextComponentHelper; 23 import com.android.systemui.res.R; 24 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; 25 26 import dagger.Binds; 27 import dagger.Module; 28 import dagger.Provides; 29 import dagger.multibindings.ClassKey; 30 import dagger.multibindings.IntoMap; 31 import dagger.multibindings.IntoSet; 32 33 /** 34 * Dagger injection module for {@link RecentsImplementation} 35 */ 36 @Module 37 public abstract class RecentsModule { 38 39 /** Start Recents. */ 40 @Binds 41 @IntoMap 42 @ClassKey(Recents.class) bindRecentsStartable(Recents impl)43 abstract CoreStartable bindRecentsStartable(Recents impl); 44 45 /** Listen to config changes for Recents. */ 46 @Binds 47 @IntoSet bindRecentsConfigChanges(Recents impl)48 abstract ConfigurationListener bindRecentsConfigChanges(Recents impl); 49 50 /** Start ScreenPinningRequest. */ 51 @Binds 52 @IntoMap 53 @ClassKey(ScreenPinningRequest.class) bindScreenPinningRequestStartable(ScreenPinningRequest impl)54 abstract CoreStartable bindScreenPinningRequestStartable(ScreenPinningRequest impl); 55 56 /** Listen to config changes for ScreenPinningRequest. */ 57 @Binds 58 @IntoSet bindScreenPinningRequestConfigChanges(ScreenPinningRequest impl)59 abstract ConfigurationListener bindScreenPinningRequestConfigChanges(ScreenPinningRequest impl); 60 61 /** 62 * @return The {@link RecentsImplementation} from the config. 63 */ 64 @Provides provideRecentsImpl(Context context, ContextComponentHelper componentHelper)65 public static RecentsImplementation provideRecentsImpl(Context context, 66 ContextComponentHelper componentHelper) { 67 final String clsName = context.getString(R.string.config_recentsComponent); 68 if (clsName == null || clsName.length() == 0) { 69 throw new RuntimeException("No recents component configured", null); 70 } 71 RecentsImplementation impl = componentHelper.resolveRecents(clsName); 72 73 if (impl == null) { 74 Class<?> cls = null; 75 try { 76 cls = context.getClassLoader().loadClass(clsName); 77 } catch (Throwable t) { 78 throw new RuntimeException("Error loading recents component: " + clsName, t); 79 } 80 try { 81 impl = (RecentsImplementation) cls.newInstance(); 82 } catch (Throwable t) { 83 throw new RuntimeException("Error creating recents component: " + clsName, t); 84 } 85 } 86 87 return impl; 88 } 89 90 /** */ 91 @Binds 92 @IntoMap 93 @ClassKey(OverviewProxyRecentsImpl.class) bindOverviewProxyRecentsImpl( OverviewProxyRecentsImpl impl)94 public abstract RecentsImplementation bindOverviewProxyRecentsImpl( 95 OverviewProxyRecentsImpl impl); 96 } 97