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

Commit 237a2992 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Move backlight brightness from HardwareService to PowerManager



to prevent apps from changing the hardware behind its back.
Fixes b/2041941 Lock screen flashes the screen very bright before dimming

Change-Id: Ice757f7ae87902bdfb3634471cf44f020ebfaae4
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent f02c0740
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -29,12 +29,6 @@ interface IHardwareService
    void setFlashlightEnabled(boolean on);
    void enableCameraFlash(int milliseconds);

    // sets the brightness of the backlights (screen, keyboard, button) 0-255
    void setBacklights(int brightness);

    // enables or disables automatic brightness mode
    void setAutoBrightness(boolean on);

    // for the phone
    void setAttentionLight(boolean on);
}
+6 −0
Original line number Diff line number Diff line
@@ -31,4 +31,10 @@ interface IPowerManager
    long getScreenOnTime();
    void preventScreenOn(boolean prevent);
    void setScreenBrightnessOverride(int brightness);

    // sets the brightness of the backlights (screen, keyboard, button) 0-255
    void setBacklightBrightness(int brightness);

    // enables or disables automatic brightness mode
    void setAutoBrightness(boolean on);
}
+15 −0
Original line number Diff line number Diff line
@@ -379,6 +379,21 @@ public class PowerManager
        }
    }

    /**
     * sets the brightness of the backlights (screen, keyboard, button).
     *
     * @param brightness value from 0 to 255
     *
     * {@hide}
     */
    public void setBacklightBrightness(int brightness)
    {
        try {
            mService.setBacklightBrightness(brightness);
        } catch (RemoteException e) {
        }
    }

   /**
     * Returns the set of flags for {@link #newWakeLock(int, String) newWakeLock()}
     * that are supported on the device.
+5 −5
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.content.IContentService;
import android.content.res.Configuration;
import android.location.LocationManager;
import android.media.AudioManager;
import android.os.IHardwareService;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
@@ -94,10 +94,10 @@ public class SettingsHelper {

    private void setBrightness(int brightness) {
        try {
            IHardwareService hardware = IHardwareService.Stub
                    .asInterface(ServiceManager.getService("hardware"));
            if (hardware != null) {
                hardware.setBacklights(brightness);
            IPowerManager power = IPowerManager.Stub.asInterface(
                    ServiceManager.getService("power"));
            if (power != null) {
                power.setBacklightBrightness(brightness);
            }
        } catch (RemoteException doe) {

+0 −28
Original line number Diff line number Diff line
@@ -269,26 +269,6 @@ public class HardwareService extends IHardwareService.Stub {
        Hardware.enableCameraFlash(milliseconds);
    }

    public void setBacklights(int brightness) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) 
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires HARDWARE_TEST permission");
        }
        // Don't let applications turn the screen all the way off
        brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
        setLightBrightness_UNCHECKED(LIGHT_ID_BACKLIGHT, brightness);
        setLightBrightness_UNCHECKED(LIGHT_ID_KEYBOARD, brightness);
        setLightBrightness_UNCHECKED(LIGHT_ID_BUTTONS, brightness);
        long identity = Binder.clearCallingIdentity();
        try {
            mBatteryStats.noteScreenBrightness(brightness);
        } catch (RemoteException e) {
            Log.w(TAG, "RemoteException calling noteScreenBrightness on BatteryStatsService", e);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    void setLightOff_UNCHECKED(int light) {
        setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0);
    }
@@ -307,14 +287,6 @@ public class HardwareService extends IHardwareService.Stub {
        setLight_native(mNativePointer, light, color, mode, onMS, offMS);
    }

    public void setAutoBrightness(boolean on) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires HARDWARE_TEST permission");
        }
        setAutoBrightness_UNCHECKED(on);
    }

    void setAutoBrightness_UNCHECKED(boolean on) {
        if (mAutoBrightnessAvailable) {
            setAutoBrightness_native(mNativePointer, on);
Loading