am 6d9eebe7: Merge change 25090 into eclair
Merge commit '6d9eebe7320637f0256c077ba5ed6724b5a4ab0d' into eclair-plus-aosp * commit '6d9eebe7320637f0256c077ba5ed6724b5a4ab0d': Move backlight brightness from HardwareService to PowerManager
This commit is contained in:
@@ -28,12 +28,6 @@ interface IHardwareService
|
||||
boolean getFlashlightEnabled();
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2061,6 +2061,42 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setBacklightBrightness(int brightness) {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
|
||||
// Don't let applications turn the screen all the way off
|
||||
brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, brightness);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, brightness);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.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);
|
||||
}
|
||||
|
||||
// update our animation state
|
||||
if (ANIMATE_SCREEN_LIGHTS) {
|
||||
mScreenBrightness.curValue = brightness;
|
||||
mScreenBrightness.animating = false;
|
||||
}
|
||||
if (ANIMATE_KEYBOARD_LIGHTS) {
|
||||
mKeyboardBrightness.curValue = brightness;
|
||||
mKeyboardBrightness.animating = false;
|
||||
}
|
||||
if (ANIMATE_BUTTON_LIGHTS) {
|
||||
mButtonBrightness.curValue = brightness;
|
||||
mButtonBrightness.animating = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAutoBrightness(boolean on) {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
|
||||
mHardware.setAutoBrightness_UNCHECKED(on);
|
||||
}
|
||||
|
||||
private SensorManager getSensorManager() {
|
||||
if (mSensorManager == null) {
|
||||
mSensorManager = new SensorManager(mHandlerThread.getLooper());
|
||||
|
||||
@@ -63,6 +63,8 @@ public class PowerManagerTest extends AndroidTestCase {
|
||||
wl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PARTIAL_WAKE_LOCK");
|
||||
doTestWakeLock(wl);
|
||||
|
||||
doTestSetBacklightBrightness();
|
||||
|
||||
// TODO: Some sort of functional test (maybe not in the unit test here?)
|
||||
// that confirms that things are really happening e.g. screen power, keyboard power.
|
||||
}
|
||||
@@ -121,5 +123,20 @@ public class PowerManagerTest extends AndroidTestCase {
|
||||
// TODO: Threaded test (needs handler) to make sure timed wakelocks work too
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test that calling {@link android.os.IHardwareService#setBacklights(int)} requires
|
||||
* permissions.
|
||||
* <p>Tests permission:
|
||||
* {@link android.Manifest.permission#DEVICE_POWER}
|
||||
*/
|
||||
private void doTestSetBacklightBrightness() {
|
||||
try {
|
||||
mPm.setBacklightBrightness(0);
|
||||
fail("setBacklights did not throw SecurityException as expected");
|
||||
} catch (SecurityException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.frameworktest.settings;
|
||||
|
||||
import android.os.IHardwareService;
|
||||
import android.os.IPowerManager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
@@ -45,11 +45,11 @@ public class BrightnessLimit extends Activity implements OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
IHardwareService hardware = IHardwareService.Stub.asInterface(
|
||||
ServiceManager.getService("hardware"));
|
||||
if (hardware != null) {
|
||||
IPowerManager power = IPowerManager.Stub.asInterface(
|
||||
ServiceManager.getService("power"));
|
||||
if (power != null) {
|
||||
try {
|
||||
hardware.setBacklights(0);
|
||||
power.setBacklightBrightness(0);
|
||||
} catch (RemoteException darn) {
|
||||
|
||||
}
|
||||
|
||||
@@ -117,20 +117,4 @@ public class HardwareServicePermissionTest extends TestCase {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that calling {@link android.os.IHardwareService#setBacklights(int)} requires
|
||||
* permissions.
|
||||
* <p>Tests permission:
|
||||
* {@link android.Manifest.permission#HARDWARE_TEST}
|
||||
* @throws RemoteException
|
||||
*/
|
||||
public void testSetBacklights() throws RemoteException {
|
||||
try {
|
||||
mHardwareService.setBacklights(0);
|
||||
fail("setBacklights did not throw SecurityException as expected");
|
||||
} catch (SecurityException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user