Skip to content

Commit

Permalink
cmsdk: Add initial DisplayMode and AutoContrast support to CMHW
Browse files Browse the repository at this point in the history
Change-Id: I71f3599c64c03efc4b090ea71e583c942d0c03c2
  • Loading branch information
ryzenforce990 authored and hyperb1iss committed Aug 19, 2015
1 parent 5ee87cb commit e18f6d8
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import cyanogenmod.app.CMContextConstants;
import cyanogenmod.hardware.ICMHardwareService;
import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.hardware.DisplayMode;

import java.io.File;

import org.cyanogenmod.hardware.AdaptiveBacklight;
import org.cyanogenmod.hardware.AutoContrast;
import org.cyanogenmod.hardware.ColorEnhancement;
import org.cyanogenmod.hardware.DisplayColorCalibration;
import org.cyanogenmod.hardware.DisplayGammaCalibration;
import org.cyanogenmod.hardware.DisplayModeControl;
import org.cyanogenmod.hardware.HighTouchSensitivity;
import org.cyanogenmod.hardware.KeyDisabler;
import org.cyanogenmod.hardware.LongTermOrbits;
Expand Down Expand Up @@ -71,6 +74,11 @@ private interface CMHardwareInterface {
public String getSerialNumber();

public boolean requireAdaptiveBacklightForSunlightEnhancement();

public DisplayMode[] getDisplayModes();
public DisplayMode getCurrentDisplayMode();
public DisplayMode getDefaultDisplayMode();
public boolean setDisplayMode(DisplayMode mode);
}

