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 com.android.systemui.util.LargeScreenUtils 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 private val context: Context, 34 private val commandQueue: CommandQueue, 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 LargeScreenUtils.shouldUseSplitNotificationShade(context.resources) 47 configController.addCallback(this) 48 } 49 50 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 61 fun setRemoteInputActive(active: Boolean) { 62 if (remoteInputActive != active) { 63 remoteInputActive = active 64 recomputeDisableFlags() 65 } 66 } 67 68 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 = LargeScreenUtils.shouldUseSplitNotificationShade(context.resources) 78 if (newSplitShadeFlag != shouldUseSplitNotificationShade) { 79 shouldUseSplitNotificationShade = newSplitShadeFlag 80 needToRecompute = true 81 } 82 if (needToRecompute) { 83 recomputeDisableFlags() 84 } 85 } 86 87 /** 88 * Called in order to trigger a refresh of the disable flags after a relevant configuration 89 * change or when a [RemoteInputView] has changed its active state. The method 90 * [adjustDisableFlags] will be invoked to modify the disable flags according to 91 * [remoteInputActive], [isLandscape] and [shouldUseSplitNotificationShade]. 92 */ 93 private fun recomputeDisableFlags() { 94 commandQueue.recomputeDisableFlags(context.displayId, true) 95 } 96 }