Java Code Examples for android.view.Display#STATE_DOZE

The following examples show how to use android.view.Display#STATE_DOZE . 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: LocalDisplayAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
static int getPowerModeForState(int state) {
    switch (state) {
        case Display.STATE_OFF:
            return SurfaceControl.POWER_MODE_OFF;
        case Display.STATE_DOZE:
            return SurfaceControl.POWER_MODE_DOZE;
        case Display.STATE_DOZE_SUSPEND:
            return SurfaceControl.POWER_MODE_DOZE_SUSPEND;
        case Display.STATE_ON_SUSPEND:
            return SurfaceControl.POWER_MODE_ON_SUSPEND;
        default:
            return SurfaceControl.POWER_MODE_NORMAL;
    }
}
 
Example 3
Source File: BurnInProtectionHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisplayChanged(int displayId) {
    if (displayId == mDisplay.getDisplayId()) {
        if (mDisplay.getState() == Display.STATE_DOZE
                || mDisplay.getState() == Display.STATE_DOZE_SUSPEND
                || mDisplay.getState() == Display.STATE_ON_SUSPEND) {
            startBurnInProtection();
        } else {
            cancelBurnInProtection();
        }
    }
}
 
Example 4
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void prepareToDraw() {
    if (mDisplayState == Display.STATE_DOZE
            || mDisplayState == Display.STATE_DOZE_SUSPEND) {
        try {
            mSession.pokeDrawLock(mWindow);
        } catch (RemoteException e) {
            // System server died, can be ignored.
        }
    }
}
 
Example 5
Source File: FlutterIncallManagerPlugin.java    From flutter-incall-manager with ISC License 5 votes vote down vote up
private void debugScreenPowerState() {
    String isDeviceIdleMode = "unknow"; // --- API 23
    String isIgnoringBatteryOptimizations = "unknow"; // --- API 23
    String isPowerSaveMode = "unknow"; // --- API 21
    String isInteractive = "unknow"; // --- API 20 ( before since API 7 is: isScreenOn())
    String screenState = "unknow"; // --- API 20

    if (Build.VERSION.SDK_INT >= 23) {
        isDeviceIdleMode = String.format("%s", mPowerManager.isDeviceIdleMode());
        isIgnoringBatteryOptimizations = String.format("%s", mPowerManager.isIgnoringBatteryOptimizations(mPackageName));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        isPowerSaveMode = String.format("%s", mPowerManager.isPowerSaveMode());
    }
    if (Build.VERSION.SDK_INT >= 20) {
        isInteractive = String.format("%s", mPowerManager.isInteractive());
        Display display = mWindowManager.getDefaultDisplay();
        switch (display.getState()) {
            case Display.STATE_OFF:
                screenState = "STATE_OFF";
                break;
            case Display.STATE_ON:
                screenState = "STATE_ON";
                break;
            case Display.STATE_DOZE:
                screenState = "STATE_DOZE";
                break;
            case Display.STATE_DOZE_SUSPEND:
                screenState = "STATE_DOZE_SUSPEND";
                break;
            default:
                break;
        }
    } else {
        isInteractive = String.format("%s", mPowerManager.isScreenOn());
    }
    Log.d(TAG, String.format("debugScreenPowerState(): screenState='%s', isInteractive='%s', isPowerSaveMode='%s', isDeviceIdleMode='%s', isIgnoringBatteryOptimizations='%s'", screenState, isInteractive, isPowerSaveMode, isDeviceIdleMode, isIgnoringBatteryOptimizations));
}
 
Example 6
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 5 votes vote down vote up
private void debugScreenPowerState() {
    String isDeviceIdleMode = "unknow"; // --- API 23
    String isIgnoringBatteryOptimizations = "unknow"; // --- API 23
    String isPowerSaveMode = "unknow"; // --- API 21
    String isInteractive = "unknow"; // --- API 20 ( before since API 7 is: isScreenOn())
    String screenState = "unknow"; // --- API 20

    if (android.os.Build.VERSION.SDK_INT >= 23) {
        isDeviceIdleMode = String.format("%s", mPowerManager.isDeviceIdleMode());
        isIgnoringBatteryOptimizations = String.format("%s", mPowerManager.isIgnoringBatteryOptimizations(mPackageName));
    }
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        isPowerSaveMode = String.format("%s", mPowerManager.isPowerSaveMode());
    }
    if (android.os.Build.VERSION.SDK_INT >= 20) {
        isInteractive = String.format("%s", mPowerManager.isInteractive());
        Display display = mWindowManager.getDefaultDisplay();
        switch (display.getState()) {
            case Display.STATE_OFF:
                screenState = "STATE_OFF";
                break;
            case Display.STATE_ON:
                screenState = "STATE_ON";
                break;
            case Display.STATE_DOZE:
                screenState = "STATE_DOZE";
                break;
            case Display.STATE_DOZE_SUSPEND:
                screenState = "STATE_DOZE_SUSPEND";
                break;
            default:
                break;
        }
    } else {
        isInteractive = String.format("%s", mPowerManager.isScreenOn());
    }
    Log.d(TAG, String.format("debugScreenPowerState(): screenState='%s', isInteractive='%s', isPowerSaveMode='%s', isDeviceIdleMode='%s', isIgnoringBatteryOptimizations='%s'", screenState, isInteractive, isPowerSaveMode, isDeviceIdleMode, isIgnoringBatteryOptimizations));
}
 
Example 7
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;
}