What is the best way to ensure adb access if a screen breaks? I just broke the screen on my OnePlus 6, which doesn't allow adb debugging until you change the USB Connection Type to 'MTP' (via the screen), and their repair service states they will wipe any device they are sent, no exceptions. I didn't unlock the bootloader, and so unlocking it to flash a different recovery will also wipe the device. It also removed adb over wifi, so it appears it is completely locked down.

On my next phone (Razer Phone 2), I want to ensure this never happens again. I am concerned that potential Android updates may also require screen interaction before it will allow adb over USB, or that adb over wifi may be removed.

What is the best way to ensure that I can maintain adb access without screen interaction in the case of a future breakage?

I plan on:


Unlocking the bootloader right away, so that worst case I could flash a custom recovery like twrp that would allow adb access
Enabling adb
Authorizing at least two computers
Setting the default USB mode to MTP (if possible)
Enabling adb over wifi, but ONLY if I can lock it down


Regarding adb over WiFi, I don't want this fully enabled on every network I join. Is there a way to whitelist only my home WiFi, or to only allow it from authorized computers?

I'm looking for ways to not lose access like this in the future - I have to order a replacement screen and repair it myself in order to try and retrieve the data. It's also important to me that I don't lose access via any system updates in the future, though this is difficult to ensure. Perhaps a nandroid backup of a system with everything ready that could be restored through the recovery?

In devices like the OnePlus 6, that have removed adb over WiFi and require touch input to adb over USB, what are the viable options?
This could be a problem with the installed drivers if you need to switch to a data transfer mode such as MTP to use adb. I use adb on charging only in data transfer mode, which is status-by-design, in OnePlus 6.

For the broken screen issue, I don't know if this would help. You could try with an OTG cable and a mouse to see if it works automatically. There is an OTG toggle in Settings app so it might be the cause if this approach doesn't work as plug-n-play.

As for your approach on your new phone, understand that adb over wifi is safe. Whether on wifi or on USB, your phone would show an authorisation approval dialog to approve a machine (PC) for USB Debugging, be it on USB or Wifi. So you need to careful more on what machine to allow for, instead of restricting the access over a specific Wifi.

However, it is possible to mistakenly authorize adb over wifi when unsuspecting that the dialog would show up suddenly, say when you were playing a game and so deeply engaged that you just nearly click anything as ok that shows up on screen, so for that you would want to restrict access to adb only on your personal wifi with trusted machines.

Now for that, you can use automation. I use Tasker app to automatically enable adb over wifi on boot. For your case, here are the instructions (tested with a rooted OnePlus running Android 8.1):


Profile: State &rarr; Net &rarr; Wifi Connected (requires Location permission and Location enabled at all times):


SSID: select your SSID/WiFi's name
Active: Yes
leave the rest untouched

Task: Code &rarr; Run Shell:


Command: 

setprop service.adb.tcp.port 9999
stop adbd &amp;&amp; start adbd

Tick Use Root

Long press the task next to profile and select Add Exit Task.
Exit Task: Code &rarr; Run Shell:


Command: 

setprop service.adb.tcp.port ''
stop adbd &amp;&amp; start adbd

Tick Use Root



Now, as long as location service remains enabled, Tasker would detect when the phone gets connected and disconnected to your SSID. When connected, adb would be listening over your WiFI on port 9999 (choose any port of your choice but above 1024). When the WiFi disconnects from that SSID, adb would not listen on a port. 



If you plan to use TWRP than even if a system update messes up with your USB Debugging settings TWRP would always grant you access to debugging automatically as it works independently of Android system installed in the device. You don't need to change data transfer mode there either. If you need to do it, something is definitely not right. Furthermore, if you have TWRP installed than you have deeper access to your data that which adb can never have so you need not to worry about debugging in Android if TWRP is available and kicking.