Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions mobile/src/main/java/net/activitywatch/android/RustInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ class RustInterface(context: Context? = null) {
}

fun getDeviceName(context: Context): String {
return Settings.Global.getString(context.contentResolver, Settings.Global.DEVICE_NAME)
?: android.os.Build.MODEL ?: "Unknown"
val raw = Settings.Global.getString(context.contentResolver, Settings.Global.DEVICE_NAME)
?.trim()
?.takeIf { it.isNotEmpty() }
?: android.os.Build.DEVICE
?: "unknown"
Comment thread
TimeToBuildBob marked this conversation as resolved.
return raw.trim()
.lowercase(java.util.Locale.ROOT)
.replace(Regex("[^a-z0-9_-]+"), "_")
.trim('_')
.ifEmpty { "unknown" }
}

}
12 changes: 9 additions & 3 deletions mobile/src/main/java/net/activitywatch/android/SyncInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ class SyncInterface(context: Context) {
external fun getSyncDir(): String

private fun getDeviceName(): String {
return android.provider.Settings.Global.getString(
appContext.contentResolver,
val raw = android.provider.Settings.Global.getString(
appContext.contentResolver,
android.provider.Settings.Global.DEVICE_NAME
) ?: android.os.Build.MODEL ?: "Unknown"
)?.trim()?.takeIf { it.isNotEmpty() }
?: android.os.Build.DEVICE ?: "unknown"
return raw.trim()
.lowercase(java.util.Locale.ROOT)
.replace(Regex("[^a-z0-9_-]+"), "_")
.trim('_')
.ifEmpty { "unknown" }
}

// Async wrapper for syncPullAll
Expand Down
Loading