Skip to content

Instantly share code, notes, and snippets.

@basilgello
Created May 16, 2020 21:16
Show Gist options
  • Save basilgello/9a4651f464107ab4993191a53acb9549 to your computer and use it in GitHub Desktop.
Save basilgello/9a4651f464107ab4993191a53acb9549 to your computer and use it in GitHub Desktop.
Set timezone by geolocation on Android using root sheel, Termux and IPgeolocation.io
#!/bin/sh
#
# Proof-of-concept geolocation-based timezone changer
#
# Requires:
#
# * Termux with termux-api package installed
# * Fine locatiin permission granted
# * Free API ey from https://ipgeolocation.io
# * Root access
#
# Author: Vasyl Gello <[email protected]>
# License: Apache-2.0
#
# Change this to your IPGeolocation.io API key
IPGEOLOCATION_API_KEY=""
GEOLOCATION=$(termux-location | jq -r '"lat=\(.latitude)&long=\(.longitude)"')
RESPONSE=$(curl "https://api.ipgeolocation.io/timezone?apiKey=$IPGEOLOCATION_API_KEY&$GEOLOCATION")
if [ ! -z "$RESPONSE" ]; then
TIMEZONE=$(echo "$RESPONSE" | jq -r '.timezone')
if [ -z "$TIMEZONE" ]; then
echo "ERROR: Timezone response is empty"
exit 1
fi
# Call AlarmManager.setTimeZone on LineageOS 14.1 (Android 7.1.2)
# Idea taken from:
# http://v-kompany.blogspot.com/2014/07/how-to-call-system-service-in-adb.html
su -c "service call alarm 3 s16 \"$TIMEZONE\" | \
grep \"Result: Parcel(00000000 \" \
1>/dev/null 2>/dev/null"
if [ $? -eq 0 ]; then
echo "Timezone set to: $TIMEZONE"
else
echo "ERROR: Cannot call AlarmManager.setTimezone!"
fi
else
echo "ERROR: Timezone response is empty"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment