Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [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 | |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 19 | import android.view.Display; |
| 20 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 21 | import androidx.annotation.VisibleForTesting; |
| 22 | |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 23 | import com.android.systemui.statusbar.phone.DozeParameters; |
| 24 | |
| 25 | /** |
| 26 | * Prevents usage of doze screen states on devices that don't support them. |
| 27 | */ |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 28 | public class DozeSuspendScreenStatePreventingAdapter extends DozeMachine.Service.Delegate { |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 29 | |
| 30 | @VisibleForTesting |
| 31 | DozeSuspendScreenStatePreventingAdapter(DozeMachine.Service inner) { |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 32 | super(inner); |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public void setDozeScreenState(int state) { |
| 37 | if (state == Display.STATE_DOZE_SUSPEND) { |
| 38 | state = Display.STATE_DOZE; |
| 39 | } |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 40 | super.setDozeScreenState(state); |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * If the device supports the doze display state, return {@code inner}. Otherwise |
| 45 | * return a new instance of {@link DozeSuspendScreenStatePreventingAdapter} wrapping {@code inner}. |
| 46 | */ |
| 47 | public static DozeMachine.Service wrapIfNeeded(DozeMachine.Service inner, |
| 48 | DozeParameters params) { |
| 49 | return isNeeded(params) ? new DozeSuspendScreenStatePreventingAdapter(inner) : inner; |
| 50 | } |
| 51 | |
| 52 | private static boolean isNeeded(DozeParameters params) { |
| 53 | return !params.getDozeSuspendDisplayStateSupported(); |
| 54 | } |
| 55 | } |