Merge "Add display white balance enabled methods to CDS"

This commit is contained in:
Christine Franks
2019-04-04 01:38:46 +00:00
committed by Android (Google) Code Review
5 changed files with 99 additions and 58 deletions

View File

@@ -391,6 +391,26 @@ public final class ColorDisplayManager {
return mManager.setAppSaturationLevel(packageName, saturationLevel);
}
/**
* Enables or disables display white balance.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS)
public boolean setDisplayWhiteBalanceEnabled(boolean enabled) {
return mManager.setDisplayWhiteBalanceEnabled(enabled);
}
/**
* Returns whether display white balance is currently enabled. Even if enabled, it may or may
* not be active, if another transform with higher priority is active.
*
* @hide
*/
public boolean isDisplayWhiteBalanceEnabled() {
return mManager.isDisplayWhiteBalanceEnabled();
}
/**
* Returns {@code true} if Night Display is supported by the device.
*
@@ -616,6 +636,22 @@ public final class ColorDisplayManager {
}
}
boolean isDisplayWhiteBalanceEnabled() {
try {
return mCdm.isDisplayWhiteBalanceEnabled();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
boolean setDisplayWhiteBalanceEnabled(boolean enabled) {
try {
return mCdm.setDisplayWhiteBalanceEnabled(enabled);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
int getColorMode() {
try {
return mCdm.getColorMode();

View File

@@ -42,4 +42,7 @@ interface IColorDisplayManager {
int getColorMode();
void setColorMode(int colorMode);
boolean isDisplayWhiteBalanceEnabled();
boolean setDisplayWhiteBalanceEnabled(boolean enabled);
}

View File

@@ -572,9 +572,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
public void onSwitchUser(@UserIdInt int newUserId) {
handleSettingsChange(true /* userSwitch */);
mBrightnessTracker.onSwitchUser(newUserId);
if (mDisplayWhiteBalanceSettings != null) {
mDisplayWhiteBalanceSettings.onSwitchUser();
}
}
public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats(

View File

@@ -596,7 +596,19 @@ public final class ColorDisplayService extends SystemService {
}
}
private boolean setDisplayWhiteBalanceSettingEnabled(boolean enabled) {
if (mCurrentUser == UserHandle.USER_NULL) {
return false;
}
return Secure.putIntForUser(getContext().getContentResolver(),
Secure.DISPLAY_WHITE_BALANCE_ENABLED,
enabled ? 1 : 0, mCurrentUser);
}
private boolean isDisplayWhiteBalanceSettingEnabled() {
if (mCurrentUser == UserHandle.USER_NULL) {
return false;
}
return Secure.getIntForUser(getContext().getContentResolver(),
Secure.DISPLAY_WHITE_BALANCE_ENABLED, 0, mCurrentUser) == 1;
}
@@ -1213,6 +1225,13 @@ public final class ColorDisplayService extends SystemService {
return mDisplayWhiteBalanceTintController.isActivated();
}
/**
* Returns whether Display white balance is currently enabled.
*/
public boolean isDisplayWhiteBalanceEnabled() {
return isDisplayWhiteBalanceSettingEnabled();
}
/**
* Adds a {@link WeakReference<ColorTransformController>} for a newly started activity, and
* invokes {@link ColorTransformController#applyAppSaturation(float[], float[])} if needed.
@@ -1233,7 +1252,7 @@ public final class ColorDisplayService extends SystemService {
* Notify that the display white balance status has changed, either due to preemption by
* another transform or the feature being turned off.
*/
void onDisplayWhiteBalanceStatusChanged(boolean enabled);
void onDisplayWhiteBalanceStatusChanged(boolean activated);
}
private final class TintHandler extends Handler {
@@ -1499,6 +1518,29 @@ public final class ColorDisplayService extends SystemService {
}
}
@Override
public boolean setDisplayWhiteBalanceEnabled(boolean enabled) {
getContext().enforceCallingOrSelfPermission(
Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS,
"Permission required to set night display activated");
final long token = Binder.clearCallingIdentity();
try {
return setDisplayWhiteBalanceSettingEnabled(enabled);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public boolean isDisplayWhiteBalanceEnabled() {
final long token = Binder.clearCallingIdentity();
try {
return isDisplayWhiteBalanceSettingEnabled();
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) {

View File

@@ -18,13 +18,9 @@ package com.android.server.display.whitebalance;
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.UserHandle;
import android.provider.Settings.Secure;
import android.util.Slog;
import com.android.internal.util.Preconditions;
@@ -46,22 +42,19 @@ public class DisplayWhiteBalanceSettings implements
protected static final String TAG = "DisplayWhiteBalanceSettings";
protected boolean mLoggingEnabled;
private static final String SETTING_URI = Secure.DISPLAY_WHITE_BALANCE_ENABLED;
private static final int SETTING_DEFAULT = 0;
private static final int SETTING_ENABLED = 1;
private static final int MSG_SET_ACTIVE = 1;
private final Context mContext;
private final Handler mHandler;
private final SettingsObserver mSettingsObserver;
private final ColorDisplayServiceInternal mCdsi;
// To decouple the DisplayPowerController from the DisplayWhiteBalanceSettings, the DPC
// implements Callbacks and passes itself to the DWBS so it can call back into it without
// knowing about it.
private Callbacks mCallbacks;
private int mSetting;
private boolean mEnabled;
private boolean mActive;
/**
@@ -79,18 +72,12 @@ public class DisplayWhiteBalanceSettings implements
mLoggingEnabled = false;
mContext = context;
mHandler = new DisplayWhiteBalanceSettingsHandler(handler.getLooper());
mSettingsObserver = new SettingsObserver(mHandler);
mSetting = getSetting();
mActive = false;
mCallbacks = null;
mContext.getContentResolver().registerContentObserver(
Secure.getUriFor(SETTING_URI), false /* notifyForDescendants */, mSettingsObserver,
UserHandle.USER_ALL);
ColorDisplayServiceInternal cds =
LocalServices.getService(ColorDisplayServiceInternal.class);
cds.setDisplayWhiteBalanceListener(this);
mCdsi = LocalServices.getService(ColorDisplayServiceInternal.class);
setEnabled(mCdsi.isDisplayWhiteBalanceEnabled());
final boolean isActive = mCdsi.setDisplayWhiteBalanceListener(this);
setActive(isActive);
}
/**
@@ -99,7 +86,7 @@ public class DisplayWhiteBalanceSettings implements
* @param callbacks
* The object to call back to.
*
* @return Whether the method suceeded or not.
* @return Whether the method succeeded or not.
*/
public boolean setCallbacks(Callbacks callbacks) {
if (mCallbacks == callbacks) {
@@ -131,14 +118,7 @@ public class DisplayWhiteBalanceSettings implements
* @return Whether display white-balance is enabled.
*/
public boolean isEnabled() {
return (mSetting == SETTING_ENABLED) && mActive;
}
/**
* Re-evaluate state after switching to a new user.
*/
public void onSwitchUser() {
handleSettingChange();
return mEnabled && mActive;
}
/**
@@ -152,15 +132,14 @@ public class DisplayWhiteBalanceSettings implements
writer.println(" mLoggingEnabled=" + mLoggingEnabled);
writer.println(" mContext=" + mContext);
writer.println(" mHandler=" + mHandler);
writer.println(" mSettingsObserver=" + mSettingsObserver);
writer.println(" mSetting=" + mSetting);
writer.println(" mEnabled=" + mEnabled);
writer.println(" mActive=" + mActive);
writer.println(" mCallbacks=" + mCallbacks);
}
@Override
public void onDisplayWhiteBalanceStatusChanged(boolean active) {
Message msg = mHandler.obtainMessage(MSG_SET_ACTIVE, active ? 1 : 0, 0);
public void onDisplayWhiteBalanceStatusChanged(boolean activated) {
Message msg = mHandler.obtainMessage(MSG_SET_ACTIVE, activated ? 1 : 0, 0);
msg.sendToTarget();
}
@@ -169,20 +148,14 @@ public class DisplayWhiteBalanceSettings implements
Preconditions.checkNotNull(handler, "handler must not be null");
}
private int getSetting() {
return Secure.getIntForUser(mContext.getContentResolver(), SETTING_URI, SETTING_DEFAULT,
UserHandle.USER_CURRENT);
}
private void handleSettingChange() {
final int setting = getSetting();
if (mSetting == setting) {
private void setEnabled(boolean enabled) {
if (mEnabled == enabled) {
return;
}
if (mLoggingEnabled) {
Slog.d(TAG, "Setting: " + setting);
Slog.d(TAG, "Setting: " + enabled);
}
mSetting = setting;
mEnabled = enabled;
if (mCallbacks != null) {
mCallbacks.updateWhiteBalance();
}
@@ -201,17 +174,6 @@ public class DisplayWhiteBalanceSettings implements
}
}
private final class SettingsObserver extends ContentObserver {
SettingsObserver(Handler handler) {
super(handler);
}
@Override
public void onChange(boolean selfChange, Uri uri) {
handleSettingChange();
}
}
private final class DisplayWhiteBalanceSettingsHandler extends Handler {
DisplayWhiteBalanceSettingsHandler(Looper looper) {
super(looper, null, true /* async */);
@@ -222,6 +184,7 @@ public class DisplayWhiteBalanceSettings implements
switch (msg.what) {
case MSG_SET_ACTIVE:
setActive(msg.arg1 != 0);
setEnabled(mCdsi.isDisplayWhiteBalanceEnabled());
break;
}
}