Skip to content

Commit

Permalink
Merge pull request #213 from IntergalacticPenguin/feature/random-tweaks
Browse files Browse the repository at this point in the history
atestmonkey + random tweaks = v 1.2.0
  • Loading branch information
IGPenguin authored Aug 10, 2021
2 parents eb3c1b6 + fe4b855 commit e7584c2
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 104 deletions.
18 changes: 8 additions & 10 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
🚨 **Check all before merging!**
- [ ] 🏗 Everything implemented thoroughly
- [ ] 🔨 All changes tested
- [ ] Change #1
- [ ] Change #2...
- [ ] 👀 Go through the diff
- [ ] 📝 API changes included in README.md
- [ ] 📣 Major changes listed in changelog.txt

✅ All good? -> **Merge!** 🎉🎉🎉
## ⚠️ Progress checklist
- [ ] 🏗 **Features fully completed**
- [ ] 🔬 **Shellcheck issues resolved**
- [ ] 🔨 **All changes tested**
- [ ] 💬 **Terminal output satisfactory**
- [ ] 👀 **Diff examined thoroughly**
- [ ] 📝 **API changes included in `README.md`**
- [ ] 📣 **Major changes listed in `changelog.txt`**
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
- name: Shellcheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC1090 -e SC2207 -e SC2001
SHELLCHECK_OPTS: -e SC1090 -e SC2207 -e SC2001 -e SC1091
# SC1090 - non-constant source
# SC2207 - no arrays like this ($())
# SC2001 - replace sed with ${variable//search/replace}
# SC1091 - common_tools was not specified as input (see shellcheck -x)
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Header](/header_v2.png?raw=true)
![Header](/media/header_v2.png?raw=true)
## What is this?
🛠 Capture screen, manage apps, simulate input, print system log and more using simple commands!<br>

