# This source code is "Not a Contribution" under Apache license
#
# Based on work by The Android Open Source Project
# Modified by Sierra Wireless, Inc.
#
# Copyright (C) 2018 Sierra Wireless, Inc.
#

import init.${ro.hardware}.usb.rc
import init.${ro.hardware}.power.rc

on init
    # mount debugfs
    mount debugfs /sys/kernel/debug /sys/kernel/debug mode=755

    # disable transparent huge pages
    write /sys/kernel/mm/transparent_hugepage/enabled "never"

    # Initialize cpusets to boot-time values
    write /dev/cpuset/foreground/cpus 0-7
    write /dev/cpuset/background/cpus 0-7
    write /dev/cpuset/system-background/cpus 0-7
    write /dev/cpuset/top-app/cpus 0-7

    # Create UDS structure for base VR services
    mkdir /dev/socket/pdx 0775 system system
    mkdir /dev/socket/pdx/system 0775 system system
    mkdir /dev/socket/pdx/system/buffer_hub 0775 system system
    mkdir /dev/socket/pdx/system/performance 0775 system system
    mkdir /dev/socket/pdx/system/vr 0775 system system
    mkdir /dev/socket/pdx/system/vr/display 0775 system system
    mkdir /dev/socket/pdx/system/vr/pose 0775 system system
    mkdir /dev/socket/pdx/system/vr/sensors 0775 system system

    start watchdogd

on fs
    mount_all /fstab.${ro.hardware}
    setprop ro.crypto.fuse_sdcard false

on post-fs
    # For legacy support
    # See storage config details at http://source.android.com/tech/storage/
    # since /storage is mounted on post-fs in init.rc
    symlink /sdcard /storage/sdcard0

    # BT LED sysfs entry
    write /sys/class/leds/bt_active/trigger "hci1rx"

    chmod 0666 /dev/ump
    chmod 0666 /dev/ion
    chmod 0666 /dev/graphics/fb0

# fake some battery state
    setprop status.battery.state Slow
    setprop status.battery.level 5
    setprop status.battery.level_raw  50
    setprop status.battery.level_scale 9

# Set Display density
    setprop ro.sf.lcd_density 160

# Set supported opengles version
    setprop ro.opengles.version 196608

# If an app forces screen rotation, revert it once the apps closes
    setprop persist.demo.rotationlock 1

# enable Google-specific location features,
# like NetworkLocationProvider and LocationCollector
    setprop ro.com.google.locationfeatures 1

# enable test harness
    setprop ro.test_harness true

on post-fs-data
    mkdir /data/media 0770 media_rw media_rw
    mkdir /data/misc/gatord 0700 root root
    # Set SELinux security contexts for files used by lava.
    restorecon_recursive /data/local/tmp/lava

on zygote-start
    mkdir /data/vendor/wifi 0770 wifi wifi
    mkdir /data/vendor/wifi/wpa 0770 wifi wifi
    mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi

on boot
    #SWISTART
    chmod 0755 /system/vendor/bin/slqssdk
    chmod 0755 /system/vendor/bin/init.dhcpcd
    chmod 0755 /system/vendor/bin/init.config.ip
    #SWISTOP
    
on property:sys.boot_completed=1
    # update cpuset now that processors are up
    # Foreground should contain most cores (7 is reserved for top-app)
    write /dev/cpuset/foreground/cpus 0-6

    # top-app gets all cpus (including reserved #7)
    write /dev/cpuset/top-app/cpus 0-7

    #background contains a small subset (generally one little core)
    write /dev/cpuset/background/cpus 0

    # add system-background cpuset, a new cpuset for system services
    # that should not run on larger cores
    # system-background is for system tasks that should only run on
    # little cores, not on bigs to be used only by init
    write /dev/cpuset/system-background/cpus 0-3

on property:usb_speed.switch=high
    write /sys/kernel/debug/f72c0000.usb/config "0"

on property:usb_speed.switch=full
    write /sys/kernel/debug/f72c0000.usb/config "1"

#userspace daemon needed for bluetooth
service uim /vendor/bin/uim
    class main
    user bluetooth
    group bluetooth net_bt_admin system
    oneshot

service wpa_supplicant /system/vendor/bin/hw/wpa_supplicant \
     -g@android:wpa_wlan0
     interface android.hardware.wifi.supplicant@1.0::ISupplicant default
     interface android.hardware.wifi.supplicant@1.1::ISupplicant default
     socket wpa_wlan0 dgram 660 wifi wifi
     class main
     disabled
     oneshot

# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
service watchdogd /sbin/watchdogd 10 20
    class core
    oneshot
    seclabel u:r:watchdogd:s0

#SWISTART    
service sierra_dhcpcd /vendor/bin/init.dhcpcd
    class main
    user root
    group radio cache inet misc dhcp
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled
    oneshot

service sierra_config_ip /vendor/bin/init.config.ip
    class main
    user root
    group radio cache inet misc dhcp
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled
    oneshot    

service ril-daemon-qmi /vendor/bin/hw/rild -l /vendor/lib64/libsierra-ril.so -- -a -i wwan0
    class main
    socket swigps stream 660 system radio
    user radio
    group radio cache inet misc audio log readproc wakelock
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled

service ril-daemon-at /vendor/bin/hw/rild -l /vendor/lib64/libsierraat-ril.so -- -a -i wwan0
    class main
    socket swigps stream 660 system radio
    user radio
    group radio cache inet misc audio log readproc wakelock
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled
    
service ril-daemon-hl /vendor/bin/hw/rild -l /vendor/lib64/libsierrahl-ril.so -- -a -i wwan0
    class main
    socket swigps stream 660 system radio
    user radio
    group radio cache inet misc audio log readproc wakelock
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled   

service ril-daemon-ar /vendor/bin/hw/rild -l /system/lib64/libsierraat-ril.so -- -a -i wwan0
    class main
    socket swigps stream 660 system radio
    user radio
    group radio cache inet misc audio log readproc wakelock
    capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
    disabled
    
on property:persist.sys.ril.type=QMI
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/usb/serial/sierra.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/GobiNet.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/usb/class/cdc-wdm.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/cdc_ncm.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/cdc_mbim.ko    
    start ril-daemon-qmi
    
on property:persist.sys.ril.type=AT
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/usb/serial/sierra.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/sierra_net.ko
    start ril-daemon-at
    
on property:persist.sys.ril.type=HL
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/cdc_ncm.ko
    start ril-daemon-hl    

on property:persist.sys.ril.type=AR
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/usb/serial/sierra.ko
    insmod /system/lib/modules/4.9.77-svn/kernel/drivers/net/usb/GobiNet.ko
    start ril-daemon-ar
      
#SWISTOP    