Skip to content

[Bug]: Android SecurityException - Missing WAKE_LOCK permission #570

@AdarshJais

Description

@AdarshJais

Required Reading

  • Confirmed

Plugin Version

4.1.10

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Various Android devices

Device operating-systems(s)

Android (various versions)

React Native / Expo version

React Native 0.76.9

What happened?

Description

I'm experiencing a SecurityException crash related to a missing WAKE_LOCK permission when using react-native-background-fetch on Android.

Error Stack Trace

java.lang.RuntimeException: Unable to start receiver com.transistorsoft.tsbackgroundfetch.FetchAlarmReceiver: java.lang.SecurityException: Neither user 10221 nor current process has android.permission.WAKE_LOCK.
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:5038)
    at android.app.ActivityThread.-$$Nest$mhandleReceiver(unknown:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2577)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loopOnce(Looper.java:248)
    at android.os.Looper.loop(Looper.java:338)
    at android.app.ActivityThread.main(ActivityThread.java:9067)

Expected Behavior

The background fetch should work without throwing a SecurityException.

Questions for Maintainer

  1. Should I manually add the WAKE_LOCK permission to my AndroidManifest.xml? Would adding this permission resolve the issue?

  2. Is this permission missing from the README/documentation? I noticed this permission requirement isn't clearly documented in the setup instructions.

  3. If this permission is required, should it be:

    • Automatically included by the library?
    • Explicitly documented in the installation/setup guide?

Additional Context

This seems to be occurring when the FetchAlarmReceiver attempts to start but lacks the necessary WAKE_LOCK permission.

Plugin Code and/or Config

 let status = await BackgroundFetch.configure(
        {
            minimumFetchInterval:
                backgroundFetchConfig?.minimumFetchInterval ?? 15,
            scheduleTask: true,
            stopOnTerminate: false,
            startOnBoot: true,
            enableHeadless: true,
        },
        onEvent,
        onTimeout,
    );

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions