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