Arch/Manjaro/linux android phone connectivity, scrcpy, adb #023

 A really fast way to connect to and Android phone is via USB cable, you can access files, share internet from phone to PC and remote control the phone.

 The application to control the phone is scrcpy, it requires USB debugging.
 Access  phone settings >> Software Information >> Build version >> tap it more then 8 times, and "Developer options are now enabled" should pop up.
 For LineageOS its : Settings >> About phone >> Build number
A new "Developer Options" menu should now appear on the Phone Settings, enable USB debugging and the phone is now ready.

On the computer install scrcpy, just search for it using pamac-manager Add/Remove Software(...), its in the AUR repository.
Once installed, connect the phone over USB, open terminal, type scrcpy and that's it, check if phone requested permissions and accept them.

To customize the experience, scrcpy has lots of commands, one of the best one is to turn off the phone screen while you are connected to it.

scrcpy --turn-screen-off ; this will save battery and keep the phone cooler as well
scrcpy --max-size 800 ; change the connection stream resolution
scrcpy --record phone_screen.mp4 ; record the phone screen
scrcpy --push-target /sdcard/transfer ;select the drag/drop default folder
scrcpy --help ;help on more commands and hotkeys

mouse commands :

 Middle-Click : HOME
 Right-Click : BACK
 Right-Click when screen is off : power on

usefull hotkeys :

    Ctrl+f ;switch fullscreen mode
    Ctrl+g ;resize window to 1:1 (pixel-perfect)
    Ctrl+s ;click on APP_SWITCH
    Ctrl+m ;click on MENU
    Ctrl+Up ;click on VOLUME_UP
    Ctrl+Down ;click on VOLUME_DOWN
    Ctrl+p ;click on POWER (turn screen on/off)
    Ctrl+o ;turn device screen off (keep mirroring)
    Ctrl+n ;expand notification panel
    Ctrl+Shift+n ;collapse notification panel
    Ctrl+c ;copy device clipboard to computer
    Ctrl+v ;paste computer clipboard to device
    Ctrl+Shift+v ;copy computer clipboard to device
    Ctrl+i ;enable/disable FPS counter (print frames/second in logs)
    Drag & drop APK file ; install APK from computer


While scrcpy is active and you are sharing phone internet connection with computer  MTP usb mode is not available, to transfer files while in this mode adb can be used.

adb utility is available in android-tools in pamac-manager (Add/Remove Software)

With adb installed, (note: I used scrcpy from AUR, that will install android-tools) from the linux terminal type:

to check each command, its very very usefull, all of the following commands are isted there:

adb help

to  scan for a device, then connect to it:

adb devices

to list contents of phone file system:

adb shell ls -lah


To transfer a file from the phone to computer:
  open terminal, go to the computer folder you want to download the file to

  adb should be working (check by using adb devices)

  use adb shell ls command to get the path of the file you want to transfer, example in the picture above, then type:
adb pull [path and filename]

example :

adb pull /storage/aaaa/Download/someapp.apk

adb pull  storage/.../Download/

note: it will copy folder and contents

you can also just type adb shell, and use linux commands to navigate, you can type toybox to get a lista of them.

To transfer a file from the computer to phone is the same process , except you use:

adb push [filename] [phone path]

If using Bluetooth internet sharing, to access the phone over the Bluetooth connection the phone must have debugging over TCP/Wireless must be enabled, this option is available in the same menu as USB debugging.

To connect adb to the phone, you must find the phone IP address, that will most likely be the default gateway that the computer is using to access internet(a note about finding default gateway is posted in this blog).




type:

adb connect 192.168.44.1


scrcpy will now work over bluetooth.

If the application is best viewed in landscape mode, adb can force that:

# disable auto rotation

adb shell settings put system accelerometer_rotation 0

# use custom rotation (0=portrait, 1=landscape)

adb shell settings put system user_rotation 1

Comments