Use Scrcpy to implement Android phone screen mirroring under Tongxin UOS

Foreword

This article mainly records the process of installing Scrcpy under the Tongxin UOS operating system to realize screen mirroring on Android phones. During the installation process, the author referred to many articles, but found that they were not fully introduced. After constant trying and groping, screencasting was finally successfully achieved. Therefore, the original purpose of this article is just to record the various problems encountered during the installation process for my own future reference. I also hope to provide some reference for other readers who have the same needs as me.

1. Software introduction

Scrcpy is an open source Android phone screen projection software that can project the phone screen to a computer and operate it on the computer.

2. Installation method

1. Search “Android” in the app store, find [Scrcpy Android phone screen mirroring], and click [Install];

2. After the installation is complete, search for “Android” in the launcher in the lower left corner to find [Scrcpy Android phone screen mirroring].

3. How to use

1. Connect the mobile phone to the computer: Connect the mobile phone to the computer using a data cable and select [Transfer Files / Android Atuo];

2. Enable USB debugging: Turn on the developer mode of the phone, enter the developer options, and enable [USB debugging]. After enabling, a pop-up window will appear prompting whether to allow USB debugging. Select [Allow] (you can choose whether to check “Always allow this computer to debug” according to your needs)

3. Open Scrcpy android phone screen mirroring, and you can successfully mirror the screen.

4. Frequently Asked Questions

(1) How to enable developer mode?

The method of enabling developer mode is different for each Android device. For other models, you can use Baidu or refer to the official documentation to enable developer options. The following is an example of enabling developer mode using realme GT NEO3. pattern method.

1. Open the phone settings, find [About this device], and then select [Version Information] to enter;

2. Click the [Version Number] option 7 times continuously, and you may be asked to enter the lock screen password. After successful verification, you can successfully open the developer mode and return to the settings interface. , find [Other Settings], scroll down to find [Developer Options];

3. Scroll down in the developer options. In the debugging section, you can control the switches of [USB debugging] and [Wireless debugging].

(2) How to set up wireless screen mirroring?

Mobile phones always use data cables to connect to computers, which has many limitations. For example, it occupies the U port of the computer, making the operation of the mobile phone inconvenient, and the fast charging function cannot be used. In order to solve these problems, you can use the wireless screen mirroring function through the following methods.

Because the wireless screen mirroring function requires the adb command for management, and the Linux system hopes that every user using adb needs to be in the plugdev group, otherwise it will appear An error is reported, so just follow the steps below.

Prerequisite:

①The mobile phone and computer are in the same LAN (can ping successfully);

②When setting up the wireless connection function, you need to turn on USB debugging first;

1. Add plugdev group: Open the terminal, enter root, and use the command to add the current user to the plugdev group;

usermod -aG plugdev $USER

uos@uos:~/Desktop$ su
Please enter password:
Verification successful
root@uos:/home/uos/Desktop# usermod -aG plugdev $USER

2. Check whether the group has been added successfully: Use the command to check whether the current user’s group has plugdev;

id $USER

root@uos:/home/uos/Desktop# id $USER
uid=1000(uos) gid=1000(uos) group=1000(uos),7(lp),27(sudo),46(plugdev),100(users),109(netdev),119(scanner),123 (sambashare),994(nopasswdlogin),993(autologin)

3. Check the currently connected device: According to [3. Usage], first make a USB connection, exit root mode, and use the command
Check device connection status;

adb devices

The first column of the returned information is the device name, and the second column is the status prompt. The following is the corresponding situation of each status:

uos@uos:~/Desktop$ adb devices
List of devices attached
NR6DIF59KN85CEDM device

4. Check the mobile phone IP: Use the command to check the mobile phone IP address. Two addresses may be output. The second address is the IP address of the mobile phone (of course, you can also go to the mobile phone settings–WLAN–Connected Check the IPv4 address in the WIFI details)

adb shell ip route | awk ‘{print $9}’

uos@uos:~/Desktop$ adb shell ip route | awk '{print $9}'
10.76.37.136
10.135.7.92

5. Start the daemon process and listen on the port: Use the command to start an ADB daemon process, which listens on port 5555 (the default is 5555, but it can also be set to other ports);

adb tcpip 5555

①Return “restarting in TCP mode port: 5555” to indicate successful startup;

②Return “error: no devices/emulators found” indicating that the device is not connected;

