Commit e15c7526 authored by odsazib's avatar odsazib Committed by prady

sdm660-common: Add headphone & mic gain to XiaomiPart

* This is manually ported by me from Lavender tree on Corvus-Devices
* Thanks Stylogey for reviewing the java code and giving me a better solution
* Original repo: https://github.com/Corvus-Devices/device_xiaomi_lavender.git

To get it working, you need these commits in your kernel:
>https://github.com/OdSazib/kernel_xiaomi_sdm660/commit/1d82c9f77ae281245062a8c631094a49be165084
>https://github.com/OdSazib/kernel_xiaomi_sdm660/commit/b96114ceaf5183b59bf9ef149a157629adcc6f77Signed-off-by: odsazib's avatarOdSazib <odsazib@gmail.com>
Change-Id: I1bb48ced1f23728daa2e5170647ce08a04347110
parent b829cb47
<!-- drawable/headphone-settings.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path android:fillColor="#000" android:pathData="M12,1A9,9 0 0,1 21,10V17A3,3 0 0,1 18,20H15V12H19V10A7,7 0 0,0 12,3A7,7 0 0,0 5,10V12H9V20H6A3,3 0 0,1 3,17V10A9,9 0 0,1 12,1M15,24V22H17V24H15M11,24V22H13V24H11M7,24V22H9V24H7Z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:pathData="M0 0h24v24H0V0z" />
<path
android:fillColor="#000000"
android:pathData="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1-9c0-0.55 0.45 -1 1-1s1 0.45 1 1v6c0 0.55-0.45 1-1 1s-1-0.45-1-1V5zm6 6c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-0.49 6-3.39 6-6.92h-2z" />
</vector>
......@@ -2,9 +2,12 @@
<resources>
<declare-styleable name="CustomSeekBarPreference">
<attr name="interval" format="integer" />
<attr name="showSign" format="boolean" />
<attr name="min" format="integer" />
<attr name="max" format="integer" />
<attr name="units" format="string|reference" />
<attr name="defaultText" format="string|reference" />
<attr name="showSign" format="boolean" />
<attr name="continuousUpdates" format="boolean" />
</declare-styleable>
</resources>
......@@ -19,6 +19,10 @@
<string name="display_title">Display</string>
<!-- Audio amplification -->
<string name="headphone_gain">Headphone gain</string>
<string name="mic_gain">Microphone gain</string>
<!-- Mi Note 3 Settings -->
<string name="jason_pref_title">Device Settings</string>
<string name="jason_pref_summary">Mi Note 3 extra settings</string>
......
......@@ -103,6 +103,53 @@
android:icon="@drawable/ic_thermal" />
</PreferenceCategory>
<PreferenceCategory
android:key="audio"
android:title="@string/audio_title">
<org.lineageos.settings.device.preferences.SecureSettingSwitchPreference
android:defaultValue="false"
android:key="dirac_enabled"
android:summary="@string/dirac_summary"
android:title="@string/dirac_title"
android:icon="@drawable/ic_dirac" />
<org.lineageos.settings.device.preferences.SecureSettingListPreference
android:defaultValue="0"
android:dependency="dirac_enabled"
android:entries="@array/dirac_headset_pref_entries"
android:entryValues="@array/dirac_headset_pref_values"
android:key="dirac_headset_pref"
android:summary="%s"
android:title="@string/dirac_headset_title"
android:icon="@drawable/ic_headphones" />
<org.lineageos.settings.device.preferences.SecureSettingListPreference
android:defaultValue="0,0,0,0,0,0,0"
android:dependency="dirac_enabled"
android:entries="@array/dirac_preset_pref_entries"
android:entryValues="@array/dirac_preset_pref_values"
android:key="dirac_preset_pref"
android:summary="%s"
android:title="@string/dirac_preset_title"
android:icon="@drawable/ic_preset" />
<org.lineageos.settings.device.preferences.CustomSeekBarPreference
android:defaultValue="0"
android:key="headphone_gain"
android:max="10"
app:min="-20"
android:icon="@drawable/ic_headphone"
android:title="@string/headphone_gain"/>
<org.lineageos.settings.device.preferences.CustomSeekBarPreference
android:defaultValue="0"
android:key="mic_gain"
android:max="18"
app:min="-10"
android:icon="@drawable/ic_mic"
android:title="@string/mic_gain"/>
</PreferenceCategory>
<PreferenceCategory
android:key="hall_wakeup"
android:title="@string/hall_wakeup_title">
......
......@@ -27,6 +27,9 @@ import org.lineageos.settings.device.kcal.Utils;
public class BootReceiver extends BroadcastReceiver implements Utils {
public static final String HEADPHONE_GAIN_PATH = "/sys/kernel/sound_control/headphone_gain";
public static final String MIC_GAIN_PATH = "/sys/kernel/sound_control/mic_gain";
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
......@@ -57,6 +60,12 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
PREF_HUE, HUE_DEFAULT));
}
int gain = Settings.Secure.getInt(context.getContentResolver(),
DeviceSettings.PREF_HEADPHONE_GAIN, 0);
FileUtils.setValue(HEADPHONE_GAIN_PATH, gain + " " + gain);
FileUtils.setValue(MIC_GAIN_PATH, Settings.Secure.getInt(context.getContentResolver(),
DeviceSettings.PREF_MIC_GAIN, 0));
FileUtils.setValue(DeviceSettings.NOTIF_LED_PATH, Settings.Secure.getInt(
context.getContentResolver(), DeviceSettings.PREF_NOTIF_LED, 100) / 100.0 * (DeviceSettings.MAX_LED - DeviceSettings.MIN_LED) + DeviceSettings.MIN_LED);
FileUtils.setValue(DeviceSettings.VIBRATION_STRENGTH_PATH, Settings.Secure.getInt(
......
......@@ -33,6 +33,7 @@ import org.lineageos.settings.device.preferences.SecureSettingListPreference;
import org.lineageos.settings.device.preferences.SecureSettingSwitchPreference;
import org.lineageos.settings.device.preferences.VibrationSeekBarPreference;
import org.lineageos.settings.device.preferences.NotificationLedSeekBarPreference;
import org.lineageos.settings.device.preferences.CustomSeekBarPreference;
public class DeviceSettings extends PreferenceFragment implements
Preference.OnPreferenceChangeListener {
......@@ -46,6 +47,11 @@ public class DeviceSettings extends PreferenceFragment implements
public static final String PREF_NOTIF_LED = "notification_led_brightness";
public static final String NOTIF_LED_PATH = "/sys/class/leds/white/max_brightness";
public static final String PREF_HEADPHONE_GAIN = "headphone_gain";
public static final String PREF_MIC_GAIN = "mic_gain";
public static final String HEADPHONE_GAIN_PATH = "/sys/kernel/sound_control/headphone_gain";
public static final String MIC_GAIN_PATH = "/sys/kernel/sound_control/mic_gain";
// value of vtg_min and vtg_max
public static final int MIN_VIBRATION = 116;
public static final int MAX_VIBRATION = 3596;
......@@ -92,6 +98,21 @@ public class DeviceSettings extends PreferenceFragment implements
vibrationStrength.setOnPreferenceChangeListener(this);
} else { getPreferenceScreen().removePreference(findPreference(CATEGORY_VIBRATOR)); }
// Headphone Gain
CustomSeekBarPreference headphoneGain = (CustomSeekBarPreference) findPreference(PREF_HEADPHONE_GAIN);
if (FileUtils.fileWritable(HEADPHONE_GAIN_PATH)) {
headphoneGain.setOnPreferenceChangeListener(this);
} else {
getPreferenceScreen().removePreference(headphoneGain);
}
// Mic Gain
CustomSeekBarPreference micGain = (CustomSeekBarPreference) findPreference(PREF_MIC_GAIN);
if (FileUtils.fileWritable(MIC_GAIN_PATH)) {
micGain.setOnPreferenceChangeListener(this);
} else {
getPreferenceScreen().removePreference(micGain);
}
PreferenceCategory displayCategory = (PreferenceCategory) findPreference(CATEGORY_DISPLAY);
if (isAppNotInstalled(DEVICE_DOZE_PACKAGE_NAME)) {
displayCategory.removePreference(findPreference(PREF_DEVICE_DOZE));
......@@ -140,6 +161,14 @@ public class DeviceSettings extends PreferenceFragment implements
FileUtils.setValue(VIBRATION_STRENGTH_PATH, vibrationValue);
break;
case PREF_HEADPHONE_GAIN:
FileUtils.setValue(HEADPHONE_GAIN_PATH, value + " " + value);
break;
case PREF_MIC_GAIN:
FileUtils.setValue(MIC_GAIN_PATH, (int) value);
break;
case PREF_THERMAL:
mTHERMAL.setValue((String) value);
mTHERMAL.setSummary(mTHERMAL.getEntry());
......
......@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.*;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
......
......@@ -21,6 +21,12 @@ on boot
chown system system /sys/module/hall/parameters/hall_toggle
chmod 0660 /sys/module/hall/parameters/hall_toggle
# Audio Amplification
chown system system /sys/kernel/sound_control/headphone_gain
chown system system /sys/kernel/sound_control/mic_gain
chmod 0660 /sys/kernel/sound_control/headphone_gain
chmod 0660 /sys/kernel/sound_control/mic_gain
# KCal
chown system system /sys/devices/platform/kcal_ctrl.0/kcal_cont
chown system system /sys/devices/platform/kcal_ctrl.0/kcal_enable
......
......@@ -23,6 +23,9 @@ type hall_dev, sysfs_type, fs_type;
# Kcal
type kcal_dev, sysfs_type, fs_type;
type thermal_data_file, file_type, data_file_type;
# XiaomiPart
type sysfs_fpsinfo, sysfs_type, fs_type;
type sysfs_headphonegain, sysfs_type, fs_type;
type sysfs_micgain, sysfs_type, fs_type;
......@@ -42,3 +42,7 @@ genfscon sysfs /touchpanel u:object_r:sysfs
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/button-backlight u:object_r:sysfs_graphics:s0
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/button-backlight1 u:object_r:sysfs_graphics:s0
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/white u:object_r:sysfs_graphics:s0
# XiaomiParts
genfscon sysfs /kernel/sound_control/headphone_gain u:object_r:sysfs_headphonegain:s0
genfscon sysfs /kernel/sound_control/mic_gain u:object_r:sysfs_micgain:s0
......@@ -12,6 +12,8 @@ allow system_app sysfs_vibrator:dir search;
allow system_app sysfs_fpsinfo:file rw_file_perms;
allow system_app sysfs:file { read open getattr };
allow system_app sysfs_kgsl:lnk_file read;
allow system_app sysfs_headphonegain:file rw_file_perms;
allow system_app sysfs_micgain:file rw_file_perms;
allow system_app sysfs_graphics:dir search;
allow system_app sysfs_graphics:file rw_file_perms;
allow system_app sysfs_leds:dir search;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment