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: Ic4faa008357fd3d74225ba90f05801c5127fd8c0
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e61d375..7a1760d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -6,6 +6,7 @@
<uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+ <uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.VIBRATE" />
diff --git a/src/com/android/settings/BrightnessPreference.java b/src/com/android/settings/BrightnessPreference.java
index 61d3cf9..e2fe0f2 100644
--- a/src/com/android/settings/BrightnessPreference.java
+++ b/src/com/android/settings/BrightnessPreference.java
@@ -18,7 +18,7 @@
import android.content.Context;
import android.os.RemoteException;
-import android.os.IHardwareService;
+import android.os.IPowerManager;
import android.os.ServiceManager;
import android.preference.SeekBarPreference;
import android.provider.Settings;
@@ -130,10 +130,10 @@
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) {
@@ -147,10 +147,10 @@
mSeekBar.setVisibility(View.VISIBLE);
}
try {
- IHardwareService hardware = IHardwareService.Stub.asInterface(
- ServiceManager.getService("hardware"));
- if (hardware != null) {
- hardware.setAutoBrightness(automatic != 0);
+ IPowerManager power = IPowerManager.Stub.asInterface(
+ ServiceManager.getService("power"));
+ if (power != null) {
+ power.setAutoBrightness(automatic != 0);
}
} catch (RemoteException doe) {
}
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index eddeb63..1f3c9f1 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -30,7 +30,7 @@
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
-import android.os.IHardwareService;
+import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
@@ -318,9 +318,9 @@
*/
private static boolean getBrightness(Context context) {
try {
- IHardwareService hardware = IHardwareService.Stub.asInterface(
- ServiceManager.getService("hardware"));
- if (hardware != null) {
+ IPowerManager power = IPowerManager.Stub.asInterface(
+ ServiceManager.getService("power"));
+ if (power != null) {
int brightness = Settings.System.getInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
return brightness > 100;
@@ -338,9 +338,9 @@
*/
private void toggleBrightness(Context context) {
try {
- IHardwareService hardware = IHardwareService.Stub.asInterface(
- ServiceManager.getService("hardware"));
- if (hardware != null) {
+ IPowerManager power = IPowerManager.Stub.asInterface(
+ ServiceManager.getService("power"));
+ if (power != null) {
ContentResolver cr = context.getContentResolver();
int brightness = Settings.System.getInt(cr,
Settings.System.SCREEN_BRIGHTNESS);
@@ -353,7 +353,7 @@
} else {
brightness = MINIMUM_BACKLIGHT;
}
- hardware.setBacklights(brightness);
+ power.setBacklightBrightness(brightness);
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
brightness = Settings.System.getInt(cr,
Settings.System.SCREEN_BRIGHTNESS);