This commit is contained in:
lif
2026-04-21 08:50:25 +01:00
commit 562c89064d
2 changed files with 69 additions and 0 deletions

12
Makefile Normal file
View File

@@ -0,0 +1,12 @@
start:
sh scripts/waydroid-run.sh 9:20 900
network-up:
sudo ip link set waydroid0 up
network-down:
sudo ip link set waydroid0 down
network-block:
sudo iptables -I FORWARD -i waydroid0 -j DROP
sudo iptables -I FORWARD -o waydroid0 -j DROP
network-unblock:
sudo iptables -D FORWARD -i waydroid0 -j DROP
sudo iptables -D FORWARD -o waydroid0 -j DROP

57
scripts/waydroid-run.sh Normal file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Usage: ./calc_resolution.sh <aspect_ratio> <height>
# Example: ./calc_resolution.sh 16:9 1080
if [ $# -ne 2 ]; then
echo "Usage: $0 <aspect_ratio W:H> <height>"
exit 1
fi
ASPECT="$1"
HEIGHT="$2"
# Extract numerator (W) and denominator (H) from the aspect ratio
IFS=':' read -r W_RATIO H_RATIO <<< "$ASPECT"
# Validate numeric input
if ! [[ "$W_RATIO" =~ ^[0-9]+$ && "$H_RATIO" =~ ^[0-9]+$ && "$HEIGHT" =~ ^[0-9]+$ ]]; then
echo "Error: aspect ratio and height must be numeric."
exit 1
fi
# Calculate width = (W_RATIO / H_RATIO) * HEIGHT
WIDTH=$(awk -v wr="$W_RATIO" -v hr="$H_RATIO" -v h="$HEIGHT" 'BEGIN { printf "%d", (wr/hr)*h }')
echo "Resolution: ${WIDTH}x${HEIGHT}"
waydroid session start &
WAYDROID_PID=$!
# Wait for session to be ready
while ! waydroid status | grep -E "^Session:.*RUNNING"; do
echo "Waiting for waydroid"
sleep 1
done
echo "Sleeping 4 seconds for waydroid session to start"
sleep 4
# waydroid session start --background
echo "Setting waydroid width to $WIDTH"
waydroid -w prop set persist.waydroid.width $WIDTH
echo "Setting waydroid height to $HEIGHT"
waydroid prop set persist.waydroid.height $HEIGHT
waydroid session stop
# Forward container → host → internet
sudo iptables -C FORWARD -i waydroid0 -j ACCEPT 2>/dev/null || \
sudo iptables -A FORWARD -i waydroid0 -j ACCEPT
# Forward responses from internet → host → container
sudo iptables -C FORWARD -o waydroid0 -m state --state RELATED,ESTABLISHED -j ACCEPT 2>/dev/null || \
sudo iptables -A FORWARD -o waydroid0 -m state --state RELATED,ESTABLISHED -j ACCEPT
# sudo waydroid container start
waydroid session start &
sleep 2
waydroid show-full-ui &
sleep 16