Access to `MediaProjection` APIs cause `SecurityException` crash on Android 10
Closed this issue · 7 comments
Crash being reported only on Android 10. The stack trace is as follows:
Caused by java.lang.SecurityException
Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
android.os.Parcel.createException (Parcel.java:2071)
android.os.Parcel.readException (Parcel.java:2039)
android.os.Parcel.readException (Parcel.java:1987)
android.media.projection.IMediaProjection$Stub$Proxy.start (IMediaProjection.java:231)
android.media.projection.MediaProjection.<init> (MediaProjection.java:58)
android.media.projection.MediaProjectionManager.getMediaProjection (MediaProjectionManager.java:104)
com.mattprecious.telescope.TelescopeLayout$4.onReceive (TelescopeLayout.java:198)
android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args (LoadedApk.java:1550)
android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run (-.java:2)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:7356)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:930)
Oh jeez... I really don't want to add a service.
I'm able to use this fine on my Pixel 2 running Android 10, so I'm not sure where this trace is coming from.
@mattprecious thanks for the prompt response.
We got that from a user via crashlytics. I can dig up the report once again tomorrow and provide a bit more information.
Out of curiosity, I also couldn't reproduce on my Pixel 2 with Android 10 either.
If this is of help, this is the information about the device (Pixel 3) in which the crash happened:
Build{Brand=google, Device=blueline, Hardware=blueline, Manufacturer=Google, Model=Pixel 3, Product=blueline, Type=user}
{1.0 262mcc3mnc [en_US] ldltr sw392dp w392dp h713dp 440dpi nrml long hdr widecg port night finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2160) mAppBounds=Rect(0, 0 - 1080, 2028) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0} s.10007}
This happens to me too (the crash, I haven't looked to see if the stacktrace is the same)! I thought telescope wasn't supported anymore so this is good to hear that someone is having the same issue.
To fix this you will need to add a foreground service. The foreground service requirement was introduced so that users will always be aware when their audio and/or video is being captured.
Possibly helpful resources:
https://developer.android.com/guide/components/services
Ah, I'm not targeting API 29 yet, so that's likely why I'm not seeing this. Should probably disable native capturing on 29 until it can be moved to service.