Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.linux > #82841

Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing

From Maria Sophia <mariasophia@comprehension.com>
Newsgroups alt.os.linux, comp.mobile.android, alt.comp.os.windows-10
Subject Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing
Date 2026-06-20 02:22 -0500
Organization BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID <1115f42$2l12$1@nnrp.usenet.blueworldhosting.com> (permalink)
References <110b60u$25n1$1@nnrp.usenet.blueworldhosting.com>

Cross-posted to 3 groups.

Show all headers | View raw


Maria Sophia wrote:
> PSA: 
> Persistent ADB over Wi-Fi without repeated pairing of desktop to Android

UPDATE!
The debug port is a legacy step that ADB no longer strictly requires!

The latest adbconnect script has been working wonderfully, as the goal is 
always to reduce everything we do on any computer to a single quick step.

But... the strangest thing happened earlier today... 
I found out that the debug port is a legacy port. It's not actually needed.

It was almost like when I found out that gravity isn't actually a force.
And that everything moves at the speed of light through curved spacetime.
So gravity is due to the curvature of time (mostly) & not to space curvature.

Yet, everyone (including me) always thought that gravity was a force.
And that it was due to the curvature of space (mostly) and less so of time.

It's not. And the adb connect step is also not needed either.
All we need is the adb pairing step. 

How do I know this (without being a window washer falling off a roof)?

I ran adbconnect but I accidentally mistyped the debug port.
Yet the desktop still connected over Wi-Fi to adb and to scrcpy mirroring.

Huh?

Turns out, the debug port is ... um... er... optional.
Who knew. Not me. Now I do.

All we really need is:
 a. Pair over Wi-Fi 
 b. Run adb tcpip 5555
 c. Connect to 5555
 d. Launch scrcpy

Pairing port = authentication
Debug port = optional first-connect helper

Once pairing succeeds, ADB has a trusted identity token for the device.

USB connection between phone & desktop:
 a. Already trusted
 b. No pairing needed
 c. No debug port needed
 d. We can immediately run adb tcpip 5555

Wi-Fi connection between phone & desktop:
 a. We must pair
 b. Pairing gives ADB the same trust token USB normally provides
 c. After pairing, the debug port becomes optional
Because Wi-Fi pairing replaces the need for USB.
And once paired, the debug port becomes irrelevant.

The debug port is a legacy step that ADB no longer strictly requires.
Yet, when I commented out the debug port, the script logic unexpectedly
broke when re-launching scrcpy (when it was already running). Huh?

Turns out once paired, the PC is permanently authorized to connect to that phone over Wi-Fi, regardless of what port is used next (until rebooted).

