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

Not allowed to start service in background #83

Open
uladzislau-melikhau-aionys opened this issue Apr 4, 2023 · 7 comments
Open

Not allowed to start service in background #83

uladzislau-melikhau-aionys opened this issue Apr 4, 2023 · 7 comments

Comments

@uladzislau-melikhau-aionys

My app uses Zello SDK and is often crashing in background with the following exception:

Fatal Exception: android.app.BackgroundServiceStartNotAllowedException: 
Not allowed to start service Intent { cmp=com.loudtalks/com.zello.ui.Svc }: 
app is in background uid UidRecord{ba56fa8 u0a156 TRNB idle change:idle|uncached procs:0 seq(0,0,0)}
       at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1867)
       at android.app.ContextImpl.startService(ContextImpl.java:1823)
       at android.content.ContextWrapper.startService(ContextWrapper.java:776)
       at com.zello.sdk.Sdk.onServiceConnected(Sdk.java:672)
       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2095)
       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2128)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7924)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

On Android versions >=12 i see exact this exception, on earlier versions I see IllegalStateException instead, but the rest of the stacktrace is exactly the same.

Have you come across this before?
Would really appreciate any help in solving this issue.

@zello-eugene
Copy link
Contributor

Duplicate of #53. We will be releasing an SDK update shortly to address.

@zello-eugene
Copy link
Contributor

@uladzislau-melikhau-aionys
Copy link
Author

Thank you!

@uladzislau-melikhau-aionys
Copy link
Author

Hello @zello-eugene

We have rolled out a new version with latest Zello SDK release.
However, we are still facing crashes related to the same problem.

Previously, we had crash Sdk.java: 672
now, we are having Sdk.java: 678

Fatal Exception: android.app.ForegroundServiceStartNotAllowedException:
startForegroundService() not allowed due to mAllowStartForeground false: service com.loudtalks/com.zello.ui.Svc
       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:3364)
       at android.os.Parcel.createExceptionOrNull(Parcel.java:2451)
       at android.os.Parcel.createException(Parcel.java:2440)
       at android.os.Parcel.readException(Parcel.java:2423)
       at android.os.Parcel.readException(Parcel.java:2365)
       at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6007)
       at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1848)
       at android.app.ContextImpl.startForegroundService(ContextImpl.java:1824)
       at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:781)
       at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:931)
       at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:703)
       at com.zello.sdk.Sdk.onServiceConnected(Sdk.java:678)
       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2095)
       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2128)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:207)
       at android.os.Looper.loop(Looper.java:294)
       at android.app.ActivityThread.main(ActivityThread.java:7881)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

These are changes from Zello last pull request with the fix:
image

Could you please reopen the issue and assist with it?

@zello-eugene
Copy link
Contributor

zello-eugene commented May 30, 2023

@uladzislau-melikhau-aionys please check out restrictions on background service starts. Zello has to rely on a foreground service to be able to stay running and connected in the background. When a partner app uses Zello SDK to sign in, the SDK asks the Zello app to sign in, which attempts to start a foreground service. But it’s the third-party app itself that needs to comply with the restrictions in order to make the flow work as expected.

@uladzislau-melikhau-aionys
Copy link
Author

@zello-eugene I finally found a way to reproduce this crash in our app (Rythmos).
I think Rythmos uses Zello in a right way, and this is a Zello SDK issue.

Crash only happens when user is not authorized - no need to Login neither to Zello, nor to our app.

//---

Steps to reproduce:
1/ Just launch Rythmos app (Splash screen -> Login screen).
2/ And exit Login screen (click system back button).

3/ After some time, Android OS kills Rythmos app:
• I see in logs PROCESS ENDED (7506) for package com.intrex.caregiver.

4/ After some time, Android OS restarts Rythmos app:
• I see in logs PROCESS STARTED (9345) for package com.intrex.caregiver;
• I see in logs Application onCreate is called;
• Right after that, app crashes with ForegroundServiceStartNotAllowedException.

*Android OS might restart an app after a crash, so sometimes step 4/ repeats several times in a row.

//---

The only Zello related operation we do in Application class is SDK config:

public class CareGiverApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        Zello.getInstance().configure(this);

        //...
    }
}

I tried to comment out that one line, and the crash was gone.

I suspect, calling configure attempts to start Zello foreground service.
And Application onCreate is a recommended place for calling configure.
But Application onCreate may be called when app is in the background.

Could you please check this issue?

@zello-eugene zello-eugene reopened this Apr 1, 2024
@zello-eugene
Copy link
Contributor

Re-opening the ticket based on the new information.

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

No branches or pull requests

2 participants