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 package com.android.systemui.shade.display 18 19 import com.android.systemui.shade.domain.interactor.ShadeExpandedStateInteractor.ShadeElement 20 import dagger.Binds 21 import dagger.Module 22 import dagger.Provides 23 import dagger.multibindings.ElementsIntoSet 24 import kotlinx.coroutines.flow.StateFlow 25 26 /** Describes the display the shade should be shown in. */ 27 interface ShadeDisplayPolicy { 28 /** 29 * String used to identify each policy and used to set policy via adb command. This value must 30 * match a value defined in the SettingsLib shade_display_awareness_values string array. 31 */ 32 val name: String 33 34 /** The display id the shade should be at, according to this policy. */ 35 val displayId: StateFlow<Int> 36 } 37 38 /** Return the latest element the user intended to expand in the shade (notifications or QS). */ 39 interface ShadeExpansionIntent { 40 /** 41 * Returns the latest element the user intended to expand in the shade (notifications or QS). 42 * 43 * When the shade moves to a different display (e.g., due to a touch on the status bar of an 44 * external display), it's first collapsed and then re-expanded on the target display. 45 * 46 * If the user was trying to open a specific element (QS or notifications) when the shade was on 47 * the original display, that intention might be lost during the collapse/re-expand transition. 48 * This is used to preserve the user's intention, ensuring the correct element is expanded on 49 * the target display. 50 * 51 * Note that the expansion intent is kept for a very short amount of time (ideally, just a bit 52 * above the time it takes for the shade to collapse) 53 */ consumeExpansionIntentnull54 fun consumeExpansionIntent(): ShadeElement? 55 } 56 57 @Module(includes = [AllShadeDisplayPoliciesModule::class]) 58 interface ShadeDisplayPolicyModule { 59 60 @Binds fun provideDefaultPolicy(impl: StatusBarTouchShadeDisplayPolicy): ShadeDisplayPolicy 61 62 @Binds 63 fun provideShadeExpansionIntent(impl: StatusBarTouchShadeDisplayPolicy): ShadeExpansionIntent 64 } 65 66 @Module 67 internal object AllShadeDisplayPoliciesModule { 68 @Provides 69 @ElementsIntoSet provideShadeDisplayPoliciesnull70 fun provideShadeDisplayPolicies( 71 defaultPolicy: DefaultDisplayShadePolicy, 72 externalPolicy: AnyExternalShadeDisplayPolicy, 73 statusBarPolicy: StatusBarTouchShadeDisplayPolicy, 74 focusPolicy: FocusShadeDisplayPolicy, 75 ): Set<ShadeDisplayPolicy> { 76 return setOf(defaultPolicy, externalPolicy, statusBarPolicy, focusPolicy) 77 } 78 } 79