1 /* 2 * Copyright (C) 2022 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.dream.lowlight.dagger; 18 19 import android.app.DreamManager; 20 import android.content.ComponentName; 21 import android.content.Context; 22 23 import androidx.annotation.Nullable; 24 25 import com.android.dream.lowlight.R; 26 27 import javax.inject.Named; 28 29 import dagger.Module; 30 import dagger.Provides; 31 32 /** 33 * Dagger module for low light dream. 34 * 35 * @hide 36 */ 37 @Module 38 public interface LowLightDreamModule { 39 String LOW_LIGHT_DREAM_COMPONENT = "low_light_dream_component"; 40 41 /** 42 * Provides dream manager. 43 */ 44 @Provides providesDreamManager(Context context)45 static DreamManager providesDreamManager(Context context) { 46 return context.getSystemService(DreamManager.class); 47 } 48 49 /** 50 * Provides the component name of the low light dream, or null if not configured. 51 */ 52 @Provides 53 @Named(LOW_LIGHT_DREAM_COMPONENT) 54 @Nullable providesLowLightDreamComponent(Context context)55 static ComponentName providesLowLightDreamComponent(Context context) { 56 final String lowLightDreamComponent = context.getResources().getString( 57 R.string.config_lowLightDreamComponent); 58 return lowLightDreamComponent.isEmpty() ? null 59 : ComponentName.unflattenFromString(lowLightDreamComponent); 60 } 61 } 62