1 /* 2 * Copyright (C) 2021 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.keyguard 17 18 import com.android.systemui.unfold.updates.screen.ScreenStatusProvider 19 import com.android.systemui.unfold.updates.screen.ScreenStatusProvider.ScreenListener 20 import com.android.app.tracing.traceSection 21 import java.util.concurrent.CopyOnWriteArrayList 22 import javax.inject.Inject 23 import javax.inject.Singleton 24 25 @Singleton 26 class LifecycleScreenStatusProvider @Inject constructor(screenLifecycle: ScreenLifecycle) : 27 ScreenStatusProvider, ScreenLifecycle.Observer { 28 29 init { 30 screenLifecycle.addObserver(this) 31 } 32 33 private val listeners: MutableList<ScreenListener> = CopyOnWriteArrayList() 34 removeCallbacknull35 override fun removeCallback(listener: ScreenListener) { 36 listeners.remove(listener) 37 } 38 addCallbacknull39 override fun addCallback(listener: ScreenListener) { 40 listeners.add(listener) 41 } 42 onScreenTurnedOnnull43 override fun onScreenTurnedOn() { 44 traceSection("$TRACE_TAG#onScreenTurnedOn") { 45 listeners.forEach(ScreenListener::onScreenTurnedOn) 46 } 47 } 48 onScreenTurningOffnull49 override fun onScreenTurningOff() { 50 traceSection("$TRACE_TAG#onScreenTurningOff") { 51 listeners.forEach(ScreenListener::onScreenTurningOff) 52 } 53 } 54 onScreenTurningOnnull55 override fun onScreenTurningOn() { 56 traceSection("$TRACE_TAG#onScreenTurningOn") { 57 listeners.forEach(ScreenListener::onScreenTurningOn) 58 } 59 } 60 } 61 62 private const val TRACE_TAG = "LifecycleScreenStatusProvider"