# Chipset-specific file
import /vendor/etc/init/hw/init.mmi.chipset.rc

# Target-specific file
import /vendor/etc/init/hw/init.mmi.overlay.rc

on early-boot
    write /sys/module/subsystem_restart/parameters/disable_restart_work 0x0

on init
    chown system log /proc/driver/mmi_annotate
    chmod 0640 /proc/driver/mmi_annotate

on early-init
    # Need to wait for platform path for UTAGs driver to succeed
    wait /dev/block/platform/soc/${ro.boot.bootdevice}/by-name/hw

    # initialize ro.vendor.mot.factory with default value when it is not set
    setprop ro.vendor.mot.factory false

    # If utags driver is DLKM, script will load it,
    # otherwise it has to be already loaded
    exec_start vendor.oem-hw-sh

    # Map oem properties, this must follow
    # execution of vendor.oem-hw-sh to set
    # required properties.
    setprop ro.sf.lcd_density ${ro.boot.lcd_density}
    setprop ro.vendor.fsg-id ${ro.boot.fsg-id}
    setprop ro.vendor.hw.device ${ro.boot.device}
    setprop ro.vendor.hw.hwrev ${ro.boot.hwrev}
    setprop ro.vendor.hw.modelno ${ro.boot.modelno}
    setprop ro.vendor.hw.revision ${ro.boot.revision}
    setprop ro.vendor.hw.nav_keys ${ro.boot.nav_keys}
    setprop ro.product.vendor.device ${ro.vendor.product.device}
    setprop ro.product.vendor.name ${ro.vendor.product.name}
    setprop ro.product.vendor.model ${ro.vendor.product.model}
    setprop ro.vendor.boot.cid ${ro.boot.cid}
    setprop ro.vendor.boot.powerup_reason ${ro.boot.powerup_reason}
    setprop ro.vendor.boot.bl_state ${ro.boot.bl_state}
    setprop ro.vendor.boot.serialno ${ro.boot.serialno}
    setprop ro.vendor.zygote ${ro.zygote}
    setprop persist.radio.multisim.config ${persist.vendor.radio.multisim.config}

    # Make sure ro.boot.product.hardware.sku is set before hwservicemanager startup.
    setprop ro.boot.product.hardware.sku ${ro.vendor.product.hardware.sku.variant}

    # Trigger priority stage of MMI init
    trigger mmi-priority

    # Log kernel wake-up source
    write /sys/module/msm_show_resume_irq/parameters/debug_mask 1

on fs
    insmod /vendor/lib/modules/cci_intf.ko
    mkdir /mnt/vendor/persist/fps 0770 system system
    exec_start vendor.ident-fps-sh

on fs && property:ro.vendor.hw.modem_version=*
    # Super modem detection
    exec_start vendor.oem-super-image-detector-sh

on property:ro.vendor.hw.super_image_failure=yes
    setprop sys.powerctl reboot,recovery

on post-fs && property:ro.vendor.hw.modem_super_image=yes
    umount /vendor/firmware_mnt
    mount ext4 /dev/block/bootdevice/by-name/modem${ro.boot.slot_suffix} /vendor/super_modem ro nosuid nodev context=u:object_r:firmware_file:s0
    mount ext4 loop@/vendor/super_modem/${ro.vendor.hw.modem_mount_file} /vendor/firmware_mnt ro nosuid nodev context=u:object_r:firmware_file:s0

on post-fs && property:ro.vendor.hw.fsg_super_image=yes
    umount /vendor/fsg
    mount ext4 /dev/block/bootdevice/by-name/fsg${ro.boot.slot_suffix} /vendor/super_fsg ro nosuid nodev context=u:object_r:fsg_file:s0
    mount ext4 loop@/vendor/super_fsg/${ro.vendor.hw.fsg_mount_file} /vendor/fsg ro nosuid nodev context=u:object_r:fsg_file:s0

