Java Code Examples for android.os.PowerManager#BRIGHTNESS_DEFAULT

The following examples show how to use android.os.PowerManager#BRIGHTNESS_DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void setDozeOverrideFromDreamManager(int screenState, int screenBrightness) {
    switch (screenState) {
        case Display.STATE_UNKNOWN:
        case Display.STATE_OFF:
        case Display.STATE_DOZE:
        case Display.STATE_DOZE_SUSPEND:
        case Display.STATE_ON_SUSPEND:
        case Display.STATE_ON:
        case Display.STATE_VR:
            break;
        default:
            screenState = Display.STATE_UNKNOWN;
            break;
    }
    if (screenBrightness < PowerManager.BRIGHTNESS_DEFAULT
            || screenBrightness > PowerManager.BRIGHTNESS_ON) {
        screenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    }
    setDozeOverrideFromDreamManagerInternal(screenState, screenBrightness);
}
 
Example 2
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setScreenBrightnessOverrideFromWindowManager(int screenBrightness) {
    if (screenBrightness < PowerManager.BRIGHTNESS_DEFAULT
            || screenBrightness > PowerManager.BRIGHTNESS_ON) {
        screenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    }
    setScreenBrightnessOverrideFromWindowManagerInternal(screenBrightness);
}
 
Example 3
Source File: DreamManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void cleanupDreamLocked() {
    mCurrentDreamToken = null;
    mCurrentDreamName = null;
    mCurrentDreamIsTest = false;
    mCurrentDreamCanDoze = false;
    mCurrentDreamUserId = 0;
    mCurrentDreamIsWaking = false;
    if (mCurrentDreamIsDozing) {
        mCurrentDreamIsDozing = false;
        mDozeWakeLock.release();
    }
    mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN;
    mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
}
 
Example 4
Source File: DisplayManagerInternal.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public DisplayPowerRequest() {
    policy = POLICY_BRIGHT;
    useProximitySensor = false;
    screenBrightnessOverride = -1;
    useAutoBrightness = false;
    screenAutoBrightnessAdjustmentOverride = Float.NaN;
    screenLowPowerBrightnessFactor = 0.5f;
    blockScreenOn = false;
    dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    dozeScreenState = Display.STATE_UNKNOWN;
}
 
Example 5
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void requestGlobalDisplayStateInternal(int state, int brightness) {
    if (state == Display.STATE_UNKNOWN) {
        state = Display.STATE_ON;
    }
    if (state == Display.STATE_OFF) {
        brightness = PowerManager.BRIGHTNESS_OFF;
    } else if (brightness < 0) {
        brightness = PowerManager.BRIGHTNESS_DEFAULT;
    } else if (brightness > PowerManager.BRIGHTNESS_ON) {
        brightness = PowerManager.BRIGHTNESS_ON;
    }

    synchronized (mTempDisplayStateWorkQueue) {
        try {
            // Update the display state within the lock.
            // Note that we do not need to schedule traversals here although it
            // may happen as a side-effect of displays changing state.
            synchronized (mSyncRoot) {
                if (mGlobalDisplayState == state
                        && mGlobalDisplayBrightness == brightness) {
                    return; // no change
                }

                Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState("
                        + Display.stateToString(state)
                        + ", brightness=" + brightness + ")");
                mGlobalDisplayState = state;
                mGlobalDisplayBrightness = brightness;
                applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue);
            }

            // Setting the display power state can take hundreds of milliseconds
            // to complete so we defer the most expensive part of the work until
            // after we have exited the critical section to avoid blocking other
            // threads for a long time.
            for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) {
                mTempDisplayStateWorkQueue.get(i).run();
            }
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        } finally {
            mTempDisplayStateWorkQueue.clear();
        }
    }
}
 
Example 6
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the display power state asynchronously.
 * When the update is finished, mDisplayReady will be set to true.  The display
 * controller posts a message to tell us when the actual display power state
 * has been updated so we come back here to double-check and finish up.
 *
 * This function recalculates the display power state each time.
 *
 * @return True if the display became ready.
 */
