Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(selfcheck): ask for POST_NOTIFICATIONS, which was declared and never requested

booboosui989205db793c
diff --git a/app/src/main/java/net/kuafuai/andee/device/PermissionsController.kt b/app/src/main/java/net/kuafuai/andee/device/PermissionsController.kt
index 2141843..34fe7ff 100644
--- a/app/src/main/java/net/kuafuai/andee/device/PermissionsController.kt
+++ b/app/src/main/java/net/kuafuai/andee/device/PermissionsController.kt
@@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
+import android.os.Build
import android.provider.Settings
import androidx.annotation.StringRes
import net.kuafuai.andee.R
@@ -39,6 +40,16 @@ class PermissionsController(private val context: Context) {
val permission: String?,
val special: String?, // "notification" | "overlay" | null
@StringRes val featureRes: Int,
+ /**
+ * First API where this permission means anything, or 0 for always.
+ *
+ * Not decoration: on an older device the permission does not exist, and
+ * `checkSelfPermission` answers **denied** for anything it does not know —
+ * so a row without this would report POST_NOTIFICATIONS missing on every
+ * Android 12 device, for ever, with no way to fix it. Skipping the entry
+ * entirely is the honest answer: on that device there is nothing to grant.
+ */
+ val api: Int = 0,
)
private val catalog = listOf(
@@ -51,6 +62,17 @@ class PermissionsController(private val context: Context) {
Perm("sms_send", "android.permission.SEND_SMS", null, R.string.dev_perm_feature_sms_send),
Perm("calendar", "android.permission.READ_CALENDAR", null, R.string.dev_perm_feature_calendar),
Perm("calendar_write", "android.permission.WRITE_CALENDAR", null, R.string.dev_perm_feature_calendar_write),
+ // 发通知 — a *different* thing from 通知使用权 below, which is the listener
+ // that lets the ball read other apps' notifications. This one is whether
+ // anything this app posts is seen at all, and on Android 13+ it is a runtime
+ // permission nothing was ever asking for: declared in the manifest and never
+ // requested, so the persistent "way back" notification and every reminder
+ // from [net.kuafuai.andee.config.Scheduler] were dropped in silence. The
+ // comment there already blamed POST_NOTIFICATIONS; nothing checked it.
+ Perm(
+ "notify_post", "android.permission.POST_NOTIFICATIONS", null,
+ R.string.dev_perm_feature_notify_post, api = Build.VERSION_CODES.TIRAMISU,
+ ),
Perm("notifications", null, "notification", R.string.dev_perm_feature_notifications),
Perm("overlay", null, "overlay", R.string.dev_perm_feature_overlay),
)
@@ -59,6 +81,9 @@ class PermissionsController(private val context: Context) {
val granted = JSONArray()
val missing = JSONArray()
for (p in catalog) {
+ // A permission that does not exist on this device is neither granted nor
+ // missing, so it is not reported either way — see [Perm.api].
+ if (p.api > 0 && Build.VERSION.SDK_INT < p.api) continue
val ok = when {
p.permission != null ->
context.checkSelfPermission(p.permission) == android.content.pm.PackageManager.PERMISSION_GRANTED
@@ -250,7 +275,14 @@ class PermissionsController(private val context: Context) {
* was asked once more than necessary" rather than "the ball agreed to
* something on their behalf".
*/
- private val SOLO_IDS = setOf("location", "steps", "calendar", "calendar_write")
+ private val SOLO_IDS = setOf(
+ "location", "steps", "calendar", "calendar_write",
+ // Same kind of thing as the four above — a runtime permission whose sheet
+ // waits for a finger, and not an invasive one — so it belongs here rather
+ // than in handoff. Named explicitly because this list is a whitelist and
+ // anything unnamed falls to handoff by design; see the note above.
+ "notify_post",
+ )
/** Ids with no dialog at all — only a switch inside Settings. */
private val SETTINGS_IDS = setOf("notifications", "overlay")
diff --git a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt
index 935b9b2..9d42d6c 100644
--- a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt
+++ b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt
@@ -219,7 +219,9 @@ object SelfCheck {
fun run(context: Context, probe: Boolean = true): List<Finding> {
val online = isOnline(context)
val a11yIme = imeChannelOpen()
- return listOf(
+ // listOfNotNull rather than listOf: one row only exists on API 33+ — see
+ // [postNotifications], which is where the reasoning lives.
+ return listOfNotNull(
// Overlay first, ahead of the service itself. Both are hard gates,
// but they fail in opposite directions: no accessibility service and
// the app is visibly inert (nothing to run), no overlay grant and
@@ -234,6 +236,9 @@ object SelfCheck {
backend(context, probe, online),
version(context, probe, online),
microphone(context),
+ // The ball being heard, right above the ball hearing: the two are easy to
+ // confuse and only one of them was ever checked. See [postNotifications].
+ postNotifications(context),
notificationAccess(context),
typingChannel(context),
adbKeyboard(context, a11yIme),
@@ -601,6 +606,41 @@ object SelfCheck {
* user has to do it in Settings. That makes [listenerSettings] load-bearing
* rather than cosmetic: it has to open a screen that exists.
*/
+ /**
+ * Whether anything this app posts is *seen* at all — which is a different question
+ * from [notificationAccess], and having only that one was the hole.
+ *
+ * That row is the listener: the ball **reading** other apps' notifications. This one
+ * is the ball being **heard**. On Android 13+ the second is a runtime permission,
+ * and it was declared in the manifest and never requested — so the persistent
+ * notification that is the way back to this app, and every reminder
+ * [net.kuafuai.andee.config.Scheduler] posts, were dropped in silence, while the row
+ * above showed a green tick because notification *access* really was granted.
+ * `Scheduler` already had a comment blaming POST_NOTIFICATIONS; nothing checked it.
+ *
+ * Nothing on API < 33: the permission does not exist there, `checkSelfPermission`
+ * answers *denied* for anything it does not know, and a red row with no fix would be
+ * permanent. See [PermissionsController.Perm.api], which skips it for the same reason.
+ */
+ private fun postNotifications(context: Context): Finding? {
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU) {
+ return null
+ }
+ val p = Manifest.permission.POST_NOTIFICATIONS
+ val on = context.checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED
+ return Finding(
+ id = "notify_post",
+ title = R.string.check_title_notify_post,
+ level = if (on) Level.OK else Level.WARN,
+ detail = if (on) {
+ R.string.check_detail_notify_post_on
+ } else {
+ R.string.check_detail_notify_post_off
+ },
+ fix = if (on) Fix.Nothing else Fix.Grant(listOf(p)),
+ )
+ }
+
private fun notificationAccess(context: Context): Finding {
val st = NotificationRelayService.status(context)
val enabled = st.optBoolean("listener_enabled")
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index bd7d43f..eec94a4 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -257,6 +257,7 @@
<string name="dev_perm_feature_sms_send">Send SMS</string>
<string name="dev_perm_feature_calendar">Calendar (reminders)</string>
<string name="dev_perm_feature_calendar_write">Write calendar (add events)</string>
+ <string name="dev_perm_feature_notify_post">Post notifications (reminders, and the way back to me)</string>
<string name="dev_perm_feature_notifications">Notification access (know when you get messages)</string>
<string name="dev_perm_feature_overlay">Overlay (my face)</string>
<string name="dev_perm_say_prefix">Turn on: %1$s.</string>
@@ -420,6 +421,9 @@
<string name="check_title_model">Model</string>
<string name="check_title_version">Version</string>
<string name="check_title_microphone">Microphone</string>
+ <string name="check_title_notify_post">Post notifications</string>
+ <string name="check_detail_notify_post_on">Reminders, and the way back to me, can both come through.</string>
+ <string name="check_detail_notify_post_off">I can post notifications, but the system is not letting them through — reminders, and the way back to me, are both dropped. Allow it with the button below.</string>
<string name="check_title_notifications">Notification access</string>
<string name="check_title_typing_channel">Typing channel</string>
<string name="check_title_adb_keyboard">ADB keyboard</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2352431..fc78629 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -239,6 +239,7 @@
<string name="dev_perm_feature_sms_send">发短信</string>
<string name="dev_perm_feature_calendar">日历(日程提醒)</string>
<string name="dev_perm_feature_calendar_write">写日历(记日程)</string>
+ <string name="dev_perm_feature_notify_post">弹出通知(提醒,和"回到我"的那条)</string>
<string name="dev_perm_feature_notifications">通知感知(微信来消息我知道)</string>
<string name="dev_perm_feature_overlay">悬浮窗(我的脸)</string>
<string name="dev_perm_say_prefix">需要开启: %1$s。</string>
@@ -503,6 +504,9 @@
<string name="check_title_model">模型连通</string>
<string name="check_title_version">版本</string>
<string name="check_title_microphone">麦克风</string>
+ <string name="check_title_notify_post">弹出通知</string>
+ <string name="check_detail_notify_post_on">提醒,和"回到我"的那条通知,都能弹出来。</string>
+ <string name="check_detail_notify_post_off">我是能发通知的,但系统现在没放行——提醒,和"回到我"的那条,都会被丢掉。点下面的按钮允许。</string>
<string name="check_title_notifications">通知使用权</string>
<string name="check_title_typing_channel">打字通道</string>
<string name="check_title_adb_keyboard">ADB 键盘</string>
diff --git a/app/src/test/java/net/kuafuai/andee/device/PermissionsRouteTest.kt b/app/src/test/java/net/kuafuai/andee/device/PermissionsRouteTest.kt
index cbabe85..13fb549 100644
--- a/app/src/test/java/net/kuafuai/andee/device/PermissionsRouteTest.kt
+++ b/app/src/test/java/net/kuafuai/andee/device/PermissionsRouteTest.kt
@@ -27,6 +27,9 @@ class PermissionsRouteTest {
@Test
fun `a grant with no dialog is a settings errand whatever else it is asked with`() {
assertEquals("settings", PermissionsController.routeOf(listOf("notifications")))
+ // 弹出通知 is a runtime permission, the same kind as location and steps, so its
+ // sheet is expected to go up and wait rather than to be handed to ask_user.
+ assertEquals("solo", PermissionsController.routeOf(listOf("notify_post")))
assertEquals("settings", PermissionsController.routeOf(listOf("overlay")))
// Not a severity ranking: a Settings page is the one route nothing
// here can tap at all, so it outranks both of the others.