on early-init
#    loglevel 8

    setprop ro.hw_timeout_multiplier ${ro.boot.hw_timeout_multiplier}
    setprop hypervisor.memory_reclaim.supported ${ro.boot.hypervisor.vm.supported}

    start metrics_helper
    # start module load in the background
    start vendor.dlkm_loader
    # specially load zram as it is a "leaf" GKI module
    exec u:r:modprobe:s0 -- /system/bin/modprobe -a -d /system/lib/modules zram.ko
    # only load vkms after virtio_gpu has been loaded
    wait /dev/dri/card0
    exec u:r:vendor_modprobe:s0 -- /vendor/bin/modprobe -d /vendor/lib/modules vkms.ko create_default_dev=0

on early-init && property:ro.boot.vendor.apex.com.android.hardware.keymint=\
com.android.hardware.keymint.rust_cf_guest_trusty_nonsecure
    # Enable the Trusty Security VM
    setprop trusty.security_vm.enabled 1
    # Enable KeyMint that connects to the Trusty Security VM
    setprop trusty.security_vm.keymint.enabled 1

on init
    # ZRAM setup
    write /sys/block/zram0/comp_algorithm lz4

    # EAS uclamp interfaces
    mkdir /dev/cpuctl/foreground
    mkdir /dev/cpuctl/background
    mkdir /dev/cpuctl/top-app
    mkdir /dev/cpuctl/rt
    chown system system /dev/cpuctl
    chown system system /dev/cpuctl/foreground
    chown system system /dev/cpuctl/background
    chown system system /dev/cpuctl/top-app
    chown system system /dev/cpuctl/rt
    chown system system /dev/cpuctl/tasks
    chown system system /dev/cpuctl/foreground/tasks
    chown system system /dev/cpuctl/background/tasks
    chown system system /dev/cpuctl/top-app/tasks
    chown system system /dev/cpuctl/rt/tasks
    chmod 0664 /dev/cpuctl/tasks
    chmod 0664 /dev/cpuctl/foreground/tasks
    chmod 0664 /dev/cpuctl/background/tasks
    chmod 0664 /dev/cpuctl/top-app/tasks
    chmod 0664 /dev/cpuctl/rt/tasks

on fs
    mkdir /mnt/vendor/shared 0770 system system

    # Mount everything that does not require fsck
    mount_all --early

    # So GceBootReporter can print to kmsg
    chmod 622 /dev/kmsg

on post-fs-data && property:ro.vendor.disable_rename_eth0=
    # works around framework netiface enumeration issue
    # TODO(b/202731768): Add this `start rename_eth0` command to the init.rc for rename_netiface
    start rename_eth0

on post-fs-data && property:ro.boot.wifi_impl=virt_wifi
    # TODO(b/202731768): Add this `start setup_wifi` command to the init.rc for setup_wifi
    start setup_wifi

on post-fs-data
    mkdir /data/vendor/modem_dump 0777 system system
    mkdir /data/vendor/radio 0777 system system

on late-fs
    # Mount RW partitions which need run fsck
    mount_all --late

    write /dev/kmsg "GUEST_BUILD_FINGERPRINT: ${ro.build.fingerprint}"

on post-fs-data && property:ro.boot.wifi_impl=mac80211_hwsim_virtio
    mkdir /data/vendor/wifi 0770 wifi wifi
    mkdir /data/vendor/wifi/hostapd 0770 wifi wifi
    mkdir /data/vendor/wifi/hostapd/sockets 0770 wifi wifi
    start init_wifi_sh

on boot
    chmod 0770 /dev/cpuctl
    mkdir /data/vendor/wifi 0770 wifi wifi
    mkdir /data/vendor/wifi/wpa 0770 wifi wifi
    mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi
    start socket_vsock_proxy
    setprop ro.hardware.audio.primary goldfish
    symlink /dev/hvc6 /dev/gnss0
    symlink /dev/hvc7 /dev/gnss1

on property:sys.boot_completed=1
    trigger sys-boot-completed-set
    mkdir /mnt/vendor/custom 0755 root root
    mount ext2 /dev/block/by-name/custom /mnt/vendor/custom loop rw sync

# We want one opportunity per boot to enable zram, so we
# use a trigger we fire from the above stanza. If
# persist.sys.zram_enabled becomes true after boot,
# we don't want to run swapon_all at that time.
on sys-boot-completed-set && property:persist.sys.zram_enabled=1
    swapon_all

service vendor.dlkm_loader /vendor/bin/dlkm_loader
    class main
    user root
    group root system
    disabled
    oneshot

service metrics_helper /vendor/bin/metrics_helper
    group system
    user root

service socket_vsock_proxy /vendor/bin/socket_vsock_proxy -server_type=vsock -server_vsock_port=6520 -client_type=tcp -client_tcp_host=0.0.0.0 -client_tcp_port=5555
    user root

service bugreport /system/bin/dumpstate -d -p -z
    class main
    user root
    disabled
    oneshot
    keycodes 30 48

# TODO: disable this service once cuttlefish implements system suspend
service suspend_blocker /vendor/bin/suspend_blocker
    class early_hal # Start together with system_suspend HAL
    group system
    user root

on early-init
    setprop ro.setupwizard.mode ${ro.boot.setupwizard_mode}

on early-init
    setprop ro.vendor.cuttlefish_service_bluetooth_checker ${ro.boot.cuttlefish_service_bluetooth_checker}

on early-init && property:ro.boot.enable_bootanimation=0
    setprop debug.sf.nobootanimation 1
