Settings: Use internal display brightness in overlay displays
If settings is running on an overlay display (such as floating window) the context's default display points to the overlay display, which always has its brightness set to 0. Use the internal (default) display's brightness in this case. Change-Id: I973edf8e2b65214df7b716eebb270abf3ad30c09 Signed-off-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: Dmitrii <bankersenator@gmail.com>
This commit is contained in:
@@ -35,6 +35,8 @@ import android.os.Process;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings.System;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -170,7 +172,7 @@ public class BrightnessLevelPreferenceController extends BasePreferenceControlle
|
||||
|
||||
private double getCurrentBrightness() {
|
||||
int value = 0;
|
||||
final BrightnessInfo info = mContext.getDisplay().getBrightnessInfo();
|
||||
final BrightnessInfo info = getDisplay().getBrightnessInfo();
|
||||
if (info != null) {
|
||||
value = convertLinearToGammaFloat(info.brightness, info.brightnessMinimum,
|
||||
info.brightnessMaximum);
|
||||
@@ -178,6 +180,23 @@ public class BrightnessLevelPreferenceController extends BasePreferenceControlle
|
||||
return getPercentage(value, GAMMA_SPACE_MIN, GAMMA_SPACE_MAX);
|
||||
}
|
||||
|
||||
private Display getDisplay() {
|
||||
final Display currentDisplay = mContext.getDisplay();
|
||||
final DisplayInfo info = new DisplayInfo();
|
||||
currentDisplay.getDisplayInfo(info);
|
||||
|
||||
if (info.type == Display.TYPE_OVERLAY) {
|
||||
// try to get the default (internal) display if we are in an overlay display,
|
||||
// otherwise the brightness is always zero.
|
||||
final Display defaultDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
|
||||
if (defaultDisplay != null) {
|
||||
return defaultDisplay;
|
||||
}
|
||||
}
|
||||
|
||||
return currentDisplay;
|
||||
}
|
||||
|
||||
private double getPercentage(double value, int min, int max) {
|
||||
if (value > max) {
|
||||
return 1.0;
|
||||
|
||||
Reference in New Issue
Block a user