#!/system/bin/sh
MODDIR="${0%/*}"

# Wait for boot to complete
while [ "$(getprop sys.boot_completed)" != 1 ]; do
    /system/bin/sleep 1
done

# Clean up user-installed version if it's still around
INSTALL_PATH=$(pm path com.nothing.camera2magic 2>/dev/null | grep package: | head -1)
if echo "$INSTALL_PATH" | grep -q "/data/app/"; then
    pm uninstall com.nothing.camera2magic 2>/dev/null
fi

# --- Diagnostics ---
LOG_TAG="CamSwapperModule"
log -t "$LOG_TAG" "=== CamSwapper VDM module service.sh ==="

# Verify overlay visibility
for f in \
    /system/priv-app/CamSwapper/CamSwapper.apk \
    /system/etc/permissions/privapp-permissions-camswapper.xml; do
    if [ -f "$f" ]; then
        log -t "$LOG_TAG" "OK: $f exists"
        ls -la "$f" 2>&1 | log -t "$LOG_TAG"
    else
        log -t "$LOG_TAG" "MISSING: $f NOT FOUND"
    fi
done

# Show mounts under /system
mount | grep " /system" | log -t "$LOG_TAG"
