ToolKitService代码中配置错误,修复后启动遇到Caused by: java.lang.SecurityException: Starting FGS

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, java
Domain
mobile, security

Research direction

Start by comparing the manifest service declaration with com.tencent.trtc.apiexample.ToolKitService, then inspect ToolKitService.onCreate at line 33 and the Android 14 foreground-service exception. Verify the corrected declaration and required permission handling on a target SDK 34 device; done means the service starts without the reported SecurityException.

Written by the indexing model from the issue text.

Description

ToolKitService默认配置是这样:

<service
            android:name="com.tencent.liteav.utils.ToolKitService"
            android:foregroundServiceType="mediaProjection"
            android:enabled="true"
            android:exported="false" />

这个配置和实际上ToolKitService所在路径不一样。
代码是com.tencent.trtc.apiexample.ToolKitService。
如果我修复这个路径,把target 设置34,跑在34设备上。就会遇到下面错误:

JavaExceptionHandler                 E  Process: com.tencent.trtc.api_example, PID: 12687
                                        java.lang.RuntimeException: Unable to create service com.tencent.trtc.apiexample.ToolKitService: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{3a0477f 12687:com.tencent.trtc.api_example/u0a374} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 
                                        	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4991)
                                        	at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
                                        	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)
                                        	at android.os.Handler.dispatchMessage(Handler.java:106)
                                        	at android.os.Looper.loopOnce(Looper.java:222)
                                        	at android.os.Looper.loop(Looper.java:314)
                                        	at android.app.ActivityThread.main(ActivityThread.java:8816)
                                        	at java.lang.reflect.Method.invoke(Native Method)
                                        	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
                                        	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1090)
                                        Caused by: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{3a0477f 12687:com.tencent.trtc.api_example/u0a374} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 
                                        	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.setServiceForeground(IActivityManager.java:7310)
                                        	at android.app.Service.startForeground(Service.java:775)
                                        	at com.tencent.trtc.apiexample.ToolKitService.onCreate(ToolKitService.java:33)
                                        	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4978)
                                        	at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0) 
                                        	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478) 
                                        	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                        	at android.os.Looper.loopOnce(Looper.java:222) 
                                        	at android.os.Looper.loop(Looper.java:314) 
                                        	at android.app.ActivityThread.main(ActivityThread.java:8816) 
                                        	at java.lang.reflect.Method.invoke(Native Method) 
                                        	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569) 
                                        	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1090) 
Dominant language
Java
Stars
60
Forks
48
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Tencent-RTC/TRTC_Android

All issues in Tencent-RTC/TRTC_Android

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.