Skip to content

Mobile Permissions Support #3870

Open
Open
@mcmah309

Description

@mcmah309

Feature Request

Currently, there is no way to request or manage permissions on mobile platforms in Dioxus applications. This affects critical functionality such as camera access, location services, file system access, and other platform capabilities that require user permission.

Background

Mobile applications require permissions to access sensitive device features and user data. Both Android and iOS have their own permission systems that differ significantly in implementation but serve the same purpose of protecting user privacy.

Platform Requirements

Android Permission System

Android uses a dual-layer permission system:

  1. Manifest Declaration: All permissions must be declared in AndroidManifest.xml

  2. Runtime Requests: Permissions are categorized by protection level:

    • Normal Permissions (automatically granted at install, no runtime request needed):

      • android.permission.INTERNET
      • android.permission.ACCESS_NETWORK_STATE
      • android.permission.VIBRATE
      • android.permission.SET_ALARM
    • Dangerous Permissions (require runtime request):

      • android.permission.CAMERA
      • android.permission.READ_CONTACTS
      • android.permission.ACCESS_FINE_LOCATION
      • android.permission.READ_EXTERNAL_STORAGE
      • android.permission.RECORD_AUDIO
    • Special Permissions (require specific handling):

      • android.permission.SYSTEM_ALERT_WINDOW
      • android.permission.WRITE_SETTINGS

Android provides a unified permission request API that works consistently across different permission types.

iOS Permission System

iOS has a different approach:

  1. Info.plist Declarations: All privacy-sensitive permissions must be declared in Info.plist with appropriate usage description strings (explaining why the app needs the permission)

  2. Per-Permission APIs: Unlike Android, iOS uses separate APIs for each permission type:

    • Camera access uses AVCaptureDevice.requestAccess(for:)
    • Location uses CLLocationManager.requestWhenInUseAuthorization()
    • Photo library uses PHPhotoLibrary.requestAuthorization()
    • Each with their own callback patterns
  3. Usage Descriptions: Every permission requires a corresponding entry in Info.plist:

    • NSCameraUsageDescription
    • NSPhotoLibraryUsageDescription
    • NSLocationWhenInUseUsageDescription
    • And many others
  4. Special Entitlements: Some iOS capabilities require additional entitlements beyond Info.plist entries:

    • Push Notifications
    • Apple Pay
    • iCloud
    • App Groups
    • Background Modes

Platform-Specific Permissions

Each platform has unique permissions that don't exist on the other:

Android-only Permissions:

  • android.permission.SYSTEM_ALERT_WINDOW
  • android.permission.READ_SMS / android.permission.RECEIVE_SMS
  • android.permission.READ_PHONE_STATE
  • android.permission.WRITE_SETTINGS
  • android.permission.REQUEST_INSTALL_PACKAGES

iOS-only Permissions:

  • Tracking Authorization (NSUserTrackingUsageDescription)
  • Local Network (NSLocalNetworkUsageDescription)
  • Critical Alerts (UNAuthorizationOptionCriticalAlert)
  • Face ID/Touch ID (NSFaceIDUsageDescription)
  • Photo Library Additions (NSPhotoLibraryAddUsageDescription)

Proposed Implementation

Due to the specific platform needs and evolving technologies, it may be best to expose AndroidManifest.xml and Info.plist to be used in the compiled platform projects. There should be a unified native experience for permissions. Maybe something like

let result = dioxus::mobile::android::require_permission(AndroidPermission::SystemAlertWindow); // platform specific
...
let result = dioxus::mobile::ios::require_permission(IosPermission::TrackingAuthorization); // platform specifc, corresponds to NSUserTrackingUsageDescription in Info.plist
...
let result = dioxus::mobile::require_permission(Permission::CAMERA); // cross platform

Which can be used as guards that prompt the user for permission if not already granted.

Documentation Strategy

We should provide:

  • Comprehensive API documentation for all permission-related functions
  • Feature-based guides (e.g., "Using the Camera in Dioxus Mobile")
  • Platform-specific permission best practices
  • Examples demonstrating proper permission flow handling

Alternative Implementation

A fully unified permission API in Cargo.toml or dioxus.toml would be simpler for developers but wouldn't adequately address platform-specific requirements. Even with a unified configuration approach for common permissions, exposing direct access to platform configuration files is necessary for advanced use cases. Also the merging of generated platform files with user-provided configurations introduces complexity and potential conflicts.

Unanswered Questions

How should libraries that require permissions interact with downstream applications? Maybe simply recommending including a section in the README for configuring AndroidManifest.xml and Info.plist is enough.

Prior Art

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliRelated to the dioxus-cli programenhancementNew feature or requestmobileMobile renderer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions