# MACLOADER
BOARD_HAVE_SAMSUNG_WIFI := true
+# Lineage Hardware
+BOARD_HARDWARE_CLASS := hardware/samsung/lineagehw $(LOCAL_PATH)/lineagehw
--- /dev/null
+/*
+ * Copyright (C) 2017 The LineageOS 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 org.lineageos.hardware;
+
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.util.Slog;
+
+import org.lineageos.internal.util.FileUtils;
+
+public class DisplayColorCalibration {
+
+ private static final String TAG = "DisplayColorCalibration";
+
+ private static final String RGB_FILE = "/sys/class/mdnie/mdnie/sensorRGB";
+
+ private static final boolean sUseGPUMode;
+
+ private static final int MIN = 1;
+ private static final int MAX = 255;
+
+ private static final int[] sCurColors = new int[] { MAX, MAX, MAX };
+
+ static {
+ // We can also support GPU transform using RenderEngine. This is not
+ // preferred though, as it has a high power cost.
+ sUseGPUMode = SystemProperties.getBoolean("debug.livedisplay.force_gpu", false);
+ }
+
+ public static boolean isSupported() {
+ if (!FileUtils.isFileWritable(RGB_FILE) && !sUseGPUMode) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public static int getMaxValue() {
+ return MAX;
+ }
+
+ public static int getMinValue() {
+ return MIN;
+ }
+
+ public static int getDefValue() {
+ return getMaxValue();
+ }
+
+ public static String getCurColors() {
+ if (!sUseGPUMode) {
+ return FileUtils.readOneLine(RGB_FILE);
+ }
+
+ return String.format("%d %d %d", sCurColors[0],
+ sCurColors[1], sCurColors[2]);
+ }
+
+ public static boolean setColors(String colors) {
+ if (!sUseGPUMode) {
+ return FileUtils.writeLine(RGB_FILE, colors);
+ }
+
+ float[] mat = toColorMatrix(colors);
+
+ // set to null if identity
+ if (mat == null ||
+ (mat[0] == 1.0f && mat[5] == 1.0f &&
+ mat[10] == 1.0f && mat[15] == 1.0f)) {
+ return setColorTransform(null);
+ }
+ return setColorTransform(mat);
+ }
+
+ private static float[] toColorMatrix(String rgbString) {
+ String[] adj = rgbString == null ? null : rgbString.split(" ");
+
+ if (adj == null || adj.length != 3) {
+ return null;
+ }
+
+ float[] mat = new float[16];
+
+ // sanity check
+ for (int i = 0; i < 3; i++) {
+ int v = Integer.parseInt(adj[i]);
+
+ if (v >= MAX) {
+ v = MAX;
+ } else if (v < MIN) {
+ v = MIN;
+ }
+
+ mat[i * 5] = (float)v / (float)MAX;
+ sCurColors[i] = v;
+ }
+
+ mat[15] = 1.0f;
+ return mat;
+ }
+
+ /**
+ * Sets the surface flinger's color transformation as a 4x4 matrix. If the
+ * matrix is null, color transformations are disabled.
+ *
+ * @param m the float array that holds the transformation matrix, or null to
+ * disable transformation
+ */
+ private static boolean setColorTransform(float[] m) {
+ try {
+ final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
+ if (flinger != null) {
+ final Parcel data = Parcel.obtain();
+ data.writeInterfaceToken("android.ui.ISurfaceComposer");
+ if (m != null) {
+ data.writeInt(1);
+ for (int i = 0; i < 16; i++) {
+ data.writeFloat(m[i]);
+ }
+ } else {
+ data.writeInt(0);
+ }
+ flinger.transact(1030, data, null, 0);
+ data.recycle();
+ }
+ } catch (RemoteException ex) {
+ Slog.e(TAG, "Failed to set color transform", ex);
+ return false;
+ }
+ return true;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 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 org.lineageos.hardware;
+
+import org.lineageos.internal.util.FileUtils;
+
+/*
+ * Disable capacitive keys
+ *
+ * This is intended for use on devices in which the capacitive keys
+ * can be fully disabled for replacement with a soft navbar. You
+ * really should not be using this on a device with mechanical or
+ * otherwise visible-when-inactive keys
+ */
+
+public class KeyDisabler {
+
+ private static String CONTROL_PATH = "/sys/class/sec/sec_touchkey/input/enabled";
+
+ public static boolean isSupported() {
+ return FileUtils.isFileWritable(CONTROL_PATH);
+ }
+
+ public static boolean isActive() {
+ return (FileUtils.readOneLine(CONTROL_PATH).equals("0"));
+ }
+
+ public static boolean setActive(boolean state) {
+ return FileUtils.writeLine(CONTROL_PATH, (state ? "0" : "1"));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 The CyanogenMod Project
+ * Copyright (C) 2018 The LineageOS 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 org.lineageos.hardware;
+
+import org.lineageos.internal.util.FileUtils;
+
+/**
+ * Sunlight Readability Enhancement support, aka Facemelt Mode.
+ *
+ * Brightens up the screen via image processing or other tricks when
+ * under aggressive lighting conditions. Usually depends on CABC
+ * support.
+ */
+public class SunlightEnhancement {
+
+ private static final String HBM_PATH = "/sys/class/mdnie/mdnie/lux";
+ /* see drivers/video/exynos/decon_7580/panels/mdnie_lite_table*, get_hbm_index */
+ private static final String HBM_MIN_VALUE = "40000";
+
+ /**
+ * Whether device supports SRE
+ *
+ * @return boolean Supported devices must return always true
+ */
+ public static boolean isSupported() {
+ return FileUtils.isFileWritable(HBM_PATH) &&
+ FileUtils.isFileReadable(HBM_PATH);
+ }
+
+ /**
+ * This method return the current activation status of SRE
+ *
+ * @return boolean Must be false when SRE is not supported or not activated, or
+ * the operation failed while reading the status; true in any other case.
+ */
+ public static boolean isEnabled() {
+ return Integer.parseInt(FileUtils.readOneLine(HBM_PATH)) > 0;
+ }
+
+ /**
+ * This method allows to setup SRE.
+ *
+ * @param status The new SRE status
+ * @return boolean Must be false if SRE is not supported or the operation
+ * failed; true in any other case.
+ */
+ public static boolean setEnabled(boolean status) {
+ String value = status ? HBM_MIN_VALUE : "0";
+ return FileUtils.writeLine(HBM_PATH, value);
+ }
+
+ /**
+ * Whether adaptive backlight (CABL / CABC) is required to be enabled
+ *
+ * @return boolean False if adaptive backlight is not a dependency
+ */
+ public static boolean isAdaptiveBacklightRequired() {
+ return false;
+ }
+
+ /**
+ * Set this to true if the implementation is self-managed and does
+ * it's own ambient sensing. In this case, setEnabled is assumed
+ * to toggle the feature on or off, but not activate it. If set
+ * to false, LiveDisplay will call setEnabled when the ambient lux
+ * threshold is crossed.
+ *
+ * @return true if this enhancement is self-managed
+ */
+ public static boolean isSelfManaged() {
+ return false;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 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 org.lineageos.hardware;
+
+import org.lineageos.internal.util.FileUtils;
+
+public class VibratorHW {
+
+ private static String LEVEL_PATH = "/sys/class/timed_output/vibrator/intensity";
+
+ public static boolean isSupported() {
+ return FileUtils.isFileReadable(LEVEL_PATH) && FileUtils.isFileWritable(LEVEL_PATH);
+ }
+
+ public static int getMaxIntensity() {
+ return 10000;
+ }
+
+ public static int getMinIntensity() {
+ return 0;
+ }
+
+ public static int getWarningThreshold() {
+ return 9000;
+ }
+
+ public static int getCurIntensity() {
+ String actualIntensity = FileUtils.readOneLine(LEVEL_PATH).replace("intensity: ", "");
+ return Integer.parseInt(actualIntensity);
+ }
+
+ public static int getDefaultIntensity() {
+ return 7500;
+ }
+
+ public static boolean setIntensity(int intensity) {
+ return FileUtils.writeLine(LEVEL_PATH, String.valueOf(intensity));
+ }
+}