diff --git a/CHANGELOG.md b/CHANGELOG.md index 4235058..8866f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ is in alpha and releases come off `main`. ### Changed +- **Allow once and Deny on an approval's notification ask for the phone to be unlocked first** + (Android 12 and newer), so a locked phone cannot answer for you. This holds for the + approvals a scheduled run on a computer will send too. - **The microphone in a chat follows Settings › Voice input**, as the assistant does: with *LLeMbas* it records and your instance writes the words down when you stop; with *Phone* the phone's own recogniser writes them into the box as you speak and stops at the end of what you diff --git a/app/src/main/java/eu/llembas/android/push/Push.kt b/app/src/main/java/eu/llembas/android/push/Push.kt index 3408881..e202777 100644 --- a/app/src/main/java/eu/llembas/android/push/Push.kt +++ b/app/src/main/java/eu/llembas/android/push/Push.kt @@ -122,10 +122,12 @@ object Notifications { // The body can name a command or a file; on a locked screen only the title shows. .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) // An approval can be answered from here: once, or no. "Always" and a corrected command - // need the card itself, so they stay in the app. + // need the card itself, so they stay in the app. Either answer asks for the phone to be + // unlocked first (Android 12+): a locked phone in somebody else's hand must not say yes + // to a command -- nor no to a run that waits on it, a scheduled one included. if (payload.kind == "ask" && payload.ask == "approval" && chatId != null && payload.interactionId != null) { - builder.addAction(0, context.getString(R.string.card_allow_once), answer(context, instance, chatId, payload.interactionId, "allow", id)) - builder.addAction(0, context.getString(R.string.card_deny), answer(context, instance, chatId, payload.interactionId, "deny", id)) + builder.addAction(unlocked(context.getString(R.string.card_allow_once), answer(context, instance, chatId, payload.interactionId, "allow", id))) + builder.addAction(unlocked(context.getString(R.string.card_deny), answer(context, instance, chatId, payload.interactionId, "deny", id))) } NotificationManagerCompat.from(context).notify(id, builder.build()) } @@ -163,6 +165,10 @@ object Notifications { NotificationManagerCompat.from(context).notify(notice.id, builder.build()) } + /** A notification action Android runs only once the phone is unlocked. */ + private fun unlocked(title: String, intent: PendingIntent): NotificationCompat.Action = + NotificationCompat.Action.Builder(0, title, intent).setAuthenticationRequired(true).build() + private fun opener(context: Context, instance: String, id: Int, chatId: String?, scheduleId: String? = null, runId: String? = null): PendingIntent = PendingIntent.getActivity( context,