Skip to content

Commit

Permalink
Use device name from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 17, 2023
1 parent c8542fb commit a73a8b6
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kylecorry.trail_sense.shared.alerts

import android.content.Context
import android.os.Build
import android.provider.Settings
import com.kylecorry.andromeda.alerts.Alerts
import com.kylecorry.andromeda.core.system.Android
import com.kylecorry.andromeda.markdown.MarkdownService
Expand All @@ -24,7 +25,7 @@ class MissingSensorAlert(private val context: Context) : IValueAlerter<String> {
}

fun getMissingSensorMessage(context: Context, sensor: String): CharSequence {
val deviceName = "${Android.manufacturer} ${Build.MODEL}"
val deviceName = getDeviceName(context)

val part1 = context.getString(
R.string.missing_sensor_message_1,
Expand All @@ -43,6 +44,22 @@ class MissingSensorAlert(private val context: Context) : IValueAlerter<String> {

return MarkdownService(context).toMarkdown(markdown)
}

private fun getDeviceName(context: Context): String {
val name = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Settings.Global.getString(context.contentResolver, Settings.Global.DEVICE_NAME) ?: Android.model
} else {
Android.model
}

val manufacturer = Android.manufacturer

if (name.lowercase().startsWith(manufacturer.lowercase())) {
return name
}

return "$manufacturer $name"
}
}

}

0 comments on commit a73a8b6

Please sign in to comment.