Java Code Examples for android.view.Display#STATE_OFF

The following examples show how to use android.view.Display#STATE_OFF . 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: DisplayPowerState.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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).
 */
public void setColorFadeLevel(float level) {
    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();
        }
    }
}
 
Example 2
Source File: HelperNotificationAndBadge.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Is the screen of the device on.
 *
 * @param context the context
 * @return true when (at least one) screen is on
 */
public boolean isScreenOn(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                screenOn = true;
            }
        }
        return screenOn;
    } else {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return pm.isScreenOn();
    }
}
 
Example 3
Source File: OBSystemsManager.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public boolean isScreenOn(Context context)
{
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
    {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays())
        {
            if (display.getState() != Display.STATE_OFF)
            {
                screenOn = true;
            }
        }
        return screenOn;
    } else
    {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        return pm.isScreenOn();
    }
}
 
Example 4
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void reportVisibility() {
    if (!mDestroyed) {
        mDisplayState = mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getState();
        boolean visible = mVisible && mDisplayState != Display.STATE_OFF;
        if (mReportedVisible != visible) {
            mReportedVisible = visible;
            if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
                    + "): " + this);
            if (visible) {
                // If becoming visible, in preview mode the surface
                // may have been destroyed so now we need to make
                // sure it is re-created.
                doOffsetsChanged(false);
                updateSurface(false, false, false);
            }
            onVisibilityChanged(visible);
        }
    }
}
 
Example 5
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 6
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onDisplayStateChange(int state) {
    // This method is only needed to support legacy display blanking behavior
    // where the display's power state is coupled to suspend or to the power HAL.
    // The order of operations matters here.
    synchronized (mLock) {
        if (mDisplayState != state) {
            mDisplayState = state;
            if (state == Display.STATE_OFF) {
                if (!mDecoupleHalInteractiveModeFromDisplayConfig) {
                    setHalInteractiveModeLocked(false);
                }
                if (!mDecoupleHalAutoSuspendModeFromDisplayConfig) {
                    setHalAutoSuspendModeLocked(true);
                }
            } else {
                if (!mDecoupleHalAutoSuspendModeFromDisplayConfig) {
                    setHalAutoSuspendModeLocked(false);
                }
                if (!mDecoupleHalInteractiveModeFromDisplayConfig) {
                    setHalInteractiveModeLocked(true);
                }
            }
        }
    }
}
 
Example 7
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
        SensorManager sensorManager) {
    synchronized (mSyncRoot) {
        DisplayBlanker blanker = new DisplayBlanker() {
            @Override
            public void requestDisplayState(int state, int brightness) {
                // The order of operations is important for legacy reasons.
                if (state == Display.STATE_OFF) {
                    requestGlobalDisplayStateInternal(state, brightness);
                }

                callbacks.onDisplayStateChange(state);

                if (state != Display.STATE_OFF) {
                    requestGlobalDisplayStateInternal(state, brightness);
                }
            }
        };
        mDisplayPowerController = new DisplayPowerController(
                mContext, callbacks, handler, sensorManager, blanker);
    }

    mHandler.sendEmptyMessage(MSG_LOAD_BRIGHTNESS_CONFIGURATION);
}
 
Example 8
Source File: AndroidMessenger.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean isScreenOn() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                screenOn = true;
            }
        }
        return screenOn;
    } else {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        return pm.isScreenOn();
    }
}
 
Example 9
Source File: Utils.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isScreenOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
Example 10
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 11
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 12
Source File: Utils.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isScreenOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
Example 13
Source File: HelperNotification.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isScreenOn(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        @SuppressLint("WrongConstant") DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                screenOn = true;
            }
        }
        return screenOn;
    } else {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return pm.isScreenOn();
    }
}
 
Example 14
Source File: DisplayPowerState.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the display brightness.
 *
 * @param brightness The brightness, ranges from 0 (minimum / off) to 255 (brightest).
 */
public void setScreenBrightness(int brightness) {
    if (mScreenBrightness != brightness) {
        if (DEBUG) {
            Slog.d(TAG, "setScreenBrightness: brightness=" + brightness);
        }

        mScreenBrightness = brightness;
        if (mScreenState != Display.STATE_OFF) {
            mScreenReady = false;
            scheduleScreenUpdate();
        }
    }
}
 
Example 15
Source File: Utils.java    From aosp_screen_stabilization with Apache License 2.0 5 votes vote down vote up
public static boolean isScreenOn(Context context)
{
	DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
	for (Display display : dm.getDisplays())
	{
		if (display.getState() != Display.STATE_OFF)
			return true;
	}
	return false;
}
 
