• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
18 package com.android.systemui.communal.widgets
19 
20 import android.appwidget.AppWidgetManager
21 import android.content.Context
22 import android.content.res.Resources
23 import com.android.systemui.communal.shared.model.GlanceableHubMultiUserHelper
24 import com.android.systemui.dagger.SysUISingleton
25 import com.android.systemui.dagger.qualifiers.Application
26 import com.android.systemui.dagger.qualifiers.Background
27 import com.android.systemui.dagger.qualifiers.Main
28 import com.android.systemui.log.LogBuffer
29 import com.android.systemui.log.dagger.CommunalLog
30 import com.android.systemui.res.R
31 import com.android.systemui.user.domain.interactor.SelectedUserInteractor
32 import dagger.Module
33 import dagger.Provides
34 import java.util.Optional
35 import javax.inject.Named
36 import kotlinx.coroutines.CoroutineScope
37 
38 @Module
39 interface CommunalWidgetModule {
40     companion object {
41         const val APP_WIDGET_HOST_ID = 116
42         const val DEFAULT_WIDGETS = "default_widgets"
43 
44         @SysUISingleton
45         @Provides
provideCommunalAppWidgetHostnull46         fun provideCommunalAppWidgetHost(
47             @Application context: Context,
48             @Background backgroundScope: CoroutineScope,
49             @CommunalLog logBuffer: LogBuffer,
50             glanceableHubMultiUserHelper: GlanceableHubMultiUserHelper,
51         ): CommunalAppWidgetHost {
52             return CommunalAppWidgetHost(
53                 context,
54                 backgroundScope,
55                 APP_WIDGET_HOST_ID,
56                 logBuffer,
57                 glanceableHubMultiUserHelper,
58             )
59         }
60 
61         @SysUISingleton
62         @Provides
provideCommunalWidgetHostnull63         fun provideCommunalWidgetHost(
64             @Application applicationScope: CoroutineScope,
65             appWidgetManager: Optional<AppWidgetManager>,
66             appWidgetHost: CommunalAppWidgetHost,
67             selectedUserInteractor: SelectedUserInteractor,
68             @CommunalLog logBuffer: LogBuffer,
69             glanceableHubMultiUserHelper: GlanceableHubMultiUserHelper,
70         ): CommunalWidgetHost {
71             return CommunalWidgetHost(
72                 applicationScope,
73                 appWidgetManager,
74                 appWidgetHost,
75                 selectedUserInteractor,
76                 logBuffer,
77                 glanceableHubMultiUserHelper,
78             )
79         }
80 
81         @Provides
82         @Named(DEFAULT_WIDGETS)
provideDefaultWidgetsnull83         fun provideDefaultWidgets(@Main resources: Resources): Array<String> {
84             return resources.getStringArray(R.array.config_communalWidgetAllowlist)
85         }
86     }
87 }
88