blob: 58f144830650ad3a42bf16678b11d96f2217a202 [file] [log] [blame]
Adrian Roos6023ccb2017-06-28 16:22:02 +02001/*
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
17package com.android.systemui.doze;
18
19import android.app.AlarmManager;
20import android.os.Handler;
21
22import com.android.systemui.util.AlarmTimeout;
23
24/**
25 * Moves the doze machine from the pausing to the paused state after a timeout.
26 */
27public class DozePauser implements DozeMachine.Part {
28 public static final String TAG = DozePauser.class.getSimpleName();
Adrian Roos6023ccb2017-06-28 16:22:02 +020029 private final AlarmTimeout mPauseTimeout;
30 private final DozeMachine mMachine;
Chris Wrenbaff9f02017-09-27 16:56:48 -040031 private final AlwaysOnDisplayPolicy mPolicy;
Adrian Roos6023ccb2017-06-28 16:22:02 +020032
jackqdyulei8443dd02017-08-24 16:14:34 -070033 public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager,
34 AlwaysOnDisplayPolicy policy) {
Adrian Roos6023ccb2017-06-28 16:22:02 +020035 mMachine = machine;
36 mPauseTimeout = new AlarmTimeout(alarmManager, this::onTimeout, TAG, handler);
Chris Wrenbaff9f02017-09-27 16:56:48 -040037 mPolicy = policy;
Adrian Roos6023ccb2017-06-28 16:22:02 +020038 }
39
40 @Override
41 public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
42 switch (newState) {
43 case DOZE_AOD_PAUSING:
Chris Wrenbaff9f02017-09-27 16:56:48 -040044 mPauseTimeout.schedule(mPolicy.proxScreenOffDelayMs,
45 AlarmTimeout.MODE_IGNORE_IF_SCHEDULED);
Adrian Roos6023ccb2017-06-28 16:22:02 +020046 break;
47 default:
48 mPauseTimeout.cancel();
49 break;
50 }
51 }
52
53 private void onTimeout() {
54 mMachine.requestState(DozeMachine.State.DOZE_AOD_PAUSED);
55 }
56}