/
fix-android-emulator-audio
executable file
·67 lines (55 loc) · 1.72 KB
/
fix-android-emulator-audio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
DEFAULT_AVD_PATH=~/.android/avd
function run_sed {
if [ "$(uname)" == "Darwin" ]; then
# macOS requires extra argument for -i param
sed -i '' $1 $2
else
sed -i $1 $2
fi
}
# Check the number of arguments
if [ "$#" -gt 2 ]; then
echo "❌ Too many arguments."
echo "Usage: $0 <avd-path>"
exit 1
fi
temp_avd_path=""
has_wipe_option=0
# Read user arguments
for arg in "$@"
do
if [ $arg == "--wipe" ]; then
has_wipe_option=1
else
temp_avd_path=$arg
fi
done
# Use provided path by user or fallback to the default one
avd_path=${temp_avd_path:-$DEFAULT_AVD_PATH}
# Remove trailing slash if present
avd_path=${avd_path%/}
echo "🔊 Processing emulators from: $avd_path"
for emulator in $(find $avd_path -type d -name '*.avd'); do
if [ ! -f $emulator/config.ini ]; then
echo "❌ Skipping emulator - could not config.ini inside $emulator"
continue
fi
echo "🔊 Processing - $(basename $emulator)"
# Remove line hw.audioInput - if exists
run_sed '/^hw.audioInput/d' $emulator/config.ini
# Remove line hw.audioOutput - if exists
run_sed '/^hw.audioOutput/d' $emulator/config.ini
# Disable audio input and output
echo "hw.audioInput=no" >> $emulator/config.ini
echo "hw.audioOutput=no" >> $emulator/config.ini
# Sort config keys
sort -o $emulator/config.ini $emulator/config.ini
# Wipe data when --wipe argument is present
if [ $has_wipe_option -eq 1 ]; then
echo "🗑️ Wiping data from: $(basename $emulator)"
rm -rf $emulator/snapshots
rm -f $emulator/userdata.img $emulator/userdata-qemu.img
fi
echo "✅ Done - $(basename $emulator)"
done