fix(notification): resolve granted Android permission requests (fix #3757) (#3758)

This commit is contained in:
Lorky authored and GitHub committed 2026-11-09 09:56:05 +01:00
1 parent 937f03bb57
commit 52edb98eb0
4 files changed
+70 -8

No files matched your search

@@ -0,0 +1,6 @@
---
notification: patch
notification-js: patch
---
Fix notification permission requests never resolving on Android 13 and newer when the permission has already been granted.
+4 -4
View File
@@ -91,10 +91,10 @@ skipped on desktop, and the rest run everywhere with the odd test gated.
| `geolocation` | `getCurrentPosition`, `watchPosition` (several at once) and `clearWatch` against a location simulated from the host, the granted permission state, and the rejections with location services off (Android). |
| mobile-only plugins | `barcode-scanner`, `haptics` and `nfc` need hardware or native UI the driver cannot operate, so only their global API surface is asserted. | Only there. |
The notification permission specs are desktop-only: a mobile app starts out ungranted and
`requestPermission` puts up a system dialog the session would then block on. The rest of the
notification API (action types, channels, the pending/active lists, listeners) only exists on
mobile, and is covered there without the permission.
The notification permission specs cover desktop and repeated requests on Android after
granting `POST_NOTIFICATIONS` over `adb` (Android 13+). They do not interact with the system
permission dialog. The rest of the notification API (action types, channels, the
pending/active lists, listeners) only exists on mobile and is covered there too.
The geolocation specs move the device with `adb emu geo fix` (Android) and
`xcrun simctl location` (iOS), so on Android they need an emulator rather than a device.
@@ -19,12 +19,11 @@ import {
// macOS), which the suite cannot observe, and sending is fire-and-forget, so
// only the permission model is covered on desktop.
//
// The permission specs are desktop-only: mobile starts out ungranted and
// `requestPermission` puts up a system dialog the session would then block on.
// Permission requests can open a system dialog on mobile. The Android regression
// below grants the permission over adb first, then checks the already-granted path.
//
// Scheduling, action types, channels, the pending/active lists and the
// listeners are only implemented on mobile. None of them need the permission,
// so they are covered there on an app that has not been granted it.
// listeners are only implemented on mobile and are covered separately below.
//
// On Android, what the system actually posted (`when` and the chronometer
// flags) is read back from `dumpsys notification` over adb; Appium's
@@ -92,6 +91,61 @@ async function clearNotifications(): Promise<void> {
}
describePlugin('notification', () => {
itOn(
'android',
'repeated permission requests resolve when already granted',
async () => {
adb([
'shell',
'pm',
'grant',
appId,
'android.permission.POST_NOTIFICATIONS'
])
const result = await tauri(async (api) => {
if (
!(await api.core.invoke<boolean>(
'plugin:notification|is_permission_granted'
))
) {
throw new Error('Notification permission must already be granted')
}
const request = async (fn: () => Promise<string>) => {
let timer: ReturnType<typeof setTimeout> | undefined
try {
return await Promise.race([
fn(),
new Promise<never>((_, reject) => {
timer = setTimeout(
() =>
reject(
new Error('Granted notification request did not resolve')
),
5000
)
})
])
} finally {
clearTimeout(timer)
}
}
const states = []
for (let i = 0; i < 2; i++) {
states.push(await request(() => api.notification.requestPermission()))
states.push(
await request(() => window.Notification.requestPermission())
)
}
return { states, permission: window.Notification.permission }
})
expect(result).toEqual({
states: ['granted', 'granted', 'granted', 'granted'],
permission: 'granted'
})
}
)
itDesktop('permission is granted on desktop', async () => {
const result = await tauri(async (api) => ({
granted: await api.notification.isPermissionGranted(),
@@ -258,6 +258,8 @@ class NotificationPlugin(private val activity: Activity): Plugin(activity) {
} else {
if (getPermissionState(LOCAL_NOTIFICATIONS) !== PermissionState.GRANTED) {
requestPermissionForAlias(LOCAL_NOTIFICATIONS, invoke, "permissionsCallback")
} else {
permissionState(invoke)
}
}
}