Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
permissions.hpp
Go to the documentation of this file.
1#pragma once
2
3// Cross-platform runtime permission queries and requests.
4//
5// Mobile platforms (iOS, Android) require explicit user consent for
6// microphone, camera, Bluetooth, and notifications. Desktop platforms
7// usually don't gate these through an app-level permission prompt, so
8// their backends treat most classes as `Granted` and some as
9// `Restricted` (e.g. Android's `ForegroundService`).
10//
11// The contract deliberately stays small:
12// query(p) — synchronous, never blocks, never prompts.
13// request(p) — async, always invokes the callback exactly once.
14//
15// Tests can redirect the backend with `PermissionsOverride` without
16// touching the platform implementation.
17
18#include <functional>
19
20namespace pulp::platform {
21
22enum class Permission {
23 Microphone, // iOS mic, Android RECORD_AUDIO
24 Camera, // iOS/Android camera
25 BluetoothMidi, // iOS NSBluetoothAlwaysUsageDescription, Android BLUETOOTH_*
26 LocalNetwork, // iOS NSLocalNetworkUsageDescription (RTP-MIDI, bonjour)
27 Notifications, // iOS UNUserNotificationCenter, Android POST_NOTIFICATIONS
28 BackgroundAudio, // iOS UIBackgroundModes=audio capability
29 ForegroundService, // Android FOREGROUND_SERVICE / FOREGROUND_SERVICE_MICROPHONE
30};
31
32enum class PermissionState {
33 NotDetermined, // Never asked. On platforms without a prompt, backends use Granted instead.
34 Granted, // User (or OS policy) granted it.
35 Denied, // User denied; may be re-askable depending on platform.
36 Restricted, // Policy / parental-control / unsupported-on-platform.
37};
38
39using RequestCallback = std::function<void(PermissionState)>;
40
43
48
53
60public:
63
66
69
72
73private:
74 struct Impl;
75 Impl* impl_;
76};
77
78} // namespace pulp::platform
PermissionsOverride & operator=(const PermissionsOverride &)=delete
void set(Permission p, PermissionState state)
Map this permission to state for the lifetime of the guard.
void clear(Permission p)
Remove any override for p. Subsequent queries fall through.
PermissionsOverride(const PermissionsOverride &)=delete
Device capability vocabulary: one tier ladder, one thermal ladder, and the projection from observed i...
Definition child_process.hpp:15
Permission
Definition permissions.hpp:22
@ BluetoothMidi
Definition permissions.hpp:25
@ Microphone
Definition permissions.hpp:23
@ Camera
Definition permissions.hpp:24
@ Notifications
Definition permissions.hpp:27
@ BackgroundAudio
Definition permissions.hpp:28
@ ForegroundService
Definition permissions.hpp:29
@ LocalNetwork
Definition permissions.hpp:26
std::function< void(PermissionState)> RequestCallback
Definition permissions.hpp:39
void request(Permission p, RequestCallback cb)
Async request.
PermissionState query(Permission p)
Current state. Never blocks, never shows UI.
PermissionState
Definition permissions.hpp:32
@ Denied
Definition permissions.hpp:35
@ NotDetermined
Definition permissions.hpp:33
@ Granted
Definition permissions.hpp:34
@ Restricted
Definition permissions.hpp:36
bool has_platform_backend()
True when a real platform backend is wired (iOS / Android).
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48