# Room Watchdog

Room Watchdog is a privacy-first Android companion for an ESP32 room sensor.
It shows live presence, plays and records audio only on demand, and receives
presence and sound alerts from your self-hosted Gotify server.

[![CI](https://github.com/patbaumgartner/esp32-room-watchdog-android/actions/workflows/ci.yml/badge.svg)](https://github.com/patbaumgartner/esp32-room-watchdog-android/actions/workflows/ci.yml)
[![Security](https://github.com/patbaumgartner/esp32-room-watchdog-android/actions/workflows/security.yml/badge.svg)](https://github.com/patbaumgartner/esp32-room-watchdog-android/actions/workflows/security.yml)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)

The companion firmware lives in
[esp32-room-watchdog](https://github.com/patbaumgartner/esp32-room-watchdog).

| The room, live | Listening to it |
| :---: | :---: |
| ![Home screen reading "Someone is here, about 0.8 m away" with a "Person nearby" chip above a waveform](docs/images/home.png) | ![The same screen listening, with mute, noise-filter, record and stop controls along the bottom](docs/images/listening.png) |

Presence, distance and the microphone level arrive over the device's WebSocket.
Audio only ever streams while a session is open, and only to the phone in your
hand.

## Features

- Live room presence, distance, microphone level, and device connectivity,
  pushed over the device's WebSocket instead of polled
- On-demand PCM audio listening with independent mute
- Noise reduction that learns the room during the first seconds of a session
- Local AAC/M4A recording with playback, sharing, renaming, and deletion
- Background notifications for presence and sound events, suppressed while the
  app is visible
- Mute alerts for an hour, four hours, until 18:00 or until you turn them back
  on, from Home, the Quick Settings tile or the connection notification; events
  still appear in the app while muted
- In-app presence and recent-noise indicators
- Notification actions that start listening or recording after an explicit tap
- System-aware light and dark themes
- Keystore-backed encryption for the ESP32 API token and Gotify client token

## Download

Signed builds are published on the
[Releases](https://github.com/patbaumgartner/esp32-room-watchdog-android/releases)
page:

- **Releases** (`vX.Y.Z` tags): signed APK and AAB, plus `SHA256SUMS` and the
  signer certificate fingerprint in the release notes.
- **Snapshot** (prerelease, rebuilt on every push to `main`): the latest
  signed APK for testing.

Both use the same release key. Stable releases can update to Snapshot, but Android
blocks installing stable directly over Snapshot as a downgrade. Switching channels
is manual-only in myApps, which shows a data-loss warning and does not
automatically uninstall or migrate app data. Back up recordings before switching.
Verify a download against `SHA256SUMS` before installing. Sideloading on
Android 8+ requires allowing "Install unknown apps" for the app you open the
APK with.

## Requirements

- Android 8.0 (API 26) or newer
- JDK 27
- Android SDK Platform 37.1 (`compileSdkMinor = 1`; `targetSdk` remains 37) with matching build tools
- An ESP32 running the companion firmware on a local network or VPN
- A Gotify server reachable over HTTPS and a Gotify **client** token (`gtfyc...`)

The first build downloads the Gradle distribution and Android dependencies. It
can use several gigabytes of disk space in Gradle and Android SDK caches.

## Build and run

Gradle needs to know where the Android SDK is, from either an `ANDROID_HOME`
environment variable or an `sdk.dir` line in `local.properties`. Without one of
them the build stops with `SDK location not found`.

```bash
git clone https://github.com/patbaumgartner/esp32-room-watchdog-android.git
cd esp32-room-watchdog-android
export ANDROID_HOME="$HOME/Android/Sdk"
./gradlew :app:assembleDebug
```

Install on the only attached physical Android device:

```bash
scripts/deploy-device.sh
```

Or install on an Android Virtual Device named `myAndroidEmulatorDevice`:

```bash
scripts/deploy-emulator.sh
```

Override the emulator name with `AVD_NAME`; override the physical device with
`DEVICE_SERIAL`. Both scripts respect `ANDROID_HOME` and `JAVA_HOME` and
otherwise use the tools already available in the environment.

On first launch, enter the room name, ESP32 address and API key, Gotify HTTPS
address, and Gotify client token. Android 13 and newer will then ask for
notification permission.

## Development defaults

Debug builds can prefill onboarding fields without committing credentials. Copy
the example and edit the ignored file:

```bash
cp local.properties.example local.properties
```

The same values can be supplied as environment variables:

| `local.properties` | Environment variable |
| --- | --- |
| `watchdog.roomName` | `WATCHDOG_ROOM_NAME` |
| `watchdog.deviceUrl` | `WATCHDOG_DEVICE_URL` |
| `watchdog.apiToken` | `WATCHDOG_API_TOKEN` |
| `watchdog.gotifyUrl` | `WATCHDOG_GOTIFY_URL` |
| `watchdog.gotifyClientToken` | `WATCHDOG_GOTIFY_CLIENT_TOKEN` |

These values are compiled into the debug APK. Use development credentials only,
never production secrets. Release builds always leave the fields empty.

## Network and privacy model

- Gotify must use HTTPS. The client token is rejected before any connection when
  the URL is not encrypted.
- The ESP32 can use HTTPS anywhere. Plain HTTP is limited to hosts that parse as
  loopback, link-local, RFC 1918 or IPv6 unique-local addresses, and to names in
  a local zone: a single-label hostname, `.local`, `.lan`, or `.home.arpa`.
  Addresses are classified by parsing them, not by how they are spelled, so a
  public host is never exempted for merely resembling a private one.
- ESP32 HTTPS uses Android's system certificate authorities and standard
  hostname verification. Self-signed, expired, or hostname-mismatched
  certificates are rejected.
- HTTPS and explicitly configured HTTP ports preserve proxy routing. No-port
  HTTP defaults to direct audio on the announced port (81 fallback); configure
  explicit `:80` for a standard-port cleartext proxy. A mismatching Hello host
  also keeps a no-port hostname proxy on port 80.
- Tokens are encrypted with an Android Keystore AES-GCM key before storage.
- Recordings remain in app-private storage. They are shared through a temporary
  read-only content URI only when the user chooses Share or Play.
- Backups and device-to-device transfer are disabled for credentials, events,
  and recordings.
- The app has no analytics, advertising SDK, or cloud service dependency beyond
  the Gotify server configured by the user.

## Validation

Run the same primary gates used by CI. Besides JDK 27 and SDK Platform 37.1,
validation needs Bash, `jq`, `yamllint`, ShellCheck and standard Unix utilities
(`awk`, `sed`, `grep`, `diff` and coreutils); only the live probe needs `curl`.

```bash
./gradlew testDebugUnitTest lintDebug assembleDebug assembleRelease assembleDebugAndroidTest bundleRelease
scripts/check-ci.sh
scripts/check-audio-contract.sh
scripts/test-dependabot-preflight.sh
scripts/test-firmware-probe.sh
yamllint .
find . -name '*.sh' -not -path './*/build/*' -exec shellcheck {} +
```

The release APK produced by a plain source checkout is unsigned; official
signed builds are published on the Releases page (see [Download](#download)).

See [CONTRIBUTING.md](CONTRIBUTING.md) for the contributor workflow and
[docs/architecture.md](docs/architecture.md) for the design.

## About

Settings shows the app version, open-source notices, and author information.

© 2026 [Patrick Baumgartner](https://patbaumgartner.com/) - Crafted with ❤️

## License

Room Watchdog is licensed under the [Apache License 2.0](LICENSE). The bundled
Manrope fonts are licensed under the SIL Open Font License 1.1; see
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
