1 /* 2 * Copyright (C) 2016 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.statusbar.policy 17 18 import android.app.StatusBarManager 19 import android.content.Context 20 import android.content.res.Configuration 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.shade.ShadeDisplayAware 23 import com.android.systemui.statusbar.CommandQueue 24 import javax.inject.Inject 25 26 /** 27 * Controls whether the disable flag [StatusBarManager.DISABLE2_QUICK_SETTINGS] should be set. 28 * This would happen when a [RemoteInputView] is active, the device is in landscape and not using 29 * split shade. 30 */ 31 @SysUISingleton 32 class RemoteInputQuickSettingsDisabler @Inject constructor( 33 @ShadeDisplayAware private val context: Context, 34 private val commandQueue: CommandQueue, 35 private val splitShadeStateController: SplitShadeStateController, 36 configController: ConfigurationController 37 ) : ConfigurationController.ConfigurationListener { 38 39 private var remoteInputActive = false 40 private var isLandscape: Boolean 41 private var shouldUseSplitNotificationShade: Boolean 42 43 init { 44 isLandscape = 45 context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE 46 shouldUseSplitNotificationShade = 47 splitShadeStateController.shouldUseSplitNotificationShade(context.resources) 48 configController.addCallback(this) 49 } 50 adjustDisableFlagsnull51 fun adjustDisableFlags(state: Int): Int { 52 var mutableState = state 53 if (remoteInputActive && 54 isLandscape && 55 !shouldUseSplitNotificationShade 56 ) { 57 mutableState = state or StatusBarManager.DISABLE2_QUICK_SETTINGS 58 } 59 return mutableState 60 } 61 setRemoteInputActivenull62 fun setRemoteInputActive(active: Boolean) { 63 if (remoteInputActive != active) { 64 remoteInputActive = active 65 recomputeDisableFlags() 66 } 67 } 68 onConfigChangednull69 override fun onConfigChanged(newConfig: Configuration) { 70 var needToRecompute = false 71 72 val newIsLandscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE 73 if (newIsLandscape != isLandscape) { 74 isLandscape = newIsLandscape 75 needToRecompute = true 76 } 77 78 val newSplitShadeFlag = splitShadeStateController 79 .shouldUseSplitNotificationShade(context.resources) 80 if (newSplitShadeFlag != shouldUseSplitNotificationShade) { 81 shouldUseSplitNotificationShade = newSplitShadeFlag 82 needToRecompute = true 83 } 84 if (needToRecompute) { 85 recomputeDisableFlags() 86 } 87 } 88 89 /** 90 * Called in order to trigger a refresh of the disable flags after a relevant configuration 91 * change or when a [RemoteInputView] has changed its active state. The method 92 * [adjustDisableFlags] will be invoked to modify the disable flags according to 93 * [remoteInputActive], [isLandscape] and [shouldUseSplitNotificationShade]. 94 */ recomputeDisableFlagsnull95 private fun recomputeDisableFlags() { 96 commandQueue.recomputeDisableFlags(context.displayId, true) 97 } 98 }