Skip to content

fix: use Build.DEVICE instead of Build.MODEL for hostname fallback#183

Merged
ErikBjare merged 4 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/use-build-device-for-hostname
Jul 12, 2026
Merged

fix: use Build.DEVICE instead of Build.MODEL for hostname fallback#183
ErikBjare merged 4 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/use-build-device-for-hostname

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Problem

getDeviceName() in RustInterface.kt and SyncInterface.kt falls back to android.os.Build.MODEL when Settings.Global.DEVICE_NAME is null. Build.MODEL returns the OEM marketing name (e.g. "Poco F8 Ultra") which contains spaces — that breaks hostname-based bucket matching in aw-webui and aw-server.

Reported in #176: a Xiaomi Poco F8 Ultra produced "Poco F8 Ultra" as its hostname. The webui then fails to associate it with the Android bucket view because the hostname contains spaces.

Fix

Replace the Build.MODEL fallback with Build.DEVICE, which returns the device codename (poco_f8_ultra — lowercase, underscore-delimited, no spaces). This is the correct format for a network hostname.

Property Example value Hostname-safe?
Settings.Global.DEVICE_NAME "Poco F8 Ultra" ❌ (spaces)
Build.MODEL "Poco F8 Ultra" ❌ (spaces)
Build.DEVICE "poco_f8_ultra"

Changes

  • RustInterface.kt: Build.MODELBuild.DEVICE
  • SyncInterface.kt: Build.MODELBuild.DEVICE

Closes #176 (contributes — the hostname fix is one part of the broader stability tracker).

Build.MODEL returns the OEM marketing name (e.g. 'Poco F8 Ultra') which
contains spaces that break hostname-based bucket matching in aw-webui and
aw-server. Build.DEVICE returns the device codename (e.g. 'poco_f8_ultra')
which is lower-case, underscore-delimited, and safe to use as a hostname.

Fixes the class of bug reported in ActivityWatch#176 where
Xiaomi/Poco devices produced space-containing hostnames.
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes Android hostname fallback and normalization safer. The main changes are:

  • Use Build.DEVICE instead of Build.MODEL when no configured device name is available.
  • Ignore blank configured device names before falling back.
  • Normalize hostnames to lowercase safe characters in both Rust and sync interfaces.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
mobile/src/main/java/net/activitywatch/android/RustInterface.kt Updates local bucket hostname selection to skip blank names and apply strict normalization.
mobile/src/main/java/net/activitywatch/android/SyncInterface.kt Applies the same normalized hostname selection before passing the value into sync calls.

Reviews (4): Last reviewed commit: "fix: filter blank DEVICE_NAME before fal..." | Re-trigger Greptile

Comment thread mobile/src/main/java/net/activitywatch/android/RustInterface.kt Outdated
Comment thread mobile/src/main/java/net/activitywatch/android/SyncInterface.kt Outdated
Comment thread mobile/src/main/java/net/activitywatch/android/RustInterface.kt Outdated
Comment thread mobile/src/main/java/net/activitywatch/android/SyncInterface.kt Outdated
Settings.Global.DEVICE_NAME can itself contain spaces (e.g. 'Poco F8 Ultra')
so the previous fix only addressed the fallback path. Sanitize the final
hostname by trimming, lowercasing, and replacing spaces with underscores,
ensuring bucket hostname matching works even when DEVICE_NAME is configured
with a human-readable name.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread mobile/src/main/java/net/activitywatch/android/RustInterface.kt Outdated
Comment thread mobile/src/main/java/net/activitywatch/android/SyncInterface.kt Outdated
Use strict regex [^a-z0-9_-]+ instead of only space replacement, so
configured device names with quotes or other special chars don't break
bucket JSON. Also guard whitespace-only DEVICE_NAME with takeIf so it
falls through to Build.DEVICE rather than resolving to empty string.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread mobile/src/main/java/net/activitywatch/android/RustInterface.kt
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@ErikBjare ErikBjare merged commit 39e840f into ActivityWatch:master Jul 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elevated crash/ANR rate (8.17% user-perceived crashes) and declining Play Store rating

2 participants