FileDocCategorySizeDatePackage
DisplayPowerState.javaAPI DocAndroid 5.1 API15578Thu Mar 12 22:22:42 GMT 2015com.android.server.display

DisplayPowerState

public final class DisplayPowerState extends Object
Controls the display power state.

This component is similar in nature to a {@link android.view.View} except that it describes the properties of a display. When properties are changed, the component invalidates itself and posts a callback to apply the changes in a consistent order. This mechanism enables multiple properties of the display power state to be animated together smoothly by the animation framework. Some of the work to blank or unblank the display is done on a separate thread to avoid blocking the looper.

This component must only be created or accessed by the {@link Looper} thread that belongs to the {@link DisplayPowerController}.

We don't need to worry about holding a suspend blocker here because the power manager does that for us whenever there is a change in progress.

Fields Summary
private static final String
TAG
private static boolean
DEBUG
private final android.os.Handler
mHandler
private final android.view.Choreographer
mChoreographer
private final DisplayBlanker
mBlanker
private final com.android.server.lights.Light
mBacklight
private final ColorFade
mColorFade
private final PhotonicModulator
mPhotonicModulator
private int
mScreenState
private int
mScreenBrightness
private boolean
mScreenReady
private boolean
mScreenUpdatePending
private boolean
mColorFadePrepared
private float
mColorFadeLevel
private boolean
mColorFadeReady
private boolean
mColorFadeDrawPending
private Runnable
mCleanListener
public static final android.util.FloatProperty
COLOR_FADE_LEVEL
public static final android.util.IntProperty
SCREEN_BRIGHTNESS
private final Runnable
mScreenUpdateRunnable
private final Runnable
mColorFadeDrawRunnable
Constructors Summary
public DisplayPowerState(DisplayBlanker blanker, com.android.server.lights.Light backlight, ColorFade electronBeam)


           
        mHandler = new Handler(true /*async*/);
        mChoreographer = Choreographer.getInstance();
        mBlanker = blanker;
        mBacklight = backlight;
        mColorFade = electronBeam;
        mPhotonicModulator = new PhotonicModulator();
        mPhotonicModulator.start();

        // At boot time, we know that the screen is on and the electron beam
        // animation is not playing.  We don't know the screen's brightness though,
        // so prepare to set it to a known state when the state is next applied.
        // Although we set the brightness to full on here, the display power controller
        // will reset the brightness to a new level immediately before the changes
        // actually have a chance to be applied.
        mScreenState = Display.STATE_ON;
        mScreenBrightness = PowerManager.BRIGHTNESS_ON;
        scheduleScreenUpdate();

        mColorFadePrepared = false;
        mColorFadeLevel = 1.0f;
        mColorFadeReady = true;
    
Methods Summary
public voiddismissColorFade()
Dismisses the electron beam surface.

        mColorFade.dismiss();
        mColorFadePrepared = false;
        mColorFadeReady = true;
    
public voiddump(java.io.PrintWriter pw)

        pw.println();
        pw.println("Display Power State:");
        pw.println("  mScreenState=" + Display.stateToString(mScreenState));
        pw.println("  mScreenBrightness=" + mScreenBrightness);
        pw.println("  mScreenReady=" + mScreenReady);
        pw.println("  mScreenUpdatePending=" + mScreenUpdatePending);
        pw.println("  mColorFadePrepared=" + mColorFadePrepared);
        pw.println("  mColorFadeLevel=" + mColorFadeLevel);
        pw.println("  mColorFadeReady=" + mColorFadeReady);
        pw.println("  mColorFadeDrawPending=" + mColorFadeDrawPending);

        mPhotonicModulator.dump(pw);
        mColorFade.dump(pw);
    
public floatgetColorFadeLevel()
Gets the level of the electron beam steering current.

        return mColorFadeLevel;
    
public intgetScreenBrightness()
Gets the screen brightness.

        return mScreenBrightness;
    
public intgetScreenState()
Gets the desired screen state.

        return mScreenState;
    
private voidinvokeCleanListenerIfNeeded()

        final Runnable listener = mCleanListener;
        if (listener != null && mScreenReady && mColorFadeReady) {
            mCleanListener = null;
            listener.run();
        }
    
private voidpostScreenUpdateThreadSafe()

        mHandler.removeCallbacks(mScreenUpdateRunnable);
        mHandler.post(mScreenUpdateRunnable);
    
public booleanprepareColorFade(android.content.Context context, int mode)
Prepares the electron beam to turn on or off. This method should be called before starting an animation because it can take a fair amount of time to prepare the electron beam surface.

param
mode The electron beam animation mode to prepare.
return
True if the electron beam was prepared.

        if (!mColorFade.prepare(context, mode)) {
            mColorFadePrepared = false;
            mColorFadeReady = true;
            return false;
        }

        mColorFadePrepared = true;
        mColorFadeReady = false;
        scheduleColorFadeDraw();
        return true;
    
private voidscheduleColorFadeDraw()

        if (!mColorFadeDrawPending) {
            mColorFadeDrawPending = true;
            mChoreographer.postCallback(Choreographer.CALLBACK_TRAVERSAL,
                    mColorFadeDrawRunnable, null);
        }
    
private voidscheduleScreenUpdate()

        if (!mScreenUpdatePending) {
            mScreenUpdatePending = true;
            postScreenUpdateThreadSafe();
        }
    
public voidsetColorFadeLevel(float level)
Sets the level of the electron beam steering current. The display is blanked when the level is 0.0. In normal use, the electron beam should have a value of 1.0. The electron beam is unstable in between these states and the picture quality may be compromised. For best effect, the electron beam should be warmed up or cooled off slowly. Warning: Electron beam emits harmful radiation. Avoid direct exposure to skin or eyes.

param
level The level, ranges from 0.0 (full off) to 1.0 (full on).

        if (mColorFadeLevel != level) {
            if (DEBUG) {
                Slog.d(TAG, "setColorFadeLevel: level=" + level);
            }

            mColorFadeLevel = level;
            if (mScreenState != Display.STATE_OFF) {
                mScreenReady = false;
                scheduleScreenUpdate(); // update backlight brightness
            }
            if (mColorFadePrepared) {
                mColorFadeReady = false;
                scheduleColorFadeDraw();
            }
        }
    
public voidsetScreenBrightness(int brightness)
Sets the display brightness.

param
brightness The brightness, ranges from 0 (minimum / off) to 255 (brightest).

        if (mScreenBrightness != brightness) {
            if (DEBUG) {
                Slog.d(TAG, "setScreenBrightness: brightness=" + brightness);
            }

            mScreenBrightness = brightness;
            if (mScreenState != Display.STATE_OFF) {
                mScreenReady = false;
                scheduleScreenUpdate();
            }
        }
    
public voidsetScreenState(int state)
Sets whether the screen is on, off, or dozing.


                  
        
        if (mScreenState != state) {
            if (DEBUG) {
                Slog.d(TAG, "setScreenState: state=" + state);
            }

            mScreenState = state;
            mScreenReady = false;
            scheduleScreenUpdate();
        }
    
public booleanwaitUntilClean(java.lang.Runnable listener)
Returns true if no properties have been invalidated. Otherwise, returns false and promises to invoke the specified listener when the properties have all been applied. The listener always overrides any previously set listener.

        if (!mScreenReady || !mColorFadeReady) {
            mCleanListener = listener;
            return false;
        } else {
            mCleanListener = null;
            return true;
        }