#!/bin/sh

# Wait for the property system to be up.
while [ ! -e /dev/socket/property_service ]; do sleep 0.1; done

# even if it exits out it doesn't really matter, it just has to initialize once
/usr/libexec/mtk-wmt-manager &

# Wait for nvram to be loaded.
while [ "$(getprop vendor.service.nvram_init)" != "Ready" ]; do sleep 0.2; done
while [ "$(getprop vendor.mtk.nvram.ready)" != "1" ]; do sleep 0.2; done

# enable Wi-Fi adapter in client mode
while [ ! -e /dev/wmtWifi ]; do sleep 0.2; done

# Finally enable the adapter in station mode
echo P > /dev/wmtWifi

# enables wireless display support
setprop debug.stagefright.c2inputsurface 1
setprop ubuntu.widi.supported 1

# set wifi.interface property since urfkill.conf expects that
setprop wifi.interface wlan0

# Enable WoWLAN to avoid network disconnect before suspend
while [ ! -e /sys/class/ieee80211/phy0 ]; do sleep 1; done
iw phy phy0 wowlan enable magic-packet

# allow phablet to use flashlight nodes
chown phablet:phablet /sys/class/flashlight/mt-flash-led1/*
chown phablet:phablet /sys/class/flashlight/mt-flash-led2/*
chown phablet:phablet /sys/class/flashlight_core/flashlight/*
