-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_display.sh
More file actions
67 lines (53 loc) · 1.93 KB
/
virtual_display.sh
File metadata and controls
67 lines (53 loc) · 1.93 KB
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
#!/bin/bash
# Function to clean up the virtual display when the script is terminated
cleanup() {
echo "Cleaning up..."
echo "Removing the virtual display..."
adb shell settings put global overlay_display_devices none
echo "Virtual display removed."
exit 0
}
# Trap to call cleanup function when the script is closed
trap cleanup EXIT
# Check if adb is available
if ! command -v adb &> /dev/null; then
echo "Error: adb is not installed or not in PATH. Please install Android Debug Bridge."
exit 1
fi
# Check if device is connected
if ! adb devices | grep -q device$; then
echo "Error: No Android device connected. Please connect a device and try again."
exit 1
fi
# Function to get the list of display IDs
get_display_ids() {
adb shell dumpsys display | grep "mDisplayId=" | awk '{print $1}' | cut -d= -f2 | sort -u
}
# Get initial display IDs
initial_displays=$(get_display_ids)
# Create a virtual display on the Android device
echo "Creating a virtual display..."
adb shell settings put global overlay_display_devices 1920x1080/240
# Wait for the new display to be recognized
sleep 2
# Get new display IDs
new_displays=$(get_display_ids)
# Find the new display ID
secondary_display_id=$(comm -13 <(echo "$initial_displays") <(echo "$new_displays") | tr -d '[:space:]')
if [ -z "$secondary_display_id" ]; then
echo "Failed to detect the new display ID."
cleanup
exit 1
else
echo "Detected secondary display ID: $secondary_display_id"
fi
# Check if scrcpy is available
if ! command -v scrcpy &> /dev/null; then
echo "Error: scrcpy is not installed or not in PATH. Please install scrcpy."
cleanup
exit 1
fi
# Start scrcpy with the provided options and detected display ID
echo "Starting scrcpy on the virtual display..."
scrcpy -b 24M --window-title='Pixel' --max-fps=60 --no-audio --display-id "$secondary_display_id"
# The cleanup function will be called automatically when the script exits