What is the best way to ensure adb access if a screen breaks?


Question

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?


Answer

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):




  1. Profile: State → Net → Wifi Connected (requires Location permission and Location enabled at all times):




    • SSID: select your SSID/WiFi's name

    • Active: Yes

    • leave the rest untouched


  2. Task: Code → Run Shell:




    • Command:



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

    • Tick Use Root



  3. Long press the task next to profile and select Add Exit Task.


  4. Exit Task: Code → Run Shell:




    • Command:



      setprop service.adb.tcp.port ''
      stop adbd && 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.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes