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