Android Empty_App ? - G1 Q&A, Help & Troubleshooting

Could someone inform me what empty_app is? What is the maximum highest killing value I could set it at?
Thanks in advance.

By the way, are these numbers related? It probably is but I just want someone to confirm.
Code:
# Define the oom_adj values for the classes of processes that can be
# killed by the kernel. These are used in ActivityManagerService.
setprop ro.FOREGROUND_APP_ADJ [COLOR="red"]0[/COLOR]
setprop ro.VISIBLE_APP_ADJ [COLOR="red"]1[/COLOR]
setprop ro.PERCEPTIBLE_APP_ADJ [COLOR="red"]2[/COLOR]
setprop ro.HEAVY_WEIGHT_APP_ADJ [COLOR="red"]3[/COLOR]
setprop ro.SECONDARY_SERVER_ADJ [COLOR="red"]5[/COLOR]
setprop ro.BACKUP_APP_ADJ [COLOR="red"]5[/COLOR]
setprop ro.HOME_APP_ADJ [COLOR="red"]3[/COLOR]
setprop ro.HIDDEN_APP_MIN_ADJ [COLOR="red"]2[/COLOR]
setprop ro.EMPTY_APP_ADJ [COLOR="red"]28[/COLOR]
# Define the memory thresholds at which the above process classes will
# be killed. These numbers are in pages (4k).
setprop ro.FOREGROUND_APP_MEM 256
setprop ro.VISIBLE_APP_MEM 512
setprop ro.PERCEPTIBLE_APP_MEM 4096
setprop ro.HEAVY_WEIGHT_APP_MEM 768
setprop ro.SECONDARY_SERVER_MEM 2048
setprop ro.BACKUP_APP_MEM 2048
setprop ro.HOME_APP_MEM 768
setprop ro.HIDDEN_APP_MEM 1024
setprop ro.EMPTY_APP_MEM 6144
# Enable Anr history , it would output the debuginfo to data partition
# 1: on 0: off
setprop debugtool.anrhistory 1
# Set error receiver
setprop ro.error.receiver.htc.apps com.htc.feedback
# Write value must be consistent with the above properties.
# Note that the driver only supports 6 slots, so we have combined some of
# the classes into the same memory level; the associated processes of higher
# classes will still be killed first.
write /sys/module/lowmemorykiller/parameters/adj [COLOR="Red"]0,1,2,4,7,15[/COLOR]
If so, do I set "0,1,2,4,7,15" to "0,1,2,3,5,28" to match the classes?

Related

what is this or what does it do

CAN ANY ONE TELL ME WHAT THIS MEANS OR WHAT IT IS>>>>>!!!!!!!!!.....
on boot
setprop ARGH ARGH
setprop net.eth0.dns1
setprop net.gprs.local-ip
setprop ro.radio.use-ppp no
setprop ro.build.product generic
setprop ro.product.device generic
# fake some battery state
setprop status.battery.state Slow
setprop status.battery.level 5
setprop status.battery.level_raw 50
setprop status.battery.level_scale 9
# disable some daemons the emulator doesn't want
stop dund
stop akmd
setprop ro.setupwizard.mode EMULATOR
# enable Google-specific location features,
# like NetworkLocationProvider and LocationCollector
setprop ro.com.google.locationfeatures 1
# For the emulator, which bypasses Setup Wizard, you can specify
# account info for the device via these two properties. Google
# Login Service will insert these accounts into the database when
# it is created (ie, after a data wipe).
#
# setprop ro.config.hosted_account [email protected]word
# setprop ro.config.google_account [email protected]word
#
# You MUST have a Google account on the device, and you MAY
# additionally have a hosted account. No other configuration is
# supported, and arbitrary breakage may result if you specify
# something else.
service goldfish-setup /system/etc/init.goldfish.sh
oneshot
service qemud /system/bin/qemud
socket qemud stream 666
oneshot
# -Q is a special logcat option that forces the
# program to check wether it runs on the emulator
# if it does, it redirects its output to the device
# named by the androidboot.console kernel option
# if not, is simply exit immediately
service goldfish-logcat /system/bin/logcat -Q
oneshot
This is a logcat... it lets you know what your phone is doing...

Init.d Scripts

