|
#!/bin/sh |
|
|
|
# License for any modification to the original (linked below): |
|
# ---------------------------------------------------------------------------- |
|
# "THE BEER-WARE LICENSE" (Revision 42): |
|
# Sebastiano Poggi wrote this file. As long as you retain |
|
# this notice you can do whatever you want with this stuff. If we meet some day, |
|
# and you think this stuff is worth it, you can buy us a beer in return. |
|
# |
|
# Based on http://bit.ly/295BHLx |
|
|
|
DEBUG=false |
|
if [[ $* == *--debug* ]]; then |
|
DEBUG=true |
|
fi |
|
|
|
if [ "$DEBUG" = true ]; then |
|
set -x |
|
fi |
|
|
|
function log { |
|
if [ "$DEBUG" = true ]; then |
|
echo "🐞 [DEBUG] $1" |
|
fi |
|
} |
|
|
|
function checkAdb { |
|
if [[ $ADB == "" ]]; then |
|
ADB=adb |
|
fi |
|
|
|
command -v $ADB >/dev/null 2>&1 || { echo >&2 "❌ This command requires adb but it’s not on the PATH.\nYou can specify adb's path with the ADB variable."; exit 1; } |
|
log "Using ADB with command: '$ADB'" |
|
} |
|
|
|
function silent { |
|
$1 &>/dev/null |
|
} |
|
|
|
function readClockFromDeviceOsVersion { |
|
VERSION=$($ADB shell getprop ro.build.version.release) |
|
log "Read version: $VERSION" |
|
|
|
if [[ $VERSION =~ ^\d+(\.\d+)*$ ]]; then |
|
# Example VERSION: "8.1.0" |
|
MAJOR=${VERSION%%.*} # Drop VERSION from first '.' onwards |
|
MINOR=${VERSION#*.} # Drop VERSION before first '.' (included) |
|
MINOR=${MINOR%%.*} # Drop MINOR from first '.' onwards |
|
else |
|
# Example VERSION: "9" — hopefully we won't get crazy other stuff here... |
|
MAJOR=$VERSION |
|
MINOR="0" |
|
fi |
|
log "Parsed: major='$MAJOR', minor='$MINOR'" |
|
|
|
if [[ $MINOR == "" ]]; then |
|
MINOR="0" |
|
fi |
|
if [[ $MAJOR != "" ]]; then |
|
echo "ℹ️ Using device Android version for clock time. Detected version: $MAJOR.$MINOR" |
|
MAJOR=$(printf %02d $MAJOR) # Left-pad with zeroes to 2 digits |
|
|
|
if [[ $MINOR -lt 10 ]]; then |
|
# Right-pad minor version (e.g., '1' -> '10') |
|
MINOR="${MINOR}0" |
|
fi |
|
|
|
HHMM="$MAJOR$MINOR" |
|
log "Clock value: $HHMM" |
|
else |
|
HHMM="1010" |
|
echo "❌ parsing clock value, using default: $HHMM" |
|
fi |
|
} |
|
|
|
function setupDemoMode { |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command enter || exit" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm ${HHMM}" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false -e level 100" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command network -e nosim hide" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype 4g -e level 4 -e fully true" |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false" |
|
} |
|
|
|
function enableDemoMode { |
|
adb shell settings put global sysui_demo_allowed 1 |
|
} |
|
|
|
############################################## SCRIPT BEGINS HERE ######################################### |
|
|
|
CMD=$1 |
|
|
|
checkAdb |
|
|
|
if [[ $CMD != "on" && $CMD != "off" ]]; then |
|
echo "⚠️ Usage: $0 on|off [hhmm]" >&2 |
|
exit |
|
fi |
|
|
|
echo "🔍 Finding device..." |
|
silent "$ADB wait-for-device" |
|
|
|
if [ $CMD == "on" ]; then |
|
|
|
if [[ "$2" != "" ]]; then |
|
HHMM="$2" |
|
else |
|
readClockFromDeviceOsVersion |
|
fi |
|
|
|
echo "ℹ️ Enabling demo mode..." |
|
enableDemoMode |
|
setupDemoMode |
|
elif [ $CMD == "off" ]; then |
|
echo "ℹ️ Disabling demo mode..." |
|
silent "$ADB shell am broadcast -a com.android.systemui.demo -e command exit" |
|
fi |
|
|
|
echo "✅ Done." |