A better auto brightness
Bug: 14927472 Change-Id: I62d0695b7da16ffa7a27c465c3b6bc4b1515f9c0
This commit is contained in:
@@ -365,15 +365,6 @@ public final class PowerManager {
|
||||
com.android.internal.R.integer.config_screenBrightnessSettingDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the screen auto-brightness adjustment setting should
|
||||
* be available in the UI. This setting is experimental and disabled by default.
|
||||
* @hide
|
||||
*/
|
||||
public static boolean useScreenAutoBrightnessAdjustmentFeature() {
|
||||
return SystemProperties.getBoolean("persist.power.useautobrightadj", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the twilight service should be used to adjust screen brightness
|
||||
* policy. This setting is experimental and disabled by default.
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:button="@null"
|
||||
android:background="@*android:drawable/switch_track_quantum"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
<com.android.systemui.settings.ToggleSeekBar
|
||||
android:id="@+id/slider"
|
||||
@@ -36,6 +37,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/toggle"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
@@ -51,5 +53,6 @@
|
||||
android:paddingTop="26dp"
|
||||
android:textColor="#666666"
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</merge>
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,6 +35,12 @@ import java.util.ArrayList;
|
||||
public class BrightnessController implements ToggleSlider.Listener {
|
||||
private static final String TAG = "StatusBar.BrightnessController";
|
||||
|
||||
/**
|
||||
* {@link android.provider.Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ} uses the range [-1, 1].
|
||||
* Using this factor, it is converted to [0, BRIGHTNESS_ADJ_RESOLUTION] for the SeekBar.
|
||||
*/
|
||||
private static final float BRIGHTNESS_ADJ_RESOLUTION = 100;
|
||||
|
||||
private final int mMinimumBacklight;
|
||||
private final int mMaximumBacklight;
|
||||
|
||||
@@ -51,6 +56,8 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
private ArrayList<BrightnessStateChangeCallback> mChangeCallbacks =
|
||||
new ArrayList<BrightnessStateChangeCallback>();
|
||||
|
||||
private boolean mAutomatic;
|
||||
|
||||
public interface BrightnessStateChangeCallback {
|
||||
public void onBrightnessLevelChanged();
|
||||
}
|
||||
@@ -62,6 +69,8 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE);
|
||||
private final Uri BRIGHTNESS_URI =
|
||||
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);
|
||||
private final Uri BRIGHTNESS_ADJ_URI =
|
||||
Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ);
|
||||
|
||||
public BrightnessObserver(Handler handler) {
|
||||
super(handler);
|
||||
@@ -77,7 +86,10 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
if (selfChange) return;
|
||||
if (BRIGHTNESS_MODE_URI.equals(uri)) {
|
||||
updateMode();
|
||||
} else if (BRIGHTNESS_URI.equals(uri)) {
|
||||
updateSlider();
|
||||
} else if (BRIGHTNESS_URI.equals(uri) && !mAutomatic) {
|
||||
updateSlider();
|
||||
} else if (BRIGHTNESS_ADJ_URI.equals(uri) && mAutomatic) {
|
||||
updateSlider();
|
||||
} else {
|
||||
updateMode();
|
||||
@@ -97,6 +109,9 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
cr.registerContentObserver(
|
||||
BRIGHTNESS_URI,
|
||||
false, this, UserHandle.USER_ALL);
|
||||
cr.registerContentObserver(
|
||||
BRIGHTNESS_ADJ_URI,
|
||||
false, this, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
public void stopObserving() {
|
||||
@@ -163,10 +178,8 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
}
|
||||
|
||||
public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) {
|
||||
setMode(automatic ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
|
||||
: Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
updateIcon(automatic);
|
||||
if (!automatic) {
|
||||
updateIcon(mAutomatic);
|
||||
if (!mAutomatic) {
|
||||
final int val = value + mMinimumBacklight;
|
||||
setBrightness(val);
|
||||
if (!tracking) {
|
||||
@@ -178,6 +191,18 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
final float adj = value / (BRIGHTNESS_ADJ_RESOLUTION / 2f) - 1;
|
||||
setBrignessAdj(adj);
|
||||
if (!tracking) {
|
||||
AsyncTask.execute(new Runnable() {
|
||||
public void run() {
|
||||
Settings.System.putFloatForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, adj,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (BrightnessStateChangeCallback cb : mChangeCallbacks) {
|
||||
@@ -198,6 +223,13 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void setBrignessAdj(float adj) {
|
||||
try {
|
||||
mPower.setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(adj);
|
||||
} catch (RemoteException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateIcon(boolean automatic) {
|
||||
if (mIcon != null) {
|
||||
mIcon.setImageResource(automatic ?
|
||||
@@ -210,15 +242,12 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
private void updateMode() {
|
||||
if (mAutomaticAvailable) {
|
||||
int automatic;
|
||||
try {
|
||||
automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE,
|
||||
UserHandle.USER_CURRENT);
|
||||
} catch (SettingNotFoundException snfe) {
|
||||
automatic = 0;
|
||||
}
|
||||
mControl.setChecked(automatic != 0);
|
||||
updateIcon(automatic != 0);
|
||||
automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE,
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
|
||||
UserHandle.USER_CURRENT);
|
||||
mAutomatic = automatic != 0;
|
||||
updateIcon(mAutomatic);
|
||||
} else {
|
||||
mControl.setChecked(false);
|
||||
updateIcon(false /*automatic*/);
|
||||
@@ -227,16 +256,20 @@ public class BrightnessController implements ToggleSlider.Listener {
|
||||
|
||||
/** Fetch the brightness from the system settings and update the slider */
|
||||
private void updateSlider() {
|
||||
int value;
|
||||
try {
|
||||
value = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS,
|
||||
if (mAutomatic) {
|
||||
float value = Settings.System.getFloatForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
} catch (SettingNotFoundException ex) {
|
||||
value = mMaximumBacklight;
|
||||
mControl.setMax((int) BRIGHTNESS_ADJ_RESOLUTION);
|
||||
mControl.setValue((int) ((value + 1) * BRIGHTNESS_ADJ_RESOLUTION / 2f));
|
||||
} else {
|
||||
int value;
|
||||
value = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS, mMaximumBacklight,
|
||||
UserHandle.USER_CURRENT);
|
||||
mControl.setMax(mMaximumBacklight - mMinimumBacklight);
|
||||
mControl.setValue(value - mMinimumBacklight);
|
||||
}
|
||||
mControl.setMax(mMaximumBacklight - mMinimumBacklight);
|
||||
mControl.setValue(value - mMinimumBacklight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ class AutomaticBrightnessController {
|
||||
private static final boolean DEBUG_PRETEND_LIGHT_SENSOR_ABSENT = false;
|
||||
|
||||
// If true, enables the use of the screen auto-brightness adjustment setting.
|
||||
private static final boolean USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT =
|
||||
PowerManager.useScreenAutoBrightnessAdjustmentFeature();
|
||||
private static final boolean USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT = true;
|
||||
|
||||
// The maximum range of gamma adjustment possible using the screen
|
||||
// auto-brightness adjustment setting.
|
||||
|
||||
Reference in New Issue
Block a user