blob: 1e067974e3cc5eb36cc40c55ac7f35433a7f5366 [file] [log] [blame]
Adrian Roosa1e6b312017-03-28 16:20:34 -07001/*
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.support.annotation.VisibleForTesting;
20import android.view.Display;
21
22import com.android.systemui.statusbar.phone.DozeParameters;
23
24/**
25 * Prevents usage of doze screen states on devices that don't support them.
26 */
27public class DozeSuspendScreenStatePreventingAdapter implements DozeMachine.Service {
28
29 private final DozeMachine.Service mInner;
30
31 @VisibleForTesting
32 DozeSuspendScreenStatePreventingAdapter(DozeMachine.Service inner) {
33 mInner = inner;
34 }
35
36 @Override
37 public void finish() {
38 mInner.finish();
39 }
40
41 @Override
42 public void setDozeScreenState(int state) {
43 if (state == Display.STATE_DOZE_SUSPEND) {
44 state = Display.STATE_DOZE;
45 }
46 mInner.setDozeScreenState(state);
47 }
48
49 @Override
50 public void requestWakeUp() {
51 mInner.requestWakeUp();
52 }
53
54 /**
55 * If the device supports the doze display state, return {@code inner}. Otherwise
56 * return a new instance of {@link DozeSuspendScreenStatePreventingAdapter} wrapping {@code inner}.
57 */
58 public static DozeMachine.Service wrapIfNeeded(DozeMachine.Service inner,
59 DozeParameters params) {
60 return isNeeded(params) ? new DozeSuspendScreenStatePreventingAdapter(inner) : inner;
61 }
62
63 private static boolean isNeeded(DozeParameters params) {
64 return !params.getDozeSuspendDisplayStateSupported();
65 }
66}