<h1 id="android-debugging">Android Debugging</h1>
<ul>
<li><a href="https://developer.android.com/studio/command-line/adb">Android Debug Bridge (adb) homepage</a></li>
</ul>
<h2 id="install-adb-tools">Install ADB Tools</h2>
<p>There are multiple guides online as to how to install, but I found <code>dnf install android-tools.x86_64 adb-enhanced.noarch</code> the easiest. Similar commands are available for the other distros. Use your package manager to search for <code>adb</code>.</p>
<ul>
<li><a href="https://www.xda-developers.com/install-adb-windows-macos-linux/">https://www.xda-developers.com/install-adb-windows-macos-linux/</a></li>
</ul>
<h2 id="enable-developer-options">Enable Developer options</h2>
<p>Go to Settings. Usually via the pulldown menu from the top twice, and click the cog icon. Search for 'Build Number', it's usually in Click on 'About Phone' Click on 'Build Number' seven times.</p>
<p>Go back and then search for 'Developer options' it's usually in the System section</p>
<p>You'll need to turn on two features 'Android Debugging' and 'ADB over network'</p>
<p>While we are at it, go back and then search for 'IP Address' it's usually in the <code>About phone</code> section. You should see a IPv4 address eg: 192.168.1.100. Make note of the IP address as we'll use it later.</p>
<h2 id="using-adb">Using ADB</h2>
<p>To get help use the command <code>adb help</code></p>
<ul>
<li>global options: Tell you how to connect to the phone</li>
<li>general commands: Shows your devices, and gives help</li>
<li>networking: Allows you to connect over the network but also to port forward and reverse traffic</li>
<li>file transfer: The only reliable way to get files to and from your device.</li>
<li>internal debugging: Shows how to control the server</li>
</ul>
<h3 id="usb">USB</h3>
<p>Plug your phone using a usb cable. There will be a notification and a popup to allow the connection.</p>
<p>Run <code>adb shell</code> and all going well you should see your phone. Commands like <code>ls</code>, <code>cd</code>, and <code>find</code> work well. For example <code>find /storage/self/primary/</code>.</p>
<h3 id="network">Network</h3>
<p>Unfortunately if you unplug your phone you no longer have a connection to it, but you can enable network access via tcp. Leave your phone connected to USB and then tell it to use a TCP/IP connection with the command <code>adb tcpip 5555</code>.</p>
<p>Then connect to the phone using the phones IP address and port 5555, <code>adb connect 192.168.1.100:5555</code>. It should reply with a connected to message</p>
<pre><code>$ adb connect 192.168.1.100:5555
connected to 192.168.1.100:5555</code></pre>
<p>Now commands like <code>adb shell</code> should allow you to access the phone even if it's not physically connected via usb.</p>
<h3 id="multiple-devices">Multiple devices</h3>
<p>Got multiple devices then you can connect them all in the same way as shown above. The only issue is you need to tell adb which one you want to address.</p>
<p>The first thing you need to do is list the devices</p>
<pre><code>$ adb devices -l
List of devices attached
192.168.1.100:5555   device product:XXXX model:XXXX device:XXXX transport_id:9
192.168.1.101:5555   device product:YYYY:ZZZZ device:ZZZZ transport_id:14</code></pre>
<p>The important bit is the <code>transport_id</code> at the end. You can then use the <code>adb</code> command as normal but specifying the <code>-t</code> option</p>
<pre><code>-t: allocate a pty if on a tty (-tt: force pty allocation)</code></pre>
<p>So for example <code>adb -t 14 shell</code> would connect to phone <em>YYYY</em></p>
<p>So that's it for remote control from the shell, but what if you want to see and interact with the screen itself ?</p>
<h2 id="remote-screen-sharing-with-scrcpy">Remote screen sharing with <code>scrcpy</code></h2>
<p>From <a href="https://en.wikipedia.org/wiki/scrcpy">Wikipedia</a></p>
<p><em>scrcpy is a free and open-source screen mirroring application that allows control of an Android device from a Windows, macOS, or Linux desktop computer. The software is currently developed by Genymobile, which also developed Genymotion, an Android emulator.</em></p>
<p>The <a href="https://github.com/Genymobile/scrcpy">source code is available on github</a>. It's available via <code>apt install scrcpy</code> on Ubuntu. In Fedora you'll need to enable it from the copr repo.</p>
<pre><code>dnf copr enable zeno/scrcpy
dnf install scrcpy</code></pre>
<p>With only one phone connected you can just type <code>scrcpy</code> and the screen will appear. Remember right click is power, and the mouse is your finger ;-).</p>
<p>If you have multiple devices connected you can connect using <code>scrcpy --tcpip=192.168.1.101:5555</code></p>
<p>scrcpy is a wonderful tool that deserves a show in itself, but in short it lets you interact with your phone as if it was a VNC/Remote Desktop session. You can copy text <em>from</em> the phone as well.</p>
<p>It allows for control of the screen, as well as screen recording.</p>
