• 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.Handler;
20 import android.os.Message;
21 
22 import javax.inject.Inject;
23 import javax.inject.Singleton;
24 
25 /**
26  * Dispatches the lifecycles keyguard gets from WindowManager on the main thread.
27  */
28 @Singleton
29 public class KeyguardLifecyclesDispatcher {
30 
31     static final int SCREEN_TURNING_ON = 0;
32     static final int SCREEN_TURNED_ON = 1;
33     static final int SCREEN_TURNING_OFF = 2;
34     static final int SCREEN_TURNED_OFF = 3;
35 
36     static final int STARTED_WAKING_UP = 4;
37     static final int FINISHED_WAKING_UP = 5;
38     static final int STARTED_GOING_TO_SLEEP = 6;
39     static final int FINISHED_GOING_TO_SLEEP = 7;
40 
41     private final ScreenLifecycle mScreenLifecycle;
42     private final WakefulnessLifecycle mWakefulnessLifecycle;
43 
44     @Inject
KeyguardLifecyclesDispatcher(ScreenLifecycle screenLifecycle, WakefulnessLifecycle wakefulnessLifecycle)45     public KeyguardLifecyclesDispatcher(ScreenLifecycle screenLifecycle,
46             WakefulnessLifecycle wakefulnessLifecycle) {
47         mScreenLifecycle = screenLifecycle;
48         mWakefulnessLifecycle = wakefulnessLifecycle;
49     }
50 
dispatch(int what)51     void dispatch(int what) {
52         mHandler.obtainMessage(what).sendToTarget();
53     }
54 
55     private Handler mHandler = new Handler() {
56         @Override
57         public void handleMessage(Message msg) {
58             switch (msg.what) {
59                 case SCREEN_TURNING_ON:
60                     mScreenLifecycle.dispatchScreenTurningOn();
61                     break;
62                 case SCREEN_TURNED_ON:
63                     mScreenLifecycle.dispatchScreenTurnedOn();
64                     break;
65                 case SCREEN_TURNING_OFF:
66                     mScreenLifecycle.dispatchScreenTurningOff();
67                     break;
68                 case SCREEN_TURNED_OFF:
69                     mScreenLifecycle.dispatchScreenTurnedOff();
70                     break;
71                 case STARTED_WAKING_UP:
72                     mWakefulnessLifecycle.dispatchStartedWakingUp();
73                     break;
74                 case FINISHED_WAKING_UP:
75                     mWakefulnessLifecycle.dispatchFinishedWakingUp();
76                     break;
77                 case STARTED_GOING_TO_SLEEP:
78                     mWakefulnessLifecycle.dispatchStartedGoingToSleep();
79                     break;
80                 case FINISHED_GOING_TO_SLEEP:
81                     mWakefulnessLifecycle.dispatchFinishedGoingToSleep();
82                     break;
83                 default:
84                     throw new IllegalArgumentException("Unknown message: " + msg);
85             }
86         }
87     };
88 
89 }
90