Operate Android Device on FreeBSD
Operate Android Device on FreeBSD

			I really like communicators (or communication channels) that offer a web based interface – let it be WhatsApp or Telegram for example. Unfortunately many does not – like Signal for example – and while the FreeBSD based Signal package usually works – its good to have some alternative or fallback.
There are also some apps – like SMS – that you prefer to use the one installed on Your phone because it sucks less. For example I tried to replace my phone default SMS app with Google Messages for Web … but I really did not liked the experience.

Recently I found another way to use the apps on the phone – with the help of SCRCPY that allows you to control any Android device from a desktop computer – also from FreeBSD – as its even packaged in the FreeBSD Ports as comms/scrcpy port.

You may also check the SCRCPY GitHub page for some additional information.
Android Settings
You need to set several things on your Android device.
First go to About Phone in the Settings.

Then click Software Information there.

Then you will have to tap the Build Number at least 7 times.

You will then see floating information that the Developer Mode is enabled.

Now – get back to main Settings screen and choose Developer Options there.

Make sure that the Developer Options are in On state.

Not needed for this to work – but you may want to enable Stay Awake option so your phone will not automatically lock when its attached to USB cable – useful with SCRCPY tool.

You will need to enable USB Debugging as shown below.

You can also set in which USB mode your phone is ready after attaching it with USB cable in Default USB Configuration.

For the remove SCRCPY operation the Transferring Files option is needed.

Now you Android device configuration is complete. We now need to check your Android device IP address that it got from DHCP – assuming of course that its from DHCP. Lets go to Connections in Settings.

Next select WiFi connection.

Tap the ‘gear’ icon in your current WiFi connection.

… and below in the details you fill find the Android device IP address along with its MAC address.

I also added that MAC address of my Android device in the DHCP configuration and assigned it to the 10.0.0.33 IP address – that will be useful later – for the script that automates connecting to the Android device.
Install SCRCPY and Android Tools
We will now install needed packages.
FreeBSD # pkg install -y comms/scrcpy devel/android-tools


As we have these packages installed – we may now advance to the next step.
Device Attach
Now – unlock your Android device screen and then attach it via USB cable (a cable that allows data transfer of course) to your FreeBSD computer.
Next – we will type needed commands.
FreeBSD % doas killall -9 adb

FreeBSD % adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
R58M72XN72X     device

FreeBSD % adb tcpip 5555
restarting in TCP mode port: 5555

FreeBSD % adb connect 10.0.0.33
connected to 10.0.0.33:5555

FreeBSD % scrcpy -e
scrcpy 2.7 
INFO: ADB device found:
INFO:           (usb)  R58M72XN72X                     device  SM_G970U1
INFO:     --> (tcpip)  10.0.0.33:5555                  device  SM_G970U1
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 19.5 MB/s (71200 bytes in 0.003s)
[server] INFO: Device: [samsung] samsung SM-G970U1 (Android 12)
INFO: Renderer: opengl
INFO: OpenGL version: 3.3 (Compatibility Profile) Mesa 24.1.7
INFO: Trilinear filtering enabled
INFO: Texture: 1080x2280

… and now you should have your Android device – a smartphone in my case – remote control over it – even [CTRL]+[C] and [CTRL]+[V] works 🙂

One annoying thing I noticed – that BANK related applications (or other kinda ‘security’ related apps) are often ‘blacked out’ – the entire screen is just black and You can not do anything about it.

Its some Android security (by obscurity) bullshit that You can not override – and as described here the only things that are able to overcome this bullshit are:

Run app on a device having Android version 11 or older.
Root your Android device.
Recompile your app to disable Secure Flag with tool like apk.sh for example.

So … yeah – this is the part where Google again failed to provide.
Automation
To not have to type all these commands everytime I created a short and simple POSIX compatible shell script listed below.
FreeBSD % cat phone-remote.sh 
doas killall adb
doas killall -9 adb
adb devices
adb tcpip 5555
adb connect 10.0.0.33
scrcpy -e

Feel free to use and modify it for your needs.
Summary
Not sure what I should add here – feel free to share your thoughts in the comments.
EOF
					