fix(hostname): use Build.DEVICE instead of Settings.Global.DEVICE_NAME#188
fix(hostname): use Build.DEVICE instead of Settings.Global.DEVICE_NAME#188TimeToBuildBob wants to merge 1 commit into
Conversation
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.
|
@TimeToBuildBob I thought this was already done in #183 |
Greptile SummaryThis PR changes the Android hostname source used by the Rust bridge. The main changes are:
Confidence Score: 4/5The changed hostname path can split bucket and sync behavior when Android device-name sources differ.
mobile/src/main/java/net/activitywatch/android/RustInterface.kt and the sibling sync hostname logic Important Files Changed
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
|
Closing as redundant with the already-merged #183. PR #183 (merged today) already updated both If we later want to remove |
Problem
getDeviceName()was usingSettings.Global.DEVICE_NAMEas 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 onDEVICE_NAMEintroduces 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:The normalization step (lowercase + replace non-alphanumeric with
_) is kept for any edge cases whereBuild.DEVICEmight contain unusual characters.Migration
Existing buckets created with a
DEVICE_NAME-derived hostname are migrated by the existingmigrateHostname()call inBackgroundService. On most devices the computed hostname is identical either way (sinceBuild.DEVICEis already normalized), so migration is a no-op for clean installs.Related
Discussed in #176.
cc @ErikBjare