on post-fs
    mkdir /mnt/vendor/persist/camera 0755 vendor_tcmd vendor_tcmd
    mkdir /mnt/vendor/persist/camera/dualcal 0775 camera vendor_tcmd
    mkdir /mnt/vendor/persist/camera/focus 0775 camera vendor_tcmd
    mkdir /mnt/vendor/persist/camera/ledcal 0775 camera vendor_tcmd
    mkdir /mnt/vendor/persist/camera/mot_ledcal 0775 camera camera
    mkdir /mnt/vendor/persist/camera/mot_gyrocal 0775 camera camera
    mkdir /mnt/vendor/persist/batt_health 0775 vendor_pwric vendor_pwric
    mkdir /mnt/vendor/persist/mdm 0770 radio radio
    mkdir /mnt/vendor/persist/factory 0755 vendor_tcmd vendor_tcmd
    mkdir /mnt/vendor/persist/factory/audio 0755 vendor_tcmd system
    mkdir /mnt/vendor/persist/factory/wlan 0755 vendor_tcmd vendor_tcmd
    mkdir /mnt/vendor/persist/factory/regulatory 0755 vendor_tcmd system
    mkdir /mnt/vendor/persist/public 0755 vendor_tcmd vendor_tcmd
    mkdir /mnt/vendor/persist/public/att_dm 0775 radio vendor_tcmd
    mkdir /mnt/vendor/persist/public/hiddenmenu 0775 radio vendor_tcmd
    mkdir /mnt/vendor/persist/public/hiddenmenu/data 0775 system vendor_tcmd
    mkdir /persist/public/locale 0700 system system
    mkdir /persist/public/omadm 0700 radio radio
    mkdir /persist/public/svcs 0770 system system
    mkdir /mnt/vendor/persist/wifi 0755 vendor_tcmd vendor_tcmd
    mkdir /mnt/vendor/persist/bt 0755 vendor_tcmd bluetooth
    mkdir /persist/public/usc_dm 0775 radio radio
    mkdir /mnt/vendor/persist/rfs/msm/mpss/mot_rfs 0771 vendor_rfs system
    mkdir /mnt/vendor/persist/rfs/mdm/mpss/mot_rfs 0771 vendor_rfs system

    # This dir is used to store any OMA(both DM and CP) files in persist partition
    # Any app with radio UID or vendor_tcmd GID can read/write/execute files in this dir.
    mkdir /mnt/vendor/persist/public/oma 0775 radio vendor_tcmd

    chown vendor_tcmd vendor_tcmd /mnt/vendor/persist/factory/fti
    chmod 0664 /mnt/vendor/persist/factory/fti
    chown vendor_tcmd vendor_tcmd /mnt/vendor/persist/factory/byte
    chmod 0660 /mnt/vendor/persist/factory/byte
    chmod 0660 /mnt/vendor/persist/wifi/wlan_mac.bin
    chown vendor_tcmd vendor_tcmd /mnt/vendor/persist/bt/bt_bdaddr
    chmod 0664 /mnt/vendor/persist/bt/bt_bdaddr

    # Set life_calls and life_timer file permissions
    chown radio vendor_tcmd /mnt/vendor/persist/public/hiddenmenu/life_calls
    chmod 0775 /mnt/vendor/persist/public/hiddenmenu/life_calls
    chown radio vendor_tcmd /mnt/vendor/persist/public/hiddenmenu/life_timer
    chmod 0775 /mnt/vendor/persist/public/hiddenmenu/life_timer

    chmod 0711 /mnt/vendor/persist/rfs
    chmod 0711 /mnt/vendor/persist/rfs/msm
    chmod 0711 /mnt/vendor/persist/rfs/msm/mpss
    chmod 0771 /mnt/vendor/persist/rfs/msm/mpss/mot_rfs
    chmod 0711 /mnt/vendor/persist/rfs/mdm
    chmod 0711 /mnt/vendor/persist/rfs/mdm/mpss
    chmod 0771 /mnt/vendor/persist/rfs/mdm/mpss/mot_rfs

    # Set dm-verity property for system partition
    verity_update_state

    # Set capsensor calibration sysfs for MDMCTBK
    chown radio radio /sys/class/capsense/calibrate
    chmod 0660 /sys/class/capsense/calibrate

    # Zram
    setprop ro.zram.mark_idle_delay_mins 60
    setprop ro.zram.first_wb_delay_mins 1440
    setprop ro.zram.periodic_wb_delay_hours 24
    write /sys/block/zram0/comp_algorithm lz4
    write /proc/sys/vm/swappiness 100
    setprop sys.sysctl.swappiness 100

