Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts #655

Open
kirby510 opened this issue Mar 15, 2023 · 6 comments

Comments

@kirby510
Copy link

Compile SDK Version: 34 (UPSIDE_DOWN_CAKE)
Target SDK Version: 34 (UPSIDE_DOWN_CAKE)
Phone Android API Level: 34 (UPSIDE_DOWN_CAKE)
Fetch Version: 3.1.6

Crash happened at com.tonyodev.fetch2.helper.PriorityListProcessorImpl, line 71:
context.registerReceiver(priorityBackoffResetReceiver, IntentFilter(ACTION_QUEUE_BACKOFF_RESET))

As mentioned in the Android Developers Documentation:

For apps targeting Build.VERSION_CODES.UPSIDE_DOWN_CAKE, either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED must be specified if the receiver is not being registered for system broadcasts or a SecurityException will be thrown. See registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, int) to register a receiver with flags.

FATAL EXCEPTION: main
Process: com.example, PID: 7726
java.lang.RuntimeException: Unable to create application com.example.MainApplication: java.lang.SecurityException: com.example: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6966)
    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2222)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8128)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:946)
Caused by: java.lang.SecurityException: com.example: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
    at android.os.Parcel.createException(Parcel.java:3041)
    at android.os.Parcel.readException(Parcel.java:3024)
    at android.os.Parcel.readException(Parcel.java:2966)
    at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5393)
    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1851)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1791)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1779)
    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:754)
    at com.tonyodev.fetch2.helper.PriorityListProcessorImpl.<init>(PriorityListProcessorImpl.kt:71)
    at com.tonyodev.fetch2.fetch.FetchModulesBuilder$Modules.<init>(FetchModulesBuilder.kt:125)
    at com.tonyodev.fetch2.fetch.FetchModulesBuilder.buildModulesFromPrefs(FetchModulesBuilder.kt:53)
    at com.tonyodev.fetch2.Fetch$Impl.getInstance(Fetch.kt:1026)
    at com.example.MainApplication.onCreate(MainApplication.kt:355)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1315)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6961)
    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2222) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:205) 
    at android.os.Looper.loop(Looper.java:294) 
    at android.app.ActivityThread.main(ActivityThread.java:8128) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:946) 
Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13919)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2410)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2650)
    at android.os.Binder.execTransactInternal(Binder.java:1339)
    at android.os.Binder.execTransact(Binder.java:1275)
@kirby510 kirby510 changed the title One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts Mar 15, 2023
@yd-threra-and
Copy link

@kirby510 I'm currently facing the same problem when trying to integrate my app with Android 14 - SDK 34 (UPSIDE_DOWN_CAKE) to handle the behavior changes introduced in SDK 34 and wanted to check if there have been any updates or solutions discussed regarding this issue.
If not, do you plan to reach out to the library maintainer or consider making a pull request to address the problem?
Your insights or any updates on this matter would be really helpful. Thank you!

@charles-hennge
Copy link

This also breaks something I am working on.

The fix should be very simple if the maintainer would consider pull requests...

@charles-hennge
Copy link

@kirby510 @yd-threra-and

Maybe this is a good time to fork this library and fix the issue ourselves?

Its been three years since this library saw an update so I would not expect quick movement on this even though its breaking for all users on Android 14 and later.

I have taken a look and unfortunately in order to use the updated broadcast receiver registration method, significant changes to the core dependancies (androidX, core android libs 1.9.0+) are required. These changes appear to cause a lot more build problems, so this library needs significant work to make modern Android builds work again.

@kirby510
Copy link
Author

@yd-threra-and @charles-hennge

Sorry I was just read the comments. I reported the issues on 3 months ago and it was no reply from the library maintainer. I think it could a good time to fork this library and fix it our own, but it's best to credit the library maintainer for his hardwork on the library.

To solve this issue, I had switched to other third party library in order to make it work. But will look out again if there is any related issues in the future Android SDK.

Thanks a lot for replying on the issues, and it's nice to know you here. :)

@charles-hennge
Copy link

@kirby510
I would of course continue to credit the creator, I just don't think waiting around for a fix would be a wise choice given that the last major update was 3 years ago.

I took a look myself and a fix is going to be pretty time consuming since there are quite a lot of things that need to be updated for a build to work on new enough libraries to make this fix work.

May I ask which solution you moved to?

@kirby510
Copy link
Author

@charles-hennge

Sure, as I mentioned in the earlier message I had switched to other third party library. You can try this Android Http Download Manager: https://github.com/coolerfall/Android-HttpDownloadManager

yd-threra-and pushed a commit to TheranicaRD-SW/Fetch that referenced this issue Jun 17, 2023
This commit addresses the compatibility issue with Android 14 (SDK 34) and SDK 33 by ensuring proper registration of broadcast receivers in accordance with the behavior changes introduced in SDK 34. The `PriorityListProcessorImpl` class now registers the receiver with the appropriate export flags based on the target SDK version of the app. This resolves the `SecurityException` and allows seamless integration with  SDK 34.

Fixes: tonyofrancis#655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants