Merge change 23619 into eclair
* changes: Add automatic lighting control framework
This commit is contained in:
@@ -32,6 +32,9 @@ interface IHardwareService
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -1060,6 +1060,12 @@ public final class Settings {
|
||||
*/
|
||||
public static final String SCREEN_BRIGHTNESS = "screen_brightness";
|
||||
|
||||
/**
|
||||
* Control whether to enable automatic brightness mode.
|
||||
* @hide
|
||||
*/
|
||||
public static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode";
|
||||
|
||||
/**
|
||||
* Control whether the process CPU usage meter should be shown.
|
||||
*/
|
||||
|
||||
@@ -81,4 +81,6 @@
|
||||
<item>30</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Flag indicating whether the device supports automatic brightness mode. -->
|
||||
<bool name="config_automatic_brightness_available">false</bool>
|
||||
</resources>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<bool name="def_accelerometer_rotation">true</bool>
|
||||
<!-- Default screen brightness, from 0 to 255. 102 is 40%. -->
|
||||
<integer name="def_screen_brightness">102</integer>
|
||||
<bool name="def_screen_brightness_automatic_mode">false</bool>
|
||||
<fraction name="def_window_animation_scale">100%</fraction>
|
||||
<fraction name="def_window_transition_scale">0%</fraction>
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
|
||||
// is properly propagated through your change. Not doing so will result in a loss of user
|
||||
// settings.
|
||||
private static final int DATABASE_VERSION = 39;
|
||||
private static final int DATABASE_VERSION = 40;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -465,6 +465,22 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
upgradeVersion = 39;
|
||||
}
|
||||
|
||||
if (upgradeVersion == 39) {
|
||||
db.beginTransaction();
|
||||
try {
|
||||
String value =
|
||||
mContext.getResources().getBoolean(
|
||||
R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
|
||||
db.execSQL("INSERT OR IGNORE INTO system(name,value) values('" +
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
upgradeVersion = 40;
|
||||
}
|
||||
|
||||
if (upgradeVersion != currentVersion) {
|
||||
Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
|
||||
+ ", must wipe the settings provider");
|
||||
@@ -701,6 +717,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
|
||||
R.integer.def_screen_brightness);
|
||||
|
||||
loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
|
||||
R.bool.def_screen_brightness_automatic_mode);
|
||||
|
||||
loadDefaultAnimationSettings(stmt);
|
||||
|
||||
loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
|
||||
|
||||
@@ -59,6 +59,8 @@ public class HardwareService extends IHardwareService.Stub {
|
||||
private boolean mAttentionLightOn;
|
||||
private boolean mPulsing;
|
||||
|
||||
private boolean mAutoBrightnessAvailable;
|
||||
|
||||
private class Vibration implements IBinder.DeathRecipient {
|
||||
private final IBinder mToken;
|
||||
private final long mTimeout;
|
||||
@@ -129,6 +131,9 @@ public class HardwareService extends IHardwareService.Stub {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
context.registerReceiver(mIntentReceiver, filter);
|
||||
|
||||
mAutoBrightnessAvailable = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available);
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
@@ -302,6 +307,20 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAttentionLight(boolean on) {
|
||||
// Not worthy of a permission. We shouldn't have a flashlight permission.
|
||||
synchronized (this) {
|
||||
@@ -502,6 +521,7 @@ public class HardwareService extends IHardwareService.Stub {
|
||||
private static native int init_native();
|
||||
private static native void finalize_native(int ptr);
|
||||
|
||||
private static native void setAutoBrightness_native(int ptr, boolean automatic);
|
||||
private static native void setLight_native(int ptr, int light, int color, int mode,
|
||||
int onMS, int offMS);
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import android.util.Log;
|
||||
import android.view.WindowManagerPolicy;
|
||||
import static android.provider.Settings.System.DIM_SCREEN;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN;
|
||||
|
||||
@@ -442,7 +443,11 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
|
||||
// turn everything on
|
||||
setPowerState(ALL_BRIGHT);
|
||||
|
||||
|
||||
// set auto brightness mode to user setting
|
||||
boolean brightnessMode = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, 1) != 0;
|
||||
mHardware.setAutoBrightness_UNCHECKED(brightnessMode);
|
||||
|
||||
synchronized (mHandlerThread) {
|
||||
mInitComplete = true;
|
||||
mHandlerThread.notifyAll();
|
||||
|
||||
@@ -100,6 +100,18 @@ static void finalize_native(JNIEnv *env, jobject clazz, int ptr)
|
||||
free(devices);
|
||||
}
|
||||
|
||||
static void setAutoBrightness_native(JNIEnv *env, jobject clazz, int ptr,
|
||||
jboolean automatic)
|
||||
{
|
||||
Devices* devices = (Devices*)ptr;
|
||||
|
||||
if (devices->lights[LIGHT_INDEX_BACKLIGHT] == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
devices->lights[LIGHT_INDEX_BACKLIGHT]->set_als_mode(automatic ? 0 : 1);
|
||||
}
|
||||
|
||||
static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
|
||||
int light, int colorARGB, int flashMode, int onMS, int offMS)
|
||||
{
|
||||
@@ -134,6 +146,7 @@ static void vibratorOff(JNIEnv *env, jobject clazz)
|
||||
static JNINativeMethod method_table[] = {
|
||||
{ "init_native", "()I", (void*)init_native },
|
||||
{ "finalize_native", "(I)V", (void*)finalize_native },
|
||||
{ "setAutoBrightness_native", "(IZ)V", (void*)setAutoBrightness_native },
|
||||
{ "setLight_native", "(IIIIII)V", (void*)setLight_native },
|
||||
{ "vibratorOn", "(J)V", (void*)vibratorOn },
|
||||
{ "vibratorOff", "()V", (void*)vibratorOff }
|
||||
|
||||
Reference in New Issue
Block a user