1 /* <lambda>null2 * Copyright (C) 2025 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.common.domain.interactor 18 19 import android.util.Log 20 import com.android.app.displaylib.PerDisplayRepository 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.display.data.repository.DisplayRepository 23 import com.android.systemui.model.StateChange 24 import com.android.systemui.model.SysUiState 25 import javax.inject.Inject 26 27 /** Handles [SysUiState] changes between displays. */ 28 @SysUISingleton 29 class SysUIStateDisplaysInteractor 30 @Inject 31 constructor( 32 private val sysUIStateRepository: PerDisplayRepository<SysUiState>, 33 private val displayRepository: DisplayRepository, 34 ) { 35 36 /** 37 * Sets the flags on the given [targetDisplayId] based on the [stateChanges], while making sure 38 * that those flags are not set in any other display. 39 */ 40 fun setFlagsExclusivelyToDisplay(targetDisplayId: Int, stateChanges: StateChange) { 41 if (SysUiState.DEBUG) { 42 Log.d(TAG, "Setting flags $stateChanges only for display $targetDisplayId") 43 } 44 displayRepository.displays.value 45 .mapNotNull { sysUIStateRepository[it.displayId] } 46 .apply { 47 // Let's first modify all states, without committing changes ... 48 forEach { displaySysUIState -> 49 if (displaySysUIState.displayId == targetDisplayId) { 50 stateChanges.applyTo(displaySysUIState) 51 } else { 52 stateChanges.clearFrom(displaySysUIState) 53 } 54 } 55 // ... And commit changes at the end 56 forEach { sysuiState -> sysuiState.commitUpdate() } 57 } 58 } 59 60 private companion object { 61 const val TAG = "SysUIStateInteractor" 62 } 63 } 64