# Moto USB configuration
import /init.mmi.usb.rc

on early-boot
    write /sys/module/subsystem_restart/parameters/disable_restart_work 0x0
    write /proc/sys/kernel/poweroff_cmd "/system/bin/reboot -p"

on init
    chown system log /sys/fs/pstore/console-ramoops-0
    chmod 0440 /sys/fs/pstore/console-ramoops-0
    chown system log /sys/fs/pstore/annotate-ramoops-0
    chmod 0640 /sys/fs/pstore/annotate-ramoops-0
    chown system log /sys/fs/pstore/dmesg-ramoops-0
    chmod 0640 /sys/fs/pstore/dmesg-ramoops-0

    # Setup kernel dropbox permissions so that dropboxd can utilize it
    chown root diag /sys/kernel/dropbox/event
    chown root diag /sys/kernel/dropbox/data

on fs
    # use /persist as phony PDS partition
    symlink /persist /pds

on post-fs
    mkdir /persist/camera 0755 oem_5004 oem_5004
    mkdir /persist/camera/focus 0775 camera oem_5004
    mkdir /persist/camera/ledcal 0775 camera oem_5004
    mkdir /persist/mdm 0770 radio radio
    mkdir /persist/factory 0755 oem_5004 oem_5004
    mkdir /persist/factory/audio 0755 oem_5004 system
    mkdir /persist/factory/wlan 0755 oem_5004 oem_5004
    mkdir /persist/factory/regulatory 0755 oem_5004 system
    mkdir /persist/public 0755 oem_5004 oem_5004
    mkdir /persist/public/atvc 0770 oem_5012 shell
    mkdir /persist/public/battd 0755 oem_5000 oem_5004
    mkdir /persist/public/att_dm 0775 radio oem_5004
    mkdir /persist/public/hiddenmenu 0755 radio radio
    mkdir /persist/public/hiddenmenu/data 0775 system oem_5004
    mkdir /persist/public/locale 0700 system system
    mkdir /persist/public/omadm 0700 radio radio
    mkdir /persist/public/svcs 0770 system system
    mkdir /persist/wifi 0755 oem_5004 oem_5004
    mkdir /persist/bt 0755 oem_5004 bluetooth
    mkdir /persist/wmdrm 0775 oem_5003 oem_5003
    mkdir /persist/sds 0700 vold vold
    mkdir /persist/rfs/msm/mpss/mot_rfs 0771 rfs system
    mkdir /persist/public/usc_dm 0775 radio radio

    chown oem_5004 oem_5004 /persist/factory/fti
    chmod 0660 /persist/factory/fti
    chown oem_5004 oem_5004 /persist/factory/byte
    chmod 0660 /persist/factory/byte
    chmod 0660 /persist/wifi/wlan_mac.bin
    chown oem_5004 oem_5004 /persist/bt/bt_bdaddr
    chmod 0664 /persist/bt/bt_bdaddr

    # Set life_calls and life_timer file permissions
    chown radio mot_tcmd /persist/public/hiddenmenu/life_calls
    chmod 0775 /persist/public/hiddenmenu/life_calls
    chown radio mot_tcmd /persist/public/hiddenmenu/life_timer
    chmod 0775 /persist/public/hiddenmenu/life_timer

    chmod 0711 /persist/rfs
    chmod 0711 /persist/rfs/msm
    chmod 0711 /persist/rfs/msm/mpss
    chmod 0771 /persist/rfs/msm/mpss/mot_rfs

    swapon_all fstab.qcom
    write /proc/sys/vm/page-cluster 0

