Merge "Clean up framework brightness system" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2bb1f86a17
@@ -154,10 +154,20 @@ public class BrightnessSynchronizer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stored screen brightness float value from the display brightness setting.
|
||||
* @return brightness
|
||||
*/
|
||||
private float getScreenBrightnessFloat() {
|
||||
return mDisplayManager.getBrightness(Display.DEFAULT_DISPLAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stored screen brightness int from the system settings.
|
||||
* @param context for accessing settings
|
||||
*
|
||||
* @return brightness
|
||||
*/
|
||||
private static int getScreenBrightnessInt(Context context) {
|
||||
return Settings.System.getIntForUser(context.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS, PowerManager.BRIGHTNESS_INVALID,
|
||||
|
||||
@@ -17,19 +17,14 @@
|
||||
package com.android.server.display;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* Saves brightness to a persistent data store, enabling each logical display to have its own
|
||||
@@ -39,14 +34,11 @@ public class BrightnessSetting {
|
||||
private static final String TAG = "BrightnessSetting";
|
||||
|
||||
private static final int MSG_BRIGHTNESS_CHANGED = 1;
|
||||
private static final Uri BRIGHTNESS_FLOAT_URI =
|
||||
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FLOAT);
|
||||
private final PersistentDataStore mPersistentDataStore;
|
||||
|
||||
private final boolean mIsDefaultDisplay;
|
||||
private final Context mContext;
|
||||
private final PersistentDataStore mPersistentDataStore;
|
||||
private final DisplayManagerService.SyncRoot mSyncRoot;
|
||||
|
||||
private final LogicalDisplay mLogicalDisplay;
|
||||
private final Object mLock = new Object();
|
||||
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
@@ -58,37 +50,20 @@ public class BrightnessSetting {
|
||||
}
|
||||
};
|
||||
|
||||
private final ContentObserver mBrightnessSettingsObserver = new ContentObserver(mHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (selfChange) {
|
||||
return;
|
||||
}
|
||||
if (BRIGHTNESS_FLOAT_URI.equals(uri)) {
|
||||
float brightness = getScreenBrightnessSettingFloat();
|
||||
setBrightness(brightness, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final CopyOnWriteArrayList<BrightnessSettingListener> mListeners =
|
||||
new CopyOnWriteArrayList<BrightnessSettingListener>();
|
||||
private final CopyOnWriteArraySet<BrightnessSettingListener> mListeners =
|
||||
new CopyOnWriteArraySet<>();
|
||||
|
||||
@GuardedBy("mSyncRoot")
|
||||
private float mBrightness;
|
||||
|
||||
BrightnessSetting(@NonNull PersistentDataStore persistentDataStore,
|
||||
@NonNull LogicalDisplay logicalDisplay,
|
||||
@NonNull Context context) {
|
||||
DisplayManagerService.SyncRoot syncRoot) {
|
||||
mPersistentDataStore = persistentDataStore;
|
||||
mLogicalDisplay = logicalDisplay;
|
||||
mContext = context;
|
||||
mIsDefaultDisplay = mLogicalDisplay.getDisplayIdLocked() == Display.DEFAULT_DISPLAY;
|
||||
mBrightness = mPersistentDataStore.getBrightness(
|
||||
mLogicalDisplay.getPrimaryDisplayDeviceLocked());
|
||||
if (mIsDefaultDisplay) {
|
||||
mContext.getContentResolver().registerContentObserver(BRIGHTNESS_FLOAT_URI,
|
||||
false, mBrightnessSettingsObserver);
|
||||
}
|
||||
mSyncRoot = syncRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,16 +72,19 @@ public class BrightnessSetting {
|
||||
* @return brightness for the current display
|
||||
*/
|
||||
public float getBrightness() {
|
||||
return mBrightness;
|
||||
synchronized (mSyncRoot) {
|
||||
return mBrightness;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers listener for brightness setting change events.
|
||||
*/
|
||||
public void registerListener(BrightnessSettingListener l) {
|
||||
if (!mListeners.contains(l)) {
|
||||
mListeners.add(l);
|
||||
if (mListeners.contains(l)) {
|
||||
Slog.wtf(TAG, "Duplicate Listener added");
|
||||
}
|
||||
mListeners.add(l);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,27 +97,16 @@ public class BrightnessSetting {
|
||||
}
|
||||
|
||||
void setBrightness(float brightness) {
|
||||
setBrightness(brightness, false);
|
||||
}
|
||||
|
||||
private void setBrightness(float brightness, boolean isFromSystemSetting) {
|
||||
if (brightness == mBrightness) {
|
||||
return;
|
||||
}
|
||||
if (Float.isNaN(brightness)) {
|
||||
Slog.w(TAG, "Attempting to set invalid brightness");
|
||||
return;
|
||||
}
|
||||
synchronized (mLock) {
|
||||
synchronized (mSyncRoot) {
|
||||
if (brightness == mBrightness) {
|
||||
return;
|
||||
}
|
||||
|
||||
mBrightness = brightness;
|
||||
|
||||
// If it didn't come from us
|
||||
if (mIsDefaultDisplay && !isFromSystemSetting) {
|
||||
Settings.System.putFloatForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_FLOAT, brightness,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
mPersistentDataStore.setBrightness(mLogicalDisplay.getPrimaryDisplayDeviceLocked(),
|
||||
brightness);
|
||||
int toSend = Float.floatToIntBits(mBrightness);
|
||||
@@ -148,12 +115,6 @@ public class BrightnessSetting {
|
||||
}
|
||||
}
|
||||
|
||||
private float getScreenBrightnessSettingFloat() {
|
||||
return Settings.System.getFloatForUser(mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_FLOAT, PowerManager.BRIGHTNESS_INVALID_FLOAT,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private void notifyListeners(float brightness) {
|
||||
for (BrightnessSettingListener l : mListeners) {
|
||||
l.onBrightnessChanged(brightness);
|
||||
|
||||
@@ -399,9 +399,6 @@ public final class DisplayManagerService extends SystemService {
|
||||
// Receives notifications about changes to Settings.
|
||||
private SettingsObserver mSettingsObserver;
|
||||
|
||||
// Received notifications of the device-state action (such as "fold", "unfold")
|
||||
private DeviceStateManager mDeviceStateManager;
|
||||
|
||||
private final boolean mAllowNonNativeRefreshRateOverride;
|
||||
|
||||
private final BrightnessSynchronizer mBrightnessSynchronizer;
|
||||
@@ -1236,13 +1233,6 @@ public final class DisplayManagerService extends SystemService {
|
||||
adapter.registerLocked();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void handleLogicalDisplayAdded(LogicalDisplay display) {
|
||||
synchronized (mSyncRoot) {
|
||||
handleLogicalDisplayAddedLocked(display);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLogicalDisplayAddedLocked(LogicalDisplay display) {
|
||||
final DisplayDevice device = display.getPrimaryDisplayDeviceLocked();
|
||||
final int displayId = display.getDisplayIdLocked();
|
||||
@@ -2107,7 +2097,7 @@ public final class DisplayManagerService extends SystemService {
|
||||
}
|
||||
|
||||
final BrightnessSetting brightnessSetting = new BrightnessSetting(mPersistentDataStore,
|
||||
display, mContext);
|
||||
display, mSyncRoot);
|
||||
final DisplayPowerController displayPowerController = new DisplayPowerController(
|
||||
mContext, mDisplayPowerCallbacks, mPowerHandler, mSensorManager,
|
||||
mDisplayBlanker, display, mBrightnessTracker, brightnessSetting,
|
||||
|
||||
@@ -149,9 +149,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
private static final int REPORTED_TO_POLICY_SCREEN_ON = 2;
|
||||
private static final int REPORTED_TO_POLICY_SCREEN_TURNING_OFF = 3;
|
||||
|
||||
private static final Uri BRIGHTNESS_FLOAT_URI =
|
||||
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FLOAT);
|
||||
|
||||
private final Object mLock = new Object();
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
Reference in New Issue
Block a user