How To Guide How to create or change a swap device in the OmniROM using Magisk - ASUS ZenFone 8

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

Related

help please: set up swap w/o a2sd [pretty stumped at this point]

im trying to set up a linux_swap partition, but i dont want to use apps2sd, nor do i want to use cache2sd.
can someone point me in the right direction?
kchau said:
im trying to set up a linux_swap partition, but i dont want to use apps2sd, nor do i want to use cache2sd.
can someone point me in the right direction?
Click to expand...
Click to collapse
Just create the linux-swap partition and not the ext partition.
will i have to wipe?
and what is the recommended size?
supremeteam256 said:
Just create the linux-swap partition and not the ext partition.
Click to expand...
Click to collapse
Does that work now? I know it depends on how you are doing it, but assuming a build with auto apps2sd, the script just looks at partition number and will screw up if you do that. I think cyanogen has made adjustments in his experimental line.
im running cyanogen 4.0.4. will it work?
kchau said:
im running cyanogen 4.0.4. will it work?
Click to expand...
Click to collapse
if the script does that couldnt you create a 1mb ext2/3/4?
You also need to edit the user.conf file.
linux_swap_en=1 # enable(1) or disable(0) linux swap
linux_swap_partition=/dev/block/mmcblk0p2 # swap partition device
The usual setting is mmcblk0p3 but you need to set it to mmcblk0p2 because your linus swap part is going to be 2 instead of 3
This is for swap only with no compcache
#compcache related parameters
compcache{
compcache_en=0 # enable(1) or disable(0) compcache
cc_disksize=32 # Ram swap disksize - any number between 1 to 95 should work
cc_memlimit=18 # Limite the memory usage when backing swap is used
cc_backingswap_en=0 # enable or disable backing swap
cc_backingswap=/dev/block/mmcblk0p2 # pointing to the backingswap partition device
cc_swappiness=60 # default 60
}
#Linux swap parameters
#
# linux swap can only be enabled if cc_backingswap_en is set to "0"
#
linux_swap{
linux_swap_en=1 # enable(1) or disable(0) linux swap
linux_swap_partition=/dev/block/mmcblk0p2 # swap partition device
swappiness=60 # default 60
}
will compcache improve speed while running background applications?
so do i have to create an ext3 partition to put the userconf in there?
wait, where do i put the user.conf file then?
i read around and i think im supposed to put the user.conf file into /system/sd
i also enabled compcache. let me know if that is not advised.
with a 64mb swap
#compcache related parameters
compcache{
compcache_en=1 # enable(1) or disable(0) compcache
cc_disksize=70 # Ram swap disksize - any number between 1 to 95 should work
cc_memlimit=18 # Limite the memory usage when backing swap is used
cc_backingswap_en=0 # enable or disable backing swap
cc_backingswap=/dev/block/mmcblk0p2 # pointing to the backingswap partition device
cc_swappiness=60 # default 60
}
#Linux swap parameters
#
# linux swap can only be enabled if cc_backingswap_en is set to "0"
#
linux_swap{
linux_swap_en=1 # enable(1) or disable(0) linux swap
linux_swap_partition=/dev/block/mmcblk0p2 # swap partition device
swappiness=60 # default 60
}
i have an issue with a boot loop at th eandroid screen now
ok, so, if i dont boot with the sd card inserted, it boots, but then i get to the home screen and it says none of my apps are installed.
so i go to recovery, remove the user.conf file. and same thing
so i restore, and boot with the sd card in. same thing, bootloop.
and now im restoring, but not booting with sd card.
what happened? was i not supposed to enable compcache? or keep the cc_disksize at 32?
so, ive been following this thread
http://forum.xda-developers.com/showthread.php?p=4379172
with this a2sd, it doesnt boot:
Code:
#!/system/bin/sh
#
# Apps2SD using symlinks and bind mounts
# [email protected] (cyanogen)
#
echo "--- Welcome to Android/CyanogenMod!";
sysctl -p
# execute any postinstall script then kill it
if [ -e /data/firstboot.sh ];
then
echo "--- Executing firstboot.sh";
/system/bin/sh /data/firstboot.sh;
rm -f /data/firstboot.sh;
fi;
if [ -e /dev/block/mmcblk0p2 ];
then
echo "--- Checking ext filesystems";
# fsck the sdcard filesystem first
e2fsck -y /dev/block/mmcblk0p4;
# set property with exit code in case an error occurs
setprop cm.e2fsck.errors $?;
# mount and set perms
busybox mount -o noatime,nodiratime -t auto /dev/block/mmcblk0p4 /system/sd;
busybox chown 1000:1000 /system/sd;
busybox chmod 771 /system/sd;
# clean up any old symlinks, create data directories
for i in dalvik-cache data;
do
if [ -h /data/$i ];
then
rm /data/$i;
fi;
if [ ! -d /data/$i ];
then
mkdir /data/$i;
busybox chown 1000:1000 /data/$i;
busybox chmod 771 /data/$i;
fi;
done;
# don't allow /data/data on sd because of upgrade issues - move it if possible
if [ -d /system/sd/data ];
then
busybox cp -a /system/sd/data/* /data/data/;
busybox rm -rf /system/sd/data;
fi;
# move apps and dalvik cache from internal memory to sdcard
for i in app app-private dalvik-cache;
do
if [ ! -d /system/sd/$i ];
then
mkdir /system/sd/$i;
fi
busybox chown 1000:1000 /system/sd/$i;
busybox chmod 771 /system/sd/$i
if [ -d /data/$i ] && [ ! -h /data/$i ];
then
busybox cp -a /data/$i/* /system/sd/$i/;
busybox rm -f /data/$i/*;
fi;
done;
# symlink app dirs - they must be on the same filesystem
for i in app app-private;
do
if [ -d /data/$i ] && [ ! -h /data/$i ];
then
busybox rm -rf /data/$i;
busybox ln -s /system/sd/$i /data/$i;
fi;
done;
# bind mount dalvik-cache so we can still boot without the sdcard
busybox mount -o bind /system/sd/dalvik-cache /data/dalvik-cache;
busybox chown 1000:1000 /data/dalvik-cache;
busybox chmod 771 /data/dalvik-cache;
# clean up old whiteouts
for i in local misc property system tombstones data;
do
if [ -h /system/sd/$i ]; then rm -f /system/sd/$i; fi
done;
# please don't put odex files in the app directory people!
# it causes dexopt to crash when switching builds!
busybox rm -f /system/sd/app/*.odex
# call a userinit.sh script if it's present on the sdcard
# otherwise just enable compcache with no backing swap
if [ -e /system/sd/userinit.sh ];
then
echo "--- Executing userinit.sh"
busybox chmod +x /system/sd/userinit.sh
/system/bin/sh /system/sd/userinit.sh;
else
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
fi
setprop cm.a2sd.active 1;
echo "+++ Apps-to-SD successfully enabled";
else
# replace symlinks with directories so we can boot without sd
for i in app app-private;
do
if [ -h /data/$i ];
then
rm -f /data/$i;
mkdir /data/$i;
busybox chown 1000:1000 /data/$i;
busybox chmod 771 /data/$i;
fi;
done;
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
setprop cm.a2sd.active 0;
fi;
sync;
setprop cm.filesystem.ready 1;
with this a2sd, no swap shows up when i go adb shell free:
Code:
#!/system/bin/sh
#
# Apps2SD using symlinks and bind mounts
# [email protected] (cyanogen)
#
echo "--- Welcome to Android/CyanogenMod!";
sysctl -p
# execute any postinstall script then kill it
if [ -e /data/firstboot.sh ];
then
echo "--- Executing firstboot.sh";
/system/bin/sh /data/firstboot.sh;
rm -f /data/firstboot.sh;
fi;
if [ -e /dev/block/mmcblk0p2 ];
then
echo "--- Checking ext filesystems";
# fsck the sdcard filesystem first
e2fsck -y /dev/block/mmcblk0p2;
# set property with exit code in case an error occurs
setprop cm.e2fsck.errors $?;
# mount and set perms
busybox mount -o noatime,nodiratime -t auto /dev/block/mmcblk0p2 /system/sd;
busybox chown 1000:1000 /system/sd;
busybox chmod 771 /system/sd;
fi;
sync;
setprop cm.filesystem.ready 1;
and with the default a2sd, no boot.
and this is my user.conf
Code:
# General parameters
general{
apps2sd=0 # this is useless here, require a modified a2sd script
media2sd=0 # moves the medias to sd if /system/sd/media exists
}
#compcache related parameters
compcache{
compcache_en=1 # enable(1) or disable(0) compcache
cc_disksize=70 # Ram swap disksize - any number between 1 to 95 should work
cc_memlimit=18 # Limit the memory usage for backing swap (cc .5x known issue-defaults to 15% of total RAM)
cc_backingswap_en=0 # enable(1) or disable(0) backing swap
cc_backingswap=/dev/block/mmcblk0p2 # pointing to the backingswap partition device
cc_swappiness=60 # default 60
}
#Linux swap parameters
#
# linux swap can only be enabled if cc_backingswap_en is set to "0"
#
linux_swap{
linux_swap_en=1 # enable(1) or disable(0) linux swap
linux_swap_partition=/dev/block/mmcblk0p2 # swap partition device
swappiness=60 # default 60
}
partition 1 is my fat32 which is whatever 8 gigs minus 64
partition 2 is 64 megs of linux_swap
WOW,
You have completely over complicated this. remove the user.conf file from every location you put it in, remove all partitions and leave it with none, boot in recovery and wipe, then reflash cyan 4.0.4. reboot. everything should be normal with no swap and it should ask you if you want to format the sd card. when you get it working normal post back here.
my whole point is not to wipe, and i dont want a2sd.
wiping and doing what you said above will enable a2sd.
what part of my previous post would enable apps2sd?
if you don't want to wipe, then at least do everything else i posted
ok, i removed all the user.conf and repartitioned my sdcard
now what?
reflash cyan 4.0.4 and boot so it will format the card
what is the make, size, and class of your sdcard?
why no apps2sd?

unable to boot SD. sideload_2.2_update.npk issue? (black screen for >5min between on and boot)

I'm using the wonderfully organized files from amaces' box to image an sd card for BNVT400/hummingbird. After dd-ing the .img file, the Nook seems to try to boot from it. But, after 6 minutes of a black screen, it boots into stock normally. From the stock android I can see SD card contents -- it's mounted and has the files I expect it to.
Notably, before considering a custom ROM, I recently factory reset. Because the stock setup wizard failed with an internet connectivity issue (re: TLS<1.2), I followed B&N's instructions and updated with sideload_2.2_update.npk
Even after additional factory resets, the software version remains 2.2.1
I've read in a few places (e.g leapinlar;s tips) that SD boot isn't a sure thing. I've tried maybe 10 times across 2 days. With and without powering on via USB cable. (and via adb reboot and adb reboot bootloader). That's overkill right?
Is there something obvious I missed?
Thanks!
_________
Bash:
sudo dd if=sdcard-reco-hummingbird.img of=/dev/sdd bs=1M status=progress
# 933232640 bytes (933 MB, 890 MiB) copied, 58 s, 16.1 MB/s
# 900+0 records in
# 900+0 records out
# 943718400 bytes (944 MB, 900 MiB) copied, 81.4684 s, 11.6 MB/s
SD card is formatted w/ only partition as Fat32 with boot flag, and with first file MLO
Bash:
sudo fdisk -l /dev/sdd
# Disk /dev/sdd: 7.5 GiB, 8057257984 bytes, 15736832 sectors
# Disk model: MassStorageClass
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disklabel type: dos
# Disk identifier: 0x5387f638
#
# Device Boot Start End Sectors Size Id Type
# /dev/sdd1 * 59 1757963 1757905 858.4M c W95 FAT32 (LBA)
sudo mount /dev/sdd1 /mnt/usb -o uid=1000
stat -c "%y %n" /mnt/usb/*|sort
# 2013-06-10 15:49:44.000000000 -0400 /mnt/usb/MLO
# 2013-06-10 15:49:56.000000000 -0400 /mnt/usb/u-boot.bin
# 2014-01-19 18:22:28.000000000 -0500 /mnt/usb/ramdisk.cwm
# 2016-02-13 14:48:20.000000000 -0500 /mnt/usb/ramdisk.stock
# 2016-02-13 14:50:58.000000000 -0500 /mnt/usb/OLD
# 2016-04-03 13:35:56.000000000 -0400 /mnt/usb/kernel
# 2016-04-03 13:35:56.000000000 -0400 /mnt/usb/ramdisk
# 2016-04-03 13:35:56.000000000 -0400 /mnt/usb/uImage
# added zips to flash. but never get to use them :(
cp lnos_hummingbird-ota-NJH47F.181223.zip twrp-2.8.7.5-hummingbird.zip addonsu-14.1-arm.zip /mnt/usb/
eject /mnt/usb
As a sanity check: when the sd boot fails, I confirmed the files on the SD card are readable by the Nook. and that the Nook is in fact BNVT400/hummingbird.
Bash:
aft-mtp-cli ls
# selected storage 131073 SD Card
# 155 MLO
# 156 u-boot.bin
# 157 ramdisk.stock
# 158 ramdisk
# 159 kernel
# 160 ramdisk.cwm
# 161 OLD
# 164 lnos_hummingbird-ota-NJH47F.181223.zip
# 165 twrp-2.8.7.5-hummingbird.zip
# 166 uImage
# 167 addonsu-14.1-arm.zip
# 168 B&N Downloads
# 173 My Files
adb shell cat /proc/cpuinfo
# Processor : ARMv7 Processor rev 10 (v7l)
# processor : 0
# BogoMIPS : 789.24
# processor : 1
# BogoMIPS : 792.89
# Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3
# CPU implementer : 0x41
# CPU architecture: 7
# CPU variant : 0x2
# CPU part : 0xc09
# CPU revision : 10
# Hardware : OMAP4 Hummingbird board
# Revision : 0006

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

Magisk Module Keylayout for ps4 controller [HELP]

Hello, I'm new here so please excuse me if I post this in the wrong section.
I have a OnePlus 7t on Android 11 with Magisk installed.
I am trying to swap the R3 with Circle on my controller. In the keylayout file it shows that R3 is in fact Circle but doesn't work in games. ( Reverts to default controller mapping)
I have already edited and successfully changed the keylayout file for my PS4 Controller ( Vendor_054c_Product_09cc.kl ) by creating a magisk module since I'm on a stock Os and cant copy the .kl file over to system/usr/keylayouts . SEE BELOW
Code:
# Copyright (C) 2017 The Android Open Source 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.
#
# Sony Playstation(R) DualShock 4 Controller
#
# Mapping according to https://developer.android.com/training/game-controllers/controller-input.html
# Square
key 0x130 BUTTON_X
# Cross
key 0x131 BUTTON_A
# Circle
key 0x132 BUTTON_THUMBR
# Triangle
key 0x133 BUTTON_Y
key 0x134 BUTTON_L1
key 0x135 BUTTON_R1
key 0x136 BUTTON_L2
key 0x137 BUTTON_R2
# L2 axis
axis 0x03 LTRIGGER
# R2 axis
axis 0x04 RTRIGGER
# Left Analog Stick
axis 0x00 X
axis 0x01 Y
# Right Analog Stick
axis 0x02 Z
axis 0x05 RZ
# Left stick click
key 0x13a BUTTON_THUMBL
# Right stick click
key 0x13b BUTTON_B
# Hat
axis 0x10 HAT_X
axis 0x11 HAT_Y
# Mapping according to https://www.kernel.org/doc/Documentation/input/gamepad.txt
# Share
key 0x138 BUTTON_SELECT
# Options
key 0x139 BUTTON_START
# PS key
key 0x13c BUTTON_MODE
# Touchpad press
# The touchpad for this joystick will become a separate input device in future releases
# and this button will be equivalent to left mouse button
# Therefore, map it to KEYCODE_BUTTON_1 here to allow apps to still handle this on earlier versions
key 0x13d BUTTON_1
I've made sure the permissions are set correctly as well as seen in the install.sh
Code:
##########################################################################################
#
# Magisk Module Installer Script
#
##########################################################################################
##########################################################################################
#
# Instructions:
#
# 1. Place your files into system folder (delete the placeholder file)
# 2. Fill in your module's info into module.prop
# 3. Configure and implement callbacks in this file
# 4. If you need boot scripts, add them into common/post-fs-data.sh or common/service.sh
# 5. Add your additional or modified system properties into common/system.prop
#
##########################################################################################
##########################################################################################
# Config Flags
##########################################################################################
# Set to true if you do *NOT* want Magisk to mount
# any files for you. Most modules would NOT want
# to set this flag to true
SKIPMOUNT=false
# Set to true if you need to load system.prop
PROPFILE=false
# Set to true if you need post-fs-data script
POSTFSDATA=false
# Set to true if you need late_start service script
LATESTARTSERVICE=false
##########################################################################################
# Replace list
##########################################################################################
# List all directories you want to directly replace in the system
# Check the documentations for more info why you would need this
# Construct your list in the following format
# This is an example
REPLACE_EXAMPLE="
/system/app/Youtube
/system/priv-app/SystemUI
/system/priv-app/Settings
/system/framework
"
# Construct your own list here
REPLACE="/system/usr/keylayout/Vendor_054c_Product_09cc.kl"
##########################################################################################
#
# Function Callbacks
#
# The following functions will be called by the installation framework.
# You do not have the ability to modify update-binary, the only way you can customize
# installation is through implementing these functions.
#
# When running your callbacks, the installation framework will make sure the Magisk
# internal busybox path is *PREPENDED* to PATH, so all common commands shall exist.
# Also, it will make sure /data, /system, and /vendor is properly mounted.
#
##########################################################################################
##########################################################################################
#
# The installation framework will export some variables and functions.
# You should use these variables and functions for installation.
#
# ! DO NOT use any Magisk internal paths as those are NOT public API.
# ! DO NOT use other functions in util_functions.sh as they are NOT public API.
# ! Non public APIs are not guranteed to maintain compatibility between releases.
#
# Available variables:
#
# MAGISK_VER (string): the version string of current installed Magisk
# MAGISK_VER_CODE (int): the version code of current installed Magisk
# BOOTMODE (bool): true if the module is currently installing in Magisk Manager
# MODPATH (path): the path where your module files should be installed
# TMPDIR (path): a place where you can temporarily store files
# ZIPFILE (path): your module's installation zip
# ARCH (string): the architecture of the device. Value is either arm, arm64, x86, or x64
# IS64BIT (bool): true if $ARCH is either arm64 or x64
# API (int): the API level (Android version) of the device
#
# Availible functions:
#
# ui_print <msg>
# print <msg> to console
# Avoid using 'echo' as it will not display in custom recovery's console
#
# abort <msg>
# print error message <msg> to console and terminate installation
# Avoid using 'exit' as it will skip the termination cleanup steps
#
# set_perm <target> <owner> <group> <permission> [context]
# if [context] is empty, it will default to "u:object_r:system_file:s0"
# this function is a shorthand for the following commands
# chown owner.group target
# chmod permission target
# chcon context target
#
# set_perm_recursive <directory> <owner> <group> <dirpermission> <filepermission> [context]
# if [context] is empty, it will default to "u:object_r:system_file:s0"
# for all files in <directory>, it will call:
# set_perm file owner group filepermission context
# for all directories in <directory> (including itself), it will call:
# set_perm dir owner group dirpermission context
#
##########################################################################################
##########################################################################################
# If you need boot scripts, DO NOT use general boot scripts (post-fs-data.d/service.d)
# ONLY use module scripts as it respects the module status (remove/disable) and is
# guaranteed to maintain the same behavior in future Magisk releases.
# Enable boot scripts by setting the flags in the config section above.
##########################################################################################
# Set what you want to display when installing your module
print_modname() {
ui_print "*******************************"
ui_print " Ps4 Controller Crouch Fix "
ui_print "*******************************"
}
# Copy/extract your module files into $MODPATH in on_install.
on_install() {
# The following is the default implementation: extract $ZIPFILE/system to $MODPATH
# Extend/change the logic to whatever you want
ui_print "- Extracting module files"
unzip -o "$ZIPFILE" 'system/*' -d $MODPATH >&2
ui_print "- deleting package cache"
rm -rf /data/system/package_cache/*
}
# Only some special files require specific permissions
# This function will be called after on_install is done
# The default permissions should be good enough for most cases
set_permissions() {
# The following is the default rule, DO NOT remove
set_perm_recursive $MODPATH 0 0 0755 0644
set_perm $MODPATH/system/usr/keylayout/Vendor_054c_Product_09cc.kl 0 0 0744
# Here are some examples:
# set_perm_recursive $MODPATH/system/lib 0 0 0755 0644
# set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0
# set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0
# set_perm $MODPATH/system/lib/libart.so 0 0 0644
}
# You can add more functions to assist your custom script code
So basically everything seems to be correct but yet in games and gamepad tester the control functions as default ( R3 is not circle)
I've attached images showing im rooted and have the module succesfully installed and enabled, also showing the permissions of the .kl file in the keylayout folder.
Please help! and thank you in advance.

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