on post-fs-data
    # Setup folders for security
    mkdir /mnt/vendor/persist/security 02770 drmrpc drmrpc
    mkdir /data/vendor/dbvc 0750 vendor_tcmd shell
    chown drmrpc vendor_tcmd /mnt/vendor/persist/security

    # Setup folder for Pre-Activation Kill Switch app (PAKS)
    mkdir /mnt/vendor/persist/paks 02770 vendor_tcmd vendor_tcmd

    # Create directory used by power_supply_logger
    mkdir /data/vendor/power_supply_logger 0750 vendor_pwric log
    # Create directory power_supply_logger used by memtest and batt_health
    mkdir /data/vendor_de/power_supply_logger 0770 root log
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/cycle_count
    chmod 0664 /sys/class/power_supply/battery/cycle_count
    chmod 0664 /sys/class/power_supply/battery/charge_control_limit

    # Permissions for Factory Test of Charging Paths
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_auto_enable
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_ibatt
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_itrick
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_iusb
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_idc
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_usb_suspend
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_fail_clear
    chown vendor_pwric vendor_pwric /sys/class/power_supply/battery/device/force_chg_usb_otg_ctl

    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_auto_enable
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_ibatt
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_itrick
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_iusb
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_idc
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_usb_suspend
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_fail_clear
    chown vendor_pwric vendor_pwric /sys/class/power_supply/mmi_battery/device/force_chg_usb_otg_ctl

    chown vendor_pwric vendor_pwric /sys/class/power_supply/wireless/device/chip_id
    chown vendor_pwric vendor_pwric /sys/class/power_supply/wireless/current_now
    chown vendor_pwric vendor_pwric /sys/class/power_supply/wireless/voltage_now
    chown vendor_pwric vendor_pwric /sys/class/power_supply/wireless/voltage_max
    chmod 0664 /sys/class/power_supply/wireless/voltage_max
    chown vendor_pwric vendor_pwric /sys/kernel/debug/pmic-votable/CHG_DISABLE/force_val
    chmod 0664 /sys/kernel/debug/pmic-votable/CHG_DISABLE/force_val
    chown vendor_pwric vendor_pwric /sys/kernel/debug/pmic-votable/CHG_DISABLE/force_active
    chmod 0664 /sys/kernel/debug/pmic-votable/CHG_DISABLE/force_active
    chown vendor_pwric vendor_pwric /sys/kernel/debug/regulator/smb5-vconn/enable
    chmod 0664 /sys/kernel/debug/regulator/smb5-vconn/enable

    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_start_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_stop_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_start_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_stop_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_start_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_stop_soc
    chown root vendor_mod /sys/module/qpnp_smbcharger_mmi/parameters/eb_on_sw

    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_on_sw

    chown root vendor_mod /sys/class/power_supply/usb/usb_priority
    chmod 0660 /sys/class/power_supply/usb/usb_priority
    chown root vendor_mod /sys/module/dwc3_msm/parameters/usb_priority
    chmod 0660 /sys/module/dwc3_msm/parameters/usb_priority
    chown root vendor_mod /sys/module/usbnet/parameters/force_on
    chmod 0666 /sys/module/usbnet/parameters/force_on

    # Setup folder for native to transfer data to NativeDropBoxAgent
    mkdir /data/vendor/dropbox-add 0730 log diag

    # Create panic dump dir.
    mkdir /data/vendor/dontpanic 0750 root log

    # Create directory for cutback
    mkdir /data/vendor/misc/cutback 0770 radio wifi

    # Create bug2go folder
    mkdir /data/vendor/bug2go 0770 log log

    # Setup folder for aplogd
    mkdir /data/vendor/aplogd 0770 log log

    # Create directory used by chargeonlymode
    mkdir /data/vendor/chargeonly 0750 root log

    # Subsystem RAM-dumps
    mkdir /data/vendor/ss-ram-dumps 0750 system log
    mkdir /data/vendor/ss-ram-dumps/bp-dumps 0750 system log
    mkdir /data/vendor/ss-ram-dumps/riva-dumps 0750 system log

    # folder for Blueooth ramdump
    mkdir /data/vendor/bt-ram-dumps 0750 bluetooth log

    # folder for ssrdumps
    mkdir /data/vendor/ssrdump 0775 root system

    #Folder for hardware properties
    mkdir /data/vendor/hardware_revisions 0755 system system

    # Imager tuning data for camera subsystem
    mkdir /data/vendor/misc/imager 0771 camera camera

    # NFC vendor data
    mkdir /data/vendor/nfc 0770 nfc nfc

    # Required by FingerPrint Cards (FPC) via init so we don't need to give qseecomd or fingerprintd permissions to create them
    mkdir /data/vendor/fpc 0700 system system
    mkdir /data/vendor/.fps 0770 system vendor_fingerp

    # Required by touchRec for write the touch data
    mkdir /data/vendor/touchrec 0770 input input
    chown input input /data/vendor/touchrec/bootindex
    chown input input /data/vendor/touchrec/lastbootuuid
    chown input input /data/vendor/touchrec/touch_data.txt
    chmod 0664 /data/vendor/touchrec/touch_data.txt

