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

Android 14 One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED #2568

Closed
Reign9201 opened this issue Sep 12, 2023 · 6 comments · Fixed by #2599
Closed

Android 14 One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED #2568

Reign9201 opened this issue Sep 12, 2023 · 6 comments · Fixed by #2599
Milestone

Comments

@Reign9201
Copy link

Reign9201 commented Sep 12, 2023

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:5684)
  at java.lang.reflect.Method.invoke(Native Method)
  at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:93)
  at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
  at $Proxy10.registerReceiverWithFeature(Unknown Source)
@SergJ4
Copy link

SergJ4 commented Sep 20, 2023

This crash happens if targetSdk == 34 and app launched on device with Android 14. Because API 34 is enforcing new receiver requirements introduced in Android 13. Look at documentation here. In my case receiver was inside my code, not leakcanary. I've added correct flag and fixed crash.

@vpuonti
Copy link

vpuonti commented Sep 20, 2023

Related: Getting this crash when LeakCanary dumps heap on Emulator API 34

FATAL EXCEPTION: main
Process: com.myapp, PID: 23533
java.lang.RuntimeException: Unable to create service leakcanary.internal.HeapAnalyzerService: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{9061353 23533:com.myapp/u0a188} targetSDK=34
	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4664)
	at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2264)
	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:8177)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{9061353 23533:com.myapp/u0a188} targetSDK=34
	at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
	at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
	at android.os.Parcel.readParcelableInternal(Parcel.java:4870)
	at android.os.Parcel.readParcelable(Parcel.java:4852)
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3052)
	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.setServiceForeground(IActivityManager.java:6761)
	at java.lang.reflect.Method.invoke(Native Method)
	at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:85)
	at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
	at $Proxy3.setServiceForeground(Unknown Source)
	at android.app.Service.startForeground(Service.java:775)
	at leakcanary.internal.ForegroundService.showForegroundNotification(ForegroundService.kt:51)
	at leakcanary.internal.ForegroundService.onCreate(ForegroundService.kt:33)
	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4651)
	at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2264) 
	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:8177) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

@pyricau
Copy link
Member

pyricau commented Jan 2, 2024

Looking at the Android sources, I see we call registerReceiver in 3 places: https://github.com/search?q=repo%3Asquare%2Fleakcanary%20registerReceiver&type=code

The only place that truly matters here is:

registerReceiver(visibilityTracker, IntentFilter().apply {

We need to add RECEIVER_EXPORTED (not the compat one though, so need an API check and add it appropriately)

@pyricau
Copy link
Member

pyricau commented Jan 2, 2024

@vpuonti LeakCanary is in the stacktrace but has nothing to do with this, that one is a bug in your app.

pyricau added a commit that referenced this issue Jan 2, 2024
pyricau added a commit that referenced this issue Jan 2, 2024
@pyricau pyricau added this to the 2.13 milestone Jan 2, 2024
pyricau added a commit that referenced this issue Jan 2, 2024
pyricau added a commit that referenced this issue Jan 2, 2024
@taasonei
Copy link

@vpuonti LeakCanary is in the stacktrace but has nothing to do with this, that one is a bug in your app.

I also had crash when LeakCanary dumps heap on project with targetApi = 34 when the app in the background. It was "fixed" by removing LeakCanary from project. Should I add foregroundServiceType for LeakCanary service in my project's manifest file to fix the error?

@arekolek
Copy link

arekolek commented Apr 8, 2024

LeakCanary is in the stacktrace but has nothing to do with this, that one is a bug in your app.

Yet somehow, when I got the same crash after rotating the screen while leakcanary 2.7 was dumping heap - the issue was resolved by upgrading leakcanary to 2.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants