# Copyright (c) 2013-2014,2018, 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.
#
#

import init.carrier.rc

on early-init
    exec u:r:vendor_modprobe:s0 -- /vendor/bin/modprobe -a -d /vendor/lib/modules audio_apr audio_adsp_loader audio_q6_notifier audio_q6 audio_usf audio_native audio_pinctrl_wcd audio_swr audio_platform audio_swr_ctrl audio_hdmi audio_wcd9xxx audio_wcd_core audio_wsa881x_analog audio_wsa881x audio_mbhc audio_stub audio_digital_cdc audio_analog_cdc audio_wcd_cpe audio_cpe_lsm audio_wcd9335 audio_machine_sdm450 audio_machine_ext_sdm450
    write /proc/sys/kernel/sched_boost 1
    mkdir /bt_firmware 0771 system system
    mkdir /dsp 0771 media media
    mkdir /firmware 0771 system system
    symlink /data/tombstones /tombstones

on fs
    wait /dev/block/platform/soc/${ro.boot.bootdevice}
    symlink /dev/block/platform/soc/${ro.boot.bootdevice} /dev/block/bootdevice
    mount_all /vendor/etc/fstab.qcom
    chown root system /mnt/vendor/persist
    chmod 0771 /mnt/vendor/persist
    mkdir /mnt/vendor/persist/data 0700 system system
    mkdir /mnt/vendor/persist/stability 0755 system system
    mkdir /mnt/vendor/persist/bms 0700 root system
    restorecon_recursive_force /mnt/vendor/persist

    write /proc/sys/vm/swappiness 100
    #write /sys/kernel/boot_adsp/boot 1

#HTH-44096 thermal config switch support by wangyibo at 20190121 start
    chmod 0664 /sys/class/thermal/thermal_message/sconfig
    chown system system /sys/class/thermal/thermal_message/sconfig
#HTH-44096 thermal config switch support by wangyibo at 20190121 end

    wait /dev/block/bootdevice/by-name/oem
    mount ext4 /dev/block/bootdevice/by-name/oem /oem ro nosuid nodev barrier=1

on post-fs
    # set RLIMIT_MEMLOCK to 64MB
    setrlimit 8 67108864 67108864

    start vendor.qseecomd
    exec - system system -- /vendor/bin/init.qti.qseecomd.sh
    insmod /vendor/lib/modules/exfat.ko

on post-fs-data
    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/data/sfs 0700 system system
    mkdir /persist/data/tz 0700 system system
    mkdir /data/misc/dts 0770 media audio

# add charge_logger  by wangyibo at 20190116 start
    mkdir /data/vendor/charge_logger 0771 system system
# add charge_logger  by wangyibo at 20190116 end

#   mkdir /data/vendor/hbtp 0750 system system

# modify by zhoudan for fingerprint
    mkdir /data/vendor/fpc 0700 system system
    mkdir /data/vendor/goodix 0700 system system
    chmod 0644 /dev/goodix_fp
    chown system system /dev/goodix_fp

# modify by zhoudan for fingerprint
	copy /data/vendor/fpc/user.db /data/vendor_de/0/fpdata/user.db
	chown system system /data/vendor_de/0/fpdata/user.db
	rm /data/vendor/fpc/user.db

#HTH-44096 thermal config switch support by wangyibo at 20190121 start
    mkdir /data/vendor/thermal 0771 system system
    mkdir /data/vendor/thermal/config 0771 system system
#HTH-44096 thermal config switch support by wangyibo at 20190121 end

#Create folder for mm-qcamera-daemon
    mkdir /data/vendor/camera 0770 camera camera

#start camera server as daemon
service qcamerasvr /system/vendor/bin/mm-qcamera-daemon
    class late_start
    user camera
    group camera system inet input graphics

on init
   write /dev/stune/foreground/schedtune.sched_boost_no_override 1
   write /dev/stune/top-app/schedtune.sched_boost_no_override 1
   write /dev/stune/schedtune.colocate 0
   write /dev/stune/background/schedtune.colocate 0
   write /dev/stune/foreground/schedtune.colocate 0
   write /dev/stune/top-app/schedtune.colocate 1
   write /sys/module/qpnp_rtc/parameters/poweron_alarm 1

service qfp-daemon /system/vendor/bin/qfp-daemon
   class late_start
   user system
   group system drmrpc

# Allow usb charging to be disabled peristently
on property:persist.usb.chgdisabled=1
    write /sys/class/power_supply/battery/charging_enabled 0

on property:persist.usb.chgdisabled=0
    write /sys/class/power_supply/battery/charging_enabled 1

service qrngd /system/bin/qrngd -f
   class main
   user root
   group root

service qrngp /system/bin/qrngp -f
   class main
   user root
   group root
   oneshot
   disabled

on property:sys.boot_completed=1
   start qrngp

# add charge_logger  by wangyibo at 20190116 start
service charge_logger /vendor/bin/charge_logger
   class last_start
   user system
   group system system wakelock
   disabled
   oneshot

on property:sys.boot_completed=1
    start charge_logger
# add charge_logger  by wangyibo at 20190116 start

service vendor.qseecomd /vendor/bin/qseecomd
   class core
   user root
   group root

#service aostlmd /system/bin/aostlmd
#   class late_start
#   user system
#   group system net_raw

#service mpdecision /system/bin/mpdecision --avg_comp
#   user root
#   disabled

service perfd /system/vendor/bin/perfd
   class main
   user root
   disabled

service gamed /system/vendor/bin/gamed
   class main
   user system
   group system
   disabled
   socket gamed seqpacket 0640 system system

service thermal-engine /system/vendor/bin/thermal-engine
   class main
   user root
   socket thermal-send-client stream 0666 system system
   socket thermal-recv-client stream 0660 system system
   socket thermal-recv-passive-client stream 0666 system system
   socket thermal-send-rule stream 0660 system system
   group root

service time_daemon /system/vendor/bin/time_daemon
   class late_start
   user root
   group root

service audiod /system/vendor/bin/audiod
   class late_start
   user system
   group system

on boot
    start rmt_storage
    insmod /system/lib/modules/adsprpc.ko
# access permission for secure touch
    chmod 0660 /sys/devices/soc.0/78b7000.i2c/i2c-3/3-0020/input/input0/secure_touch_enable
    chmod 0440 /sys/devices/soc.0/78b7000.i2c/i2c-3/3-0020/input/input0/secure_touch
    chmod 0660 /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/secure_touch_enable
    chmod 0440 /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/secure_touch
    chown system drmrpc /sys/devices/soc.0/78b7000.i2c/i2c-3/3-0020/input/input0/secure_touch_enable
    chown system drmrpc /sys/devices/soc.0/78b7000.i2c/i2c-3/3-0020/input/input0/secure_touch
    chown system drmrpc /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/secure_touch_enable
    chown system drmrpc /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/secure_touch
#   chown system system /sys/kernel/hbtp/display_pwr

   # 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-3
   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

    ####Regionalization config and prop files####
    chmod 0644 /persist/speccfg/spec
    chmod 0644 /persist/speccfg/devicetype
    chmod 0644 /persist/speccfg/mbnversion
    chmod 0644 /persist/speccfg/.not_triggered
    chmod 0644 /persist/speccfg/vendor_ro.prop
    chmod 0644 /persist/speccfg/vendor_persist.prop
    chmod 0644 /persist/speccfg/submask
    chmod 0644 /persist/speccfg/partition
    chown system system /persist/speccfg/spec
    chown system system /persist/speccfg/devicetype
    chown system system /persist/speccfg/mbnversion
    chown system system /persist/speccfg/.not_triggered
    chown system system /persist/speccfg/vendor_ro.prop
    chown system system /persist/speccfg/vendor_persist.prop
    chown system system /persist/speccfg/submask
    chown system system /persist/speccfg/partition
    chown system system /mnt/vendor/persist/sensors/sns.reg

# access permission for wlan
    chown system system /mnt/vendor/persist/WCNSS_qcom_wlan_nv.bin

#USB controller configuration
    write /sys/module/g_android/parameters/mtp_tx_req_len 131072
    write /sys/module/g_android/parameters/mtp_rx_req_len 131072
    write /sys/class/android_usb/android0/f_rndis_qc/rndis_transports BAM2BAM_IPA
    setprop vendor.usb.rndis.func.name "rndis_bam"
    setprop vendor.usb.rmnet.func.name "rmnet_bam"
    setprop vendor.usb.rmnet.inst.name "rmnet"
    setprop vendor.usb.dpl.inst.name "dpl"

