# Copyright (c) 2013-2018,2020, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#     * Neither the name of The Linux Foundation nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#

on early-init
    mkdir /dsp 0771 media media
    mkdir /firmware 0771 system system
    mkdir /bt_firmware 0771 system system
    symlink /data/tombstones /tombstones

on init
    write /sys/module/qpnp_rtc/parameters/poweron_alarm 1
    wait /dev/block/platform/soc/${ro.boot.bootdevice}
    symlink /dev/block/platform/soc/${ro.boot.bootdevice} /dev/block/bootdevice

on early-fs
    start vold

on fs
    start hwservicemanager
    mount_all /vendor/etc/fstab.qcom --early
    chown root system /mnt/vendor/persist
    chmod 0771 /mnt/vendor/persist
    restorecon_recursive /mnt/vendor/persist
    mkdir /mnt/vendor/persist/data 0700 system system
    mkdir /mnt/vendor/persist/subsys 0770 root system
    mkdir /mnt/vendor/persist/audio 0755 system system
    mkdir /mnt/vendor/persist/haptics 0755 system system
    chmod 0664 /sys/class/thermal/thermal_message/sconfig
    chown system system /sys/class/thermal/thermal_message/sconfig
    chmod 0666 /sys/class/thermal/thermal_message/temp_state
    chown system system /sys/class/thermal/thermal_message/temp_state

on post-fs
    # set RLIMIT_MEMLOCK to 64MB
    setrlimit 8 67108864 67108864
    write /dev/ipa 1

on late-fs
    wait_for_prop hwservicemanager.ready true
    exec_start wait_for_keymaster
    mount_all /vendor/etc/fstab.qcom --late

on post-fs-data
    mkdir /data/vendor/touchpad 0775 system system
    mkdir /data/tombstones 0771 system system
    mkdir /tombstones/modem 0771 system system
    mkdir /tombstones/lpass 0771 system system
    mkdir /tombstones/wcnss 0771 system system
    mkdir /tombstones/dsps 0771 system system
    mkdir /persist/qti_fp 0700 system system
    mkdir /data/vendor/nnhal 0700 system system
    mkdir /data/vendor/mac_addr 0771 system system
    mkdir /data/vendor/thermal 0771 root system
    mkdir /data/vendor/thermal/config 0771 root system
    mkdir /data/vendor/mac_addr 0771 system system

on boot
    chown system system /sys/class/drm/card0-DSI-1/disp_param
    chmod 0664 /sys/class/drm/card0-DSI-1/disp_param
    chown system system /sys/class/drm/card0-DSI-1/mipi_reg
    chmod 0664 /sys/class/drm/card0-DSI-1/mipi_reg
    chown system system /sys/class/drm/card0-DSI-1/panel_info
    chmod 0444 /sys/class/drm/card0-DSI-1/panel_info
    start rmt_storage
    start rfs_access

# Add a cpuset for the camera daemon
# We want all cores for camera
    mkdir /dev/cpuset/camera-daemon
    write /dev/cpuset/camera-daemon/cpus 0-7
    write /dev/cpuset/camera-daemon/mems 0
    chown cameraserver cameraserver /dev/cpuset/camera-daemon
    chown cameraserver cameraserver /dev/cpuset/camera-daemon/tasks
    chmod 0660 /dev/cpuset/camera-daemon/tasks

#add runin factory charging test
    chmod 0777 /sys/class/power_supply/battery/input_suspend
    chmod 0777 /sys/class/power_supply/battery/charging_enabled
    chmod 0777 /sys/class/power_supply/usb/typec_cc_orientation
    chown system system /sys/class/power_supply/battery/input_suspend
    chown system system /sys/class/power_supply/battery/charging_enabled
    chown system system /sys/class/power_supply/usb/typec_cc_orientation

    chmod 0666 sys/devices/platform/soc/890000.i2c/i2c-1/1-005a/cali
    chmod 0666 sys/devices/platform/soc/890000.i2c/i2c-1/1-005a/cali_save
    chmod 0666 sys/devices/platform/soc/890000.i2c/i2c-1/1-005a/f0_save
    chmod 0666 sys/devices/platform/soc/890000.i2c/i2c-1/1-005a/osc_save
    chmod 0666 sys/devices/platform/soc/890000.i2c/i2c-1/1-005a/osc_cali

# access permissions for fingerprint
    chown system system /sys/bus/platform/devices/soc/soc:fpc1020/irq
    chown system system /sys/bus/platform/devices/soc/soc:fpc1020/wakeup_enable
    chown system system /sys/bus/platform/devices/soc/soc:fpc1020/modalias
    chmod 0666 /dev/qseecom
    chmod 0644 /dev/goodix_fp
    chown system system /dev/goodix_fp

#USB controller configuration
    setprop vendor.usb.rndis.func.name "gsi"
    setprop vendor.usb.rmnet.func.name "gsi"
    setprop vendor.usb.rmnet.inst.name "rmnet"
    setprop vendor.usb.dpl.inst.name "dpl"
    setprop vendor.usb.qdss.inst.name "qdss"
    setprop sys.usb.configfs 1

#pd-mapper
service vendor.pd_mapper /vendor/bin/pd-mapper
    class core
    user system
    group system

#Peripheral manager
service vendor.per_mgr /vendor/bin/pm-service
    class core
    user system
    group system
    ioprio rt 4

service vendor.per_proxy /vendor/bin/pm-proxy
    class core
    user system
    group system
    disabled

on property:init.svc.vendor.per_mgr=running
    start vendor.per_proxy

on property:sys.shutdown.requested=*
    stop vendor.per_proxy

on charger
    mkdir /mnt/vendor/persist
    chown root system /mnt/vendor/persist
    chmod 0771 /mnt/vendor/persist
    mkdir /mnt/vendor/persist/subsys 0770 root system
    start vendor.power_off_alarm
    setprop sys.usb.controller a600000.dwc3
    setprop sys.usb.configfs 1
    chown system system /sys/class/leds/red/brightness
    chmod 0666 /sys/class/leds/red/brightness
    chmod 0666 /sys/class/backlight/panel0-backlight/brightness
    start vendor.power_off_alarm

service vibrator_calibration /vendor/bin/vibrator_calibration
     class late_start
     user system
     group system
     oneshot

on property:sys.boot_completed=1
    start vibrator_calibration

    # Enable ZRAM on boot_complete
    swapon_all /vendor/etc/fstab.qcom

    # Back to default VM settings
    write /proc/sys/vm/dirty_expire_centisecs 3000
    write /proc/sys/vm/dirty_background_ratio 10

on property:ro.boot.multisim_config=*
    setprop persist.radio.multisim.config ${ro.boot.multisim_config}
