what is this or what does it do - G1 Q&A, Help & Troubleshooting

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...

Related

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

Android Empty_App ?

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?

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

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