service ppd /system/vendor/bin/mm-pp-dpps
    class late_start
    disabled
    user system
    socket pps stream 0660 system system
    group system graphics

on property:init.svc.surfaceflinger=stopped
    stop ppd

on property:init.svc.surfaceflinger=running
    start ppd

on property:init.svc.surfaceflinger=restarting
    stop ppd

on property:init.svc.zygote=stopped
    stop ppd

on property:init.svc.zygote=running
    start ppd

on property:init.svc.zygote=restarting
    stop ppd

service wcnss-service /system/vendor/bin/wcnss_service
    class main
    user system
    group system wifi radio
    oneshot

on charger
    #add by wangyibo at 20181231 stard
    chown system system /sys/class/leds/red/blink
    chown system system /sys/class/leds/red/brightness
    chown system system /sys/class/leds/green/blink
    chown system system /sys/class/leds/green/brightness
    chmod 0664 /sys/class/leds/red/blink 
    chmod 0664 /sys/class/leds/red/brightness
    chmod 0664 /sys/class/leds/green/blink
    chmod 0664 /sys/class/leds/green/brightness
# add charge_logger  by wangyibo at 20190116 start
    mkdir /data/vendor/charge_logger 0771 system system
# add charge_logger  by wangyibo at 20190116 end
    #add by wangyibo at 20181231 end
    wait /dev/block/bootdevice/by-name/system
    mount ext4 /dev/block/bootdevice/by-name/system /system ro barrier=1
    load_all_props
    setprop sys.usb.configfs 0
    setprop persist.sys.usb.config mass_storage
    start qcom-post-boot
    setprop persist.sys.usb.config mass_storage
# add charge_logger  by wangyibo at 20190116 start
    start charge_logger
# add charge_logger  by wangyibo at 20190116 end
#   start vendor.hvdcp_opti

## imsdatadaemon starts with root and UID will be downgraded to SYSTEM.
service vendor.imsqmidaemon /system/vendor/bin/imsqmidaemon
    class main
    user system
    socket ims_qmid stream 0660 system radio
    group radio log diag

# imsdatadaemon starts with root and UID will be downgraded to SYSTEM.
service vendor.imsdatadaemon /system/vendor/bin/imsdatadaemon
    class main
    user system
    socket ims_datad stream 0660 system radio
    group system wifi radio inet log diag
    disabled

service vendor.hvdcp_opti /system/vendor/bin/hvdcp_opti
    class main
    user root
    group system wakelock
    disabled

on property:vendor.ims.QMI_DAEMON_STATUS=1
    start vendor.imsdatadaemon

service vendor.ims_rtp_daemon /system/vendor/bin/ims_rtp_daemon
   class main
   user system
   group radio diag inet log

service vendor.imsrcsservice /system/vendor/bin/imsrcsd
   class main
   user system
   group radio diag inet log wakelock

on property:vendor.ims.DATA_DAEMON_STATUS=1
    restart vendor.ims_rtp_daemon

#service hbtp /system/vendor/bin/hbtp_daemon
#    class main
#    user system
#    group system
#    disabled

service dts_configurator /system/vendor/bin/dts_configurator
    class late_start
    user system
    group media audio
    oneshot

service dtseagleservice /system/vendor/bin/dts_eagle_service
    class late_start
    user system
    group audio media
    disabled

service adsprpcd /system/vendor/bin/adsprpcd
    class main
    user media
    group media

on property:init.svc.dts_configurator=stopped
    start dtseagleservice

service vendor.per_mgr /system/vendor/bin/pm-service
    class core
    user system
    group system net_raw

service vendor.per_proxy /system/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
    stop vendor.ims_rtp_daemon

service energy-awareness /system/vendor/bin/energy-awareness
    class main
    user root
    group system
    oneshot

service mdtpd /system/vendor/bin/mdtpd
    class late_start
    user root
    group system radio drmrpc