In addition, I added logic to detect if scrcpy is already running & if so, to use the existing running connection instead of killing/restarting it.

  :: adbconnect.bat  (Automate Android-to-desktop Wi-Fi adb/scrcpy connections)
  ::  Solves two problems when connecting a desktop to adb/scrcpy for Android.
  ::  1. Eliminate all useless random-security steps in a Wi-Fi adb connection
  ::  2. Eliminate the useless scrcpy console window which just takes up space
  :: v1p8 20260619
  ::  a. The debug port user-input query was removed 
  ::  b. And the pairing to TCP/IP flow was simplified as a result
  ::  c. Plus, detection of scrcpy already running was added to prevent scrcpy
  ::     from respawning if it was already running when adbconnect is run.
  ::  Note: While Wi-Fi pairing replaces the need for the USB cable,
  ::  once paired, the Android debug port actually becomes irrelevant.
  ::  Once paired, even if the PC is rebooted, the PC is permanently authorized
  ::  to connect to that phone over Wi-Fi regardless of the debug port.
  ::  (ADB pairing only needs to be replenished after the phone has rebooted.)
  :: v1p7 20260615 
  ::  Removed the requirement for the "no-console" vbs script
  ::  by injecting the necessary commands into a temporary file
  ::  This is the cleanest way I can think of to eliminate the console.
  :: v1p6 20260614
  ::  Called the vbs "no-console" script that comes with adb.
  ::  If the script isn't there, then it defaults to the old method.
  ::  The problem is getting completely rid of the scrcpy console isn't working.
  ::  These are the known scrcpy console-hiding methods:
  ::  (a) cmd /c start "" /min (minimizes the console)
  ::      The console is not hidden. It's just minimized.
  ::  (b) cmd start "" /B (background launch of detached console)
  ::      This detaches scrcpy from the batch console
  ::  (c) adb default VBS no-console wrapper (fully hidden window)
  ::      Default GUI-subsystem scrcpy launch (so no console is created)
  ::      CreateObject("Wscript.Shell").Run strCommand, 0, False
  ::  (d) Kleebauer ShowWindow() controller trick to hide the batch console
  ::      showwin.exe 0 SW_HIDE (Hides the batch console)
  ::  (e) Powershell ShowWindowAsync (similar idea to Herbert's ShowWindow()
  ::      Add-Type '[DllImport("user32.dll")] 
  ::      public static extern bool 
  ::      ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
  ::  Here is the original scrcpy-noconsole.vbs that comes with adb
  ::  strCommand = "cmd /c scrcpy.exe"
  ::   For Each Arg In WScript.Arguments
  ::   strCommand = strCommand & " """ & replace(Arg, """", """""""""") & """"
  ::   Next
  ::   CreateObject("Wscript.Shell").Run strCommand, 0, false
  :: v1p5 20260613 Added query asking for the LAN IP address of the phone
  ::   Reordered comments to allow the current version to be obvious
  :: v1p4 20260612 minimized the scrcpy console (but it's still there)
  ::   using cmd /c start "" /min (minimizes the console only)
  ::   The only known choices are
  ::   (a) Minimized console-subsystem launch (cmd /c start "" /min)
  ::   (b) Background detached launch (start "" /B)
  ::   (c) Hidden GUI-subsystem VBS launcher (no console created)
  ::   (d) External ShowWindow() console-visibility controller (Kleebauer trick)
  ::   (e) PowerShell ShowWindowAsync console hider (similar to ShowWindow())
  :: v1p3 20260612 moved the pipe outside the FOR command for reliability
  :: v1p2 20260611 further reliability improvements added to v1p1
  ::   Use separate retry counters for pair/connect to avoid loop 
  ::   interference (ATTEMPTS_PAIR, ATTEMPTS_CONN)
  ::   Added fail-fast with clear error codes and user hints after retry 
  ::   exhaustion
  ::   Added a detection of the device id after initial connect 
  ::   (handles ephemeral adb ports like 192.168.1.4:54321)
  ::   Use DEVICE_ID for subsequent -s tcpip command (quoted) 
  ::   to avoid parsing issues with colons
  ::   Fallback device-id lookup when initial pattern match fails 
  ::   (robust parsing of "adb devices")
  ::   Consistent quoting of %ADB% and device identifiers to avoid 
  ::   CMD parsing errors
  :: v1p1 20260611 reliability improvements added to v1p0
  ::   Added better device lookup (skip header,ignore blanks,avoid false matches)
  ::   Added retry logic for adb pair & adb connect (for when phone not ready)
  ::   Improved polish (consistent quoting, stable scrcpy launch)
  :: v1p0 20260611 converted adbconnect.vbs to adbconnect.bat
  ::  Connects desktop & phone over adb & mirrors phone on the monitor
  ::  No USB cord is used in this process as it's all done over Wi-Fi
  ::  Should work even if either the PC and/or the phone is rebooted
  ::  The script will ask only for the minimum amount of data needed
  ::  Change the phone static IP address as needed to fit your LAN IP address
  
  @echo off
  setlocal enabledelayedexpansion
  :: For phones with static IP addresses, change the next line 
  set PHONE_IP=192.168.1.4
  set SCRCPY_OPTS=--keyboard=sdk --always-on-top
  
  echo.
  echo === ADB Wireless Auto-Connect ===
  echo === [Developer options > Wireless debugging > on] ===
  echo.
  
  REM 1. Find adb
  for /f "delims=" %%A in ('where adb 2^>nul') do (
  if not defined ADB set ADB=%%A
  )
  
  if not defined ADB (
  echo [ERROR] adb.exe not found.
  exit /b
  )
  
  REM Ensure .exe extension
  if /i not "%ADB:~-4%"==".exe" set ADB=%ADB%.exe
  
  echo Using ADB: "%ADB%"
  echo.
  
  REM 2. Check if already connected
  echo Checking existing ADB devices...
  
  set DEVICE_ID=
  for /f "skip=1 tokens=1" %%I in ('"%ADB%" devices') do (
      echo %%I | findstr /R "[0-9]" >nul && (
          echo %%I | findstr /I "%PHONE_IP%" >nul && (
              if not defined DEVICE_ID set DEVICE_ID=%%I
          )
      )
  )
  
  if defined DEVICE_ID (
      echo Already connected on %DEVICE_ID%
      goto RUN_TCPIP
  )
  
  echo Not connected. Need to pair.
  echo.
  
  REM 3. Ask user for pairing info
  echo Necessary pairing information will be shown on the phone:
  set /p PHONE_IP=Phone IP [%PHONE_IP%] :
  set /p PAIR_PORT=Wireless debugging pairing port :
  set /p PAIR_CODE=Wireless debugging pairing code :
  
  echo.
  echo Pairing with: %PHONE_IP%:%PAIR_PORT%
  
  REM Retry logic for adb pair (3 attempts)
  set ATTEMPTS_PAIR=0
  :PAIR_RETRY
  set /a ATTEMPTS_PAIR+=1
  "%ADB%" pair %PHONE_IP%:%PAIR_PORT% %PAIR_CODE%
  if errorlevel 1 (
  if !ATTEMPTS_PAIR! lss 3 (
  echo Pair failed, retrying...
  timeout /t 2 >nul
  goto PAIR_RETRY
  ) else (
  echo [ERROR] adb pair failed after %ATTEMPTS_PAIR% attempts.
  echo Hint: Open Wireless debugging -> "Pair device with pairing code" on the phone, then re-run this script.
  exit /b 1
  )
  )
  echo.
  
  :: NEW: Debug port removed in v1p8. Skip directly to TCP/IP mode.
  echo Skipping obsolete debug-port connect step...
  echo.
  
  :: NEW: After pairing, ADB already trusts the device. Switch directly to TCP/IP.
  echo Switching to TCP/IP 5555...
  "%ADB%" tcpip 5555
  echo.
  
  echo Connecting final port: %PHONE_IP%:5555
  "%ADB%" connect %PHONE_IP%:5555
  echo.
  
  set DEVICE_ID=%PHONE_IP%:5555
  goto RUN_SCRCPY
  
  :RUN_TCPIP
  echo Switching device !DEVICE_ID! to TCP/IP 5555...
  "%ADB%" -s "%DEVICE_ID%" tcpip 5555
  "%ADB%" connect "%PHONE_IP%:5555"
  goto RUN_SCRCPY
  
  :RUN_SCRCPY
  echo Launching scrcpy completely silent...
  
  :: NEW: Check if scrcpy is already running to avoid killing visible session
  tasklist | findstr /I "scrcpy.exe" >nul
  if not errorlevel 1 (
      echo scrcpy is already running. Skipping relaunch.
      echo Done.
      exit /b
  )
  
  set "VBS_TEMP=%TEMP%\scrcpy_runner.vbs"
  
  :: Build the standalone VBS command string directly into the temp file
  echo strCommand = "cmd /c scrcpy.exe --tcpip=%PHONE_IP% %SCRCPY_OPTS%" > "%VBS_TEMP%"
  echo CreateObject("Wscript.Shell").Run strCommand, 0, false >> "%VBS_TEMP%"
  
  :: Execute the temporary VBS script
  wscript.exe "%VBS_TEMP%"
  
  :: Brief pause to ensure script allocation completes before cleaning up the temp file
  timeout /t 1 >nul
  if exist "%VBS_TEMP%" del "%VBS_TEMP%"
  
  echo Done. 
  exit /b
  
  REM end of adbconnect.bat
  
-- 
Posted out of the goodness of my heart to help others do what I do.

Back to alt.os.linux | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-10 02:07 -0600
  Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-11 21:49 -0500
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-12 16:17 -0500
      Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Hank Rogers <Hank@nospam.invalid> - 2026-06-12 16:32 -0500
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Give It A Try <try.it@invalid.invalid> - 2026-06-12 23:20 +0100
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-13 11:31 -0500
  Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing 🇵🇱Jacek Marcin Jaworski🇵🇱 <jmj@energokod.gda.pl> - 2026-06-15 11:08 +0200
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Paul <nospam@needed.invalid> - 2026-06-15 12:11 -0400
      Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing 🇵🇱Jacek Marcin Jaworski🇵🇱 <jmj@energokod.gda.pl> - 2026-06-15 19:24 +0200
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-15 14:10 -0500
          Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-15 14:43 -0500
          Re: PSA: Streamlined persistent ADB port over   Wi‑Fi without repeated pairing vallor <vallor@vallor.earth> - 2026-06-17 00:16 +0000
            Re: PSA: Streamlined persistent ADB port over   Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 23:23 -0500
      Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-15 13:56 -0500
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Warpinator <invalid@invalid.invalid> - 2026-06-16 00:23 +0100
          Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-15 19:18 -0500
            Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-06-16 12:15 +0200
              Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-30 22:12 -0400
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-07-01 11:51 +0200
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-07-01 13:57 -0400
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Chris <ithinkiam@gmail.com> - 2026-06-16 07:07 +0000
      Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 02:21 -0500
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-06-16 12:30 +0200
          Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 12:07 -0500
            Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-06-16 20:11 +0200
              Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 14:40 -0500
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-06-16 22:47 +0200
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 15:51 -0500
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "Carlos E. R." <robin_listas@es.invalid> - 2026-06-18 00:45 +0200
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Hank Rogers <Hank@nospam.invalid> - 2026-06-17 17:56 -0500
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-30 21:46 -0400
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing "....winston" <winstonmvp@gmail.com> - 2026-06-16 19:47 -0400
                Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 23:26 -0500
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Chris <ithinkiam@gmail.com> - 2026-06-16 12:10 +0000
          Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-16 12:09 -0500
            Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-26 06:38 -0400
  Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-20 02:22 -0500
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-20 02:31 -0500
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-21 00:53 -0500
  Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-27 08:58 -0400
    Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Nadia Jarvis <invalid@invalid.invalid> - 2026-06-27 19:38 +0100
      Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Hank Rogers <Hank@nospam.invalid> - 2026-06-27 19:53 -0500
        Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-27 23:01 -0600
          Re: PSA: Streamlined persistent ADB port over Wi‑Fi without repeated pairing Maria Sophia <mariasophia@comprehension.com> - 2026-06-30 21:40 -0400

csiph-web