From c64c17d86e96d1f4c2eca08c8c4d8015fa1377e6 Mon Sep 17 00:00:00 2001 From: Andrii Dokhniak Date: Sun, 25 May 2025 16:38:52 +0200 Subject: [PATCH] adid && coord --- android/Dockerfile | 2 ++ android/code/index.mjs | 12 ++++++++++++ android/conf/set_geo.sh | 13 +++++++++++++ android/conf/start_culebra.sh | 15 +++++++++++---- docker-compose.yaml | 1 + http_server/code/index.html | 5 +++++ http_server/code/index.mjs | 11 +++++++++++ pre_android/Dockerfile | 2 +- pre_android/preconf/docker-entrypoint.sh | 3 +++ 9 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 android/conf/set_geo.sh diff --git a/android/Dockerfile b/android/Dockerfile index adc494c..2813e82 100644 --- a/android/Dockerfile +++ b/android/Dockerfile @@ -3,6 +3,8 @@ FROM pre_android/ready # Set up node RUN npm install -g n && n install 22.14.0 && n use 22.14.0 && hash -r +RUN node --version + # Set up httptoolkit-server RUN git clone https://github.com/httptoolkit/httptoolkit-server /httptoolkit-server diff --git a/android/code/index.mjs b/android/code/index.mjs index 3fc1ba3..bb5c961 100644 --- a/android/code/index.mjs +++ b/android/code/index.mjs @@ -56,6 +56,18 @@ wss.on("connection", (ws) => { dataSplit[3], dataSplit[4], ]); + } else if (data.startsWith("setcoord")) { + const dataSplit = data.split(" "); + const res = await spawnPromise("bash", [ + "/conf/set_geo.sh", + dataSplit[1], + dataSplit[2], + ]); + send_notification( + res.code === 0, + "Setting the moch location", + res.output + ); } }); ws.on("close", (_) => { diff --git a/android/conf/set_geo.sh b/android/conf/set_geo.sh new file mode 100644 index 0000000..5de2ea8 --- /dev/null +++ b/android/conf/set_geo.sh @@ -0,0 +1,13 @@ +#!/bin/bash +ko=$(( + echo "auth $(cat ~/.emulator_console_auth_token)" + echo "geo fix $1 $2 0.0" + sleep 0.2 + ) | telnet localhost 5554 | grep KO: ); + +if [ -z "${ko}" ]; then + exit 0 +else + echo "$ko" + exit 1; +fi diff --git a/android/conf/start_culebra.sh b/android/conf/start_culebra.sh index 6ceeda8..d638ea7 100644 --- a/android/conf/start_culebra.sh +++ b/android/conf/start_culebra.sh @@ -1,8 +1,15 @@ rm -f /opt/android-sdk-linux/.android/avd/virtual_dev.avd/*.lock adb start-server -emulator -avd virtual_dev -writable-system -no-window -no-audio & -adb wait-for-device -adb emu avd snapshot load configured +cat > /simple.gpx << EOF + + + + Simple Waypoint + + +EOF + +emulator -grpc 5556 -avd virtual_dev -snapshot configured -no-window -no-audio -debug all,-adb,-gles1emu,-gles,-mtport,-metrics,-memory,-car,-tvremote & adb wait-for-device export PATH=$PATH:/root/culebraDependencies @@ -12,4 +19,4 @@ cd /root/culebra #wait for the server to start while ! curl http://localhost:9987/v2/uiDevice/screenshot > /dev/null 2> /dev/null; do sleep 0.1 -done \ No newline at end of file +done diff --git a/docker-compose.yaml b/docker-compose.yaml index 1505ce7..0b693af 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,6 +23,7 @@ services: - 10001:10001 # api port - 3000:3000 # android server port - 3001:3001 # Notifications server + - 5556:5556 # emulator grpc port volumes: - $PWD/shared_buffer:/shared_buffer - $PWD/android/conf:/conf diff --git a/http_server/code/index.html b/http_server/code/index.html index 83ab631..ef48e0f 100644 --- a/http_server/code/index.html +++ b/http_server/code/index.html @@ -161,6 +161,11 @@
+
+ + + +
diff --git a/http_server/code/index.mjs b/http_server/code/index.mjs index 26c6d4a..386054e 100644 --- a/http_server/code/index.mjs +++ b/http_server/code/index.mjs @@ -109,4 +109,15 @@ app.post("/drag", function (req, res) { res.sendStatus(200); }); +app.post("/setcoord", function (req, res) { + console.log(req.body); + console.log(req.body.lat); + console.log(req.body.lon); + const lat = Number(req.body.lat); + const lon = Number(req.body.lon); + console.log(lat, lon); + android_websocket.send(`setcoord ${lat} ${lon}`); + res.sendStatus(200); +}); + app.listen(8080, () => console.log("Listening in port 8080")); diff --git a/pre_android/Dockerfile b/pre_android/Dockerfile index 95efdde..a74afaf 100644 --- a/pre_android/Dockerfile +++ b/pre_android/Dockerfile @@ -4,6 +4,6 @@ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/andro RUN sdkmanager --channel=2 "system-images;android-30;google_apis;x86_64" \ && echo no | avdmanager create avd -n virtual_dev -b google_apis/x86_64 -k "system-images;android-30;google_apis;x86_64" \ - && apt-get update && apt-get install -y iproute2 iputils-ping npm git + && apt-get update && apt-get install -y iproute2 iputils-ping npm git libxml2-utils telnet CMD bash /preconf/docker-entrypoint.sh diff --git a/pre_android/preconf/docker-entrypoint.sh b/pre_android/preconf/docker-entrypoint.sh index 149ae85..a56a68d 100644 --- a/pre_android/preconf/docker-entrypoint.sh +++ b/pre_android/preconf/docker-entrypoint.sh @@ -2,6 +2,9 @@ adb start-server emulator -avd virtual_dev -writable-system -no-window -no-audio & bash /preconf/install_culebra.sh +# Save the ad id while the emulator is still up +su root cat /data/data/com.google.android.gms/shared_prefs/adid_settings.xml | xmllint --xpath 'string(//map/string[@name="adid_key"])' - > /adid + adb emu avd snapshot save configured adb emu kill