private class LegacyCMHardware implements CMHardwareInterface {
Expand Down Expand Up @@ -102,6 +110,10 @@ public LegacyCMHardware() {
mSupportedFeatures |= CMHardwareManager.FEATURE_VIBRATOR;
if (TouchscreenHovering.isSupported())
mSupportedFeatures |= CMHardwareManager.FEATURE_TOUCH_HOVERING;
if (AutoContrast.isSupported())
mSupportedFeatures |= CMHardwareManager.FEATURE_AUTO_CONTRAST;
if (DisplayModeControl.isSupported())
mSupportedFeatures |= CMHardwareManager.FEATURE_DISPLAY_MODES;
}

public int getSupportedFeatures() {
Expand All @@ -124,6 +136,8 @@ public boolean get(int feature) {
return TapToWake.isEnabled();
case CMHardwareManager.FEATURE_TOUCH_HOVERING:
return TouchscreenHovering.isEnabled();
case CMHardwareManager.FEATURE_AUTO_CONTRAST:
return AutoContrast.isEnabled();
default:
Log.e(TAG, "feature " + feature + " is not a boolean feature");
return false;
Expand All @@ -146,6 +160,8 @@ public boolean set(int feature, boolean enable) {
return TapToWake.setEnabled(enable);
case CMHardwareManager.FEATURE_TOUCH_HOVERING:
return TouchscreenHovering.setEnabled(enable);
case CMHardwareManager.FEATURE_AUTO_CONTRAST:
return AutoContrast.setEnabled(enable);
default:
Log.e(TAG, "feature " + feature + " is not a boolean feature");
return false;
Expand Down Expand Up @@ -261,6 +277,22 @@ public String getSerialNumber() {
public boolean requireAdaptiveBacklightForSunlightEnhancement() {
return SunlightEnhancement.isAdaptiveBacklightRequired();
}

public DisplayMode[] getDisplayModes() {
return DisplayModeControl.getAvailableModes();
}

public DisplayMode getCurrentDisplayMode() {
return DisplayModeControl.getCurrentMode();
}

public DisplayMode getDefaultDisplayMode() {
return DisplayModeControl.getDefaultMode();
}

public boolean setDisplayMode(DisplayMode mode) {
return DisplayModeControl.setMode(mode, true);
}
}

private CMHardwareInterface getImpl(Context context) {
Expand Down Expand Up @@ -448,5 +480,49 @@ public boolean requireAdaptiveBacklightForSunlightEnhancement() {
}
return mCmHwImpl.requireAdaptiveBacklightForSunlightEnhancement();
}

@Override
public DisplayMode[] getDisplayModes() {
mContext.enforceCallingOrSelfPermission(
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
if (!isSupported(CMHardwareManager.FEATURE_DISPLAY_MODES)) {
Log.e(TAG, "Display modes are not supported");
return null;
}
return mCmHwImpl.getDisplayModes();
}

@Override
public DisplayMode getCurrentDisplayMode() {
mContext.enforceCallingOrSelfPermission(
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
if (!isSupported(CMHardwareManager.FEATURE_DISPLAY_MODES)) {
Log.e(TAG, "Display modes are not supported");
return null;
}
return mCmHwImpl.getCurrentDisplayMode();
}

@Override
public DisplayMode getDefaultDisplayMode() {
mContext.enforceCallingOrSelfPermission(
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
if (!isSupported(CMHardwareManager.FEATURE_DISPLAY_MODES)) {
Log.e(TAG, "Display modes are not supported");
return null;
}
return mCmHwImpl.getDefaultDisplayMode();
}

@Override
public boolean setDisplayMode(DisplayMode mode) {
mContext.enforceCallingOrSelfPermission(
cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null);
if (!isSupported(CMHardwareManager.FEATURE_DISPLAY_MODES)) {
Log.e(TAG, "Display modes are not supported");
return false;
}
return mCmHwImpl.setDisplayMode(mode);
}
};
}
60 changes: 60 additions & 0 deletions src/java/cyanogenmod/hardware/CMHardwareManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public final class CMHardwareManager {
*/
public static final int FEATURE_TOUCH_HOVERING = 0x800;

/**
* Auto contrast
*/
public static final int FEATURE_AUTO_CONTRAST = 0x1000;

/**
* Display modes
*/
public static final int FEATURE_DISPLAY_MODES = 0x2000;

private static final List<Integer> BOOLEAN_FEATURES = Arrays.asList(
FEATURE_ADAPTIVE_BACKLIGHT,
FEATURE_COLOR_ENHANCEMENT,
Expand All @@ -108,6 +118,7 @@ public final class CMHardwareManager {
FEATURE_SUNLIGHT_ENHANCEMENT,
FEATURE_TAP_TO_WAKE,
FEATURE_TOUCH_HOVERING,
FEATURE_AUTO_CONTRAST
);

private static CMHardwareManager sCMHardwareManagerInstance;
Expand Down Expand Up @@ -417,6 +428,7 @@ private int[] getDisplayGammaCalibrationArray(int idx) {
/**
* @return the number of RGB controls the device supports
*/
@Deprecated
public int getNumGammaControls() {
try {
return getService().getNumGammaControls();
Expand All @@ -430,6 +442,7 @@ public int getNumGammaControls() {
*
* @return the current RGB gamma calibration for the given control
*/
@Deprecated
public int[] getDisplayGammaCalibration(int idx) {
int[] arr = getDisplayGammaCalibrationArray(idx);
if (arr == null || arr.length < 3) {
Expand All @@ -441,13 +454,15 @@ public int[] getDisplayGammaCalibration(int idx) {
/**
* @return the minimum value for all colors
*/
@Deprecated
public int getDisplayGammaCalibrationMin() {
return getArrayValue(getDisplayGammaCalibrationArray(0), GAMMA_CALIBRATION_MIN_INDEX, 0);
}

/**
* @return the maximum value for all colors
*/
@Deprecated
public int getDisplayGammaCalibrationMax() {
return getArrayValue(getDisplayGammaCalibrationArray(0), GAMMA_CALIBRATION_MAX_INDEX, 0);
}
Expand All @@ -462,6 +477,7 @@ public int getDisplayGammaCalibrationMax() {
*
* @return true on success, false otherwise.
*/
@Deprecated
public boolean setDisplayGammaCalibration(int idx, int[] rgb) {
try {
return getService().setDisplayGammaCalibration(idx, rgb);
Expand Down Expand Up @@ -525,4 +541,48 @@ public boolean requireAdaptiveBacklightForSunlightEnhancement() {
}
return false;
}

/**
* @return a list of available display modes on the devices
*/
public DisplayMode[] getDisplayModes() {
try {
return getService().getDisplayModes();
} catch (RemoteException e) {
}
return null;
}

/**
* @return the currently active display mode
*/
public DisplayMode getCurrentDisplayMode() {
try {
return getService().getCurrentDisplayMode();
} catch (RemoteException e) {
}
return null;
}

/**
* @return the default display mode to be set on boot
*/
public DisplayMode getDefaultDisplayMode() {
try {
return getService().getDefaultDisplayMode();
} catch (RemoteException e) {
}
return null;
}

/**
* @return true if setting the mode was successful
*/
public boolean setDisplayMode(DisplayMode mode) {
try {
return getService().setDisplayMode(mode);
} catch (RemoteException e) {
}
return false;
}
}
19 changes: 19 additions & 0 deletions src/java/cyanogenmod/hardware/DisplayMode.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cyanogenmod.hardware;

parcelable DisplayMode;
68 changes: 68 additions & 0 deletions src/java/cyanogenmod/hardware/DisplayMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cyanogenmod.hardware;

import android.os.Parcel;
import android.os.Parcelable;

/*
* Display Modes API
*
* A device may implement a list of preset display modes for different
* viewing intents, such as movies, photos, or extra vibrance. These
* modes may have multiple components such as gamma correction, white
* point adjustment, etc, but are activated by a single control point.
*
* This API provides support for enumerating and selecting the
* modes supported by the hardware.
*
* A DisplayMode is referenced by it's identifier and carries an
* associated name (up to the user to translate this value).
*/
public class DisplayMode implements Parcelable {
public final int id;
public final String name;

public DisplayMode(int id, String name) {
this.id = id;
this.name = name;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(id);
out.writeString(name);
}

/** @hide */
public static final Parcelable.Creator<DisplayMode> CREATOR = new Parcelable.Creator<DisplayMode>() {
public DisplayMode createFromParcel(Parcel in) {
return new DisplayMode(in.readInt(), in.readString());
}

@Override
public DisplayMode[] newArray(int size) {
return new DisplayMode[size];
}
};

}
7 changes: 7 additions & 0 deletions src/java/cyanogenmod/hardware/ICMHardwareService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package cyanogenmod.hardware;

import cyanogenmod.hardware.DisplayMode;

/** @hide */
interface ICMHardwareService {

Expand All @@ -40,4 +42,9 @@ interface ICMHardwareService {
String getSerialNumber();

boolean requireAdaptiveBacklightForSunlightEnhancement();

DisplayMode[] getDisplayModes();
DisplayMode getCurrentDisplayMode();
DisplayMode getDefaultDisplayMode();
boolean setDisplayMode(in DisplayMode mode);
}

0 comments on commit e18f6d8

Please sign in to comment.