• 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.systemui.dreams.dagger;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.content.res.Resources;
23 
24 import com.android.dream.lowlight.dagger.LowLightDreamModule;
25 import com.android.settingslib.dream.DreamBackend;
26 import com.android.systemui.R;
27 import com.android.systemui.dagger.SysUISingleton;
28 import com.android.systemui.dagger.qualifiers.Main;
29 import com.android.systemui.dreams.DreamOverlayNotificationCountProvider;
30 import com.android.systemui.dreams.DreamOverlayService;
31 import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
32 import com.android.systemui.dreams.touch.scrim.dagger.ScrimModule;
33 import com.android.systemui.process.condition.SystemProcessCondition;
34 import com.android.systemui.shared.condition.Condition;
35 import com.android.systemui.shared.condition.Monitor;
36 
37 import java.util.Optional;
38 import java.util.Set;
39 import java.util.concurrent.Executor;
40 
41 import javax.inject.Named;
42 
43 import dagger.Binds;
44 import dagger.Module;
45 import dagger.Provides;
46 import dagger.multibindings.IntoSet;
47 
48 /**
49  * Dagger Module providing Dream-related functionality.
50  */
51 @Module(includes = {
52             RegisteredComplicationsModule.class,
53             LowLightDreamModule.class,
54             ScrimModule.class
55         },
56         subcomponents = {
57             DreamOverlayComponent.class,
58         })
59 public interface DreamModule {
60     String DREAM_ONLY_ENABLED_FOR_DOCK_USER = "dream_only_enabled_for_dock_user";
61     String DREAM_OVERLAY_SERVICE_COMPONENT = "dream_overlay_service_component";
62     String DREAM_OVERLAY_ENABLED = "dream_overlay_enabled";
63 
64     String DREAM_SUPPORTED = "dream_supported";
65     String DREAM_PRETEXT_CONDITIONS = "dream_pretext_conditions";
66     String DREAM_PRETEXT_MONITOR = "dream_prtext_monitor";
67     String DREAM_OVERLAY_WINDOW_TITLE = "dream_overlay_window_title";
68 
69 
70     /**
71      * Provides the dream component
72      */
73     @Provides
74     @Named(DREAM_OVERLAY_SERVICE_COMPONENT)
providesDreamOverlayService(Context context)75     static ComponentName providesDreamOverlayService(Context context) {
76         return new ComponentName(context, DreamOverlayService.class);
77     }
78 
79     /**
80      * Provides whether dream overlay is enabled.
81      */
82     @Provides
83     @Named(DREAM_OVERLAY_ENABLED)
providesDreamOverlayEnabled(PackageManager packageManager, @Named(DREAM_OVERLAY_SERVICE_COMPONENT) ComponentName component)84     static Boolean providesDreamOverlayEnabled(PackageManager packageManager,
85             @Named(DREAM_OVERLAY_SERVICE_COMPONENT) ComponentName component) {
86         try {
87             return packageManager.getServiceInfo(component, PackageManager.GET_META_DATA).enabled;
88         } catch (PackageManager.NameNotFoundException e) {
89             return false;
90         }
91     }
92 
93     /**
94      * Provides an instance of the dream backend.
95      */
96     @Provides
providesDreamBackend(Context context)97     static DreamBackend providesDreamBackend(Context context) {
98         return DreamBackend.getInstance(context);
99     }
100 
101     /**
102      * Provides an instance of a {@link DreamOverlayNotificationCountProvider}.
103      */
104     @SysUISingleton
105     @Provides
106     static Optional<DreamOverlayNotificationCountProvider>
providesDreamOverlayNotificationCountProvider()107             providesDreamOverlayNotificationCountProvider() {
108         // If we decide to bring this back, we should gate it on a config that can be changed in
109         // an overlay.
110         return Optional.empty();
111     }
112 
113     /** */
114     @Provides
115     @Named(DREAM_ONLY_ENABLED_FOR_DOCK_USER)
providesDreamOnlyEnabledForDockUser(@ain Resources resources)116     static boolean providesDreamOnlyEnabledForDockUser(@Main Resources resources) {
117         return resources.getBoolean(
118                 com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser);
119     }
120 
121     /** */
122     @Provides
123     @Named(DREAM_SUPPORTED)
providesDreamSupported(@ain Resources resources)124     static boolean providesDreamSupported(@Main Resources resources) {
125         return resources.getBoolean(com.android.internal.R.bool.config_dreamsSupported);
126     }
127 
128     /** */
129     @Binds
130     @IntoSet
131     @Named(DREAM_PRETEXT_CONDITIONS)
bindSystemProcessCondition(SystemProcessCondition condition)132     Condition bindSystemProcessCondition(SystemProcessCondition condition);
133 
134     /** */
135     @Provides
136     @Named(DREAM_PRETEXT_MONITOR)
providesDockerPretextMonitor( @ain Executor executor, @Named(DREAM_PRETEXT_CONDITIONS) Set<Condition> pretextConditions)137     static Monitor providesDockerPretextMonitor(
138             @Main Executor executor,
139             @Named(DREAM_PRETEXT_CONDITIONS) Set<Condition> pretextConditions) {
140         return new Monitor(executor, pretextConditions);
141     }
142 
143     /** */
144     @Provides
145     @Named(DREAM_OVERLAY_WINDOW_TITLE)
providesDreamOverlayWindowTitle(@ain Resources resources)146     static String providesDreamOverlayWindowTitle(@Main Resources resources) {
147         return resources.getString(R.string.app_label);
148     }
149 }
150