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:
Mike Lockwood
2009-09-15 13:46:43 -07:00
committed by Android Git Automerger
9 changed files with 85 additions and 61 deletions

View File

@@ -28,12 +28,6 @@ interface IHardwareService
boolean getFlashlightEnabled(); boolean getFlashlightEnabled();
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);

View File

@@ -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);
} }

View File

@@ -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.

View File

@@ -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) {

View File

@@ -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);

View File

@@ -2061,6 +2061,42 @@ class PowerManagerService extends IPowerManager.Stub
return result; 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() { private SensorManager getSensorManager() {
if (mSensorManager == null) { if (mSensorManager == null) {
mSensorManager = new SensorManager(mHandlerThread.getLooper()); mSensorManager = new SensorManager(mHandlerThread.getLooper());

View File

@@ -63,6 +63,8 @@ public class PowerManagerTest extends AndroidTestCase {
wl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PARTIAL_WAKE_LOCK"); wl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PARTIAL_WAKE_LOCK");
doTestWakeLock(wl); doTestWakeLock(wl);
doTestSetBacklightBrightness();
// TODO: Some sort of functional test (maybe not in the unit test here?) // 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. // 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 // 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
}
}
} }

View File

@@ -16,7 +16,7 @@
package com.android.frameworktest.settings; package com.android.frameworktest.settings;
import android.os.IHardwareService; import android.os.IPowerManager;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
@@ -45,11 +45,11 @@ public class BrightnessLimit extends Activity implements OnClickListener {
} }
public void onClick(View v) { public void onClick(View v) {
IHardwareService hardware = IHardwareService.Stub.asInterface( IPowerManager power = IPowerManager.Stub.asInterface(
ServiceManager.getService("hardware")); ServiceManager.getService("power"));
if (hardware != null) { if (power != null) {
try { try {
hardware.setBacklights(0); power.setBacklightBrightness(0);
} catch (RemoteException darn) { } catch (RemoteException darn) {
} }

View File

@@ -117,20 +117,4 @@ public class HardwareServicePermissionTest extends TestCase {
// expected // 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
}
}
} }