sdm660-common: XiaomiParts: add notification LED brightness slider

Signed-off-by: Dušan Uverić <dusan.uveric9@gmail.com>
Change-Id: I86851420cca27d34e36f8e385859c5be63545bba
This commit is contained in:
Dušan Uverić 2020-04-15 15:43:56 +02:00 committed by OdSazib
parent b0fa4e9f51
commit 3476f16be6
No known key found for this signature in database
GPG key ID: CB336514F9F5CF69
7 changed files with 64 additions and 0 deletions

View file

@ -22,6 +22,10 @@
<!-- KCal -->
<string name="device_kcal_title">Display Color Calibration</string>
<!-- Notification LED brightness -->
<string name="notification_title">Notification LED</string>
<string name="notification_led_title">LED brightness</string>
<!-- Ambient Display -->
<string name="ambient_display_xiaomi">Xiaomi Doze</string>
<string name="advanced_doze_summary">Ambient Display</string>

View file

@ -28,6 +28,17 @@
app:units="%" />
</PreferenceCategory>
<PreferenceCategory
android:key="notification_led"
android:title="@string/notification_title">
<org.lineageos.settings.device.preferences.NotificationLedSeekBarPreference
android:key="notification_led_brightness"
android:title="@string/notification_led_title"
android:max="64"
app:min="1"
android:defaultValue="64" />
</PreferenceCategory>
<PreferenceCategory
android:key="display"
android:title="@string/display_title">

View file

@ -53,6 +53,8 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
PREF_HUE, HUE_DEFAULT));
}
FileUtils.setValue(DeviceSettings.NOTIF_LED_PATH, Settings.Secure.getInt(
context.getContentResolver(), DeviceSettings.PREF_NOTIF_LED, 64));
FileUtils.setValue(DeviceSettings.VIBRATION_STRENGTH_PATH, Settings.Secure.getInt(
context.getContentResolver(), DeviceSettings.PREF_VIBRATION_STRENGTH, 80) / 100.0 * (DeviceSettings.MAX_VIBRATION - DeviceSettings.MIN_VIBRATION) + DeviceSettings.MIN_VIBRATION);
FileUtils.setValue(DeviceSettings.THERMAL_PATH, Settings.Secure.getString(

View file

@ -27,6 +27,7 @@ import org.lineageos.settings.device.kcal.KCalSettingsActivity;
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;
public class DeviceSettings extends PreferenceFragment implements
Preference.OnPreferenceChangeListener {
@ -34,6 +35,10 @@ public class DeviceSettings extends PreferenceFragment implements
public static final String PREF_VIBRATION_STRENGTH = "vibration_strength";
public static final String VIBRATION_STRENGTH_PATH = "/sys/devices/virtual/timed_output/vibrator/vtg_level";
public static final String CATEGORY_NOTIF = "notification_led";
public static final String PREF_NOTIF_LED = "notification_led_brightness";
public static final String NOTIF_LED_PATH = "/sys/class/leds/white/max_brightness";
// value of vtg_min and vtg_max
public static final int MIN_VIBRATION = 116;
public static final int MAX_VIBRATION = 3596;
@ -62,6 +67,12 @@ public class DeviceSettings extends PreferenceFragment implements
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences_xiaomi_parts, rootKey);
if (FileUtils.fileWritable(NOTIF_LED_PATH)) {
NotificationLedSeekBarPreference notifLedBrightness =
(NotificationLedSeekBarPreference) findPreference(PREF_NOTIF_LED);
notifLedBrightness.setOnPreferenceChangeListener(this);
} else { getPreferenceScreen().removePreference(findPreference(CATEGORY_NOTIF)); }
VibrationSeekBarPreference vibrationStrength = (VibrationSeekBarPreference) findPreference(PREF_VIBRATION_STRENGTH);
vibrationStrength.setEnabled(FileUtils.fileWritable(VIBRATION_STRENGTH_PATH));
vibrationStrength.setOnPreferenceChangeListener(this);
@ -121,6 +132,10 @@ public class DeviceSettings extends PreferenceFragment implements
public boolean onPreferenceChange(Preference preference, Object value) {
final String key = preference.getKey();
switch (key) {
case PREF_NOTIF_LED:
FileUtils.setValue(NOTIF_LED_PATH, (int) value);
break;
case PREF_VIBRATION_STRENGTH:
double vibrationValue = (int) value / 100.0 * (MAX_VIBRATION - MIN_VIBRATION) + MIN_VIBRATION;
FileUtils.setValue(VIBRATION_STRENGTH_PATH, vibrationValue);

View file

@ -0,0 +1,26 @@
package org.lineageos.settings.device.preferences;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;
import org.lineageos.settings.device.FileUtils;
public class NotificationLedSeekBarPreference extends SecureSettingCustomSeekBarPreference {
public static final String NOTIF_LED_PATH = "/sys/class/leds/white/brightness";
public NotificationLedSeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
notifyChanged();
FileUtils.setValue(NOTIF_LED_PATH, 64);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
notifyChanged();
FileUtils.setValue(NOTIF_LED_PATH, 0);
}
}

View file

@ -44,6 +44,10 @@
/sys/devices/platform/kcal_ctrl.0(/.*)? u:object_r:kcal_dev:s0
/sys/bus/platform/drivers/kcal_ctrl(/.*)? u:object_r:kcal_dev:s0
# Notification LED
/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/white/max_brightness u:object_r:sysfs_graphics:s0
/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/white/brightness u:object_r:sysfs_graphics:s0
# Light HAL
/(vendor|system/vendor)/bin/hw/android\.hardware\.light@2\.0-service\.xiaomi_sdm660 u:object_r:hal_light_default_exec:s0

View file

@ -9,6 +9,8 @@ allow system_app sysfs_thermal:file rw_file_perms;
allow system_app sysfs_thermal:dir search;
allow system_app sysfs_vibrator:file rw_file_perms;
allow system_app sysfs_vibrator:dir search;
allow system_app sysfs_graphics:dir search;
allow system_app sysfs_graphics:file rw_file_perms;
allow system_app sysfs_leds:dir search;
set_prop(system_app, system_prop);