# Copyright (c) 2013-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 /vendor/etc/init/hw/init.lenovo.rc
import /vendor/etc/init/hw/init.power.rc

on early-init
    write /proc/sys/kernel/sched_boost 1
    mkdir /firmware 0771 system system
    mkdir /bt_firmware 0771 system system
    mkdir /dsp 0771 media media
    symlink /data/tombstones /tombstones

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/system-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

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

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

    write /dev/ipa 1

on late-fs
    mount_all /vendor/etc/fstab.qcom --late

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 /data/vendor/hbtp 0750 system system
    mkdir /data/vendor/nnhal 0700 system system

# For cpusets initialize for Silver Only first and then Silver + Gold
# Silver Only configuration cannot work with 0-7
on boot
    chown system system /sys/kernel/hbtp/display_pwr
    start rmt_storage
    start rfs_access
    write /dev/cpuset/top-app/cpus 0-7
    write /dev/cpuset/foreground/cpus 0-7
    write /dev/cpuset/foreground/boost/cpus 0-7
    write /dev/cpuset/background/cpus 0-7
    write /dev/cpuset/system-background/cpus 0-7

# 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

#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

    # touch gesture wake node permission
    chown system system /sys/class/touch/tp_dev/gesture_on
    chmod 0660 /sys/class/touch/tp_dev/gesture_on

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
    setprop sys.usb.configfs 1

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 adsprpcd /vendor/bin/adsprpcd rootpd
   class main
   user system
   group system

service adsprpcd_audiopd /vendor/bin/adsprpcd audiopd
   class main
   user media
   group media

service adsprpcd_sensorspd /vendor/bin/adsprpcd sensorspd
   class core
   user system
   group system

service cdsprpcd /vendor/bin/cdsprpcd
   class main
   user system
   group system

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

on property:init.svc.vendor.hwcomposer-2-3=stopped
    stop ppd

on property:init.svc.vendor.hwcomposer-2-3=running
    start ppd

on property:init.svc.vendor.hwcomposer-2-3=restarting
    stop ppd

on charger
     setprop sys.usb.configfs 1