# Copyright (c) 2019-2023, 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.
#
#

service logger /system/bin/logcat -b all -D -f /metadata/boot_log.txt
    class main
    user root
    group root system
    disabled
    oneshot

on early-init

on init

on late-init

on post-fs
    start logger

on late-fs

on post-fs-data
#mAFPC
    mkdir /efs/afc 0760 system system
    exec - system system -- /system/bin/mafpc_write

on boot
    write /proc/sys/vm/swappiness 100

# SDHMS Slowdown : Cpuset
    write /dev/cpuset/abnormal/cpus 0-1,5-6
    write /dev/cpuset/moderate/cpus 0-1,5-6

# [ Permissions for Range Sensor Sensor
# Range Sensor
    chown system radio /sys/class/sensors/range_sensor/ambient
    chown system radio /sys/class/sensors/range_sensor/cal01
    chown system radio /sys/class/sensors/range_sensor/cal02
    chown system radio /sys/class/sensors/range_sensor/cal_uid
    chown system radio /sys/class/sensors/range_sensor/open_calibration
    chown system radio /sys/class/sensors/range_sensor/calibration
    chown system radio /sys/class/sensors/range_sensor/enable
    chown system radio /sys/class/sensors/range_sensor/error
    chown system radio /sys/class/sensors/range_sensor/frame_rate
    chown system radio /sys/class/sensors/range_sensor/fw_version
    chown system radio /sys/class/sensors/range_sensor/interrupt
    chown system radio /sys/class/sensors/range_sensor/mode
    chown system radio /sys/class/sensors/range_sensor/name
    chown system radio /sys/class/sensors/range_sensor/range_sigma
    chown system radio /sys/class/sensors/range_sensor/status
    chown system radio /sys/class/sensors/range_sensor/target_status
    chown system radio /sys/class/sensors/range_sensor/temp
    chown system radio /sys/class/sensors/range_sensor/test01
    chown system radio /sys/class/sensors/range_sensor/test02
    chown system radio /sys/class/sensors/range_sensor/test03
    chown system radio /sys/class/sensors/range_sensor/test_mode
    chown system radio /sys/class/sensors/range_sensor/uid
    chown system radio /sys/class/sensors/range_sensor/vendor
    chown system radio /sys/class/sensors/range_sensor/zone
    chown system radio /sys/class/sensors/range_sensor/file_cal
    chown system radio /sys/class/sensors/range_sensor/file_p2p
    chown system radio /sys/class/sensors/range_sensor/file_shape
# ] Permissions for Range Sensor
on shutdown

# service definition

# on property triggers

# Create carrier folder for HiddenMenu
on post-fs
    mkdir /efs/carrier 0755 radio system
    chown radio system /efs/carrier
    chown radio system /efs/carrier/HiddenMenu
# For Range Sensor
    chmod 0660 /dev/range_sensor
    chown system system /dev/range_sensor
	mkdir /efs/range_sensor 0770 system system
    chown system system /efs/range_sensor/cal_data.bin
    chmod 0660 /efs/range_sensor/cal_data.bin
    chown system system /efs/range_sensor/vl53l5_cal_shape.bin
    chmod 0660 /efs/range_sensor/vl53l5_cal_shape.bin
    chown system system /efs/range_sensor/vl53l5_cal_p2p.bin
    chmod 0660 /efs/range_sensor/vl53l5_cal_p2p.bin

# Range Sensor
on property:sys.boot_completed=1
	write /sys/class/sensors/range_sensor/calibration 0

# some priv-apps of DSH bind mount to DSA priv-apps
on post-fs-data && property:ro.csc.sales_code=DSA
    umount /system/carrier
    mkdir /mnt/temp
    mount none /system/carrier/DSH /mnt/temp bind
    mount none /system/carrier/DSA /system/carrier bind
    mount none /mnt/temp/priv-app/VisualVoicemailDsh_Stub /system/carrier/priv-app/VisualVoicemailDsh_Stub bind
    umount /mnt/temp
    rmdir /mnt/temp
	
# some priv-apps of DSH & DSA bind mount to DSG priv-apps
on post-fs-data && property:ro.csc.sales_code=DSG
    umount /system/carrier
    mkdir /mnt/temp1
    mkdir /mnt/temp2
    mount none /system/carrier/DSH /mnt/temp1 bind
    mount none /system/carrier/DSA /mnt/temp2 bind
    mount none /system/carrier/DSG /system/carrier bind
    mount none /mnt/temp1/priv-app/NetworkCompanion /system/carrier/priv-app/NetworkCompanion bind
    mount none /mnt/temp1/priv-app/VisualVoicemailDsh_Stub /system/carrier/priv-app/VisualVoicemailDsh_Stub bind
    mount none /mnt/temp2/priv-app/Opportunistic /system/carrier/priv-app/Opportunistic bind
    umount /mnt/temp1
    umount /mnt/temp2
    rmdir /mnt/temp1
    rmdir /mnt/temp2
	
# some priv-apps of DSA bind mount to DSH priv-apps
on post-fs-data && property:ro.csc.sales_code=DSH
    umount /system/carrier
    mkdir /mnt/temp
    mount none /system/carrier/DSA /mnt/temp bind
    mount none /system/carrier/DSH /system/carrier bind
    mount none /mnt/temp/priv-app/Opportunistic /system/carrier/priv-app/Opportunistic bind
    umount /mnt/temp
    rmdir /mnt/temp	

# some priv-apps of TMB bind mount to ASR priv-apps
on post-fs-data && property:ro.csc.sales_code=ASR
    umount /system/carrier
    mkdir /mnt/temp
    mount none /system/carrier/TMB /mnt/temp bind
    mount none /system/carrier/ASR /system/carrier bind
    mount none /mnt/temp/priv-app/SprintAndroidExtension2_TMB /system/carrier/priv-app/SprintAndroidExtension2_TMB bind
    umount /mnt/temp
    rmdir /mnt/temp

	
# some priv-apps of TMB bind mount to TMK priv-apps
on post-fs-data && property:ro.csc.sales_code=TMK
    umount /system/carrier
    mkdir /mnt/temp
    mount none /system/carrier/TMB /mnt/temp bind
    mount none /system/carrier/TMK /system/carrier bind
    mount none /mnt/temp/priv-app/SprintAndroidExtension2_TMB /system/carrier/priv-app/SprintAndroidExtension2_TMB bind
    umount /mnt/temp
    rmdir /mnt/temp

# Pageboostd
on property:sys.boot_completed=1
    start pageboostd

service pageboostd /system/bin/pageboostd
    class main
    user system
    group system mount radio net_bt sdcard_rw shell media media_rw
    socket pageboostd seqpacket 0660 system system
    disabled
