Merge "Add display white balance enabled methods to CDS" into qt-dev

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

View File

@@ -391,6 +391,26 @@ public final class ColorDisplayManager {
return mManager.setAppSaturationLevel(packageName, saturationLevel); 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. * 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() { int getColorMode() {
try { try {
return mCdm.getColorMode(); return mCdm.getColorMode();

View File

@@ -42,4 +42,7 @@ interface IColorDisplayManager {
int getColorMode(); int getColorMode();
void setColorMode(int colorMode); 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) { public void onSwitchUser(@UserIdInt int newUserId) {
handleSettingsChange(true /* userSwitch */); handleSettingsChange(true /* userSwitch */);
mBrightnessTracker.onSwitchUser(newUserId); mBrightnessTracker.onSwitchUser(newUserId);
if (mDisplayWhiteBalanceSettings != null) {
mDisplayWhiteBalanceSettings.onSwitchUser();
}
} }
public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats( public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats(

View File

@@ -610,6 +610,15 @@ 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() { private boolean isDisplayWhiteBalanceSettingEnabled() {
if (mCurrentUser == UserHandle.USER_NULL) { if (mCurrentUser == UserHandle.USER_NULL) {
return false; return false;
@@ -1233,6 +1242,13 @@ public final class ColorDisplayService extends SystemService {
return mDisplayWhiteBalanceTintController.isActivated(); 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 * Adds a {@link WeakReference<ColorTransformController>} for a newly started activity, and
* invokes {@link ColorTransformController#applyAppSaturation(float[], float[])} if needed. * invokes {@link ColorTransformController#applyAppSaturation(float[], float[])} if needed.
@@ -1253,7 +1269,7 @@ public final class ColorDisplayService extends SystemService {
* Notify that the display white balance status has changed, either due to preemption by * Notify that the display white balance status has changed, either due to preemption by
* another transform or the feature being turned off. * another transform or the feature being turned off.
*/ */
void onDisplayWhiteBalanceStatusChanged(boolean enabled); void onDisplayWhiteBalanceStatusChanged(boolean activated);
} }
private final class TintHandler extends Handler { private final class TintHandler extends Handler {
@@ -1525,6 +1541,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 @Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) { if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) {

View File

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