Android14 Service

sumi Yoo·2023년 10월 24일
  1. Android 14 버전에서만 서비스 관련 문제로 앱이 중단되는 현상이 발생했다. 아래와 같은 로그를 보여주고 앱이 죽는다.

2023-10-24 17:24:56.334 14799-14799/com.kt.familysafeandroid E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kt.familysafeandroid, PID: 14799
android.app.RemoteServiceExceptionForegroundServiceDidNotStartInTimeException:Context.startForegroundService()didnotthencallService.startForeground():ServiceRecord41d680bu0com.kt.familysafeandroid/.MyActiveServiceatandroid.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2104)atandroid.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2075)atandroid.app.ActivityThread.ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{41d680b u0 com.kt.familysafeandroid/.MyActiveService} at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2104) at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2075) at android.app.ActivityThread.-NestNestmthrowRemoteServiceException(Unknown Source:0)

  1. 앱 시작시에 아래와 같은 오류 발생

2023-10-24 16:37:10.432 10771-11016/com.kt.familysafeandroid E/AndroidRuntime: FATAL EXCEPTION: LibActiveService
Process: com.kt.familysafeandroid, PID: 10771
android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{d21dfc5 10771:com.kt.familysafeandroid/u0a192} targetSDK=34
at android.app.MissingForegroundServiceTypeException1.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.IActivityManagerStubProxy.setServiceForeground(IActivityManager.java:6761)atandroid.app.Service.startForeground(Service.java:775)atkr.co.soosanint.android.lib.childcare.service.LibActiveServiceProxy.setServiceForeground(IActivityManager.java:6761) at android.app.Service.startForeground(Service.java:775) at kr.co.soosanint.android.lib.childcare.service.LibActiveServiceServiceHandler.handleMessage(LibActiveService.kt:2838)
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.os.HandlerThread.run(HandlerThread.java:67)

  1. Android 14는 Manifest에 서비스 타입을 지정해줘야 한다.

  2. Permission 선언

권한 선언 하지 않으면 아래와 같은 오류가 발생한다.

2023-10-24 17:12:28.882 13209-13292/com.kt.familysafeandroid E/AndroidRuntime: FATAL EXCEPTION: LibActiveService
Process: com.kt.familysafeandroid, PID: 13209
java.lang.SecurityException: Starting FGS with type dataSync callerApp=ProcessRecord{25fb60f 13209:com.kt.familysafeandroid/u0a193} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_DATA_SYNC]
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)

  1. 정리

참고자료:
https://developside.tistory.com/96
https://medium.com/@merkost/foreground-services-in-android-14-whats-changing-dcd56ad72788
https://developer.android.com/about/versions/14/changes/fgs-types-required?hl=ko

0개의 댓글