on post-fs-data
    #setup folder for WLAN WAPI
    chmod 0770 /data/wapi_certificate
	
    # Setup folders for security
    mkdir /persist/security 02770 oem_5007 oem_5007
    mkdir /data/local/dbvc 0750 oem_5004 shell

    # Create directory used by power_supply_logger
    mkdir /data/power_supply_logger 0750 oem_5001 log

    # Create moodle directory that MOT_MOODLE can write to
    mkdir /data/local/moodle 0770 graphics oem_5004

    # Permissions for Factory Test of Charging Paths
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_auto_enable
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_ibatt
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_itrick
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_iusb
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_usb_suspend
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_fail_clear
    chown oem_5001 oem_5001 /sys/class/power_supply/battery/device/force_chg_usb_otg_ctl

    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_rechrg_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_attach_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_start_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_low_stop_soc
    chmod 0664 /sys/module/qpnp_smbcharger_mmi/parameters/eb_on_sw

    # Sensor Hub calibration data directory
    mkdir /data/misc/sensorhub 0770 system compass

    # Setup folder for native to transfer data to NativeDropBoxAgent
    mkdir /data/system/dropbox-add 0730 system diag

    # Create directory for cutback
    mkdir /data/misc/cutback 0770 radio wifi

    # Create directory for fm_radio
    mkdir /data/misc/fm_radio 0770 system system

    #setup folder for WLAN WAPI
    mkdir /data/wapi_certificate 0750 system wifi
    chown system wifi /data/wapi_certificate

    # Create bug2go folder
    mkdir /data/bug2go 0770 log log

    # Subsystem RAM-dumps
    mkdir /data/ss-ram-dumps 0750 system log
    mkdir /data/ss-ram-dumps/bp-dumps 0750 system log
    mkdir /data/ss-ram-dumps/riva-dumps 0750 system log

    # folder for Blueooth ramdump
    mkdir /data/bt-ram-dumps 0750 bluetooth log

    # SD card encryption metadata
    mkdir /data/misc/sds 0750 root root

    # Required by FingerPrint Cards (FPC) via init so we don't need to give qseecomd or fingerprintd permissions to create them
    mkdir /data/fpc 0700 system system
    mkdir /data/.fps 0770 system input

    #Folder for hardware properties
    mkdir /data/hardware_revisions 0755 system system

    #Create directory for adspd
    mkdir /data/adspd 0770 audio diag

    # Setup folder for camera dump subsystem
    mkdir /data/camera_dump 0750 media media

    # Imager tuning data for camera subsystem
    mkdir /data/misc/imager 0770 camera camera

    # OTA Package directory
    mkdir /data/misc_ne 0770 system cache

    # NFC vendor data
    mkdir /data/vendor/nfc 0770 nfc nfc

    #setup folder for WLAN WAPI
    chmod 0770 /data/wapi_certificate

on boot
   # restore default console_loglevel to KERN_DEBUG
   # restore default_message_loglevel to KERN_WARNING
   write /proc/sys/kernel/printk "7 4 1 7"

   chown root oem_5004 /sys/module/phy_msm_usb/parameters/host_mode_disable
   chmod 0660 /sys/module/phy_msm_usb/parameters/host_mode_disable
   chown root oem_5004 /sys/devices/soc/7000000.ssusb/disable_id_pin
   chmod 0220 /sys/devices/soc/7000000.ssusb/disable_id_pin
    
   #change ownership and permission for LTR559
   chown system system /sys/class/sensors/Rear\ Proximity\ sensor/enable
   chown system system /sys/class/sensors/Rear\ Proximity\ sensor/poll_delay
   chown system system /sys/class/sensors/Rear\ Proximity\ sensor/enable_wakeup
   chmod 0660 /sys/class/sensors/Rear\ Proximity\ sensor/enable
   chmod 0660 /sys/class/sensors/Rear\ Proximity\ sensor/poll_delay
   chmod 0660 /sys/class/sensors/Rear\ Proximity\ sensor/enable_wakeup

   # Change permission for type C params
   chown root oem_5004 /sys/devices/soc/78b6000.i2c/i2c-2/2-0022/CC_state
   chown root oem_5004 /sys/devices/soc/78b6000.i2c/i2c-2/2-0022/enable_vconn
   # Change ownership and permission for AMPS factory testing
   chown root oem_5004 /sys/class/i2c-adapter/i2c-2/2-002d/enable
   chmod 0660 /sys/class/i2c-adapter/i2c-2/2-002d/enable
   chown root oem_5004 /sys/class/i2c-adapter/i2c-2/2-002d/hsic_vdd
   chmod 0660 /sys/class/i2c-adapter/i2c-2/2-002d/hsic_vdd

   # Change permission for fingerprint sensor
   chown system oem_5004 /sys/bus/spi/devices/spi8.0/nav
   chown system oem_5004 /sys/bus/spi/devices/spi8.0/clk_enable
   chown system oem_5004 /sys/bus/spi/devices/spi8.0/dev_enable
   chown system oem_5004 /sys/bus/spi/devices/spi8.0/irq
   chown system oem_5004 /sys/bus/spi/devices/spi8.0/irq_cnt
   chmod 0440 /sys/bus/spi/devices/spi8.0/irq_cnt

 # Change ownership and permission for backlight
   chown system system /sys/class/backlight/lcd-backlight:0/brightness
   chmod 0664 /sys/class/backlight/lcd-backlight:0/brightness
   chown system system /sys/class/backlight/lcd-backlight:0/max_brightness
   chmod 0664 /sys/class/backlight/lcd-backlight:0/max_brightness
   chmod 0664 /sys/class/leds/lcd-backlight/brightness
   chown system system /sys/class/leds/charging/brightness
   chmod 0664 /sys/class/leds/charging/brightness

   # Change ownership for Dynamic-CABC feature
   chown system system /sys/class/graphics/fb0/cabc_mode
   # Change ownership for for HBM feature
   chown system system /sys/class/graphics/fb0/hbm
   # Change ownership for for ACL feature
   chown system system /sys/class/graphics/fb0/acl_mode

   # Change ownership and permission for vibrator
   chown system system /sys/class/timed_output/vibrator/enable
   chmod 0660 /sys/class/timed_output/vibrator/enable

   chown root oem_5004 /sys/class/graphics/fb0/te_enable
   chown root oem_5004 /sys/class/graphics/fb0/frame_counter

   chown audio audio /sys/kernel/aov/trigger
   chown audio audio /sys/kernel/aov/register
   chown audio audio /sys/kernel/aov/event

   # Quiet binder logs
   write /sys/module/binder/parameters/debug_mask 0x5

