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