Example 16
Source File: StarterService.java    From always-on-amoled with GNU General Public License v3.0 5 votes vote down vote up
boolean isScreenOn() {
    if (Utils.isAndroidNewerThanL()) {
        DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
Example 17
Source File: ChargeChangeReceiver.java    From always-on-amoled with GNU General Public License v3.0 5 votes vote down vote up
private boolean isDisplayOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
Example 18
Source File: DisplayPowerController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean setScreenState(int state, boolean reportOnly) {
    final boolean isOff = (state == Display.STATE_OFF);
    if (mPowerState.getScreenState() != state) {

        // If we are trying to turn screen off, give policy a chance to do something before we
        // actually turn the screen off.
        if (isOff && !mScreenOffBecauseOfProximity) {
            if (mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_ON) {
                setReportedScreenState(REPORTED_TO_POLICY_SCREEN_TURNING_OFF);
                blockScreenOff();
                mWindowManagerPolicy.screenTurningOff(mPendingScreenOffUnblocker);
                unblockScreenOff();
            } else if (mPendingScreenOffUnblocker != null) {
                // Abort doing the state change until screen off is unblocked.
                return false;
            }
        }

        if (!reportOnly) {
            Trace.traceCounter(Trace.TRACE_TAG_POWER, "ScreenState", state);
            mPowerState.setScreenState(state);
            // Tell battery stats about the transition.
            try {
                mBatteryStats.noteScreenState(state);
            } catch (RemoteException ex) {
                // same process
            }
        }
    }

    // Tell the window manager policy when the screen is turned off or on unless it's due
    // to the proximity sensor.  We temporarily block turning the screen on until the
    // window manager is ready by leaving a black surface covering the screen.
    // This surface is essentially the final state of the color fade animation and
    // it is only removed once the window manager tells us that the activity has
    // finished drawing underneath.
    if (isOff && mReportedScreenStateToPolicy != REPORTED_TO_POLICY_SCREEN_OFF
            && !mScreenOffBecauseOfProximity) {
        setReportedScreenState(REPORTED_TO_POLICY_SCREEN_OFF);
        unblockScreenOn();
        mWindowManagerPolicy.screenTurnedOff();
    } else if (!isOff
            && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_TURNING_OFF) {

        // We told policy already that screen was turning off, but now we changed our minds.
        // Complete the full state transition on -> turningOff -> off.
        unblockScreenOff();
        mWindowManagerPolicy.screenTurnedOff();
        setReportedScreenState(REPORTED_TO_POLICY_SCREEN_OFF);
    }
    if (!isOff && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_OFF) {
        setReportedScreenState(REPORTED_TO_POLICY_SCREEN_TURNING_ON);
        if (mPowerState.getColorFadeLevel() == 0.0f) {
            blockScreenOn();
        } else {
            unblockScreenOn();
        }
        mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker);
    }

    // Return true if the screen isn't blocked.
    return mPendingScreenOnUnblocker == null;
}
 
Example 19
Source File: VirtualDisplayAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
    if (mInfo == null) {
        mInfo = new DisplayDeviceInfo();
        mInfo.name = mName;
        mInfo.uniqueId = getUniqueId();
        mInfo.width = mWidth;
        mInfo.height = mHeight;
        mInfo.modeId = mMode.getModeId();
        mInfo.defaultModeId = mMode.getModeId();
        mInfo.supportedModes = new Display.Mode[] { mMode };
        mInfo.densityDpi = mDensityDpi;
        mInfo.xDpi = mDensityDpi;
        mInfo.yDpi = mDensityDpi;
        mInfo.presentationDeadlineNanos = 1000000000L / (int) REFRESH_RATE; // 1 frame
        mInfo.flags = 0;
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE
                    | DisplayDeviceInfo.FLAG_NEVER_BLANK;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
            mInfo.flags &= ~DisplayDeviceInfo.FLAG_NEVER_BLANK;
        } else {
            mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
        }

        if ((mFlags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;

            if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
                // For demonstration purposes, allow rotation of the external display.
                // In the future we might allow the user to configure this directly.
                if ("portrait".equals(SystemProperties.get(
                        "persist.demo.remoterotation"))) {
                    mInfo.rotation = Surface.ROTATION_270;
                }
            }
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL) != 0) {
          mInfo.flags |= DisplayDeviceInfo.FLAG_DESTROY_CONTENT_ON_REMOVAL;
        }

        mInfo.type = Display.TYPE_VIRTUAL;
        mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ?
                DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL;
        mInfo.state = mSurface != null ? Display.STATE_ON : Display.STATE_OFF;
        mInfo.ownerUid = mOwnerUid;
        mInfo.ownerPackageName = mOwnerPackageName;
    }
    return mInfo;
}
 
Example 20
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();
        }
    }
}