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.touchpad.tutorial.domain.interactor
18 
19 import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
20 import com.android.systemui.model.SysUiState
21 import com.android.systemui.settings.DisplayTracker
22 import com.android.systemui.shared.system.QuickStepContract
23 import kotlinx.coroutines.CoroutineScope
24 import com.android.app.tracing.coroutines.launchTraced as launch
25 
26 class TouchpadGesturesInteractor(
27     private val sysUiState: SysUiState,
28     private val displayTracker: DisplayTracker,
29     private val backgroundScope: CoroutineScope,
30     private val logger: InputDeviceTutorialLogger,
31 ) {
disableGesturesnull32     fun disableGestures() {
33         logger.d("Disabling touchpad gestures across the system")
34         setGesturesState(disabled = true)
35     }
36 
enableGesturesnull37     fun enableGestures() {
38         logger.d("Enabling touchpad gestures across the system")
39         setGesturesState(disabled = false)
40     }
41 
setGesturesStatenull42     private fun setGesturesState(disabled: Boolean) {
43         backgroundScope.launch {
44             sysUiState
45                 .setFlag(QuickStepContract.SYSUI_STATE_TOUCHPAD_GESTURES_DISABLED, disabled)
46                 .commitUpdate(displayTracker.defaultDisplayId)
47         }
48     }
49 }
50