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