Solution: Re-open the USB connection according to [3. Usage];

uos@uos:~/Desktop$ adb tcpip 5555
restarting in TCP mode port: 5555

① When the startup is successful, a pop-up window may appear on the phone asking whether USB debugging is allowed. Just select [Allow];

② If you click [Cancel], the status of the connected device will change to “unauthorized” (unauthorized);

Solution: Turn off [USB debugging] and then turn it back on. When a pop-up window appears, click [Allow], and then perform step 5 again;

6. Connect wirelessly: Unplug the data cable and use the command to connect wirelessly. When connecting, a pop-up window will appear on your phone asking whether USB debugging is allowed. Select [Allow];

adb connect IP:port

For example: adb connect 10.135.7.92:5555

  • Returning “connected to 10.135.7.92:5555” indicates that the connection is successful;
  • Returning “already connected to 10.135.7.92:5555” indicates that it has been successfully connected and there is no need to connect again;
uos@uos:~/Desktop$ adb connect 10.135.7.92:5555
connected to 10.135.7.92:5555

7. View currently connected devices: Use the command adb devices again to view the device connection status. If the status is normal, proceed to the next step;

uos@uos:~/Desktop$ adb devices
List of devices attached
10.135.7.92:5555 devices
  • If a pop-up window appears in step 6 and you click [Cancel], the status of the connected device will change to “unauthorized” (unauthorized);
  • Solution: Turn off [USB debugging] and then turn it back on, and re-execute step 6. When a pop-up window appears, click [Allow];

8. Open the screen mirroring software for screen mirroring: Open Scrcpy Android phone screen mirroring and successfully achieve wireless screen mirroring.

(3) How to achieve screen-off control?

Screen-off control means that when the computer controls the mobile phone, the screen of the mobile phone does not have to be on all the time. This not only saves the power of the mobile phone, but also

1. Install the required software packages: Open the terminal, enter root, and enter the command to install;

apt install ffmpeg libsdl2-2.0-0 adb wget gcc git pkg-config meson ninja-build libsdl2-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswresample-dev libusb-1.0-0 libusb-1.0-0-dev – y

uos@uos:~/Desktop$ su
Please enter password:
Verification successful
root@uos:/home/uos/Desktop# apt install ffmpeg libsdl2-2.0-0 adb wget gcc git pkg-config meson ninja-build libsdl2-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswresample-dev libusb- 1.0-0 libusb-1.0-0-dev -y

2. Clone the repo and execute the installation script: You can exit root mode, enter the folder where the scrcpy software is stored, and then use the command to clone. After the download is successful, enter the directory and execute the script for installation;

git clone https://github.com/Genymobile/scrcpy

uos@uos:~/Downloads$ git clone https://github.com/Genymobile/scrcpy
Cloning to 'scrcpy'...
remote: Enumerating objects: 28342, done.
remote: Counting objects: 100% (1281/1281), done.
remote: Compressing objects: 100% (436/436), done.
remote: Total 28342 (delta 778), reused 1077 (delta 648), pack-reused 27061
Received: 100% (28342/28342), 5.52 MiB | 3.00 MiB/s, done.
Processing delta: 100% (18117/18117), completed.

cd scrcpy

uos@uos:~/Downloads$ cd scrcpy

./install_release.sh

Note: When configuring the last file, you will be prompted to enter the power-on password. Enter the power-on password and press Enter (if the current user is not in sudoers, enter root and re-execute the script);

