Skip to content

fix(hostname): use Build.DEVICE instead of Settings.Global.DEVICE_NAME#188

Closed
TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/hostname-use-build-device
Closed

fix(hostname): use Build.DEVICE instead of Settings.Global.DEVICE_NAME#188
TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/hostname-use-build-device

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Problem

getDeviceName() was using Settings.Global.DEVICE_NAME as the primary hostname source. On many Android devices (particularly Xiaomi/POCO), this returns the OEM marketing name — e.g. "Poco F8 Ultra" with spaces and mixed case. While the existing normalization step converts this to "poco_f8_ultra", relying on DEVICE_NAME introduces OEM-specific and locale-specific variation.

The symptom: aw-webui's Raw Data (Buckets) view shows "Poco F8 Ultra" as the device hostname instead of a clean machine-readable identifier.

Fix

Use Build.DEVICE (the hardware codename, e.g. "poco_f8_ultra") as the primary source. It is:

  • Stable across reboots and locale changes
  • Already lowercase and underscore-delimited on most devices
  • Not subject to OEM customization of display names

The normalization step (lowercase + replace non-alphanumeric with _) is kept for any edge cases where Build.DEVICE might contain unusual characters.

Migration

Existing buckets created with a DEVICE_NAME-derived hostname are migrated by the existing migrateHostname() call in BackgroundService. On most devices the computed hostname is identical either way (since Build.DEVICE is already normalized), so migration is a no-op for clean installs.

Related

Discussed in #176.

cc @ErikBjare

Settings.Global.DEVICE_NAME returns OEM marketing names like "Poco F8 Ultra"
(with spaces, mixed case). While the normalization step converts these to
"poco_f8_ultra", relying on DEVICE_NAME adds an unnecessary indirection and
varies by OEM/locale configuration.

Build.DEVICE returns the hardware codename (e.g. "poco_f8_ultra") which is
already stable, lowercase, and underscore-delimited. Using it directly as
the primary source produces more predictable hostnames across devices.

The normalization step (lowercase + replace non-alphanumeric with _) is kept
for edge cases where Build.DEVICE might contain unexpected characters.

Migration via migrateHostname() handles the transition for existing buckets
that were created with DEVICE_NAME-derived hostnames.
@ErikBjare

Copy link
Copy Markdown
Member

@TimeToBuildBob I thought this was already done in #183

@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR changes the Android hostname source used by the Rust bridge. The main changes are:

  • Removes the direct Settings.Global.DEVICE_NAME lookup from RustInterface.
  • Uses android.os.Build.DEVICE as the primary hostname value.
  • Keeps the existing lowercase and character normalization.

Confidence Score: 4/5

The changed hostname path can split bucket and sync behavior when Android device-name sources differ.

  • RustInterface now uses Build.DEVICE, while a sibling sync path still uses the old source first.
  • Upgrade migration only receives the newly computed hostname from this path, so old metadata can remain under the previous name when the values differ.
  • The removed import does not leave an executable compile issue in the changed file.

mobile/src/main/java/net/activitywatch/android/RustInterface.kt and the sibling sync hostname logic

Important Files Changed

Filename Overview
mobile/src/main/java/net/activitywatch/android/RustInterface.kt Updates hostname generation to use Build.DEVICE; the main follow-up is keeping all hostname users consistent across bucket and sync paths.

Reviews (1): Last reviewed commit: "fix(hostname): use Build.DEVICE instead ..." | Re-trigger Greptile

// Use Build.DEVICE (hardware codename, e.g. "poco_f8_ultra") rather than
// Settings.Global.DEVICE_NAME (OEM marketing name, e.g. "Poco F8 Ultra").
// Marketing names contain spaces and vary by locale, breaking hostname-based
// bucket lookup in aw-webui. Build.DEVICE is stable and already underscore-delimited.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Hostname Sources Diverge

When Build.DEVICE differs from the normalized Settings.Global.DEVICE_NAME, bucket creation and migration now use the hardware codename while sync still has a separate hostname implementation that uses the old source first. Sync calls can then operate under a different hostname than the buckets created by this path, causing data to be missed or synced under the wrong device name.

// Use Build.DEVICE (hardware codename, e.g. "poco_f8_ultra") rather than
// Settings.Global.DEVICE_NAME (OEM marketing name, e.g. "Poco F8 Ultra").
// Marketing names contain spaces and vary by locale, breaking hostname-based
// bucket lookup in aw-webui. Build.DEVICE is stable and already underscore-delimited.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Old Hostname Becomes Unrecoverable

On upgrade from a version that stored bucket metadata with a DEVICE_NAME-derived hostname, this path now computes only the new Build.DEVICE value before BackgroundService calls migrateHostname(hostname). If the native migration needs to move buckets from the old hostname to the new one, the old value is no longer available here, so existing buckets whose old normalized name differs from Build.DEVICE can remain under the pre-upgrade hostname while new buckets use the new one.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Closing as redundant with the already-merged #183.

PR #183 (merged today) already updated both RustInterface.kt and SyncInterface.kt to use Build.DEVICE in the fallback path. This PR was opened in error, missing that context.

If we later want to remove Settings.Global.DEVICE_NAME as the primary source (not just the fallback), that should be done consistently in both files together — tracked in the follow-up issue Erik requested.

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.

2 participants