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