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

Unverified Commit cefd5bab authored by Adrian DC's avatar Adrian DC Committed by Michael Bestas
Browse files

frameworks/base: Lights notifications brightness support



Co-authored-by: default avatarAdnan Begovic <adnan@cyngn.com>
Co-authored-by: default avatarGabriele M <moto.falcon.git@gmail.com>
Change-Id: I1c0de01b1c6a2a2cf1432028a2e69f90b2373b2c
parent b802d842
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1392,9 +1392,11 @@ public final class BatteryService extends SystemService {
            if (!ledValues.isEnabled()) {
                mBatteryLight.turnOff();
            } else if (ledValues.isPulsed()) {
                mBatteryLight.setModes(ledValues.getBrightness());
                mBatteryLight.setFlashing(ledValues.getColor(), LogicalLight.LIGHT_FLASH_TIMED,
                        ledValues.getOnMs(), ledValues.getOffMs());
            } else {
                mBatteryLight.setModes(ledValues.getBrightness());
                mBatteryLight.setColor(ledValues.getColor());
            }
        }
+27 −4
Original line number Diff line number Diff line
/* * Copyright (C) 2008 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -317,6 +318,14 @@ public class LightsService extends SystemService {
            }
        }

        @Override
        public void setModes(int brightnessLevel) {
            synchronized (this) {
                mBrightnessLevel = brightnessLevel;
                mModesUpdate = true;
            }
        }

        @Override
        public void pulse() {
            pulse(0x00ffffff, 7);
@@ -375,7 +384,7 @@ public class LightsService extends SystemService {
            }

            if (!mInitialized || color != mColor || mode != mMode || onMS != mOnMS ||
                    offMS != mOffMS || mBrightnessMode != brightnessMode) {
                    offMS != mOffMS || mBrightnessMode != brightnessMode || mModesUpdate) {
                if (DEBUG) {
                    Slog.v(TAG, "setLight #" + mHwLight.id + ": color=#"
                            + Integer.toHexString(color) + ": brightnessMode=" + brightnessMode);
@@ -387,6 +396,7 @@ public class LightsService extends SystemService {
                mOnMS = onMS;
                mOffMS = offMS;
                mBrightnessMode = brightnessMode;
                mModesUpdate = false;
                setLightUnchecked(color, mode, onMS, offMS, brightnessMode);
            }
        }
@@ -398,14 +408,24 @@ public class LightsService extends SystemService {
            try {
                if (mVintfLights != null) {
                    HwLightState lightState = new HwLightState();
                    if (mBrightnessLevel > 0 && mBrightnessLevel <= 0xFF) {
                        int colorAlpha = color >>> 24;
                        if (colorAlpha == 0x00) {
                            colorAlpha = 0xFF;
                        }
                        colorAlpha = (colorAlpha * mBrightnessLevel) / 0xFF;
                        lightState.color = (colorAlpha << 24) + (color & 0x00FFFFFF);
                    } else {
                        lightState.color = color;
                    }
                    lightState.flashMode = (byte) mode;
                    lightState.flashOnMs = onMS;
                    lightState.flashOffMs = offMS;
                    lightState.brightnessMode = (byte) brightnessMode;
                    mVintfLights.get().setLightState(mHwLight.id, lightState);
                } else {
                    setLight_native(mHwLight.id, color, mode, onMS, offMS, brightnessMode);
                    setLight_native(mHwLight.id, color, mode, onMS, offMS,
                            brightnessMode, mBrightnessLevel);
                }
            } catch (RemoteException | UnsupportedOperationException ex) {
                Slog.e(TAG, "Failed issuing setLightState", ex);
@@ -437,6 +457,7 @@ public class LightsService extends SystemService {
        private int mMode;
        private int mOnMS;
        private int mOffMS;
        private int mBrightnessLevel;
        private boolean mFlashing;
        private int mBrightnessMode;
        private int mLastBrightnessMode;
@@ -444,6 +465,8 @@ public class LightsService extends SystemService {
        private boolean mVrModeEnabled;
        private boolean mUseLowPersistenceForVR;
        private boolean mInitialized;
        private boolean mLocked;
        private boolean mModesUpdate;
    }

    public LightsService(Context context) {
@@ -553,5 +576,5 @@ public class LightsService extends SystemService {
    }

    static native void setLight_native(int light, int color, int mode,
            int onMS, int offMS, int brightnessMode);
            int onMS, int offMS, int brightnessMode, int brightnessLevel);
}
+6 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -74,6 +75,11 @@ public abstract class LogicalLight {
     */
    public abstract void setFlashing(int color, int mode, int onMS, int offMS);

    /**
     * Set the modes of light.
     */
    public abstract void setModes(int brightnessLevel);

    /**
     * Pulses the light.
     */
+2 −0
Original line number Diff line number Diff line
@@ -948,6 +948,8 @@ public final class NotificationAttentionHelper {
        if (!ledValues.isEnabled()) {
            mNotificationLight.turnOff();
        } else {
            mNotificationLight.setModes(ledValues.getBrightness());

            // we are using 1:0 to indicate LED should stay always on
            if (ledValues.getOnMs() == 1 && ledValues.getOffMs() == 0) {
                mNotificationLight.setColor(ledValues.getColor());
+13 −2
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -131,7 +132,8 @@ static void setLight_native(
        jint flashMode,
        jint onMS,
        jint offMS,
        jint brightnessMode) {
        jint brightnessMode,
        jint brightnessLevel) {

    if (!sLightSupported) {
        return;
@@ -141,6 +143,15 @@ static void setLight_native(
        return;
    }

    if (brightnessLevel > 0 && brightnessLevel <= 0xFF) {
        int colorAlpha = (colorARGB & 0xFF000000) >> 24;
        if (colorAlpha == 0x00) {
            colorAlpha = 0xFF;
        }
        colorAlpha = (colorAlpha * brightnessLevel) / 0xFF;
        colorARGB = (colorAlpha << 24) + (colorARGB & 0x00FFFFFF);
    }

    Type type = static_cast<Type>(light);
    LightState state = constructState(
        colorARGB, flashMode, onMS, offMS, brightnessMode);
@@ -159,7 +170,7 @@ static void setLight_native(
}

static const JNINativeMethod method_table[] = {
    { "setLight_native", "(IIIIII)V", (void*)setLight_native },
    { "setLight_native", "(IIIIIII)V", (void*)setLight_native },
};

int register_android_server_LightsService(JNIEnv *env) {