#!/bin/sh

# Allow ayatana-indicator-power to toggle torchlight
chmod g+w /sys/class/flashlight_core/flashlight/flashlight_torch
chgrp phablet /sys/class/flashlight_core/flashlight/flashlight_torch

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

# 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

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


# Wait for /dev/wmtWifi to exist..
while [ ! -c /dev/wmtWifi ]; do sleep 0.2; done

# Silence all wlan debug logging down to just errors/warnings
printf '0xFF:0x03' > /proc/net/wlan/dbgLevel

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

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

# 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

# Disable graphics.allocator service in Waydroid as it should use the host one
if [ ! -e /var/lib/waydroid/overlay/vendor/etc/init/android.hardware.graphics.allocator@2.0-service.rc ]; then
    mkdir -p /var/lib/waydroid/overlay/vendor/etc/init
    ln -sf /dev/null /var/lib/waydroid/overlay/vendor/etc/init/android.hardware.graphics.allocator@2.0-service.rc
fi