I've been talking with a few people and I've received different info for each. What is wrong with this script? I want to set the new build.prop values via init.d scripts but some think that the way I did it is wrong/i need to correct things. Thanks in advance
Edit: looked up setprop and these are my questions
kifno said:
Looked on google and xda and found nothing about mounting before applying setprop ro.* values using the script I looked at about 8 scripts and they just place setprop ro.* or whatever line they wanted a value applied to. So I still can't figure out why you and say it won't work because the line is read only or already found in the build.prop because again I saw and read plenty of scripts with setprop ro.* and other lines with different values set with setprop that were already in their rom's init.rc or build.prop....so why wouldn't it work?
Click to expand...
Click to collapse
Code:
#!/system/bin/sh
#!/xbin/sh
#
#kifno tweaks
# Network Speed
setprop net.tcp.buffersize.default 4096,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.wifi 4095,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.umts 4094,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.edge 4093,262140,770880,4096,30643,770880;
setprop net.tcp.buffersize.gprs 4094,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.wimax 4094,87380,256960,4096,16384,256960;
setprop ro.ril.hsxpa 2;
setprop ro.ril.gprsclass 8;
setprop ro.ril.hep 1;
setprop ro.ril.enable.dtm 1;
setprop ro.ril.hsdpa.category 24;
setprop ro.ril.enable.a53 1;
setprop ro.ril.enable.3g.prefix 1;
setprop ro.ril.htcmaskw1.bitmask 4294967295;
setprop ro.ril.htcmaskw1 14449;
setprop ro.ril.hsupa.category 3;
setprop wifi.supplicant_scan_interval 200;
echo 256960 > proc/sys/net/core/wmem_max;
echo 256960 > proc/sys/net/core/rmem_max;
echo 256960 > proc/sys/net/core/wmem_default;
echo 256960 > proc/sys/net/core/rmem_default;
echo 4096 16384 256960 > /proc/sys/net/ipv4/tcp_wmem;
echo 4096 87380 256960 > /proc/sys/net/ipv4/tcp_rmem;
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout;
echo 30 > /proc/sys/net/ipv4/tcp_keepalive_intvl;
echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes;
echo 0 > /proc/sys/net/ipv4/tcp_timestamps;
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse;
# Memory Threshold (Process Killing)
setprop ro.FOREGROUND_APP_MEM 1536;
setprop ro.VISIBLE_APP_MEM 3072;
setprop ro.SECONDARY_SERVER_MEM 4096;
setprop ro.BACKUP_APP_MEM 4096;
setprop ro.HOME_APP_MEM 4096;
setprop ro.HIDDEN_APP_MEM 21000;
setprop ro.CONTENT_PROVIDER_MEM 23000;
setprop ro.EMPTY_APP_MEM 25000;
# VM parameters
echo 0 > /proc/sys/vm/swappiness;
echo 0 > /proc/sys/vm/dirty_expire_centisecs;
echo 0 > /proc/sys/vm/dirty_writeback_centisecs;
echo 60 > /proc/sys/vm/dirty_background_ratio;
echo 95 > /proc/sys/vm/dirty_ratio;
echo 10 > /proc/sys/vm/vfs_cache_pressure;
echo 1652 > /proc/sys/vm/min_free_kbytes;
#Boot
MMC=`ls -d /sys/block/mmc*`;
# Optimize NRS
for i in $MMC;
do
echo 0 > $i/queue/rotational;
done;
# Optimize I/O Scheduler
for i in $MMC;
do
echo $IO_SCHEDULER > $i/queue/scheduler;
case $IO_SCHEDULER in
"noop")
echo 1 > $i/queue/iosched/fifo_batch;;
"cfq")
echo 1 > $i/queue/iosched/back_seek_penalty;
echo 0 > $i/queue/iosched/slice_idle;;
"bfq")
echo 1 > $i/queue/iosched/back_seek_penalty;
echo 0 > $i/queue/iosched/slice_idle;;
esac;
done;
# Set "No-op" scheduler for mtdblocks and mmc
for i in `ls -1 /sys/block/mtdblock*` /sys/block/mmcblk0
do
echo "noop" > $i/queue/scheduler
done
# Less Lag When Making Phone Calls
setprop ro.telephony.call_ring.delay 1000;
setprop ro.mot.eri.losalert.delay 1000;
MAX_PHONE()
{
pidphone=`pidof com.android.phone`;
if [ $pidphone ]; # Wait for com.android.phone to start;
then
echo -17 > /proc/$pidphone/oom_adj;
renice -20 $pidphone;
(while [ 1 ];
do
sleep 10;
MAX_PHONE;
done &);
# DF MODs
setprop ro.media.dec.vid.wmv.enabled 1;
setprop ro.media.dec.aud.wma.enabled 1;
setprop ro.media.dec.aud.flac.enabled 1;
setprop ro.media.dec.aud.ape.enabled 0;
setprop ro.media.dec.vid.avi.enabled 1;
setprop ro.media.dec.vid.flv.enabled 0;
setprop ro.media.dec.vid.qt.enabled 0;
setprop ro.media.dec.vid.rm.enabled 0;
setprop video.accelerate.hw 1;
setprop debug.performance.tuning 1;
# miscellaneous
setprop dalvik.vm.startheapsize 8m;
setprop windowsmgr.max_events_per_sec 60;
setprop ro.product.multi_touch_enabled true;
setprop ro.product.max_num_touch 2;
setprop keyguard.no_require_sim true;
setprop debug.sf.hw=1;
setprop ro.opengles.version=131072;
setprop ro.default_usb_mode 2;
setprop ro.qualcomm.proprietary_obex false;
setprop ro.display.width 320;
setprop ro.display.height 960;
As I already mentioned to you several times, you can't overwrite a value that starts with "ro." once it has already been set, no matter the method. And as I've already mentioned to you, half of the properties you're trying to set don't actually do anything. You should really try finding documentation of these properties (or their location in the source code if you can't find that) if you're going to be changing them.
Please don't PM me anymore if you're not even going to listen to my responses. I appreciate that you're trying to do something productive, but you need to spend more time researching and less time "jumping the gun" to make changes.
jasonmaloney said:
As I already mentioned to you several times, you can't overwrite a value that starts with "ro." once it has already been set, no matter the method. And as I've already mentioned to you, half of the properties you're trying to set don't actually do anything. You should really try finding documentation of these properties (or their location in the source code if you can't find that) if you're going to be changing them.
Please don't PM me anymore if you're not even going to listen to my responses. I appreciate that you're trying to do something productive, but you need to spend more time researching and less time "jumping the gun" to make changes.
Click to expand...
Click to collapse
I've been researching A LOT and I've read lots of scripts and I.m learning along the way but I'm working with uncorrupted now on this and I did jump the gun just a tad lol but I'm taking it slow now again thanks for the information you did supply me with

How To Guide How to disable or change the swap device in the Android 12 from ASUS for the Zenfone 8

How to disable or change the swap device in the Android 12 from ASUS for the Zenfone 8
In the original Android 12 from ASUS for the Zenfone 8 a swap device is configured by default:
Code:
ASUS_I006D:/ # getprop ro.product.build.fingerprint
asus/WW_I006D/ASUS_I006D:12/SKQ1.210821.001/31.1010.0411.113:user/release-keys
ASUS_I006D:/ #
ASUS_I006D:/ # getprop ro.product.build.date
Wed Jul 27 02:56:23 CST 2022
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7389499392 223170560 84582400 12218368
-/+ buffers/cache: 7377281024 235388928
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #
Note:
All commands in these instructions must be done by the user root.
To disable the swap device in the Android 12 from ASUS open a shell and execute:
setprop vendor.zram.enable 0
Example:
Code:
ASUS_I006D:/data/adb/workdir/ramdisk # free
total used free shared buffers
Mem: 7612669952 7334137856 278532096 82571264 19410944
-/+ buffers/cache: 7314726912 297943040
Swap: 4294963200 0 4294963200
[email protected]_I006D:/data/adb/workdir/ramdisk #
ASUS_I006D:/ # setprop vendor.zram.enable 0
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7392669696 220000256 84586496 12263424
-/+ buffers/cache: 7380406272 232263680
Swap: 0 0 0
ASUS_I006D:/ #
Note:
To execute the command via adb use
Code:
adb shell su - -c setprop vendor.zram.enable 0
To re-enable the swap device execute as user root :
setprop vendor.zram.enable 1
e.g.
Code:
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7392796672 219873280 84598784 12288000
-/+ buffers/cache: 7380508672 232161280
Swap: 0 0 0
ASUS_I006D:/ #
ASUS_I006D:/ # setprop vendor.zram.enable 1
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7397068800 215601152 84598784 12292096
-/+ buffers/cache: 7384776704 227893248
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #
To change the size of the swap device change the value for the variable
vendor.zram.disksize
and disable and re-enable the swap device. The default unit for the value of the variable vendor.zram.disksize is byte; use the postfix M for megabytes or G for gigabytes.
e.g. to use a swap device with 2 GB do:
Code:
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7398703104 213966848 84631552 12365824
-/+ buffers/cache: 7386337280 226332672
Swap: 4294963200 0 4294963200
ASUS_I006D:/ #
ASUS_I006D:/ # setprop vendor.zram.enable 0
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7394570240 218099712 84631552 12361728
-/+ buffers/cache: 7382208512 230461440
Swap: 0 0 0
ASUS_I006D:/ #
ASUS_I006D:/ # setprop vendor.zram.disksize 2G
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7533645824 79024128 86020096 12369920
-/+ buffers/cache: 7521275904 91394048
Swap: 0 0 0
ASUS_I006D:/ #
ASUS_I006D:/ # setprop vendor.zram.enable 1
ASUS_I006D:/ #
ASUS_I006D:/ # free
total used free shared buffers
Mem: 7612669952 7514472448 98197504 85999616 12374016
-/+ buffers/cache: 7502098432 110571520
Swap: 2147479552 0 2147479552
ASUS_I006D:/ #
Note:
This can also be done in a Magisk script to make the new config for the swap device persistent:
e.g.
Code:
cat <<EOT >/data/adb/service.d/0010reconfigure_swap
#
# change the size of the swap volume to 2 GB
#
setprop vendor.zram.enable 0
setprop vendor.zram.disksize 2G
setprop vendor.zram.enable 1
EOT
chmod 755 /data/adb/service.d/0010reconfigure_swap
Result after a reboot:
Code:
ASUS_I006D:/ $ free
total used free shared buffers
Mem: 7612669952 6047076352 1565593600 58441728 17780736
-/+ buffers/cache: 6029295616 1583374336
Swap: 2147479552 0 2147479552
ASUS_I006D:/ $
To disable the swap device completely via Magisk script use these commands:
Code:
cat <<EOT >/data/adb/service.d/0010disable_swap
#
# disable the swap device
#
setprop vendor.zram.enable 0
EOT
chmod 755 /data/adb/service.d/0010disable_swap
Result after a reboot:
Code:
[email protected]_I006D:/ $ free
total used free shared buffers
Mem: 7612669952 5930426368 1682243584 55574528 17719296
-/+ buffers/cache: 5912707072 1699962880
Swap: 0 0 0
[email protected]_I006D:/ $
Note that this approach does not work in the OmniROM 12 for the ASUS Zenfone 8.
Update 20.09.2022 /bs
see How to create or change a swap device in the OmniROM using Magisk for how to change or disable the swap device in the OmniROM.
Update 04.10.2022 /bs
See How to trigger an action when a property is changed for how to implement enabling or disabling the swap device on ZRAM via a property value in the OmniROM or other OS

How To Guide How to create or change a swap device in the OmniROM using Magisk

How to create or change a swap device in the OmniROM using Magisk
The init script in the OmniROM running on the ASUS Zenfone 8 to create a swap device is:
/vendor/bin/init.asus.zram.sh
This script will create a swap device while booting the OS if that functionality is enabled.
To check if there is a swap device configured use the OS command free:
Code:
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612493824 4732076032 2880417792 12857344 15298560
-/+ buffers/cache: 4716777472 2895716352
Swap: 4294963200 0 4294963200
[email protected]_I006D:/ #
If the result of the script is not okay you can create a Magisk script to correct the config for the swap device.
The script /vendor/bin/init.asus.zram.sh uses the property
vendor.zram.enable
to determine if a swap device should be created and the property
vendor.zram.disksize
for the (new) size for the swap device.
If the property vendor.zram.enable is set to 1 but the property vendor.zram.disksize is not set the script uses a default value for the size of the swap device depending on the amount of installed memory.
To create a swap device via a Magisk Script (or change the config of the swap device created by default) it's sufficient to just set the two properties to the approbiate values and execute the init script , e.g.
Note:
This must be done as user root.
Code:
cat >/data/adb/service.d/0010create_swap_device.sh <<EOT
#!/system/bin/sh
# there is a missing leading slash (/) in one of the commands in the file /vendor/bin/init.asus.zram.sh
# therefor the working directory when executing the script must be /
#
cd /
#
# enable creating the swap device
#
setprop vendor.zram.enable 1
#
# use a 512 MB swap device
# The default unit for vendor.zram.disksize is bytes; use the prefix M for megabytes or G for gigabytes
#
#
# Do not set this property to use the default value for the swap device (which is depending on the installed memory)
#
setprop vendor.zram.disksize 512M
#
# now (re)create the swap device
#
/vendor/bin/init.asus.zram.sh
EOT
chmod 755 /data/adb/service.d/0010create_swap_device.sh
To disable the swap device at all use this Magisk script:
Code:
cat >/data/adb/service.d/0010disable_swap_device.sh <<EOT
#!/system/bin/sh
# there is a missing leading slash (/) in one of the commands in the file /vendor/bin/init.asus.zram.sh
# therefor the working directory when executing the script must be /
#
cd /
#
# enable creating the swap device (-> necessary to delete an existing swap device)
#
setprop vendor.zram.enable 1
# new size for the swap device (0 = do not configure a swap device)
#
setprop vendor.zram.disksize 0
#
# now (re)create the swap device (-> only delete an existing swap device)
#
/vendor/bin/init.asus.zram.sh
EOT
chmod 755 /data/adb/service.d/0010disable_swap_device.sh
Notes:
See https://forum.xda-developers.com/t/...droid-12-from-asus-for-the-zenfone-8.4495085/ for how to reconfigure swap in the Original Android 12 from ASUS for the Zenfone 8
Please note that the device /dev/block/zram0 is created in the RAM but the memory for the device /dev/block/zram0 device is only allocated on demand - e.g.:
Code:
#
# free memory with a free swap device on zram0 with 6 GB is about 2783735808 (about 2 GB)
#
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612489728 4828753920 2783735808 13639680 15556608
-/+ buffers/cache: 4813197312 2799292416
Swap: 6442446848 0 6442446848
[email protected]_I006D:/ #
[email protected]_I006D:/ # setprop vendor.zram.disksize 0
[email protected]_I006D:/ # /vendor/bin/init.asus.zram.sh
[email protected]_I006D:/ #
#
# free memory with no swap device on zram0 is about 2802741248 (about 2 GB)
#
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612489728 4809748480 2802741248 13750272 15577088
-/+ buffers/cache: 4794171392 2818318336
Swap: 0 0 0
[email protected]_I006D:/ #
[email protected]_I006D:/ # setprop vendor.zram.disksize 4G
[email protected]_I006D:/ #
[email protected]_I006D:/ # /vendor/bin/init.asus.zram.sh
Swapspace size: 4194300k, UUID=4a914375-e28f-4181-850a-87cc792eacbe
[email protected]_I006D:/ #
#
# free memory with a free swap device on zram0 with 4 GB is about 2773835776 (about 2 GB)
#
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612489728 4838653952 2773835776 13877248 15581184
-/+ buffers/cache: 4823072768 2789416960
Swap: 4294963200 0 4294963200
[email protected]_I006D:/ #
Update 04.10.2022 /bs
See How to trigger an action when a property is changed for how to implement enabling or disabling the swap device on ZRAM via a property value in the OmniROM or another OS

How To Guide How to trigger an action when a property is changed

How to trigger an action when a property is changed
In Android it's possible to trigger various actions by changing the value of a property.
This feature is quite handy and the implementation using Magisk is not really difficult.
As an example:
In the original Android from ASUS for the Zenfone 8 you can disable and enable the swap on a ZRAM device by changing the value for the property vendor.zram.enable:
e.g.:
To turn the swap on use
Code:
setprop vendor.zram.enable 1
and to turn the swap off use
Code:
setprop vendor.zram.enable 0
To get the current value use
Code:
getprop vendor.zram.enable
or
check the output of the OS command free.
(see How to disable or change the swap device in the Android 12 from ASUS for the Zenfone 8 for details)
This feature is not implemented in the OmniROM for the ASUS Zenfone 8 but quite useful so let's see how to implement it in the OmniROM.
The Triggers and Action for this Android feature are configured in the init.rc files in the root filesystem for the OS (see https://android.googlesource.com/platform/system/core/+/master/init/README.md for details). The root filesystem for Android is read-only mounted so without creating your own Android OS image for the phone it's not possible to add the functionality to the OS.
But we can use the Root Directory Overlay System from Magisk (see https://github.com/topjohnwu/Magisk/blob/master/docs/guides.md for the documentation) to implement it.
The detailed process for creating additional *.rc files for Android via Magisk is described here:
How to run a script at shutdown
Therefore I will not go into the details here. But please read that post before you continue
First we check how this feature is implemented in the Original Android for the Zenfone:
Enabling and disabling the swap device on ZRAM is configured in the .rc file
/vendor/etc/hw/init.asus.debugtool.rc
using these settings in the original Android OS for the Zenfone 8:
Code:
service asus_zram /system/vendor/bin/sh /vendor/bin/init.asus.zram.sh
user root
group root
disabled
seclabel u:r:vendor_qti_init_shell:s0
oneshot
on property:persist.vendor.zram.enable=1
setprop vendor.zram.enable "1"
setprop vendor.zram.disksize ${persist.vendor.zram.disksize}
on property:persist.vendor.zram.enable=0
setprop vendor.zram.enable "0"
setprop vendor.zram.disksize ${persist.vendor.zram.disksize}
on property:vendor.zram.enable=*
start asus_zram
The script used to enable or disable the swap device on ZRAM in the original Android for the Zenfone 8 is:
/vendor/bin/init.asus.zram.sh
The script is quite simple (see also below):
It uses two properties to configure the swap device:
vendor.zram.enable : if this property is set to 1 the script enables the swap device and if the property is set to 0 it disables the swap device
vendor.zram.disksize : the value of this property is the size of the ramdisk.
Now we can implement this feature for the OmniROM:
Note:
All commands must be done as user root in a shell on the phone or in an adb shell
First we check the prerequisites for the feature:
The used shell for the service exists in the OmniROM:
Code:
[email protected]_I006D:/data/adb/workdir # ls -Zl /vendor/bin/sh
-rwxr-xr-x 1 root shell u:object_r:vendor_shell_exec:s0 318216 2009-01-01 01:00 /vendor/bin/sh
[email protected]_I006D:/data/adb/workdir #
The script to toggle the ramdisk on the swap device also already exists in the OmniROM:
Code:
[email protected]_I006D:/data/adb/test # ls -l /vendor/bin/init.asus.zram.sh
-rwxr-xr-x 1 root shell 1127 2009-01-01 01:00 /vendor/bin/init.asus.zram.sh
[email protected]_I006D:/data/adb/test #
And the necessary SELinux contexts are also already defined in the OmniROM.
So, let's start:
Code:
# create a temporary directory
#
mkdir /data/adb/workdir
cd /data/adb/workdir
# create the additional .rc file
#
cat >init.asus.zram.rc <<-\EOT
#
# Note:
#
# The service definition for an OS without the script init.asus.zram.sh should be
#
# service asus_zram /system/bin/sh /system/sbin/init.asus.zram.sh
#
service asus_zram /system/vendor/bin/sh /vendor/bin/init.asus.zram.sh
user root
group root
disabled
seclabel u:r:vendor_qti_init_shell:s0
oneshot
#
# these properties can be used to define the initial state of the ramdisk on ZRAM
#
on property:persist.vendor.zram.enable=1
setprop vendor.zram.enable "1"
setprop vendor.zram.disksize ${persist.vendor.zram.disksize}
on property:persist.vendor.zram.enable=0
setprop vendor.zram.enable "0"
setprop vendor.zram.disksize ${persist.vendor.zram.disksize}
on property:vendor.zram.enable=*
start asus_zram
# The property persist.vendor.zram.enable is not defined in the OmniROM. If necessary you can add another triger in the .rc file,
# e.g to enable the swap device by default use
#
on early-init
setprop persist.vendor.zram.enable 1
EOT
# get the current active slot
#
CURRENT_SLOT=$( getprop ro.boot.slot_suffix )
echo "The current active slot is: ${CURRENT_SLOT}"
# copy the boot partition from the active slot to a file
dd if=/dev/block/by-name/boot${CURRENT_SLOT} of=./boot_root.img
# unpack the image file
/data/adb/magisk/magiskboot unpack ./boot_root.img
# add the new dir and file to the ramdisk from the boot partition
/data/adb/magisk/magiskboot cpio ramdisk.cpio \
"mkdir 0700 overlay.d" \
"add 0700 overlay.d/init.custom.rc init.asus.zram.rc"
# recreate the image file for the boot partition
/data/adb/magisk/magiskboot repack boot_root.img
# write the corrected image file to the boot partition
dd if=./new-boot.img of=/dev/block/by-name/boot${CURRENT_SLOT}
That's it.
After the next reboot switching the ramdisk on the ZRAM device via an property should be active:
Code:
[email protected]_I006D:/ # reboot
# .....
# start a new adb session
# ....
[email protected]_I006D:/ $ getprop ro.omni.version
12-20220703-zenfone8-MICROG
#
# Note: The property is only visible to the user root
#
[email protected]_I006D:/ $ su -
[email protected]_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
[email protected]_I006D:/ #
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612493824 4835229696 2777264128 14585856 14487552
-/+ buffers/cache: 4820742144 2791751680
Swap: 4294963200 0 4294963200
[email protected]_I006D:/ #
[email protected]_I006D:/ # getprop vendor.zram.enable
1
[email protected]_I006D:/ #
# -> now disable the swap on ZRAM
[email protected]_I006D:/ # setprop vendor.zram.enable 0
[email protected]_I006D:/ #
[email protected]_I006D:/ # getprop vendor.zram.enable
0
[email protected]_I006D:/ #
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612493824 4840824832 2771668992 14524416 14483456
-/+ buffers/cache: 4826341376 2786152448
Swap: 0 0 0
[email protected]_I006D:/ #
# -> now enable the swap on ZRAM again
[email protected]_I006D:/ # setprop vendor.zram.enable 1
[email protected]_I006D:/ #
[email protected]_I006D:/ # getprop vendor.zram.enable
1
[email protected]_I006D:/ #
[email protected]_I006D:/ # free
total used free shared buffers
Mem: 7612493824 4844777472 2767716352 14524416 14512128
-/+ buffers/cache: 4830265344 2782228480
Swap: 4294963200 0 4294963200
[email protected]_I006D:/ #
Workarounds for other configuration
Find below some workarounds for OS versions without the prerequisites for implementing this feature.
1. The script to toggle the swap /vendor/bin/init.asus.zram.sh does not exist
If the script /vendor/bin/init.asus.zram.sh does not exist in your OS create a Magisk Module for the script
To create a (dummy) Magisk Module for the script do:
Code:
mkdir -p /data/adb/modules/toggle_ram/system/bin
#
# create the script to toggle the ramdisk on ZRAM
#
cat >/data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh <<-\EOT
lahaina_set=`getprop vendor.asus.zram_setting`
if test "$lahaina_set" != "1"; then
echo "[asus_zram] init.kernel.post_boot-lahaina.sh not finished yet!"> /dev/kmsg
exit 0
fi
disksize=`getprop vendor.zram.disksize`
zram_enable=`getprop vendor.zram.enable`
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
let RamSizeGB="( $MemTotal / 1048576 ) + 1"
if test "$disksize" = ""; then
disksize="4096M"
fi
echo "[asus_zram]RamSizeGB=${RamSizeGB}" > /dev/kmsg
if test "$zram_enable" = "1"; then
if [ $RamSizeGB -le 7 ]; then #this is for 6G; or the value will be 4G(8G,12G,16G,18G,etc)
disksize="( $RamSizeGB * 1024 ) / 2""M"
fi
swapoff /dev/block/zram0 2>/dev/kmsg
echo 1 > sys/block/zram0/reset 2>/dev/kmsg
sleep 1
echo lz4 > /sys/block/zram0/comp_algorithm
echo $disksize > /sys/block/zram0/disksize 2>/dev/kmsg
mkswap /dev/block/zram0 2>/dev/kmsg
swapon /dev/block/zram0 -p 32758 2>/dev/kmsg
echo "[asus_zram]write zram disksize=${disksize}" > /dev/kmsg
fi
if test "$zram_enable" = "0"; then
swapoff /dev/block/zram0 2>/dev/kmsg
echo "[asus_zram]turn off the zram" > /dev/kmsg
fi
EOT
chmod 755 /data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh
chown root:shell /data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh
chcon u:object_r:vendor_file:s0 /data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh
Check the result:
Code:
[email protected]_I006D:/ # ls -lZ /data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh
-rwxr-xr-x 1 root shell u:object_r:vendor_file:s0 1109 2022-10-03 21:14 /data/adb/modules/toggle_ram/system/bin/init.asus.zram.sh
[email protected]_I006D:/ #
Then change the script to execute in the service definition in the .rc file to /system/bin/init.asus.zram.sh:
Code:
service asus_zram /system/vendor/bin/sh /system/bin/init.asus.zram.sh
The rest of the instructions can be be used without changes.
2. The binary /system/vendor/bin/sh does not exist
If the shell /system/vendor/bin/sh does not exist in the OS create an Magisk Module with an approbiate shell:
Note:
The shell /system/bin/sh can not be used because it's configured with another SELinux context:
Code:
[email protected]_I006D:/ # ls -lZ /system/vendor/bin/sh
-rwxr-xr-x 1 root shell u:object_r:vendor_shell_exec:s0 318216 2009-01-01 01:00 /system/vendor/bin/sh
[email protected]_I006D:/ #
# but
[email protected]_I006D:/data/adb/workdir # ls -Zl /system/bin/sh
-rwxr-xr-x 1 root shell u:object_r:shell_exec:s0 307768 2009-01-01 01:00 /system/bin/sh
[email protected]_I006D:/data/adb/workdir #
To create a (dummy) Magisk Module for the necessary shell do:
Code:
mkdir -p /data/adb/modules/vendorshell/system/bin
cp /system/bin/sh /data/adb/modules/vendorshell/system/bin/sh
chcon u:object_r:vendor_shell_exec:s0 /data/adb/modules/vendorshell/system/bin/vendor_sh
Check the result:
Code:
[email protected]_I006D:/data/adb/workdir # ls -lZ /data/adb/modules/vendorshell/system/bin/vendor_sh
-rwxr-xr-x 1 root root u:object_r:vendor_shell_exec:s0 307768 2022-10-03 20:41 /data/adb/modules/vendorshell/system/bin/vendor_sh
[email protected]_I006D:/data/adb/workdir #
Now change the shell in the service definition in the .rc file to /system/bin/vendor_sh:
Code:
service asus_zram /system/bin/vendor_sh /vendor/bin/init.asus.zram.sh
The rest of the instructions can be be used without changes.
3. The necessary shell /system/vendor/bin/sh and the script /vendor/bin/init.asus.zram.sh do both not exist
If the necessary shell /system/vendor/bin/sh and the script /vendor/bin/init.asus.zram.sh do not exist you can also create one (dummy) Magisk module for both.
See
https://topjohnwu.github.io/Magisk/guides.html
and
Some hints for using Magisk on Android phones
for instructions and infos about how to create a real Magisk Module
4. Missing SELinux contexts
These instructions assume that all necessary SELinux contexts are already defined in the used OS.
If there are SELinux contexts missing it might not work without adding the missing SELinux contexts
(that might be difficult and I must admit that I did not test that)
5. only for the records:
The magiskboot command can also be used to add new files to the /sbin directory in the root filesystem.
This can be can be configured like this:
Code:
/data/adb/magisk/magiskboot cpio ramdisk.cpio \
"mkdir 0700 overlay.d" \
"add 0700 overlay.d/init.custom.rc init.asus.zram.rc" \
"mkdir 0700 overlay.d/sbin" \
"add 0700 overlay.d/sbin/my_new_script.sh my_script.sh"
This is useful for adding binaries or scripts for actions that should be executed while the other partitions are not yet mounted and therefor the files in these filesystems not yet available. But for the action defined in this post this is not necessary.
And be aware that the files added to the root filesystem ( /sbin/my_new_script.sh in this example) is only available while booting the phone.
6. Other problems
In case of problems please check the post
How to run a script at shutdown
again.
Also check the restrictions for this approach documented in that post
History
06.10.2022 /bs
corrected some typos

Categories

Resources