[Galaxy S Plus I9001 Android Development] Christopher83:
Special features and sysfs settings (Part 1):

Here you can find some useful scripts that can be used with the following described features:

Scripts​

Phantom Key Presses filter

This feature is an attempt to workaround a well known hardware bug of some Samsung devices.

Pratically, the high activity of the radio hardware, in particular the antenna, could cause interference on Melfas chip, which is located very close to the antenna.

This interference could induce bad interrupts that are seen by the chip as possible HOME, MENU or BACK key presses.

These phantom key presses are happening expecially in 2G mode.

The solution includes a new device module (phantom_kp_filter), which also allows the filtering parameters customization, and various changes to cypress-touchkey and pmic8xxx-keypad modules.

The phantom key presses filtering is enabled by default for incoming MENU and BACK touch keys, because for these keys is simpler to recognize a bad interrupt or an invalid key press, instead it's disabled for incoming HOME key (read the next howto infos to enable it).

I also developed a new app to better manage the filtering status and the filtering parameters customization, you can find it on this thread:

Phantom Key Presses Filter Manager​

How to enable/disable the feauture and customize the filtering parameters:

The new device module allows to show the number of ignored key presses and to customize the filtering parameters by means of a sysfs interface, at the following system path: /sys/class/misc/phantom_kp_filter

The interface exposes these files:

home_enabled: show/edit the enable status of the phantom HOME key presses filtering (0 = disabled and 1 = enabled, disabled by default)

home_allowed_irqs: show/edit the allowed max number of incoming interrupts to consider a HOME key press as valid (from 1 to 32, default = 4), a lower value allows to have a more aggressive filtering, instead a higher value allows to have a more permissive filtering

home_report_wait: show/edit the wait time in ms before report the collected HOME key presses (from 5 to 25 ms, default = 12 ms), the key presses during this wait time are collected and reported only if the system received a number of interrupts less than or equal to the allowed max number of incoming interrupts (home_allowed_irqs parameter)

home_ignored_kp: show the ignored possible phantom HOME key presses

menuback_enabled: show/edit the enable status of the phantom MENU and BACK key presses filtering (0 = disabled, 1 = enabled, enabled by default)

menuback_interrupt_checks: show/edit the number of interrupt checks to be performed for the incoming MENU and BACK key presses (from 1 to 10, default = 10), a lower value is more permissive, a higher value securely avoids most of the bad interrupts

menuback_first_err_wait: show/edit the time in ms to wait after the first error on MENU or BACK keys if there are many invalid key errors in rapid sequence (from 50 to 1000 ms, default = 500 ms), the default value is optimal and well tested

menuback_last_err_wait: show/edit the time in ms to wait after the last error on MENU or BACK keys if there are many invalid key errors in rapid sequence (from 50 to 1000 ms, default = 100 ms), the default value is optimal and well tested

menuback_ignored_kp: show the ignored possible phantom MENU and BACK key presses

version: show the module version

To change the filtering parameters:

1) By downloading and using my new app PkfManager

2) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 05pkf_alt

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred filtering parameters (the downloaded script has the default filtering parameter values and enables the phantom HOME key presses filtering)

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By directly editing the files inside /sys/class/misc/phantom_kp_filter (the values you set will be lost after a reboot/shutdown)

4) By using Terminal Emulator (note that set values will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands

su
echo [COLOR="Blue"][I]value[/I][/COLOR] > /sys/class/misc/phantom_kp_filter/[COLOR="Green"][I]parameter_name[/I][/COLOR]

where value is the value you want to set and parameter_name is one of the previously described editable parameters

For example, these commands will enable phantom HOME key presses filtering:

su
echo 1 > /sys/class/misc/phantom_kp_filter/home_enabled

To show the number of ignored key presses (possible phantom key presses):

1) By directly opening the files /sys/class/misc/phantom_kp_filter/home_ignored_kp and /sys/class/misc/phantom_kp_filter/menuback_ignored_kp

2) By using Terminal Emulator

- Open Terminal Emulator

- Run these commands

su
cat /sys/class/misc/phantom_kp_filter/home_ignored_kp
cat /sys/class/misc/phantom_kp_filter/menuback_ignored_kp

Customizable timeout of touchkeys backlight after press

This feature allows to set a customized timeout of touchkeys backlight after a key press or touchscreen press. The default value is 1600 ms.

How to set the timeout of touchkeys backlight:

1) By using the related setting inside System -> Advanced -> Backlight Timeout

2) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 20backlight_timeout

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred timeout (the downloaded script will set the status to 0 = disabled)

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By directly editing the file /sys/class/misc/notification/bl_timeout (the value you set will be lost after a reboot/shutdown)

4) By using Terminal Emulator (note that set values will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands to set the timeout of touchkeys backlight to 1000 ms (1 second)

su
echo 1000 > /sys/class/misc/notification/bl_timeout

Customizable activation status of touchkeys backlight on touchscreen press

This feature allows to enable/disable the touchkeys backlight after a touchscreen press.

How to set the status of touchkeys backlight on touchscreen press:

1) By using the related setting inside System -> Advanced -> Backlight on Touchscreen Press

2) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 25touchlight_status

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred status(the downloaded script will set the status to 0 = disabled)

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By directly editing the file /sys/class/misc/notification/touchlight_enabled (the value you set will be lost after a reboot/shutdown)

4) By using Terminal Emulator (note that set values will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands to disable the touchkeys backlight on touchscreen press

su
echo 0 > /sys/class/misc/notification/touchlight_enabled

- Or run these commands to enable the touchkeys backlight on touchscreen press

su
echo 1 > /sys/class/misc/notification/touchlight_enabled

CPU voltage control VDD sys interface

This feature allows to customize the voltage assumed by each cpu scaling frequency.

It could be useful if you'd like to decrease one or more voltages for battery saving purposes (undervolting), or to increase/adjust them to prevent phone freezes (overvolting).

How to customize the voltages:

1) By downloading and using Trickster MOD or IncrediControl and changing the voltages table inside the SVS tab

2) By using customized init.d scripts (the custom values will be always restored after a reboot, if you don't format the system partition)

- Download one of the script named 01vdd_levels*

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your customized voltages, where each line has this syntax

echo "[I][B][COLOR="Blue"]cpu_freq_HZ[/COLOR][/B][/I] [I][COLOR="SeaGreen"][B]mV[/B][/COLOR][/I]" > /sys/devices/system/cpu/cpu0/cpufreq/vdd_levels

cpu_freq_HZ is the cpu frequency in Hz you'd like to change

mV is the voltage you want to set

For example, the following line means that when the cpu frequency is 1516800 Hz = 1516 MHz, the voltage used will be 1175 mV

echo "1516800 1175" > /sys/devices/system/cpu/cpu0/cpufreq/vdd_levels

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By using Terminal Emulator (note that the values you set will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands

su
# Run a command for each cpu frequency voltage you'd like to change
echo "[I][B][COLOR="Blue"]cpu_freq_HZ[/COLOR][/B][/I] [I][COLOR="SeaGreen"][B]mV[/B][/COLOR][/I]" > /sys/devices/system/cpu/cpu0/cpufreq/vdd_levels

cpu_freq_HZ is the cpu frequency in Hz you'd like to change

mV is the voltage you want to set

For example, the following line means that when the cpu frequency is 1516800 Hz = 1516 MHz, the voltage used will be 1175 mV

echo "1516800 1175" > /sys/devices/system/cpu/cpu0/cpufreq/vdd_levels

Alternative Extreme Undervolted (ExUV) settings

If after overclocking your I9001 you noticed some freezes when on ExUV kernel builds, you may use an alternative extremely undervolted setting with the init.d script you can find here: 01vdd_levels_alt_exuv

- Download the script

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

Customized vibration intensity

This feature has been developed by CastagnaIT and allows to set a customized vibration intensity (121 is the default stock value).

It could be useful if you don't like the stock vibration intensity and you'd like to have a lower / stronger vibration.

The setting will affect the haptic feedback and the notification vibration intensity.

How to set a customized vibration intensity:

1) By using the related setting inside System->Advanced->Vibration (only on CM 10 Beta 4 and next releases)

2) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 10vibetonz

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred vibration intensity (the downloaded script will set the vibration intensity to 70)

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By directly editing the file /sys/class/vibetonz/immDuty/pwmvalue_intensity (the value you set will be lost after a reboot/shutdown)

4) By using Terminal Emulator (note that set values will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands (changing the intensity value = 70 with the preferred one)

su
echo 70 > /sys/class/vibetonz/immDuty/pwmvalue_intensity

Backlight Notification V10 (BLNv10)

This feature allows to notify you of missing calls, messages, emails, etc... by lighting up or blinking the Menu and Back buttons.

With BLNv10 enabled you don't need to unlock the screen to see if you have new notifications.

How to configure the BLNv10:

1) By using new AriesParts (Advanced Settings) or by downloading and using BLN Control Free, BLN Control Pro or NsTools

2) By directly editing the file /sys/class/misc/backlightnotification/enabled and setting 1 to enable the feature, 0 to disable it (note that set value will be lost after a reboot/shutdown)

3) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run this command to enable the feature

su
echo 1 > /sys/class/misc/backlightnotification/enabled

- Run, instead, this command to disable the feature

su
echo 0 > /sys/class/misc/backlightnotification/enabled

Work in progress (init.d, blinking and other settings)...

Force Fast Charge

This feature allows you to force AC charging for any charger that is detected as USB (eg. PC USB ports, USB Car Chargers) and pull the full current the charger can support, in such a way as to speed up the time required for a complete battery recharge.

By enabling this feature, the USB / ADB data transfers will be disabled (security limitation to protect your data).

How to enable/disable the Force Fast Charge:

1) By using the related setting inside System->Advanced->Force Fast Charge (only on CM 10 Beta 3 and next releases)

2) By downloading and using Trickster MOD or IncrediControl or NsTools

2) By directly editing the file /sys/kernel/fast_charge/force_fast_charge and setting 1 to enable the force charge, 0 to disable it (note that set value will be lost after a reboot/shutdown)

3) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run this command to enable the force fast charge feature

su
echo 1 > /sys/kernel/fast_charge/force_fast_charge

- Then, when you want to restore the normal status, run this command to disable the force fast charge feature

su
echo 0 > /sys/kernel/fast_charge/force_fast_charge

4) By using a customized init.d script, but I don't recommend it because you have to remember to disable the feature every time you want to connect your device to a pc for data transfering after every reboot

Battery life extender (BLX)

This feature has been developed by Ezekeel and allows to set a customized battery charging limit (100% is the default stock value, if you want, you can set a lower value).

As Ezekeel said, it is commonly accepted that both very low and very high charge states accelerate the degradation of the battery capacity (that is why you should store Li-Ion batteries at around 40% charge).

If you set a charging limit equal to 100, this feature will be disabled.

How to activate this feature and set a customized charging limit:

1) By downloading and using Trickster MOD or NsTools by setting the customized battery life extender charging limit

2) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 15blx

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred charging limit (the downloaded script will set the charging limit to 95%)

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

3) By directly editing the file /sys/class/misc/batterylifeextender/charging_limit (the value you set will be lost after a reboot/shutdown)

4) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands (changing the charging limit = 95 with the preferred one)

su
echo 95 > /sys/class/misc/batterylifeextender/charging_limit

LowMemoryKiller

The LowMemoryKiller driver is used to kill a selected process and free the memory when it is under one of the defined thresholds.

The tuning of the driver could be achieved by means of two parameters exposed by the kernel module via sysfs interface:

- /sys/module/lowmemorykiller/parameters/minfree

This file includes a comma separated array of the threshold numbers for minfree memory size (in page units).

- /sys/module/lowmemorykiller/parameters/adj

This file includes the comma separated array of oomadj factors, if the corresponding minfree threshold has been reached, one of the process with an oomadj greater than this number will be killed.

The oomadj factor is a property associated to each process, its value is in a range from -17 to +15, the processes with a higher oomadj factor will be the first to be killed when a specific minfree threshold has been reached.

RAM Console

This feature is useful expecially for development and debugging purposes, when occurs kernel panic / unexpected shutdowns or reboots. Pratically, the kernel messages are also stored inside a little RAM portion and restored during reboot after a kernel panic, inside the file /proc/last_kmsg.

Dynamic FSync

This feature has been developed by Faux123 and allows to dynamically manage the synchronous writes performed on file system (FSync).

It uses asynchronous writes when the screen is on, instead of synchronous writes, to have better performance and a slightly lower battery drain, while when the screen is off the synchronous writes are re-enabled to flush all the outstanding writes and prevent possible data loss.

How to enable/disable the Dynamic FSync (default enabled):

1) By downloading and using Trickster MOD

2) By directly editing the file /sys/kernel/dyn_fsync/Dyn_fsync_active and setting 1 to enable the dynamic fsync, 0 to disable it (note that set value will be lost after a reboot/shutdown)

3) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run this command to disable the dynamic fsync feature

su
echo 0 > /sys/kernel/dyn_fsync/Dyn_fsync_active

- Or run this command to re-enable the dynamic fsync feature

su
echo 1 > /sys/kernel/dyn_fsync/Dyn_fsync_active

Dynamic dirty page writebacks

This feature has been developed by me and allows to dynamically manage the dirty page writebacks with two different intervals, one when the screen is on and another when the screen is off.

It is based on a commit of Francisco Franco, but instead of using hard coded values and of disabling at all the dirty page writebacks while the screen is on (possibility of data loss), I preferred to use a customizable higher dirty page writebacks interval (15 seconds) than the default one (5 seconds) while the screen is on and a customizable default interval (5 seconds) when the screen is off.

By using a higher interval we have better performance and less battery consumption, with a very low risk of data loss.

How to customize the dynamic dirty page writebacks feature (default enabled):

Three new procfs parameters are exposed inside /proc/sys/vm path:

- dynamic_dirty_writeback is the activation status of this feature, set 1 to enable it, set 0 to disable it and use the standard behaviour

- dirty_writeback_active_centisecs is the interval for the dirty page writebacks when the system is active (screen on), the default value is 1500 centisecs (15 seconds)

- dirty_writeback_suspend_centisecs is the interval for the dirty page writebacks when the system is suspended (screen off), the default value is 500 centisecs (5 seconds)

In my kernel builds, during boot, I set other customized values:

- an interval of 30 seconds while the screen is on

- an interval of 10 seconds when the screen is off

1) By directly editing one of the file written above inside /proc/sys/vm and setting the preferred value (note that set value will be lost after a reboot/shutdown)

2) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run this command to disable the dynamic dirty page writebacks feature

su
echo 0 > /proc/sys/vm/dynamic_dirty_writeback

- Or run this command to re-enable the dynamic dirty page writebacks feature

su
echo 1 > /proc/sys/vm/dynamic_dirty_writeback

- Run this command to set customize the two intervals (30 seconds while the screen is on, 10 seconds when the screen is off)

su
echo "3000" > /proc/sys/vm/dirty_writeback_active_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_suspend_centisecs