Reputation: 433
I am working on a shell script that runs on an Android 8.0 TV device. The script is designed to:
Here is the script I have so far:
#!/system/bin/sh
# Azure Function URL
azure_function_url="path to azure function"
# Sample result: URLs = ["https://google.com", "https://bing.com", "https://stackoverflow.com"]
# Fetch URLs from the Azure Function
json_response=$(/data/local/tmp/curl "$azure_function_url" -k -L)
echo "JSON Response: $json_response"
# Extract URLs using jq
URLs=($(echo $json_response | /data/local/tmp/jq171 -r '.[]'))
# Print the URLs array
echo "Extracted URLs:"
for url in "${URLs[@]}"; do
echo "$url"
done
# Function to reset sleep timer
reset_timer() {
echo 30 > /data/local/tmp/sleep_timer.txt
}
# Initial sleep timer value
echo 30 > /data/local/tmp/sleep_timer.txt
index=0
url_count=${#URLs[@]}
# Loop through each URL
while true
do
url="${URLs[$index]}"
am start -a android.intent.action.VIEW -d "$url"
# Loop with sleep timer
while [ $(cat /data/local/tmp/sleep_timer.txt) -gt 0 ]; do
already_reset=false
getevent -lt /dev/input/event1 | while read line
do
if echo "$line" | grep -q "ABS_MT_POSITION_X"; then
if [ "$already_reset" = "false" ]; then
reset_timer
already_reset=true
fi
fi
done &
sleep 1
sleep_timer=$(cat /data/local/tmp/sleep_timer.txt)
((sleep_timer--))
echo $sleep_timer > /data/local/tmp/sleep_timer.txt
done
index=$(( (index + 1) % url_count ))
echo 30 > /data/local/tmp/sleep_timer.txt
done
Problem:
The script works, but the entire device (currently an emulator) freezes and becomes very slow when interacting with the touch screen.
Questions:
Any ideas or suggestions to improve the script or an alternative solution would be greatly appreciated. Thank you!
Upvotes: 0
Views: 30