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 Original line Diff line number Diff line
@@ -29,12 +29,6 @@ interface IHardwareService
    void setFlashlightEnabled(boolean on);
    void setFlashlightEnabled(boolean on);
    void enableCameraFlash(int milliseconds);
    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
    // for the phone
    void setAttentionLight(boolean on);
    void setAttentionLight(boolean on);
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -31,4 +31,10 @@ interface IPowerManager
    long getScreenOnTime();
    long getScreenOnTime();
    void preventScreenOn(boolean prevent);
    void preventScreenOn(boolean prevent);
    void setScreenBrightnessOverride(int brightness);
    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 Original line 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()}
     * Returns the set of flags for {@link #newWakeLock(int, String) newWakeLock()}
     * that are supported on the device.
     * that are supported on the device.
+5 −5
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@ import android.content.IContentService;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.location.LocationManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.AudioManager;
import android.os.IHardwareService;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.provider.Settings;
import android.provider.Settings;
@@ -94,10 +94,10 @@ public class SettingsHelper {


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


+0 −28
Original line number Original line Diff line number Diff line
@@ -269,26 +269,6 @@ public class HardwareService extends IHardwareService.Stub {
        Hardware.enableCameraFlash(milliseconds);
        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) {
    void setLightOff_UNCHECKED(int light) {
        setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0);
        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);
        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) {
    void setAutoBrightness_UNCHECKED(boolean on) {
        if (mAutoBrightnessAvailable) {
        if (mAutoBrightnessAvailable) {
            setAutoBrightness_native(mNativePointer, on);
            setAutoBrightness_native(mNativePointer, on);
Loading