Initial commit

This commit is contained in:
Halim Qarroum
2023-02-15 03:01:51 +00:00
commit b021fd4d0d
16 changed files with 1612 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
set -e
# Writes a log with a key and a value
# as a JSON object on the standard output.
function write_log() {
echo "{ \"type\": \"$1\", \"value\": \"$2\" }"
}
# Writes a state update on the standard output.
function update_state() {
write_log "state-update" "$1"
}
# Waits for the emulator to boot and writes
# state updates on the standard output.
function wait_for_boot() {
update_state "booting"
# Waiting for the ADB server to start.
while [ -n "$(adb wait-for-device > /dev/null)" ]; do
adb wait-for-device
sleep 1
done
# Waiting for the boot sequence to be completed.
COMPLETED=$(adb shell getprop sys.boot_completed | tr -d '\r')
while [ "$COMPLETED" != "1" ]; do
COMPLETED=$(adb shell getprop sys.boot_completed | tr -d '\r')
sleep 5
done
update_state "booted"
}
+14
View File
@@ -0,0 +1,14 @@
# If the installation flag of the Android SDK is set
# we download the Android command-line tools,
# install the SDK, platform tools and the emulator.
if [ "$INSTALL_ANDROID_SDK" == "1" ]; then
echo "Installing the Android SDK, platform tools and emulator ..."
wget https://dl.google.com/android/repository/commandlinetools-linux-${CMD_LINE_VERSION}.zip -P /tmp && \
mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/ && \
unzip -d $ANDROID_SDK_ROOT/cmdline-tools/ /tmp/commandlinetools-linux-${CMD_LINE_VERSION}.zip && \
mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/ $ANDROID_SDK_ROOT/cmdline-tools/tools/ && \
rm /tmp/commandlinetools-linux-${CMD_LINE_VERSION}.zip && \
yes | sdkmanager --licenses && \
sdkmanager --install "$PACKAGE_PATH" && \
yes | sdkmanager --verbose $PACKAGE_PATH $ANDROID_PLATFORM_VERSION platform-tools emulator
fi
+46
View File
@@ -0,0 +1,46 @@
#!/bin/bash
set -e
source ./emulator-monitoring.sh
# The emulator console port.
EMULATOR_CONSOLE_PORT=5554
# The ADB port used to connect to ADB.
ADB_PORT=5555
# Start ADB server by listening on all interfaces.
echo "Starting the ADB server ..."
adb -a -P 5037 server nodaemon &
# Detect ip and forward ADB ports outside to outside interface
ip=$(ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)
redir --laddr=$ip --lport=$EMULATOR_CONSOLE_PORT --caddr=127.0.0.1 --cport=$EMULATOR_CONSOLE_PORT &
redir --laddr=$ip --lport=$ADB_PORT --caddr=127.0.0.1 --cport=$ADB_PORT &
export USER=root
# Creating the Android Virtual Emulator.
echo "Creating the Android Virtual Emulator ..."
echo no | avdmanager create avd -n android --abi ${ABI} -k "$PACKAGE_PATH" --device "pixel"
# Asynchronously write updates on the standard output
# about the state of the boot sequence.
#cat ~/.android/avd/android.avd/config.ini
wait_for_boot &
# Start the emulator with no audio, no GUI, and no snapshots.
echo "Starting the emulator ..."
if emulator \
-avd android \
-noaudio \
-no-boot-anim \
-no-window \
-no-snapshot-save \
-qemu \
-enable-kvm;
then
update_state "stopped"
else
update_state "stopped"
fi