Expand Down Expand Up @@ -215,6 +215,21 @@ _Note: This repository is mainly focused on macOS compatibility, but majority of
* `telnet <command>` - call command via telnet
* example commands `event | redir | sensor | physics | finger | rotate | fold | unfold...` see [Android emulator documentation](https://developer.android.com/studio/run/emulator-console#console-session) for more information

### 🐒 atestmonkey
* Perform automated stress test using [Application Excersciser Monkey](https://developer.android.com/studio/test/monkey)
* Default test length is `15000` input events, support for custom count will be added in future update
* You can end test prematurely using ctrl^c or `atestmonkeykill` in case something goes wrong
* App under test needs to be pinned to fullscreen mode to prevent unwanted interactions elsewhere
* Screen pinning button location is directly tied to OS version and device manufacturer skin. It may be tricky to find, see examples below:<br><br>
* <details>
<summary>Google Nexus 5 (Android 6)</summary>
<br><em>You need to bring the app window to foreground, the button is located in bottom right corner.</em><br><br>
<img src="/media/Pinning_Nexus_v3.png" width="420"></details>
* <details>
<summary>Google Pixel 3 (Android 11)</summary>
<br><em>You need to click on the app icon, the button is located in popup menu.</em><br><br>
<img src="/media/Pinning_Pixel.png" width="420"></details>

# 🍎 iOS commands

## Capture screen
Expand All @@ -225,19 +240,12 @@ _Note: This repository is mainly focused on macOS compatibility, but majority of

### 🎥 irecord
**Required**: Install [videosnap](https://github.com/matthutchinson/videosnap/releases "videosnap") -> download and run `videosnap-0.0.6.pkg`

1. `irecord` Record screen
2. End recording using `ctrl + c`
3. Save screen video footage to ~/Desktop

### 🖼 igif
**Required**: Install [ffmpeg](https://www.ffmpeg.org/ "ffmpeg") `brew install ffmpeg`

1. Record screen (take as many screenshots per second as possible) to ~/Desktop
1. `irecord` Record screen
2. End recording using `ctrl + c`
3. Compose .mp4 from screenshots and save it to ~/Desktop
4. (Optional) Delete screenshots
* Specify your own filename by passing it as argument
3. Video footage is saved to ~/Desktop
4. File is compressed using ffmpeg

## Manage applications
### 🚚 iinstall
Expand Down
2 changes: 1 addition & 1 deletion android/abuildproject
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ find_apk_path(){
}

launch(){
detect_package_info "$1"
android_detect_package_info "$1"
echo "🚀 Launching $APP_NAME..."
adb -s "$SELECTED_DEVICE" shell monkey -p "$PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 &> /dev/null
}
Expand Down
1 change: 0 additions & 1 deletion android/acheckdevice
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ open_gsmarena(){
}

android_choose_device
android_unlock_device "$SELECTED_DEVICE"
echo_info
check_screen_timeout
check_screen_brightness
Expand Down
2 changes: 1 addition & 1 deletion android/aemulator
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ check_running_emulator(){
get_emulator_list(){
echo "⏳ Getting Android emulator list..."
rm -f "$LOCAL_EMULATOR_LIST"
~/Library/Android/sdk/tools/bin/avdmanager list avd | grep Name | awk '{print $2}' >> "$LOCAL_EMULATOR_LIST"
"$ANDROID_HOME"/cmdline-tools/latest/bin/avdmanager list avd | grep Name | awk '{print $2}' >> "$LOCAL_EMULATOR_LIST"
if [ "$(nl "$LOCAL_EMULATOR_LIST")" == "" ]; then
should_proceed "🤷‍ No emulators installed, install via Android Studio?"
echo "⏳ Opening Android Studio..."
Expand Down
4 changes: 2 additions & 2 deletions android/ainstall
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ run()
check_for_update
android_check_connected
android_get_devices_auth_dump
detect_package_info "$2"
android_detect_package_info "$2"
for line in $(adb devices | grep -v "List" | awk '{print $1}')
do
DEVICE=$(echo "$line" | awk '{print $1}')
Expand All @@ -47,7 +47,7 @@ run()
wait
else
android_choose_device
detect_package_info "$1"
android_detect_package_info "$1"
install_app "$SELECTED_DEVICE" "$1"
fi
}
Expand Down
13 changes: 9 additions & 4 deletions android/aoptions
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ import_intents(){
start_settings_intent(){
SETTINGS_INTENT=$(sed "$LINE"!d "$LOCAL_SETTINGS_LIST_PATH")
echo "🚀 Starting $SETTINGS_INTENT"
adb -s "$SELECTED_DEVICE" shell am start -a "$SETTINGS_INTENT" | grep error
adb -s "$SELECTED_DEVICE" shell am start -a "$SETTINGS_INTENT" &> /dev/null
}

search_for_intent(){
if nl "$LOCAL_SETTINGS_LIST_PATH" | grep -i "$1"; then
read -r -p "📝 Choose option number: " LINE
if nl "$LOCAL_SETTINGS_LIST_PATH" | grep -i -q "$1"; then
if [[ $(grep -c -i "$1" "$LOCAL_SETTINGS_LIST_PATH") -eq 1 ]]; then #If there is only one result
LINE=$(nl "$LOCAL_SETTINGS_LIST_PATH" | grep -i "$1" | awk '{print $1}')
else
nl "$LOCAL_SETTINGS_LIST_PATH" | grep -i "$1"
read -r -p "📝 Choose option number: " LINE
fi
start_settings_intent
else
read -r -p "🤷‍ No \"$1\" intent found, try again or leave blank: " KEYWORD
Expand All @@ -46,7 +51,7 @@ handle_preset(){
adb -s "$SELECTED_DEVICE" shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS &> /dev/null
;;

"2" | "locale")
"2" | "locale" | "lang" | "language")
echo "🌍 Opening locale settings..."
adb -s "$SELECTED_DEVICE" shell am start -a android.settings.LOCALE_SETTINGS &> /dev/null
;;
Expand Down
2 changes: 1 addition & 1 deletion android/arecord
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ android_get_device_sdk "$SELECTED_DEVICE"
android_get_storage_location_per_SDK "$SDK"

RECORDING=true
echo "📹 Recording screen on $SELECTED_DEVICE, stop it with ctrl^c"
echo "📹 Recording screen on $SELECTED_DEVICE, stop it using ctrl^c"
adb -s "$SELECTED_DEVICE" shell settings put system show_touches 1
adb -s "$SELECTED_DEVICE" shell screenrecord "$DEVICE_FILE_PATH"/output.mp4
68 changes: 68 additions & 0 deletions android/atestmonkey
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
LOCATION=$(dirname "$0")
source "$LOCATION"/../common_tools
trap 'ctrlc' 1 2 3 6 15

ctrlc(){
if $RUNNING_TESTS; then
MONKEY_TASK_ID=$(adb -s "$SELECTED_DEVICE" shell pidof "com.android.commands.monkey")
adb -s "$SELECTED_DEVICE" shell kill "$MONKEY_TASK_ID" >/dev/null 2>&1
echo "🔪 Test monkey terminated, the device is safe to use now!"
fi

unlock_app_fullscreen
exit 2
}

unlock_app_fullscreen(){
adb -s "$1" shell am task lock stop >/dev/null 2>&1
echo "🔓 App fullscreen pinning disabled"
}

update_package_name(){
APP_PACKAGE_NAME="$(android_get_foreground_package "$1")"
}

check_screen_pinning(){
PINNING_ENABLED=$(adb -s "$1" shell settings get system lock_to_app_enabled)
PINNING_ENABLED=${PINNING_ENABLED%$'\r'} # remove trailing carriage return
if [ "$PINNING_ENABLED" != "1" ]; then
adb -s "$1" shell am start -a android.settings.SECURITY_SETTINGS >/dev/null 2>&1
read -r -p "🔑 Enable \"Screen pinning\" option in security settings, then press enter..."
fi
}

lock_task_fullscreen(){
check_screen_pinning "$1"
adb -s "$1" shell monkey -p "$APP_PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 &> /dev/null
adb -s "$1" shell input keyevent "KEYCODE_APP_SWITCH"
read -r -p "📌 Press the \"Pin\" button in \"$APP_PACKAGE_NAME\" window, then press enter... " #TODO add check if already on
tput setaf 3 && should_proceed "🔥 DANGER ZONE ⊗ Perform monkey test on \"$APP_PACKAGE_NAME\"? (it will take a while)" && tput sgr0 #set red and white text color
}

run_test(){
SEED="$2"
echo "🐒 Running monkey stress test... (press ctrl^c to end now)"
RUNNING_TESTS=true
LOG_FILE=~/Desktop/"monkey-test-log-seed-$SEED-$APP_PACKAGE_NAME-$MANUFACTURER-$MODEL-API$SDK-$(date +%Y-%m-%d-%H-%M-%S).txt"
adb -s "$1" shell monkey -p "$APP_PACKAGE_NAME" -s "$SEED" --pct-appswitch 0 --pct-syskeys 0 --pct-anyevent 0 "$EVENT_COUNT" &> "$LOG_FILE"
unlock_app_fullscreen "$@"
grep -q "CRASH" "$LOG_FILE" && tput setaf 1 && echo "❌ Test failed, see crash log for details, seed: $SEED" && tput sgr0 && open "$LOG_FILE" && exit 1
tput setaf 2 && echo "✅ Test passed, successfully executed all input events, seed: $SEED" && tput sgr0
}

RUNNING_TESTS=false
EVENT_COUNT=15000 #Should convert to argument later, this is bad
SEED="$RANDOM"

android_choose_device
android_device_info "$SELECTED_DEVICE"
update_package_name "$SELECTED_DEVICE"
lock_task_fullscreen "$SELECTED_DEVICE"

case "$1" in #if $1 not number, LOL
''|*[!0-9]*) ;; #nothing left to do
*) SEED="$1" ;;
esac

run_test "$SELECTED_DEVICE" "$SEED"
16 changes: 16 additions & 0 deletions android/atestmonkeykill
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
LOCATION=$(dirname "$0")
source "$LOCATION"/../common_tools
trap "kill 0" SIGINT # Kill all spawned subprocesses on ctrl^c

android_choose_device

MONKEY_TASK_ID=$(adb -s "$SELECTED_DEVICE" shell pidof "com.android.commands.monkey")

if [ -z "$MONKEY_TASK_ID" ]; then
echo "🙈 No test monkey running, device is safe to use"

else
adb -s "$SELECTED_DEVICE" shell kill "$MONKEY_TASK_ID" >/dev/null 2>&1
echo "🔪 Test monkey terminated, the device is safe to use now!"
fi
2 changes: 1 addition & 1 deletion android/auninstall
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source "$LOCATION"/../common_tools

init_uninstalling(){
echo "⏳ Getting third-party package list..."
IGNORED_PACKAGES=( "com.microsoft.hockeyapp.testerapp" "io.crash.air" "de.codenauts.hockeyapp" "ar.core" "com.framerjs.android" "com.figma.mirror" "com.invisionapp.ifa" "com.android.chrome" "com.google.ar.core" "no.nordicsemi.android.mcp" )
IGNORED_PACKAGES=( "com.microsoft.hockeyapp.testerapp" "io.crash.air" "de.codenauts.hockeyapp" "ar.core" "com.framerjs.android" "com.figma.mirror" "com.invisionapp.ifa" "com.android.chrome" "com.google.ar.core" "no.nordicsemi.android.mcp" "com.x8bit.bitwarden" )
PACKAGES=($(adb -s "$SELECTED_DEVICE" shell pm list packages -f -3 | sed -e 's/.*=//' | sort))
}

Expand Down
13 changes: 12 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
🩹 Fix brew cask usage in dependency check
🎉 Celebrate new release 1.2.0 together as a community!
⭐️ Leave a star on GitHub, that makes me real happy
📬 Share Mobile Toolkit to your friends and colleagues
📨 Any feedback is highly appreciated
🌍 https://github.com/IntergalacticPenguin/mobile-toolkit

🆕 Notable changes:
🐒 New "atestmonkey" tool for app stress testing
📦 Automatic "irecord" video compression (saves a lot space)
🚀 Launch "aoptions" single activity result automatically
👋 Remove "igif" (irecord made it obsolete)
😌 Remove emulator prompt on "no device detected"
51 changes: 28 additions & 23 deletions common_tools
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ android_check_connected(){
if [ ${#DEVICES[@]} -eq 0 ]
then
echo "❌ No Android devices detected"
yes_or_no "❓ Start Android Emulator?"; if [[ "$RESPONSE" == "y" || "$RESPONSE" == "Y" ]]; then "$SCRIPT_LOCATION"/aemulator "start"; fi
exit 1
fi
}
Expand Down Expand Up @@ -103,26 +102,10 @@ SELECTED_DEVICE_MODEL=$(adb -s "$SELECTED_DEVICE" shell getprop ro.product.model
SELECTED_DEVICE_SDK=$(adb -s "$SELECTED_DEVICE" shell getprop ro.build.version.sdk | tr -cd '[[:alnum:]]._-')
}

check_screen_on(){
CURRENT_FOCUS=$(adb -s "$1" shell dumpsys window windows | grep mCurrentFocus | cut -d'/' -f1 | rev | cut -d' ' -f1 | rev)
if [[ "$CURRENT_FOCUS" == *"StatusBar"* ]] || [[ "$CURRENT_FOCUS" == *"mCurrentFocus=null"* ]] || [[ "$CURRENT_FOCUS" == *"Keyguard"* ]]; then
return 1
else
return 0
fi
}

android_unlock_device(){ #🤮
if [[ $(check_screen_on "$1") -eq 1 ]]; then
echo "🛌 Waking up the device..."
adb -s "$1" shell input keyevent KEYCODE_HOME
if [[ $(check_screen_on "$1") -eq 1 ]]; then
adb -s "$1" shell input keyevent KEYCODE_POWER
if [[ $(check_screen_on "$1") -eq 1 ]]; then
adb -s "$1" shell input keyevent 82
fi
fi
fi
android_device_unlocked(){
echo "📱 Checking screen status..."
adb -s "$1" shell dumpsys power | grep "mWakefulness=" | grep "Awake" &> /dev/null
return $?
}

android_get_foreground_package(){
Expand Down Expand Up @@ -165,7 +148,7 @@ android_is_package_installed() {
fi
}

detect_package_info(){
android_detect_package_info(){
echo "🔍 Detecting package name..."
AAPPT_PATH=$(find ~/Library/Android/sdk -name 'aapt' | sort | tail -1)
PACKAGE_INFO=$($AAPPT_PATH dump badging "$1" > $TEMPORARY_FILE)
Expand All @@ -176,6 +159,29 @@ detect_package_info(){
APP_NAME=${APP_NAME#"application-label:"}
}

android_unlock_device(){
# arg1 = DEVICE_ID
# arg2 = MAX_RETRIES
MAX_RETRIES="$2"
UNLOCK_RETRIES=1
until android_device_unlocked "$1";
do
if [ "$UNLOCK_RETRIES" -le "$MAX_RETRIES" ]; then
echo "🔆 Screen on attempt $UNLOCK_RETRIES..."
((UNLOCK_RETRIES++));
adb -s "$1" shell input keyevent KEYCODE_POWER
adb -s "$1" shell input keyevent 82
sleep 1;
else
read -r -p "❌ Screen-wake failed, press ANY KEY after manual unlock..."
break
fi
done

delete_lastline
echo "📱 Screen unlocked..."
}

##############################################################################
### iOS

Expand Down Expand Up @@ -241,7 +247,6 @@ ios_choose_device(){
if [ ${#IOS_USB_DEVICES[@]} -eq 0 ] #No device connected
then
echo "❌ No iOS devices detected"
yes_or_no "❓ Start iOS Simulator?"; if [[ "$RESPONSE" == "y" || "$RESPONSE" == "Y" ]]; then "$SCRIPT_LOCATION"/isimulator start; exit; fi
exit 1
fi

Expand Down
Loading

0 comments on commit e7584c2

Please sign in to comment.