Android 12 - Samsung Accessory SDK can not start foreground service

I am trying to update my Samsung accessory provider app to target Android 12 (API 31)

com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver tries to bring up the service but it can not.
As described here:

Android 12 does not allow starting a foreground service except a few special cases.

So my service crash with this error:

2022-04-05 15:06:28.927 28310-28310/com.mycom.gear E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycom.gear, PID: 28310
java.lang.RuntimeException: Unable to start receiver com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.mycom.gear/.service
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4766)
at android.app.ActivityThread.access$1800(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
Caused by: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.mycom.gear/.service
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
at android.os.Parcel.readParcelable(Parcel.java:3345)
at android.os.Parcel.createExceptionOrNull(Parcel.java:2432)
at android.os.Parcel.createException(Parcel.java:2421)
at android.os.Parcel.readException(Parcel.java:2404)
at android.os.Parcel.readException(Parcel.java:2346)
at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6914)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1926)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1892)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:796)
at com.samsung.android.sdk.accessory.m.a(Unknown Source:51)
at com.samsung.android.sdk.accessory.m.a(Unknown Source:2)
at com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver.onReceive(Unknown Source:72)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4757)
at android.app.ActivityThread.access$1800(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:771)
at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:679)
at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:14013)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2943)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3034)

is there a solution to this within Samsung accessory sdk ?
what can I do ?

Hi Ilker,

I’d suggest you create a Developer Support Request That is all I can think of.

Ron

thank you.
I’ll do that. But the forums are losing its value day by day.
I had a few issues recently , and for none of them I could get a solution…

Hi Ilker,
I saw you have submitted this issue on the Developer Support channel. We are currently investigating this issue.

Thank you

Yes I submitted but the first answer is weird. It says:
" Galaxy Accessory SDK is not supported for API 31. Currently there is no plan to upgrade the Galaxy Accessory SDK. We recommend you to not to update the Target SDK as of now."

However, Google Play Policy says that we have to upgrade our apps to Android 12 (API 31) until 2023

If we can’t update, companion apps will not be available to new users for download.

Any updates on this topic?

We need an update on the Samsung Accessory SDK, otherwise me, and I am sure many more developers, will need to drop the support for galaxy watches in our companion apps because of the Google Play restrictions.

Also, how do we explain to our users that they can no longer use their galaxy watch when their device gets upgraded to Android 12?

There is a solution in this Stack Overflow thread for Android 11 and I asked one of my gurus and he thought it would work with Android 12 as well.

You don’t need SAP for Galaxy Watch4 and newer Wear OS watches.

Ron
Samsung Developer Relations

@r.liechty_SDP
This question is not about “query packages” permission. It was a different issue in Android 11 and was solved with the solution in the thread you wrote.
But this question is about another problem starting in Android 12.
It is about starting a foreground service in Android 12 which is prohibited.

Unfortunately I could not find a solution to this. I also wrote it as a problem to Developer Support
But could not receive a reasonable response yet.

I know Wear OS watches do not need SAP but the older Tizen watches still need this to work with our apps.

SO Samsung;
We ARE WAITING FOR HELP on this matter !!!

@sonit1980 ,
Please write it to Developer Support as I wrote.
If they respond with a solution , please share.
Thanks

Hi ilkeraktuna I looked in the support data base and couldn’t find your request. Do you have the ticket number. I don’t have quick access to all of the support database.

Ron
Samsung Developer Relations

@r.liechty_SDP

Ticket number is 39914
https://developer.samsung.com/dashboard/support/39914

I have opened it on April 14th. I received some unreasonable answers with no actual solution.
Since April 27th , I am waiting for a solution…

I don’t have access to it for some reason. I’ve asked that I be given permission for it.

Ron
Samsung Developer Relations

Thanks I checked out the support request. And I understand it a bit better now.

The reason there is no response from support is that they have gotten no response from the Galaxy Accessory SDK Development team. They note every time they remind the team and every 4 weeks they update the reminder.

From reading the report I am betting that this is a security issue. It looks to me like you need to run your watch app in the foreground when you send a service request to the mobile.

Since there is a date to comply it probably means it is required for GDPR and other governments privacy regulations.

I wish I had better news, my guess is it is not going away.

Ron
Samsung Developer Relations

@r.liechty_SDP

Ron,

Thanks for checking and for the information. Unfortunately I could not find a way in SAP implementation to run the process in foreground when there is a service request to the mobile app.
If there is an example/sample app without a “service” , I would be happy to implement it.

Btw, it is not a GDPR issue. Android prevents background/foreground service to minimize battery usage by services. But if it is possible to start a foregorund process from a SAP service request, that would be enough for me.

@r.liechty_SDP

Now I am not able to login to my Samsung developer account.
It says “account deactivated for security reasons”

why ?

Please enter password.

Please enter ID and password.

In settings on your browser, please allow sites to save and read cookie data.

Can’t sign in. Account deactivated for security reasons.

Use 8 or more characters with a mix of letters, numbers, and symbols.

Can’t include more than {{$parent.passwordLimitedSameCharNum}} repeated or consecutive character in your password.

Can’t include more than 3 repeated or consecutive character in your password.

Can’t include your email address or phone number in your password.

This is not you. They implemented something Friday that broke the seller Portal sign in process (and other services) they fixed it for Samsung.com and Developer Portal . The way I had to go was sign into Developer Support and from there go to the seller portal and click on the sign in it should bypass the credentials there and go straight to your account page.

Since it is a weekend in Korea and I assume they thing they fixed the problem it will be Monday before I can notify them.

Ron
Samsung Developer Relations

Hi Ilkertuna

The login was fixed but I had to clear my browser history to sign in.

Ron

I was able to access login but for that I had to clear cookies on my 2nd browser.
I don’T want to do that for my primary browser…

Anyway, back to the subject:

nfortunately I could not find a way in SAP implementation to run the process in foreground when there is a service request to the mobile app.
If there is an example/sample app without a “service” , I would be happy to implement it.

Btw, it is not a GDPR issue. Android prevents background/foreground service to minimize battery usage by services. But if it is possible to start a foregorund process from a SAP service request, that would be enough for me.

1 Like

I didn’t have to clear my browser today when I tried it on my personal computer browser that didn’t work Friday.

That makes sense, I was guessing due to the “timeline” of it.

Respond to the last response to your support request and add that bit.

Ron