Wire the merged prefs into Settings and permission flow

Settings now actually exposes everything the merge added instead of
leaving it as code-only defaults: strict wake, call/text direct (asks
for Call/SMS permission right when you turn one on, falls back
quietly if denied), pass-text-to-Claude, the nicknames box, and
driving mode plus auto-arm, with a status line and a button for the
Bluetooth permission auto-arm needs.

Driving mode's on/off state is now actually persisted: saying
"hey dummy, driving mode on/off" sticks across restarts, and the
service honors the stored value when it starts instead of always
coming up off.

MainActivity's first-run permission prompt now also asks for
Contacts and Bluetooth up front, alongside mic and notifications,
since those gate the call/text-by-name and auto-arm features. Both
degrade gracefully if denied, same as before.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JW57ZsDX1dKfj2Bozu4D65
This commit is contained in:
Weishaupt
2026-11-14 02:47:13 +00:00
co-authored by Claude Sonnet 5
parent 30f978b40a
commit 1850cdd9a5
3 changed files with 139 additions and 1 deletions
@@ -96,6 +96,7 @@ class ListenService : Service() {
Bus.running = true
stopFlag = false
DrivingMode.init(this)
DrivingMode.setActive(this, Prefs.drivingMode(this), announce = false)
if (!btReceiverRegistered) {
try {
registerReceiver(btReceiver, DrivingMode.BtReceiver.filter())
@@ -278,11 +279,13 @@ class ListenService : Service() {
val lower = words.trim().lowercase()
if (lower == "driving mode on" || lower == "turn on driving mode") {
DrivingMode.setActive(this, true)
Prefs.setDrivingMode(this, true)
backToListening()
return
}
if (lower == "driving mode off" || lower == "turn off driving mode") {
DrivingMode.setActive(this, false)
Prefs.setDrivingMode(this, false)
backToListening()
return
}
@@ -133,6 +133,13 @@ class MainActivity : Activity() {
if (!hasMic()) need.add(Manifest.permission.RECORD_AUDIO)
if (Build.VERSION.SDK_INT >= 33 && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED)
need.add(Manifest.permission.POST_NOTIFICATIONS)
// Optional extras for the voice-command side: calling/texting by name, and
// auto-arming driving mode over Bluetooth. Asked for once here, up front, but
// nothing breaks if these get denied — the matching features just stay off.
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED)
need.add(Manifest.permission.READ_CONTACTS)
if (Build.VERSION.SDK_INT >= 31 && checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED)
need.add(Manifest.permission.BLUETOOTH_CONNECT)
if (need.isNotEmpty()) { requestPermissions(need.toTypedArray(), 1); return }
ListenService.start(this)
}
@@ -1,10 +1,14 @@
package space.bloggin.scribe
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.text.InputType
import android.view.Gravity
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.EditText
@@ -13,6 +17,8 @@ import android.widget.ScrollView
import android.widget.Toast
class SettingsActivity : Activity() {
private lateinit var btStatus: android.widget.TextView
override fun onCreate(b: Bundle?) {
super.onCreate(b)
val root = LinearLayout(this)
@@ -31,7 +37,7 @@ class SettingsActivity : Activity() {
wake.setText(Prefs.wake(this))
wake.inputType = InputType.TYPE_CLASS_TEXT
body.addView(wake)
body.addView(Ui.text(this, "Type it the way the speech model spells it, so “dumby” is “dummy” here. Longer phrases of ordinary words almost never trigger by accident. A word the model does not know will never trigger.", 13f, Ui.MUTED))
body.addView(Ui.text(this, "Type it the way the speech model spells it, so “dumby” is “dummy” here. Longer phrases of ordinary words almost never trigger by accident. A word the model does not know will never trigger. Say it by itself (“hey dummy”, “hey dumby”, “okay dummy”) and it listens for a command instead of a note.", 13f, Ui.MUTED))
body.addView(Ui.text(this, "Seconds of silence before a note ends", 16f, Ui.INK, true).also { it.setPadding(0, pad, 0, 0) })
val sil = EditText(this)
@@ -45,6 +51,70 @@ class SettingsActivity : Activity() {
for (c in listOf(beep, vib, cpu)) { c.setTextColor(Ui.INK); c.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4)); body.addView(c) }
body.addView(Ui.text(this, "Keeping the processor awake is what lets it hear you with the screen off. It uses more battery.", 13f, Ui.MUTED))
// ---- Commands (ported from Hey Claude) ----
body.addView(divider())
body.addView(Ui.text(this, "Commands", 16f, Ui.INK, true))
val strictWake = CheckBox(this)
strictWake.text = "Wait for the full \"hey dummy\" before listening for a command"
strictWake.isChecked = Prefs.strictWake(this)
strictWake.setTextColor(Ui.INK); strictWake.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4))
body.addView(strictWake)
body.addView(Ui.text(this, "Off is quicker to respond. On waits for a clean, finished phrase, which can help in a loud car.", 13f, Ui.MUTED))
val callDirect = CheckBox(this)
callDirect.text = "Place calls directly instead of opening the dialer"
callDirect.isChecked = Prefs.callDirect(this)
callDirect.setTextColor(Ui.INK); callDirect.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4))
body.addView(callDirect)
val textDirect = CheckBox(this)
textDirect.text = "Send texts directly instead of opening Messages"
textDirect.isChecked = Prefs.textDirect(this)
textDirect.setTextColor(Ui.INK); textDirect.setPadding(0, Ui.dp(this, 4), 0, Ui.dp(this, 4))
body.addView(textDirect)
body.addView(Ui.text(this, "Both of these need extra phone permissions (Call and SMS). You'll be asked for them the moment you turn one on. Left off, it hands you the dialer or Messages with everything filled in, same as before.", 13f, Ui.MUTED))
val passText = CheckBox(this)
passText.text = "If nothing else matches, send what you said to the Claude app"
passText.isChecked = Prefs.passText(this)
passText.setTextColor(Ui.INK); passText.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4))
body.addView(passText)
body.addView(Ui.text(this, "Off just opens the Claude app. On also hands it whatever you said, as a share.", 13f, Ui.MUTED))
body.addView(Ui.text(this, "Nicknames", 16f, Ui.INK, true).also { it.setPadding(0, pad, 0, 0) })
body.addView(Ui.text(this, "One per line: what you say = the app or contact name it should open.", 13f, Ui.MUTED))
val aliases = EditText(this)
aliases.setText(Prefs.aliasText(this))
aliases.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
aliases.minLines = 4
aliases.gravity = Gravity.TOP
body.addView(aliases)
// ---- Driving mode ----
body.addView(divider())
body.addView(Ui.text(this, "Driving mode", 16f, Ui.INK, true))
body.addView(Ui.text(this, "Speaks command results out loud instead of only showing them, so you don't have to look at the phone. Dictated notes stay silent except for \"Note saved\". Turn it on or off any time by saying “hey dummy, driving mode on” or “…off”.", 13f, Ui.MUTED))
val driving = CheckBox(this)
driving.text = "Driving mode on"
driving.isChecked = Prefs.drivingMode(this)
driving.setTextColor(Ui.INK); driving.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4))
body.addView(driving)
val autoDriving = CheckBox(this)
autoDriving.text = "Auto-arm when the phone connects to the car's Bluetooth"
autoDriving.isChecked = Prefs.autoDrivingMode(this)
autoDriving.setTextColor(Ui.INK); autoDriving.setPadding(0, Ui.dp(this, 4), 0, Ui.dp(this, 4))
body.addView(autoDriving)
body.addView(Ui.text(this, "Android has no real way to tell \"this is a car\" over Bluetooth, so this fires for any audio device it connects to, a speaker or headset included. If that's wrong for you, leave this off and just toggle it by voice.", 13f, Ui.MUTED))
btStatus = Ui.text(this, "", 13f, Ui.MUTED).also { it.setPadding(0, Ui.dp(this, 6), 0, 0) }
body.addView(btStatus)
val btGrant = Ui.ghostButton(this, "Grant Bluetooth permission")
btGrant.setOnClickListener { requestBtPermission() }
body.addView(btGrant, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { it.topMargin = Ui.dp(this, 6) })
refreshBtStatus()
val save = Ui.button(this, "Save")
save.setOnClickListener {
val w = wake.text.toString().trim().lowercase().replace(Regex("[^a-z' ]"), "").replace(Regex("\\s+"), " ")
@@ -54,6 +124,22 @@ class SettingsActivity : Activity() {
Prefs.setBeep(this, beep.isChecked)
Prefs.setVibrate(this, vib.isChecked)
Prefs.setCpu(this, cpu.isChecked)
Prefs.setStrictWake(this, strictWake.isChecked)
Prefs.setPassText(this, passText.isChecked)
Prefs.setAliasText(this, aliases.text.toString())
Prefs.setDrivingMode(this, driving.isChecked)
Prefs.setAutoDrivingMode(this, autoDriving.isChecked)
if (callDirect.isChecked && !hasPerm(Manifest.permission.CALL_PHONE)) {
requestPermissions(arrayOf(Manifest.permission.CALL_PHONE), 2)
}
Prefs.setCallDirect(this, callDirect.isChecked)
if (textDirect.isChecked && !hasPerm(Manifest.permission.SEND_SMS)) {
requestPermissions(arrayOf(Manifest.permission.SEND_SMS), 3)
}
Prefs.setTextDirect(this, textDirect.isChecked)
if (Bus.running) {
ListenService.stop(this)
android.os.Handler(mainLooper).postDelayed({ ListenService.start(this) }, 900)
@@ -85,4 +171,46 @@ class SettingsActivity : Activity() {
root.addView(sv, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
setContentView(root)
}
private fun divider(): android.view.View {
val v = android.view.View(this)
v.setBackgroundColor(Ui.LINE)
val lp = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Ui.dp(this, 1))
lp.topMargin = Ui.dp(this, 20)
lp.bottomMargin = Ui.dp(this, 4)
v.layoutParams = lp
return v
}
private fun hasPerm(p: String) = checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED
private fun hasBtPermission(): Boolean =
if (Build.VERSION.SDK_INT >= 31) hasPerm(Manifest.permission.BLUETOOTH_CONNECT) else true
private fun refreshBtStatus() {
btStatus.text = if (hasBtPermission())
"Bluetooth permission granted; auto-arm can work."
else
"Bluetooth permission not granted yet; auto-arm will stay off until you grant it."
}
private fun requestBtPermission() {
if (Build.VERSION.SDK_INT >= 31 && !hasBtPermission()) {
requestPermissions(arrayOf(Manifest.permission.BLUETOOTH_CONNECT), 4)
} else {
Toast.makeText(this, "Already granted", Toast.LENGTH_SHORT).show()
}
}
override fun onRequestPermissionsResult(code: Int, perms: Array<out String>, res: IntArray) {
if (code == 4) refreshBtStatus()
if (code == 2 && res.firstOrNull() != PackageManager.PERMISSION_GRANTED) {
Prefs.setCallDirect(this, false)
Toast.makeText(this, "Call permission denied; calls will open the dialer instead", Toast.LENGTH_LONG).show()
}
if (code == 3 && res.firstOrNull() != PackageManager.PERMISSION_GRANTED) {
Prefs.setTextDirect(this, false)
Toast.makeText(this, "SMS permission denied; texts will open Messages instead", Toast.LENGTH_LONG).show()
}
}
}