on boot
   # restore default console_loglevel to KERN_DEBUG
   # restore default_message_loglevel to KERN_WARNING
   write /proc/sys/kernel/printk "7 4 1 7"

    # MOTO, NJH348, IKHALFMWK-1864, change system max tcp buffer sizes based on RAT changes
    # Define system changable TCP buffer max values
    chown system system /proc/sys/net/core/rmem_max
    chown system system /proc/sys/net/core/wmem_max

 # Change ownership and permission for leds backlight
   chmod 0664 /sys/class/leds/lcd-backlight/brightness
   chown system system /sys/class/leds/charging/brightness
   chmod 0664 /sys/class/leds/charging/brightness

   # change permission of red leds
   chown system system /sys/class/leds/red/brightness
   chmod 0664 /sys/class/leds/red/brightness

   # Change ownership and permission for vibrator
   chown system system /sys/class/timed_output/vibrator/enable
   chmod 0660 /sys/class/timed_output/vibrator/enable
   chown system system /sys/class/leds/vibrator/state
   chmod 0660 /sys/class/leds/vibrator/state
   chown system system /sys/class/leds/vibrator/activate
   chmod 0660 /sys/class/leds/vibrator/activate
   chown system system /sys/class/leds/vibrator/duration
   chmod 0660 /sys/class/leds/vibrator/duration
   chown system system /sys/class/leds/vibrator/seq
   chmod 0660 /sys/class/leds/vibrator/seq
   chown system system /sys/class/leds/vibrator/extra
   chmod 0660 /sys/class/leds/vibrator/extra
   chown root vendor_mod /sys/bus/i2c/devices/2-005a/reduce

   # Change ownership of aov related sysfs entries
   chown audio audio /sys/kernel/aov/trigger
   chown audio audio /sys/kernel/aov/register
   chown audio audio /sys/kernel/aov/event

   # Clear cooldown state
   mkdir /mnt/vendor/persist/chargeonly 0770 system system
   write /mnt/vendor/persist/chargeonly/cooldown n
   chown system system /mnt/vendor/persist/chargeonly/cooldown
   chmod 0660 /mnt/vendor/persist/chargeonly/cooldown

   # Quiet binder logs
   write /sys/module/binder/parameters/debug_mask 0x5

   # Change owner ship of l5 laser calibration
   chown camera vendor_tcmd /mnt/vendor/persist/camera/focus/offset_cal
   chmod 0660 /mnt/vendor/persist/camera/focus/offset_cal

   # change ownership of capsensor related sysfs node
   chown system system /sys/class/capsense/reset
   chown system system /sys/class/capsense/int_state