uos@uos:~/Downloads/scrcpy$ ./install_release.sh
[scrcpy] Downloading prebuilt server...
--2023-10-10 12:54:37-- https://github.com/Genymobile/scrcpy/releases/download/v2.1.1/scrcpy-server-v2.1.1
Connecting 127.0.0.1:7890... Connected.
Proxy request sent, waiting for response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/111583593/ecb6f5da-9e0d-4f0a-a475-666fd905b94e?X-Amz-Algorithm=AWS4-HMAC-SHA256 &X- Amz-Credential=AKIAIWNJYAX4CSVEH53A/20231010/us-east-1/s3/aws4_request &X-Amz-Date=20231010T045438Z &X-Amz-Expires=300 & e769d384a08cfc69c7a1a7fa7892f957e4128fcc1eab2a5 & X-Amz-SignedHeaders=host & amp;actor_id=0 & amp;key_id=0 & amp;repo_id=111583593 & amp;response-content-disposition=attachment; filename=scrcpy-server-v2.1.1 & amp;response- content-type=application/octet-stream [Follow to new URL]
--2023-10-10 12:54:38-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/111583593/ecb6f5da-9e0d-4f0a-a475-666fd905b94e?X-Amz- Algorithm=AWS4-HMAC-SHA256 & X-Amz-Credential=AKIAIWNJYAX4CSVEH53A/20231010/us-east-1/s3/aws4_request & X-Amz-Signature=8f8c19c5a4d84b9d9e769d384a08cfc69c7a1a7fa7892f957e4128fcc1eab2a5 & 3593 &response-content-disposition=attachment; filename= scrcpy-server-v2.1.1 & response-content-type=application/octet-stream
Connecting 127.0.0.1:7890... Connected.
Proxy request sent, waiting for response... 200 OK
Length: 56995 (56K) [application/octet-stream]
Saving to: "scrcpy-server"

scrcpy-server 100%[==============================>] 55.66K 320KB/s Time 0.2s

2023-10-10 12:54:39 (320 KB/s) - Saved "scrcpy-server" [56995/56995])

[scrcpy] Verifying prebuilt server...
scrcpy-server: successful
[scrcpy] Building client...
The Meson build system
Version: 0.56.2
Source dir: /home/uos/Downloads/scrcpy
Build dir: /home/uos/Downloads/scrcpy/build-auto
Build type: native build
Project name: scrcpy
Project version: 2.1.1
C compiler for the host machine: cc (gcc 8.3.0 "cc (Uos 8.3.0.10-deepin1) 8.3.0")
C linker for the host machine: cc ld.bfd 2.31.1
Host machine cpu family: aarch64
Host machine cpu: aarch64
Found pkg-config: /usr/bin/pkg-config (0.29)
Run-time dependency libavformat found: YES 58.20.100
Run-time dependency libavcodec found: YES 58.35.100
Run-time dependency libavutil found: YES 56.22.100
Run-time dependency libswresample found: YES 3.3.100
Run-time dependency sdl2 found: YES 2.0.9
Run-time dependency libavdevice found: YES 58.5.100
Run-time dependency libusb-1.0 found: YES 1.0.22
Checking for function "strdup" : YES
Checking for function "asprintf" : YES
Checking for function "vasprintf" : YES
Checking for function "nrand48" : YES
Checking for function "jrand48" : YES
Checking for function "reallocarray" : YES
Header <sys/socket.h> has symbol "SOCK_CLOEXEC" : YES
Configuring config.h using configuration
Build targets in project: 3

Found ninja-1.8.2 at /usr/bin/ninja
[64/64] Linking target app/scrcpy
[scrcpy] Installing (sudo)...
Please enter password:
Verification successful
[0/1] Installing files.
Installing app/scrcpy to /usr/local/bin
Stripping target 'app/scrcpy' using strip.
Installing server/scrcpy-server to /usr/local/share/scrcpy
Installing /home/uos/Downloads/scrcpy/app/scrcpy.1 to /usr/local/share/man/man1
Installing /home/uos/Downloads/scrcpy/app/data/icon.png to /usr/local/share/icons/hicolor/256x256/apps
Installing /home/uos/Downloads/scrcpy/app/data/zsh-completion/_scrcpy to /usr/local/share/zsh/site-functions
Installing /home/uos/Downloads/scrcpy/app/data/bash-completion/scrcpy to /usr/local/share/bash-completion/completions
Installing /home/uos/Downloads/scrcpy/app/data/scrcpy.desktop to /usr/local/share/applications
Installing /home/uos/Downloads/scrcpy/app/data/scrcpy-console.desktop to /usr/local/share/applications
uos@uos:~/Downloads/scrcpy$

3. Control the connected device with screen off: Use the command scrcpy -Sw to wirelessly connect the device and control the screen off;

scrcpy-Sw

