Skip to content

Commit e7584c2

Browse files
authored
Merge pull request #213 from IntergalacticPenguin/feature/random-tweaks
atestmonkey + random tweaks = v 1.2.0
2 parents eb3c1b6 + fe4b855 commit e7584c2

20 files changed

+181
-104
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
🚨 **Check all before merging!**
2-
- [ ] 🏗 Everything implemented thoroughly
3-
- [ ] 🔨 All changes tested
4-
- [ ] Change #1
5-
- [ ] Change #2...
6-
- [ ] 👀 Go through the diff
7-
- [ ] 📝 API changes included in README.md
8-
- [ ] 📣 Major changes listed in changelog.txt
9-
10-
✅ All good? -> **Merge!** 🎉🎉🎉
1+
## ⚠️ Progress checklist
2+
- [ ] 🏗 **Features fully completed**
3+
- [ ] 🔬 **Shellcheck issues resolved**
4+
- [ ] 🔨 **All changes tested**
5+
- [ ] 💬 **Terminal output satisfactory**
6+
- [ ] 👀 **Diff examined thoroughly**
7+
- [ ] 📝 **API changes included in `README.md`**
8+
- [ ] 📣 **Major changes listed in `changelog.txt`**
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
- name: Shellcheck
1010
uses: ludeeus/action-shellcheck@master
1111
env:
12-
SHELLCHECK_OPTS: -e SC1090 -e SC2207 -e SC2001
12+
SHELLCHECK_OPTS: -e SC1090 -e SC2207 -e SC2001 -e SC1091
1313
# SC1090 - non-constant source
1414
# SC2207 - no arrays like this ($())
1515
# SC2001 - replace sed with ${variable//search/replace}
16+
# SC1091 - common_tools was not specified as input (see shellcheck -x)

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Header](/header_v2.png?raw=true)
1+
![Header](/media/header_v2.png?raw=true)
22
## What is this?
33
🛠 Capture screen, manage apps, simulate input, print system log and more using simple commands!<br>
44

@@ -215,6 +215,21 @@ _Note: This repository is mainly focused on macOS compatibility, but majority of
215215
* `telnet <command>` - call command via telnet
216216
* 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
217217

218+
### 🐒 atestmonkey
219+
* Perform automated stress test using [Application Excersciser Monkey](https://developer.android.com/studio/test/monkey)
220+
* Default test length is `15000` input events, support for custom count will be added in future update
221+
* You can end test prematurely using ctrl^c or `atestmonkeykill` in case something goes wrong
222+
* App under test needs to be pinned to fullscreen mode to prevent unwanted interactions elsewhere
223+
* 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>
224+
* <details>
225+
<summary>Google Nexus 5 (Android 6)</summary>
226+
<br><em>You need to bring the app window to foreground, the button is located in bottom right corner.</em><br><br>
227+
<img src="/media/Pinning_Nexus_v3.png" width="420"></details>
228+
* <details>
229+
<summary>Google Pixel 3 (Android 11)</summary>
230+
<br><em>You need to click on the app icon, the button is located in popup menu.</em><br><br>
231+
<img src="/media/Pinning_Pixel.png" width="420"></details>
232+
218233
# 🍎 iOS commands
219234

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

226241
### 🎥 irecord
227242
**Required**: Install [videosnap](https://github.com/matthutchinson/videosnap/releases "videosnap") -> download and run `videosnap-0.0.6.pkg`
228-
229-
1. `irecord` Record screen
230-
2. End recording using `ctrl + c`
231-
3. Save screen video footage to ~/Desktop
232-
233-
### 🖼 igif
234243
**Required**: Install [ffmpeg](https://www.ffmpeg.org/ "ffmpeg") `brew install ffmpeg`
235244

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

242250
## Manage applications
243251
### 🚚 iinstall

android/abuildproject

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ find_apk_path(){
6767
}
6868

6969
launch(){
70-
detect_package_info "$1"
70+
android_detect_package_info "$1"
7171
echo "🚀 Launching $APP_NAME..."
7272
adb -s "$SELECTED_DEVICE" shell monkey -p "$PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 &> /dev/null
7373
}

android/acheckdevice

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ open_gsmarena(){
125125
}
126126

127127
android_choose_device
128-
android_unlock_device "$SELECTED_DEVICE"
129128
echo_info
130129
check_screen_timeout
131130
check_screen_brightness

android/aemulator

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ check_running_emulator(){
4747
get_emulator_list(){
4848
echo "⏳ Getting Android emulator list..."
4949
rm -f "$LOCAL_EMULATOR_LIST"
50-
~/Library/Android/sdk/tools/bin/avdmanager list avd | grep Name | awk '{print $2}' >> "$LOCAL_EMULATOR_LIST"
50+
"$ANDROID_HOME"/cmdline-tools/latest/bin/avdmanager list avd | grep Name | awk '{print $2}' >> "$LOCAL_EMULATOR_LIST"
5151
if [ "$(nl "$LOCAL_EMULATOR_LIST")" == "" ]; then
5252
should_proceed "🤷‍ No emulators installed, install via Android Studio?"
5353
echo "⏳ Opening Android Studio..."

android/ainstall

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ run()
3838
check_for_update
3939
android_check_connected
4040
android_get_devices_auth_dump
41-
detect_package_info "$2"
41+
android_detect_package_info "$2"
4242
for line in $(adb devices | grep -v "List" | awk '{print $1}')
4343
do
4444
DEVICE=$(echo "$line" | awk '{print $1}')
@@ -47,7 +47,7 @@ run()
4747
wait
4848
else
4949
android_choose_device
50-
detect_package_info "$1"
50+
android_detect_package_info "$1"
5151
install_app "$SELECTED_DEVICE" "$1"
5252
fi
5353
}

android/aoptions

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ import_intents(){
2121
start_settings_intent(){
2222
SETTINGS_INTENT=$(sed "$LINE"!d "$LOCAL_SETTINGS_LIST_PATH")
2323
echo "🚀 Starting $SETTINGS_INTENT"
24-
adb -s "$SELECTED_DEVICE" shell am start -a "$SETTINGS_INTENT" | grep error
24+
adb -s "$SELECTED_DEVICE" shell am start -a "$SETTINGS_INTENT" &> /dev/null
2525
}
2626

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

49-
"2" | "locale")
54+
"2" | "locale" | "lang" | "language")
5055
echo "🌍 Opening locale settings..."
5156
adb -s "$SELECTED_DEVICE" shell am start -a android.settings.LOCALE_SETTINGS &> /dev/null
5257
;;

android/arecord

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ android_get_device_sdk "$SELECTED_DEVICE"
2828
android_get_storage_location_per_SDK "$SDK"
2929

3030
RECORDING=true
31-
echo "📹 Recording screen on $SELECTED_DEVICE, stop it with ctrl^c"
31+
echo "📹 Recording screen on $SELECTED_DEVICE, stop it using ctrl^c"
3232
adb -s "$SELECTED_DEVICE" shell settings put system show_touches 1
3333
adb -s "$SELECTED_DEVICE" shell screenrecord "$DEVICE_FILE_PATH"/output.mp4

android/atestmonkey

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
LOCATION=$(dirname "$0")
3+
source "$LOCATION"/../common_tools
4+
trap 'ctrlc' 1 2 3 6 15
5+
6+
ctrlc(){
7+
if $RUNNING_TESTS; then
8+
MONKEY_TASK_ID=$(adb -s "$SELECTED_DEVICE" shell pidof "com.android.commands.monkey")
9+
adb -s "$SELECTED_DEVICE" shell kill "$MONKEY_TASK_ID" >/dev/null 2>&1
10+
echo "🔪 Test monkey terminated, the device is safe to use now!"
11+
fi
12+
13+
unlock_app_fullscreen
14+
exit 2
15+
}
16+
17+
unlock_app_fullscreen(){
18+
adb -s "$1" shell am task lock stop >/dev/null 2>&1
19+
echo "🔓 App fullscreen pinning disabled"
20+
}
21+
22+
update_package_name(){
23+
APP_PACKAGE_NAME="$(android_get_foreground_package "$1")"
24+
}
25+
26+
check_screen_pinning(){
27+
PINNING_ENABLED=$(adb -s "$1" shell settings get system lock_to_app_enabled)
28+
PINNING_ENABLED=${PINNING_ENABLED%$'\r'} # remove trailing carriage return
29+
if [ "$PINNING_ENABLED" != "1" ]; then
30+
adb -s "$1" shell am start -a android.settings.SECURITY_SETTINGS >/dev/null 2>&1
31+
read -r -p "🔑 Enable \"Screen pinning\" option in security settings, then press enter..."
32+
fi
33+
}
34+
35+
lock_task_fullscreen(){
36+
check_screen_pinning "$1"
37+
adb -s "$1" shell monkey -p "$APP_PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 &> /dev/null
38+
adb -s "$1" shell input keyevent "KEYCODE_APP_SWITCH"
39+
read -r -p "📌 Press the \"Pin\" button in \"$APP_PACKAGE_NAME\" window, then press enter... " #TODO add check if already on
40+
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
41+
}
42+
43+
run_test(){
44+
SEED="$2"
45+
echo "🐒 Running monkey stress test... (press ctrl^c to end now)"
46+
RUNNING_TESTS=true
47+
LOG_FILE=~/Desktop/"monkey-test-log-seed-$SEED-$APP_PACKAGE_NAME-$MANUFACTURER-$MODEL-API$SDK-$(date +%Y-%m-%d-%H-%M-%S).txt"
48+
adb -s "$1" shell monkey -p "$APP_PACKAGE_NAME" -s "$SEED" --pct-appswitch 0 --pct-syskeys 0 --pct-anyevent 0 "$EVENT_COUNT" &> "$LOG_FILE"
49+
unlock_app_fullscreen "$@"
50+
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
51+
tput setaf 2 && echo "✅ Test passed, successfully executed all input events, seed: $SEED" && tput sgr0
52+
}
53+
54+
RUNNING_TESTS=false
55+
EVENT_COUNT=15000 #Should convert to argument later, this is bad
56+
SEED="$RANDOM"
57+
58+
android_choose_device
59+
android_device_info "$SELECTED_DEVICE"
60+
update_package_name "$SELECTED_DEVICE"
61+
lock_task_fullscreen "$SELECTED_DEVICE"
62+
63+
case "$1" in #if $1 not number, LOL
64+
''|*[!0-9]*) ;; #nothing left to do
65+
*) SEED="$1" ;;
66+
esac
67+
68+
run_test "$SELECTED_DEVICE" "$SEED"

0 commit comments

Comments
 (0)