on late-fs-charger
    class_start early_hal
    wait_for_prop hwservicemanager.ready true
    exec_start wait_for_keymaster
    mount_all /vendor/etc/fstab.qcom --late
    # Boot time fs tune
    write /sys/block/dm-9/queue/read_ahead_kb 2048

on charger
    trigger early-fs
    trigger fs
    trigger post-fs
    trigger late-fs-charger
    trigger post-fs-data
    trigger moto-charger
    class_stop main
    class_stop late_start

on property:sys.boot_completed=1 && property:ro.vendor.zram.product_swapon=""
    write /proc/sys/vm/page-cluster 0
    swapon_all /vendor/etc/fstab.qcom
    write /proc/sys/vm/swappiness 100
    setprop sys.sysctl.swappiness 100

on property:sys.sysctl.swappiness=*
    write /proc/sys/vm/swappiness ${sys.sysctl.swappiness}

service vendor.mmi-touch-sh /vendor/bin/init.mmi.touch.sh
    class core
    user root
    oneshot

service vendor.touchUpg /vendor/bin/touchUpg
    class core
    user root
    oneshot
    disabled

service vendor.oem-hw-sh /vendor/bin/init.oem.hw.sh
    class core
    user root
    oneshot
    disabled

service vendor.oem-super-image-detector-sh /vendor/bin/init.oem.hw.sh -M
    class core
    user root
    oneshot
    disabled

service vendor.hal-fps-sh /vendor/bin/init.oem.fingerprint2.sh
    class late_start
    user root
    group system
    oneshot

service fpc_ident /vendor/bin/fpc_ident
    class late_start
    user system
    group system
    oneshot
    disabled

service vendor.touch-dead-sh /vendor/bin/init.oem.hw.sh -f
    class main
    user root
    oneshot
    disabled

service vendor.touch-ready-sh /vendor/bin/init.oem.hw.sh -r
    class main
    user root
    oneshot
    disabled

service vendor.oem-hw-config-sh /vendor/bin/init.oem.hw.sh -p
    class main
    user root
    oneshot
    disabled

on property:vendor.hw.touch.status="dead"
    start vendor.touch-dead-sh

on property:vendor.hw.touch.status="ready"
    start vendor.touch-ready-sh

service vendor.charge_only_mode /vendor/bin/charge_only_mode
    user root
    group graphics system input
    capabilities SYS_BOOT
    disabled

# bugreport is triggered by holding down volume down, volume up and power
service bugreport /system/bin/dumpstate -d -p -B -z \
        -o /data/user_de/0/com.android.shell/files/bugreports/bugreport
    class main
    disabled
    oneshot
    keycodes 114 115 116

# touchRec
service vendor.touchRec /vendor/bin/touchRec
    class late_start
    user input
    group input
    oneshot
    disabled

# Override the AOSP sensor HAL service definition
# from hardware/interfaces/sensors/2.0/multihal
# to add input and uhid group access
service vendor.sensors-hal-2-0-multihal /vendor/bin/hw/android.hardware.sensors@2.0-service.multihal
    class hal
    user system
    group system wakelock context_hub input uhid
    writepid /dev/cpuset/system-background/tasks
    capabilities BLOCK_SUSPEND
    rlimit rtprio 10 10

# from hardware/interfaces/sensors/2.1/multihal
# to add input and uhid group access
service vendor.sensors-hal-2-1-multihal /vendor/bin/hw/android.hardware.sensors@2.1-service.multihal
    class hal
    user system
    group system wakelock context_hub input uhid
    writepid /dev/cpuset/system-background/tasks
    capabilities BLOCK_SUSPEND
    rlimit rtprio 10 10
