• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 import java.io.FileDescriptor;
24 import java.io.PrintWriter;
25 
26 /**
27  * Tracks the screen lifecycle.
28  */
29 public class ScreenLifecycle extends Lifecycle<ScreenLifecycle.Observer> implements Dumpable {
30 
31     public static final int SCREEN_OFF = 0;
32     public static final int SCREEN_TURNING_ON = 1;
33     public static final int SCREEN_ON = 2;
34     public static final int SCREEN_TURNING_OFF = 3;
35 
36     private int mScreenState = SCREEN_OFF;
37 
getScreenState()38     public int getScreenState() {
39         return mScreenState;
40     }
41 
dispatchScreenTurningOn()42     public void dispatchScreenTurningOn() {
43         setScreenState(SCREEN_TURNING_ON);
44         dispatch(Observer::onScreenTurningOn);
45     }
46 
dispatchScreenTurnedOn()47     public void dispatchScreenTurnedOn() {
48         setScreenState(SCREEN_ON);
49         dispatch(Observer::onScreenTurnedOn);
50     }
51 
dispatchScreenTurningOff()52     public void dispatchScreenTurningOff() {
53         setScreenState(SCREEN_TURNING_OFF);
54         dispatch(Observer::onScreenTurningOff);
55     }
56 
dispatchScreenTurnedOff()57     public void dispatchScreenTurnedOff() {
58         setScreenState(SCREEN_OFF);
59         dispatch(Observer::onScreenTurnedOff);
60     }
61 
62     @Override
dump(FileDescriptor fd, PrintWriter pw, String[] args)63     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
64         pw.println("ScreenLifecycle:");
65         pw.println("  mScreenState=" + mScreenState);
66     }
67 
setScreenState(int screenState)68     private void setScreenState(int screenState) {
69         mScreenState = screenState;
70         Trace.traceCounter(Trace.TRACE_TAG_APP, "screenState", screenState);
71     }
72 
73     public interface Observer {
onScreenTurningOn()74         default void onScreenTurningOn() {}
onScreenTurnedOn()75         default void onScreenTurnedOn() {}
onScreenTurningOff()76         default void onScreenTurningOff() {}
onScreenTurnedOff()77         default void onScreenTurnedOff() {}
78     }
79 
80 }
81