on boot
    mkdir /dev/cpuset/top-app/boost
    write /dev/cpuset/top-app/boost/mems 0


    write /dev/cpuset/foreground/cpus 0-2,4-7
    write /dev/cpuset/foreground/boost/cpus 4-7
    write /dev/cpuset/background/cpus 0-1
    write /dev/cpuset/system-background/cpus 0-2
    write /dev/cpuset/top-app/cpus 0-7
    write /dev/cpuset/top-app/boost/cpus 4-7

    chown system system /dev/cpuset/top-app/boost
    chown system system /dev/cpuset/top-app/boost/tasks

    chmod 0664 /dev/cpuset/top-app/boost/tasks

    write /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/fw_name PR1702898-s3528t_00260005_00380008.img
    write /sys/devices/soc.0/78b8000.i2c/i2c-4/4-0020/input/input0/update_fw 1

#begin zhanghua 20171123 create cabc/ce interface
on property:persist.sys.display_ce=4
    write /sys/class/graphics/fb0/msm_fb_ce 1

on property:persist.sys.display_ce=0
    write /sys/class/graphics/fb0/msm_fb_ce 2

on property:persist.sys.display_cabc=1
    write /sys/class/graphics/fb0/msm_fb_cabc 1

on property:persist.sys.display_cabc=2
    write /sys/class/graphics/fb0/msm_fb_cabc 2
#end zhanghua 20171123

on property:persist.sys.display_srgb=1
    write /sys/class/graphics/fb0/msm_fb_srgb 1

on property:persist.sys.display_srgb=2
    write /sys/class/graphics/fb0/msm_fb_srgb 2

on property:persist.sys.display_gamma=1
    write /sys/class/graphics/fb0/msm_fb_gamma 1

on property:persist.sys.display_gamma=2
    write /sys/class/graphics/fb0/msm_fb_gamma 2
#end xiaopei add    
#service adswitch /system/vendor/bin/adswitch xiaopei add begin
service adswitch /system/bin/adswitch
    user root
    group root
    disabled
    oneshot

on property:sys.ad.enable=on
    start adswitch

on property:sys.ad.enable=off
    start adswitch

#service sviswitch add begin @20180303
service sviswitch /vendor/bin/sviswitch
    user system
    group system
    disabled
    oneshot

on property:sys.svi.enable=on
    start sviswitch

on property:sys.svi.enable=off
    start sviswitch
#service sviswitch add end @20180303  xiaopei add end 

# Add check nv by 20190114 20190114 begin
service checknv /system/bin/checknv
    class late_start
    user root
    oneshot
    seclabel u:r:vendor_init:s0
# Add check nv by 20190114 20190114 end

#add by panpeng for tcpdump service 
service vendor.tcpdump /system/xbin/tcpdump -i wlan0 -s 0 -vv -W 5 -C 20 -w /sdcard/wlan_logs/tcpdump.pcap
    class main
    user  root
    group root wifi inet net_admin sdcard_rw media_rw diag
    disabled
    oneshot
    
    
on property:sys.cnss_diag_system.log=1
    start vendor.tcpdump

#end by panpeng 

on boot
    chown system system /sys/class/leds/red/blink
    chown system system /sys/class/leds/red/breath
    chown system system /sys/class/leds/red/delay_on
    chown system system /sys/class/leds/red/delay_off
    chown system system /sys/class/leds/green/blink
    chown system system /sys/class/leds/green/breath
    chown system system /sys/class/leds/green/delay_on
    chown system system /sys/class/leds/green/delay_off
    chown system system /sys/class/leds/blue/blink
    chown system system /sys/class/leds/blue/breath
    chown system system /sys/class/leds/blue/delay_on
    chown system system /sys/class/leds/blue/delay_off
#wangyuwei add for flashlight selinux
    chmod 0660 /sys/class/leds/led:flash_0/brightness
    chmod 0660 /sys/class/leds/led:flash_1/brightness
    chmod 0660 /sys/class/leds/led:torch_0/brightness
    chmod 0660 /sys/class/leds/led:torch_1/brightness
    chmod 0660 /sys/class/leds/flashlight/brightness
    chmod 0660 /sys/class/leds/led:switch/brightness
    chown system system /sys/class/leds/led:flash_0/brightness
    chown system system /sys/class/leds/led:flash_1/brightness
    chown system system /sys/class/leds/led:torch_0/brightness
    chown system system /sys/class/leds/led:torch_1/brightness
    chown system system /sys/class/leds/flashlight/brightness
    chown system system /sys/class/leds/led:switch/brightness
