Sarab

Using Sarab

Running in the background

How Android starts, pauses when you are not using it, and stops; and how to start it at login.

Start and stop

sarab start      # returns once Android is up
sarab stop
sarab restart
sarab status     # running, paused, booting or stopped

You rarely need sarab start by hand: opening an app from your launcher, double-clicking an .apk, and every sarab command that talks to Android start it when it is not running.

There is only ever one Android. sarab status says which state it is in and who started it:

$ sarab status
state          paused
pid            3377318
started by     systemd (sarab.service)
cgroup         /sys/fs/cgroup/user.slice/user-1000.slice/[email protected]/app.slice/sarab-3377310.scope

Add --json for scripts.

Paused when idle

A minute after the last Android window closes, Sarab freezes every Android process with the cgroup freezer. A paused Android uses no CPU and causes no wakeups at all; its memory is kept, so opening an app again resumes it in about 13 ms, not a boot.

After ten minutes paused, Sarab also asks the kernel to move Android’s memory out to swap or zram, when the host has any, which leaves a physical footprint of about 172 MB. The first app you open after that takes a moment longer while pages come back.

Every command that talks to Android resumes it first, and an open sarab exec shell counts as activity, so Android does not pause under you. To pause or resume by hand:

sarab pause
sarab unpause

The minute is an option of sarab start --foreground, the process that owns Android: --idle-freeze SECS, where 0 never pauses. Plain sarab start and the unit use the default.

Start at login

Sarab installs a systemd user unit, sarab.service, but does not enable it. To boot Android at every login:

systemctl --user enable --now sarab

Whenever the unit is installed, enabled or not, sarab start, stop and restart, a click on an app and a double-clicked .apk go through it; enabling it only adds the start at login. If Sarab’s host service, sarab-hostd, crashes, Android’s windows go with it, so the unit stops Android and starts both again.

The unit needs your Wayland session’s environment. Hyprland under uwsm puts it into the user manager; otherwise run this once before enabling:

systemctl --user import-environment WAYLAND_DISPLAY

Without the unit, sarab start starts Android in the background by itself instead; its log is sarab logs --daemon.

Memory and CPU

sarab stats              # live, until Ctrl+C
sarab stats --no-stream  # one reading
STATE       MEMORY      SWAP     CPU   PIDS
running     359 MB    374 MB   0.20%    821

Everything is read from /proc and the cgroup, on the host, for the whole Android tree. --json prints one object per reading.

    Type to search the documentation.