uos@uos:~/Downloads/scrcpy$ scrcpy -Sw
scrcpy 2.1.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO: --> (tcpip) 10.135.7.92:5555 device RMX3562
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed. 0.7 MB/s (56995 bytes in 0.075s)
[server] INFO: Device: [realme] realme RMX3562 (Android 13)
[server] ERROR: Could not change "stay_on_while_plugged_in"
com.genymobile.scrcpy.SettingsException: Could not access settings: put global stay_on_while_plugged_in 7
        at com.genymobile.scrcpy.Settings.execSettingsPut(Settings.java:24)
        at com.genymobile.scrcpy.Settings.putValue(Settings.java:59)
        at com.genymobile.scrcpy.Settings.getAndPutValue(Settings.java:78)
        at com.genymobile.scrcpy.Server.initAndCleanUp(Server.java:63)
        at com.genymobile.scrcpy.Server.lambda$startInitThread$2(Server.java:168)
        at com.genymobile.scrcpy.Server$$ExternalSyntheticLambda3.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:1012)
Caused by: java.io.IOException: Command [settings, put, global, stay_on_while_plugged_in, 7] returned with value 255
        at com.genymobile.scrcpy.Command.exec(Command.java:16)
        at com.genymobile.scrcpy.Settings.execSettingsPut(Settings.java:22)
        ... 6 more
INFO: Renderer: opengl
INFO: OpenGL version: 3.1 Mesa 19.2.6
INFO: Trilinear filtering enabled
Cannot find ff_h264_mwv206_decoder, /lib/aarch64-linux-gnu/libmwv206dec.so: undefined symbol: ff_h264_mwv206_decoder
INFO: Texture: 1080x2408
[server] INFO: Device screen turned off

If you only connect one device, you can directly use scrcpy -Sw to connect. If there are multiple devices, you need to specify the device:

①Specify the USB connected device: scrcpy -Sw –serial=device name

For example: scrcpy -Sw –serial=NR6DIF59KN85CEDM

②Specify the device for wireless connection: scrcpy -Sw –tcpip=IP:port

For example: scrcpy -Sw –tcpip=10.135.7.92:5555

5. Summary

This article introduces how Tongxin UOS system uses Scrcpy to implement screencasting on Android phones, which can be connected through USB wired connection and WiFi wireless connection, and can realize screen-off control. For more ways to play Scrcpy, please refer to the last article.

Reference article

The artifact that connects the PC desktop and the android phone–scrcpy_genymobile/scrcpy: display and control your androi-CSDN blog accidentally discovered an artifact for mobile phone debugging and automated testing, Scrcpy, which is very powerful. After some exploration, it can be implemented more effectively with minitouch. Automated operations, but you can also use tools such as python’s pythonautogui to automatically control the mouse and keyboard on the PC side, so as to automatically click or open applications on the mobile phone. Of course, this requires identifying and analyzing the display content of the mobile phone screen. , or based on absolute coordinates. Open source library link scrcpyhttps://github.com/Genymobile/scrcpyminitouchhttps://github.com/opens_genymobile/scrcpy: display and control your android devicehttps://blog.csdn.net/pocean2012/article/details/113824333

https://developer.android.com/studio/run/device?hl=zh-cnicon-default.png?t=N7T8https://developer.android.com/studio/run /device?hl=zh-cn
https://github.com/Genymobile/scrcpy/blob/master/doc/linux.mdicon-default.png?t=N7T8https://github.com/Genymobile/scrcpy/blob /master/doc/linux.md
https://github.com/Genymobile/scrcpy/blob/master/doc/connection.mdicon-default.png?t=N7T8https://github.com/Genymobile/scrcpy/blob /master/doc/connection.md
Mac-Scrcpy implements same-screen/multi-screen collaborative operation on Macbook and Android phone interface (supports Win, Mac, Linux) icon-default.png?t=N7T8https://www.cnblogs.com /Formulate0303/p/16055424.html

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS entry skill treeLinux introductionFirst introduction to Linux 37266 people are learning the system

syntaxbug.com © 2021 All Rights Reserved.
Status column Correspondence Solution
No return information Device not detected Connect the device to the computer using a data cable
no permissions (user uos is not in the plugdev group) Not joinedplugdev group Re-add the plugdev group, if it still doesn’t work, log out of the computer and log in again
no permissions (user in plugdev group; are your udev rules wrong?) Has joined the plugdev group, but the data cable is connected Is “Charging Only” Find “Charging via USB” in the notification bar, change it to “Transfer Files”, or re-plug the data cable and select “Transfer Files”
unauthorized Enable [USB debugging< /strong>] After the pop-up window appeared, you did not click [Allow], prompting that you are not authorized Close [USB debugging< /strong>] and then reopen it. When a pop-up window appears, click [Allow]
device The device is connected normally