1 /* 2 * Copyright (C) 2017 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.keyguard; 18 19 import com.android.app.tracing.coroutines.TrackTracer; 20 import com.android.systemui.Dumpable; 21 import com.android.systemui.dump.DumpManager; 22 import com.android.systemui.power.domain.interactor.PowerInteractor; 23 24 import java.io.PrintWriter; 25 26 import javax.inject.Inject; 27 import javax.inject.Singleton; 28 29 /** 30 * Tracks the screen lifecycle. 31 * 32 * @deprecated Collect flows from {@link PowerInteractor} instead. 33 */ 34 @Singleton 35 @Deprecated 36 public class ScreenLifecycle extends Lifecycle<ScreenLifecycle.Observer> implements Dumpable { 37 38 public static final int SCREEN_OFF = 0; 39 public static final int SCREEN_TURNING_ON = 1; 40 public static final int SCREEN_ON = 2; 41 public static final int SCREEN_TURNING_OFF = 3; 42 43 private int mScreenState = SCREEN_OFF; 44 45 @Inject ScreenLifecycle(DumpManager dumpManager)46 public ScreenLifecycle(DumpManager dumpManager) { 47 dumpManager.registerDumpable(getClass().getSimpleName(), this); 48 } 49 getScreenState()50 public int getScreenState() { 51 return mScreenState; 52 } 53 dispatchScreenTurningOn()54 public void dispatchScreenTurningOn() { 55 setScreenState(SCREEN_TURNING_ON); 56 dispatch(Observer::onScreenTurningOn); 57 } 58 dispatchScreenTurnedOn()59 public void dispatchScreenTurnedOn() { 60 setScreenState(SCREEN_ON); 61 dispatch(Observer::onScreenTurnedOn); 62 } 63 dispatchScreenTurningOff()64 public void dispatchScreenTurningOff() { 65 setScreenState(SCREEN_TURNING_OFF); 66 dispatch(Observer::onScreenTurningOff); 67 } 68 dispatchScreenTurnedOff()69 public void dispatchScreenTurnedOff() { 70 setScreenState(SCREEN_OFF); 71 dispatch(Observer::onScreenTurnedOff); 72 } 73 74 @Override dump(PrintWriter pw, String[] args)75 public void dump(PrintWriter pw, String[] args) { 76 pw.println("ScreenLifecycle:"); 77 pw.println(" mScreenState=" + mScreenState); 78 } 79 setScreenState(int screenState)80 private void setScreenState(int screenState) { 81 mScreenState = screenState; 82 TrackTracer.instantForGroup("screen", "screenState", screenState); 83 } 84 85 public interface Observer { onScreenTurningOn()86 default void onScreenTurningOn() {} onScreenTurnedOn()87 default void onScreenTurnedOn() {} onScreenTurningOff()88 default void onScreenTurningOff() {} onScreenTurnedOff()89 default void onScreenTurnedOff() {} 90 } 91 92 } 93