Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 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(); |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 29 | private final AlarmTimeout mPauseTimeout; |
| 30 | private final DozeMachine mMachine; |
Chris Wren | baff9f0 | 2017-09-27 16:56:48 -0400 | [diff] [blame] | 31 | private final AlwaysOnDisplayPolicy mPolicy; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 32 | |
jackqdyulei | 8443dd0 | 2017-08-24 16:14:34 -0700 | [diff] [blame] | 33 | public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager, |
| 34 | AlwaysOnDisplayPolicy policy) { |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 35 | mMachine = machine; |
| 36 | mPauseTimeout = new AlarmTimeout(alarmManager, this::onTimeout, TAG, handler); |
Chris Wren | baff9f0 | 2017-09-27 16:56:48 -0400 | [diff] [blame] | 37 | mPolicy = policy; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { |
| 42 | switch (newState) { |
| 43 | case DOZE_AOD_PAUSING: |
Chris Wren | baff9f0 | 2017-09-27 16:56:48 -0400 | [diff] [blame] | 44 | mPauseTimeout.schedule(mPolicy.proxScreenOffDelayMs, |
| 45 | AlarmTimeout.MODE_IGNORE_IF_SCHEDULED); |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 46 | 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 | } |