# Pass carrier to wlan
service init_wifi /system/vendor/bin/wlan_carrier_bin.sh
    class main
    user root
    group root
    oneshot

on charger
    trigger early-fs
    trigger fs
    trigger post-fs
    trigger post-fs-data
    trigger moto-charger
    class_stop main
    class_stop late_start

on moto-charger
    setprop ro.board.platform msm8953
    trigger firmware_mounts_complete
    start charge_only_mode
    start thermal-com

on property:ro.boot.dualsim=true
   setprop persist.radio.multisim.config dsds
   setprop ro.telephony.default_network 10,10

on property:ro.boot.dualsim=false
   setprop persist.radio.multisim.config ""
   setprop ro.telephony.default_network 10

service adspd /system/vendor/bin/adspd
   class main
   socket adspdsock stream 0660 system audio
   user audio
   group audio input diag

service fingerprintd /system/bin/fingerprintd
    class late_start
    user system
    group input

service mmi-boot-sh /system/vendor/bin/init.mmi.boot.sh
    class core
    user root
    oneshot

service mmi-touch-sh /system/vendor/bin/init.mmi.touch.sh
    class core
    user root
    oneshot

service oem-hw-sh /system/vendor/bin/init.oem.hw.sh
    class core
    user root
    oneshot

# Sanders uses qcom sensor service
service sensors /system/vendor/bin/sensors.qcom
    class core
    user root
    group root

service charge_only_mode /system/bin/charge_only_mode
    user root
    group graphics system input
    disabled

service thermal-com /system/vendor/bin/thermal-engine --minimode
    class main
    user root
    disabled

# Set RPS Mask for Wifi Hotspot
on property:sys.wifi.tethering=true
    write /sys/class/net/rmnet_data0/queues/rx-0/rps_cpus ${sys.usb.rps_mask}
    write /sys/class/net/wlan0/queues/rx-0/rps_cpus ${sys.usb.rps_mask}
    write /sys/class/net/wlan0/queues/rx-1/rps_cpus ${sys.usb.rps_mask}
    write /sys/class/net/wlan0/queues/rx-2/rps_cpus ${sys.usb.rps_mask}
    write /sys/class/net/wlan0/queues/rx-3/rps_cpus ${sys.usb.rps_mask}
    write /sys/class/net/wlan0/queues/rx-4/rps_cpus ${sys.usb.rps_mask}

on property:sys.wifi.tethering=false
    write /sys/class/net/rmnet_data0/queues/rx-0/rps_cpus ${sys.rmnet_vnd.rps_mask}

on property:ro.bootmode=normal
   write /sys/module/usb3813_hub/parameters/boost_val 3
