Merge "Add a SystemApi to control display saturation." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
49c27f2267
@@ -57,6 +57,7 @@ package android {
|
||||
field public static final java.lang.String CONFIGURE_DISPLAY_BRIGHTNESS = "android.permission.CONFIGURE_DISPLAY_BRIGHTNESS";
|
||||
field public static final java.lang.String CONNECTIVITY_INTERNAL = "android.permission.CONNECTIVITY_INTERNAL";
|
||||
field public static final java.lang.String CONNECTIVITY_USE_RESTRICTED_NETWORKS = "android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS";
|
||||
field public static final java.lang.String CONTROL_DISPLAY_SATURATION = "android.permission.CONTROL_DISPLAY_SATURATION";
|
||||
field public static final java.lang.String CONTROL_INCALL_EXPERIENCE = "android.permission.CONTROL_INCALL_EXPERIENCE";
|
||||
field public static final java.lang.String CONTROL_LOCATION_UPDATES = "android.permission.CONTROL_LOCATION_UPDATES";
|
||||
field public static final java.lang.String CONTROL_VPN = "android.permission.CONTROL_VPN";
|
||||
@@ -1252,6 +1253,7 @@ package android.hardware.display {
|
||||
method public android.hardware.display.BrightnessConfiguration getDefaultBrightnessConfiguration();
|
||||
method public android.graphics.Point getStableDisplaySize();
|
||||
method public void setBrightnessConfiguration(android.hardware.display.BrightnessConfiguration);
|
||||
method public void setSaturationLevel(float);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -534,6 +534,19 @@ public final class DisplayManager {
|
||||
return mGlobal.getWifiDisplayStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level of color saturation to apply to the display.
|
||||
* @param level The amount of saturation to apply, between 0 and 1 inclusive.
|
||||
* 0 produces a grayscale image, 1 is normal.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.CONTROL_DISPLAY_SATURATION)
|
||||
public void setSaturationLevel(float level) {
|
||||
mGlobal.setSaturationLevel(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a virtual display.
|
||||
*
|
||||
|
||||
@@ -384,6 +384,17 @@ public final class DisplayManagerGlobal {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level of color saturation to apply to the display.
|
||||
*/
|
||||
public void setSaturationLevel(float level) {
|
||||
try {
|
||||
mDm.setSaturationLevel(level);
|
||||
} catch (RemoteException ex) {
|
||||
throw ex.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
public VirtualDisplay createVirtualDisplay(Context context, MediaProjection projection,
|
||||
String name, int width, int height, int densityDpi, Surface surface, int flags,
|
||||
VirtualDisplay.Callback callback, Handler handler, String uniqueId) {
|
||||
|
||||
@@ -65,6 +65,9 @@ interface IDisplayManager {
|
||||
// Requires CONFIGURE_DISPLAY_COLOR_MODE
|
||||
void requestColorMode(int displayId, int colorMode);
|
||||
|
||||
// Requires CONTROL_DISPLAY_SATURATION
|
||||
void setSaturationLevel(float level);
|
||||
|
||||
// Requires CAPTURE_VIDEO_OUTPUT, CAPTURE_SECURE_VIDEO_OUTPUT, or an appropriate
|
||||
// MediaProjection token for certain combinations of flags.
|
||||
int createVirtualDisplay(in IVirtualDisplayCallback callback,
|
||||
|
||||
@@ -3121,6 +3121,12 @@
|
||||
<permission android:name="android.permission.CONFIGURE_DISPLAY_COLOR_MODE"
|
||||
android:protectionLevel="signature" />
|
||||
|
||||
<!-- Allows an application to control the color saturation of the display.
|
||||
@hide
|
||||
@SystemApi -->
|
||||
<permission android:name="android.permission.CONTROL_DISPLAY_SATURATION"
|
||||
android:protectionLevel="signature|privileged" />
|
||||
|
||||
<!-- Allows an application to collect usage infomation about brightness slider changes.
|
||||
<p>Not for use by third-party applications.</p>
|
||||
@hide
|
||||
|
||||
@@ -695,6 +695,27 @@ public final class DisplayManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
private void setSaturationLevelInternal(float level) {
|
||||
if (level < 0 || level > 1) {
|
||||
throw new IllegalArgumentException("Saturation level must be between 0 and 1");
|
||||
}
|
||||
float[] matrix = (level == 1.0f ? null : computeSaturationMatrix(level));
|
||||
DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class);
|
||||
dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_SATURATION, matrix);
|
||||
}
|
||||
|
||||
private static float[] computeSaturationMatrix(float saturation) {
|
||||
float desaturation = 1.0f - saturation;
|
||||
float[] luminance = {0.231f * desaturation, 0.715f * desaturation, 0.072f * desaturation};
|
||||
float[] matrix = {
|
||||
luminance[0] + saturation, luminance[0], luminance[0], 0,
|
||||
luminance[1], luminance[1] + saturation, luminance[1], 0,
|
||||
luminance[2], luminance[2], luminance[2] + saturation, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
return matrix;
|
||||
}
|
||||
|
||||
private int createVirtualDisplayInternal(IVirtualDisplayCallback callback,
|
||||
IMediaProjection projection, int callingUid, String packageName, String name, int width,
|
||||
int height, int densityDpi, Surface surface, int flags, String uniqueId) {
|
||||
@@ -1686,6 +1707,19 @@ public final class DisplayManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
public void setSaturationLevel(float level) {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
Manifest.permission.CONTROL_DISPLAY_SATURATION,
|
||||
"Permission required to set display saturation level");
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
setSaturationLevelInternal(level);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
public int createVirtualDisplay(IVirtualDisplayCallback callback,
|
||||
IMediaProjection projection, String packageName, String name,
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.server.display;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.IActivityManager;
|
||||
import android.opengl.Matrix;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
@@ -28,7 +27,6 @@ import android.util.Log;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -45,6 +43,10 @@ public class DisplayTransformManager {
|
||||
* Color transform level used by Night display to tint the display red.
|
||||
*/
|
||||
public static final int LEVEL_COLOR_MATRIX_NIGHT_DISPLAY = 100;
|
||||
/**
|
||||
* Color transform level used to adjust the color saturation of the display.
|
||||
*/
|
||||
public static final int LEVEL_COLOR_MATRIX_SATURATION = 150;
|
||||
/**
|
||||
* Color transform level used by A11y services to make the display monochromatic.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user