Home | History | Annotate | Download | only in power
      1 /*
      2  * Copyright (C) 2012 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.server.power;
     18 
     19 import android.os.PowerManager;
     20 
     21 /**
     22  * Describes the requested power state of the display.
     23  *
     24  * This object is intended to describe the general characteristics of the
     25  * power state, such as whether the screen should be on or off and the current
     26  * brightness controls leaving the {@link DisplayPowerController} to manage the
     27  * details of how the transitions between states should occur.  The goal is for
     28  * the {@link PowerManagerService} to focus on the global power state and not
     29  * have to micro-manage screen off animations, auto-brightness and other effects.
     30  */
     31 final class DisplayPowerRequest {
     32     public static final int SCREEN_STATE_OFF = 0;
     33     public static final int SCREEN_STATE_DIM = 1;
     34     public static final int SCREEN_STATE_BRIGHT = 2;
     35 
     36     // The requested minimum screen power state: off, dim or bright.
     37     public int screenState;
     38 
     39     // If true, the proximity sensor overrides the screen state when an object is
     40     // nearby, turning it off temporarily until the object is moved away.
     41     public boolean useProximitySensor;
     42 
     43     // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
     44     // The display power controller may choose to clamp the brightness.
     45     // When auto-brightness is enabled, this field should specify a nominal default
     46     // value to use while waiting for the light sensor to report enough data.
     47     public int screenBrightness;
     48 
     49     // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
     50     public float screenAutoBrightnessAdjustment;
     51 
     52     // If true, enables automatic brightness control.
     53     public boolean useAutoBrightness;
     54 
     55     // If true, prevents the screen from completely turning on if it is currently off.
     56     // The display does not enter a "ready" state if this flag is true and screen on is
     57     // blocked.  The window manager policy blocks screen on while it prepares the keyguard to
     58     // prevent the user from seeing intermediate updates.
     59     //
     60     // Technically, we may not block the screen itself from turning on (because that introduces
     61     // extra unnecessary latency) but we do prevent content on screen from becoming
     62     // visible to the user.
     63     public boolean blockScreenOn;
     64 
     65     public DisplayPowerRequest() {
     66         screenState = SCREEN_STATE_BRIGHT;
     67         useProximitySensor = false;
     68         screenBrightness = PowerManager.BRIGHTNESS_ON;
     69         screenAutoBrightnessAdjustment = 0.0f;
     70         useAutoBrightness = false;
     71         blockScreenOn = false;
     72     }
     73 
     74     public DisplayPowerRequest(DisplayPowerRequest other) {
     75         copyFrom(other);
     76     }
     77 
     78     public void copyFrom(DisplayPowerRequest other) {
     79         screenState = other.screenState;
     80         useProximitySensor = other.useProximitySensor;
     81         screenBrightness = other.screenBrightness;
     82         screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
     83         useAutoBrightness = other.useAutoBrightness;
     84         blockScreenOn = other.blockScreenOn;
     85     }
     86 
     87     @Override
     88     public boolean equals(Object o) {
     89         return o instanceof DisplayPowerRequest
     90                 && equals((DisplayPowerRequest)o);
     91     }
     92 
     93     public boolean equals(DisplayPowerRequest other) {
     94         return other != null
     95                 && screenState == other.screenState
     96                 && useProximitySensor == other.useProximitySensor
     97                 && screenBrightness == other.screenBrightness
     98                 && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
     99                 && useAutoBrightness == other.useAutoBrightness
    100                 && blockScreenOn == other.blockScreenOn;
    101     }
    102 
    103     @Override
    104     public int hashCode() {
    105         return 0; // don't care
    106     }
    107 
    108     @Override
    109     public String toString() {
    110         return "screenState=" + screenState
    111                 + ", useProximitySensor=" + useProximitySensor
    112                 + ", screenBrightness=" + screenBrightness
    113                 + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
    114                 + ", useAutoBrightness=" + useAutoBrightness
    115                 + ", blockScreenOn=" + blockScreenOn;
    116     }
    117 }
    118