#!/bin/bash

LXC_ROOTFS="/var/lib/lxc/android/rootfs"

# Get Android container version
ANDROID_SDK_VERSION=$(grep ro.build.version.sdk= ${LXC_ROOTFS}/system/build.prop | cut -d "=" -f2)

# Wait for the container
lxc-wait -n android -t 10 -s "RUNNING"

if [ $ANDROID_SDK_VERSION -ge 29 ]; then
	# Android >= 10. Keep waiting for apexd before notifying systemd so
	# dependent services retain the existing container-ready timing.
	/usr/sbin/droidian-apex --timeout 90 wait ready || exit 1
fi

# Notify systemd we're done
systemd-notify --ready --status="Container ready"

# Block on lxc-wait
lxc-wait -n android -s "STOPPED"
