Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c55929a2 authored by Prashant Malani's avatar Prashant Malani
Browse files

Add call to set power mode for display



The blank/unblank interface is being replaced by a generic
setPowerMode() call. This will allow the support of low power modes in
displays where such functionality is available. Currently three modes
are defined:

- POWER_MODE_OFF
- POWER_MODE_DOZE
- POWER_MODE_NORMAL

POWER_MODE_OFF would be analogous to blanking the screen,
POWER_MODE_NORMAL akin to unblanking it, and POWER_MODE_DOZE would
trigger an entry into the display's low power mode.

We also tie the JNI call to set power mode to the call from services which
actually invokes it.

The generic setPowerMode() call can be expanded to potentially include
other display power states.

Bug: 13472578
Change-Id: I74677506d3ee2ccc50ba70c5102d96b31fe7b837
Signed-off-by: default avatarPrashant Malani <pmalani@google.com>
parent d79b3922
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ public class SurfaceControl {
            IBinder displayToken);
    private static native int nativeGetActiveConfig(IBinder displayToken);
    private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
    private static native void nativeBlankDisplay(IBinder displayToken);
    private static native void nativeUnblankDisplay(IBinder displayToken);
    private static native void nativeSetDisplayPowerMode(
            IBinder displayToken, int mode);


    private final CloseGuard mCloseGuard = CloseGuard.get();
@@ -209,6 +209,25 @@ public class SurfaceControl {
     */
    public static final int BUILT_IN_DISPLAY_ID_HDMI = 1;

    /* Display power modes * /

    /**
     * Display power mode off: used while blanking the screen.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_OFF = 0;

    /**
     * Display power mode doze: used while putting the screen into low power mode.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_DOZE = 1;

    /**
     * Display power mode normal: used while unblanking the screen.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_NORMAL = 2;


    /**
@@ -487,18 +506,11 @@ public class SurfaceControl {
        }
    }

    public static void unblankDisplay(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        nativeUnblankDisplay(displayToken);
    }

    public static void blankDisplay(IBinder displayToken) {
    public static void setDisplayPowerMode(IBinder displayToken, int mode) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        nativeBlankDisplay(displayToken);
        nativeSetDisplayPowerMode(displayToken, mode);
    }

    public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) {
+5 −15
Original line number Diff line number Diff line
@@ -412,20 +412,12 @@ static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenOb
    return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
}

static void nativeBlankDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;

    ALOGD_IF_SLOW(100, "Excessive delay in blankDisplay() while turning screen off");
    SurfaceComposerClient::blankDisplay(token);
}

static void nativeUnblankDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;

    ALOGD_IF_SLOW(100, "Excessive delay in unblankDisplay() while turning screen on");
    SurfaceComposerClient::unblankDisplay(token);
    ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
    SurfaceComposerClient::setDisplayPowerMode(token, mode);
}

static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
@@ -628,10 +620,6 @@ static JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeGetActiveConfig },
    {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
            (void*)nativeSetActiveConfig },
    {"nativeBlankDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeBlankDisplay },
    {"nativeUnblankDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeUnblankDisplay },
    {"nativeClearContentFrameStats", "(J)Z",
            (void*)nativeClearContentFrameStats },
    {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
@@ -640,6 +628,8 @@ static JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeClearAnimationFrameStats },
    {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
            (void*)nativeGetAnimationFrameStats },
    {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
            (void*)nativeSetDisplayPowerMode },
};

int register_android_view_SurfaceControl(JNIEnv* env)
+11 −11
Original line number Diff line number Diff line
@@ -111,12 +111,15 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        }
    }

    static boolean shouldBlank(int state) {
        return state == Display.STATE_OFF;
    static int getPowerModeForState(int state) {
        switch (state) {
            case Display.STATE_OFF:
                return SurfaceControl.POWER_MODE_OFF;
            case Display.STATE_DOZING:
                return SurfaceControl.POWER_MODE_DOZE;
            default:
                return SurfaceControl.POWER_MODE_NORMAL;
        }

    static boolean shouldUnblank(int state) {
        return state == Display.STATE_ON || state == Display.STATE_DOZING;
    }

    private final class LocalDisplayDevice extends DisplayDevice {
@@ -204,11 +207,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        @Override
        public void requestDisplayStateLocked(int state) {
            if (mState != state) {
                if (shouldBlank(state) && !shouldBlank(mState)) {
                    SurfaceControl.blankDisplay(getDisplayTokenLocked());
                } else if (shouldUnblank(state) && !shouldUnblank(mState)) {
                    SurfaceControl.unblankDisplay(getDisplayTokenLocked());
                }
                SurfaceControl.setDisplayPowerMode(getDisplayTokenLocked(),
                        getPowerModeForState(state));
                mState = state;
                updateDeviceInfoLocked();
            }