private boolean updateDisplayPowerStateLocked(int dirty) {
    final boolean oldDisplayReady = mDisplayReady;
    if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS
            | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED
            | DIRTY_SETTINGS | DIRTY_SCREEN_BRIGHTNESS_BOOST | DIRTY_VR_MODE_CHANGED |
            DIRTY_QUIESCENT)) != 0) {
        mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked();

        // Determine appropriate screen brightness and auto-brightness adjustments.
        final boolean autoBrightness;
        final int screenBrightnessOverride;
        if (!mBootCompleted) {
            // Keep the brightness steady during boot. This requires the
            // bootloader brightness and the default brightness to be identical.
            autoBrightness = false;
            screenBrightnessOverride = mScreenBrightnessSettingDefault;
        } else if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) {
            autoBrightness = false;
            screenBrightnessOverride = mScreenBrightnessOverrideFromWindowManager;
        } else {
            autoBrightness = (mScreenBrightnessModeSetting ==
                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
            screenBrightnessOverride = -1;
        }

        // Update display power request.
        mDisplayPowerRequest.screenBrightnessOverride = screenBrightnessOverride;
        mDisplayPowerRequest.useAutoBrightness = autoBrightness;
        mDisplayPowerRequest.useProximitySensor = shouldUseProximitySensorLocked();
        mDisplayPowerRequest.boostScreenBrightness = shouldBoostScreenBrightness();

        updatePowerRequestFromBatterySaverPolicy(mDisplayPowerRequest);

        if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_DOZE) {
            mDisplayPowerRequest.dozeScreenState = mDozeScreenStateOverrideFromDreamManager;
            if ((mWakeLockSummary & WAKE_LOCK_DRAW) != 0
                    && !mDrawWakeLockOverrideFromSidekick) {
                if (mDisplayPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND) {
                    mDisplayPowerRequest.dozeScreenState = Display.STATE_DOZE;
                }
                if (mDisplayPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND) {
                    mDisplayPowerRequest.dozeScreenState = Display.STATE_ON;
                }
            }
            mDisplayPowerRequest.dozeScreenBrightness =
                    mDozeScreenBrightnessOverrideFromDreamManager;
        } else {
            mDisplayPowerRequest.dozeScreenState = Display.STATE_UNKNOWN;
            mDisplayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
        }

        mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest,
                mRequestWaitForNegativeProximity);
        mRequestWaitForNegativeProximity = false;

        if ((dirty & DIRTY_QUIESCENT) != 0) {
            sQuiescent = false;
        }
        if (DEBUG_SPEW) {
            Slog.d(TAG, "updateDisplayPowerStateLocked: mDisplayReady=" + mDisplayReady
                    + ", policy=" + mDisplayPowerRequest.policy
                    + ", mWakefulness=" + mWakefulness
                    + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary)
                    + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
                    + ", mBootCompleted=" + mBootCompleted
                    + ", screenBrightnessOverride=" + screenBrightnessOverride
                    + ", useAutoBrightness=" + autoBrightness
                    + ", mScreenBrightnessBoostInProgress=" + mScreenBrightnessBoostInProgress
                    + ", mIsVrModeEnabled= " + mIsVrModeEnabled
                    + ", sQuiescent=" + sQuiescent);
        }
    }
    return mDisplayReady && !oldDisplayReady;
}
 
Example 7
Source File: DreamService.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the screen brightness to use while dozing.
 * <p>
 * The value of this property determines the power state of the primary display
 * once {@link #startDozing} has been called.  The default value is
 * {@link PowerManager#BRIGHTNESS_DEFAULT} which lets the system decide.
 * The dream may set a different brightness before starting to doze and may adjust
 * the brightness while dozing to conserve power and achieve various effects.
 * </p><p>
 * Note that dream may specify any brightness in the full 0-255 range, including
 * values that are less than the minimum value for manual screen brightness
 * adjustments by the user.  In particular, the value may be set to 0 which may
 * turn off the backlight entirely while still leaving the screen on although
 * this behavior is device dependent and not guaranteed.
 * </p><p>
 * The available range of display brightness values and their behavior while dozing is
 * hardware dependent and may vary across devices.  The dream may therefore
 * need to be modified or configured to correctly support the hardware.
 * </p>
 *
 * @param brightness The screen brightness while dozing as a value between
 * {@link PowerManager#BRIGHTNESS_OFF} (0) and {@link PowerManager#BRIGHTNESS_ON} (255),
 * or {@link PowerManager#BRIGHTNESS_DEFAULT} (-1) to ask the system to apply
 * its default policy based on the screen state.
 *
 * @hide For use by system UI components only.
 */
public void setDozeScreenBrightness(int brightness) {
    if (brightness != PowerManager.BRIGHTNESS_DEFAULT) {
        brightness = clampAbsoluteBrightness(brightness);
    }
    if (mDozeScreenBrightness != brightness) {
        mDozeScreenBrightness = brightness;
        updateDoze();
    }
}