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

Commit 6b441055 authored by Joey's avatar Joey
Browse files

sdk: livedisplay: add a method to determine whether night mode is enabled



LiveDisplayManager.getMode() returns MODE_AUTO when night mode is enabled
automatically, so there's no way to determine if night is on when livedisplay
changes automatically

Change-Id: Ia47fc127232c2bb3b6634b55712060a919f8c9c1
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent 157a7c1c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ package lineageos.hardware {
    method public boolean setMode(int);
    method public boolean setNightColorTemperature(int);
    method public boolean setPictureAdjustment(lineageos.hardware.HSIC);
    method public boolean isNightModeEnabled();
    field public static final int ADJUSTMENT_CONTRAST = 3; // 0x3
    field public static final int ADJUSTMENT_HUE = 0; // 0x0
    field public static final int ADJUSTMENT_INTENSITY = 2; // 0x2
+1 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public abstract class LiveDisplayFeature {
        return mState.mTwilight;
    }

    protected final boolean isNight() {
    public final boolean isNight() {
        return mState.mTwilight != null && mState.mTwilight.isNight();
    }

+6 −0
Original line number Diff line number Diff line
@@ -370,6 +370,12 @@ public class LiveDisplayService extends LineageSystemService {
                mFeatures.get(i).dump(pw);
            }
        }

        @Override
        public boolean isNight() {
            final TwilightState twilight = mTwilightTracker.getCurrentState();
            return twilight != null && twilight.isNight();
        }
    };

    // Listener for screen on/off events
+1 −0
Original line number Diff line number Diff line
@@ -52,4 +52,5 @@ interface ILiveDisplayService {
    HSIC getPictureAdjustment();
    HSIC getDefaultPictureAdjustment();
    boolean setPictureAdjustment(in HSIC adj);
    boolean isNight();
}
+15 −0
Original line number Diff line number Diff line
@@ -482,4 +482,19 @@ public class LiveDisplayManager {
        }
        return null;
    }

    /**
     * Determine whether night mode is enabled (be it automatic or manual)
     */
    public boolean isNightModeEnabled() {
        // This method might be called before config has been set up
        // so a NPE would have been thrown, just report night mode is disabled instead
        try {
            return getMode() == MODE_NIGHT || sService.isNight();
        } catch (NullPointerException e) {
            Log.w(TAG, "Can\'t check whether night mode is enabled because the service isn\'t ready");
        } catch (RemoteException ignored) {
        }
        return false;
    }
}