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.doze; 18 19 import android.app.AlarmManager; 20 import android.os.Handler; 21 22 import com.android.systemui.util.AlarmTimeout; 23 24 /** 25 * Moves the doze machine from the pausing to the paused state after a timeout. 26 */ 27 public class DozePauser implements DozeMachine.Part { 28 public static final String TAG = DozePauser.class.getSimpleName(); 29 private final AlarmTimeout mPauseTimeout; 30 private final DozeMachine mMachine; 31 private final AlwaysOnDisplayPolicy mPolicy; 32 DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager, AlwaysOnDisplayPolicy policy)33 public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager, 34 AlwaysOnDisplayPolicy policy) { 35 mMachine = machine; 36 mPauseTimeout = new AlarmTimeout(alarmManager, this::onTimeout, TAG, handler); 37 mPolicy = policy; 38 } 39 40 @Override transitionTo(DozeMachine.State oldState, DozeMachine.State newState)41 public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { 42 switch (newState) { 43 case DOZE_AOD_PAUSING: 44 mPauseTimeout.schedule(mPolicy.proxScreenOffDelayMs, 45 AlarmTimeout.MODE_IGNORE_IF_SCHEDULED); 46 break; 47 default: 48 mPauseTimeout.cancel(); 49 break; 50 } 51 } 52 onTimeout()53 private void onTimeout() { 54 mMachine.requestState(DozeMachine.State.DOZE_AOD_PAUSED); 55 } 56 } 57