MobDev.AdbRoot (mob_dev v0.7.22)

Copy Markdown View Source

adb root that waits for the adbd restart it causes.

On a non-root adbd, adb root answers restarting adbd as root and drops the device's transport while adbd restarts. Under CPU load that restart takes seconds, so a fixed sleep races it and the next adb command fails with "device not found" / "Selected Android device(s) disconnected" (MOB-459). root/2 instead waits with adb -s <serial> wait-for-device plus a getprop sys.boot_completed round trip, bounded by a timeout.

The timeout defaults to 30 s; override it with the MOB_ADB_RESTART_TIMEOUT_MS environment variable, config :mob_dev, adb_restart_timeout_ms: ms, or the :timeout_ms option.

Summary

Types

Runs adb with the given args, returning {output, exit_status}.

Functions

Runs adb -s <serial> root.

Waits until serial is listed again and answers a shell round trip with sys.boot_completed = 1, after anything that restarts adbd (adb root, adb unroot, adb remount). Same options as root/2, plus :uid: the shell uid the restarted adbd must report. The old adbd can still answer for a moment after adb root returns, so root/2 passes uid: 0 to tell the new adbd from the old one.

Types

runner()

@type runner() :: ([String.t()] -> {String.t(), non_neg_integer()})

Runs adb with the given args, returning {output, exit_status}.

Functions

root(serial, opts \\ [])

@spec root(
  String.t(),
  keyword()
) :: :rooted | :not_rooted | {:error, String.t()}

Runs adb -s <serial> root.

Returns :rooted once adbd runs as root and answers again, :not_rooted if the device refuses root (production builds) or adb fails, and {:error, message} if adbd restarted but the device didn't come back as root within the timeout. Waits unless adbd already runs as root or refuses it; adb sometimes prints nothing while it restarts adbd, so an empty reply waits too.

Options: :runner (see runner/0), :timeout_ms.

wait_for_device(serial, opts \\ [])

@spec wait_for_device(
  String.t(),
  keyword()
) :: :ok | {:error, String.t()}

Waits until serial is listed again and answers a shell round trip with sys.boot_completed = 1, after anything that restarts adbd (adb root, adb unroot, adb remount). Same options as root/2, plus :uid: the shell uid the restarted adbd must report. The old adbd can still answer for a moment after adb root returns, so root/2 passes uid: 0 to tell the new adbd from the old one.