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 package com.android.systemui.smartspace.dagger 17 18 import android.app.PendingIntent 19 import android.content.Intent 20 import android.view.View 21 import android.view.ViewGroup 22 import com.android.systemui.plugins.ActivityStarter 23 import com.android.systemui.plugins.BcSmartspaceDataPlugin 24 import com.android.systemui.plugins.BcSmartspaceDataPlugin.UI_SURFACE_DREAM 25 import com.android.systemui.plugins.FalsingManager 26 import com.android.systemui.smartspace.dagger.SmartspaceViewComponent.SmartspaceViewModule.PLUGIN 27 import dagger.BindsInstance 28 import dagger.Module 29 import dagger.Provides 30 import dagger.Subcomponent 31 import javax.inject.Named 32 33 @Subcomponent(modules = [SmartspaceViewComponent.SmartspaceViewModule::class]) 34 interface SmartspaceViewComponent { 35 @Subcomponent.Factory 36 interface Factory { createnull37 fun create( 38 @BindsInstance parent: ViewGroup, 39 @BindsInstance @Named(PLUGIN) plugin: BcSmartspaceDataPlugin, 40 @BindsInstance onAttachListener: View.OnAttachStateChangeListener, 41 @BindsInstance viewWithCustomLayout: View? = null 42 ): SmartspaceViewComponent 43 } 44 45 fun getView(): BcSmartspaceDataPlugin.SmartspaceView 46 47 @Module 48 object SmartspaceViewModule { 49 const val PLUGIN = "plugin" 50 51 @Provides 52 fun providesSmartspaceView( 53 activityStarter: ActivityStarter, 54 falsingManager: FalsingManager, 55 parent: ViewGroup, 56 @Named(PLUGIN) plugin: BcSmartspaceDataPlugin, 57 viewWithCustomLayout: View?, 58 onAttachListener: View.OnAttachStateChangeListener 59 ): 60 BcSmartspaceDataPlugin.SmartspaceView { 61 val ssView = viewWithCustomLayout 62 as? BcSmartspaceDataPlugin.SmartspaceView 63 ?: plugin.getView(parent) 64 // Currently, this is only used to provide SmartspaceView on Dream surface. 65 ssView.setUiSurface(UI_SURFACE_DREAM) 66 ssView.registerDataProvider(plugin) 67 68 ssView.setIntentStarter(object : BcSmartspaceDataPlugin.IntentStarter { 69 override fun startIntent(view: View, intent: Intent, showOnLockscreen: Boolean) { 70 activityStarter.startActivity( 71 intent, 72 true, /* dismissShade */ 73 null, /* launch animator */ 74 showOnLockscreen 75 ) 76 } 77 78 override fun startPendingIntent(pi: PendingIntent, showOnLockscreen: Boolean) { 79 if (showOnLockscreen) { 80 pi.send() 81 } else { 82 activityStarter.startPendingIntentDismissingKeyguard(pi) 83 } 84 } 85 }) 86 (ssView as View).addOnAttachStateChangeListener(onAttachListener) 87 ssView.setFalsingManager(falsingManager) 88 return ssView 89 } 90 } 91 } 92