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

[Android 14+] InvalidForegroundServiceTypeException #3617

Closed
shivprakash86 opened this issue Jul 22, 2024 · 9 comments
Closed

[Android 14+] InvalidForegroundServiceTypeException #3617

shivprakash86 opened this issue Jul 22, 2024 · 9 comments
Assignees
Labels
bug Something isn't working pending-release Code has been merged but pending release s3 Issues with the AWS Android SDK for Simple Storage Service (S3).

Comments

@shivprakash86
Copy link

Describe the bug
After upgrading our project to targetSdkVersion version from 33 to 34 we are getting crash InvalidForegroundServiceTypeException: Starting FGS with type none callerApp=ProcessRecord{a64075a 8552:com.xx.xx/u0a196} targetSDK=34 has been prohibited.

android.app.InvalidForegroundServiceTypeException: Starting FGS with type none callerApp=ProcessRecord{a64075a 8552:com.xx.xx/u0a196} targetSDK=34 has been prohibited
                                                                                                    	at android.app.InvalidForegroundServiceTypeException$1.createFromParcel(InvalidForegroundServiceTypeException.java:53)
                                                                                                    	at android.app.InvalidForegroundServiceTypeException$1.createFromParcel(InvalidForegroundServiceTypeException.java:49)
                                                                                                    	at android.os.Parcel.readParcelableInternal(Parcel.java:5075)
                                                                                                    	at android.os.Parcel.readParcelable(Parcel.java:5057)
                                                                                                    	at android.os.Parcel.createExceptionOrNull(Parcel.java:3237)
                                                                                                    	at android.os.Parcel.createException(Parcel.java:3226)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3209)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3151)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7164)
                                                                                                    	at android.app.Service.startForeground(Service.java:863)
                                                                                                    	at androidx.work.impl.foreground.SystemForegroundService$Api31Impl.startForeground(SystemForegroundService.java:194)
                                                                                                    	at androidx.work.impl.foreground.SystemForegroundService$1.run(SystemForegroundService.java:130)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:959)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:100)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                    	at android.os.Looper.loop(Looper.java:317)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8674)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
has context menu

To Reproduce
A code sample or steps:

**Manifest file code**
<service
            android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
            android:enabled="true" />
**Java code**
context.startForegroundService(transferService);

Which AWS service(s) are affected?
AWS s3 media upload service

Environment Information (please complete the following information):

  • AWS Android SDK Version: [2.76.0]
    implementation('com.amazonaws:aws-android-sdk-mobile-client:2.76.0@aar') { transitive = true }
    implementation 'com.amazonaws:aws-android-sdk-s3:2.76.0'

  • Device: [ One Plus, Simulator]

  • Android Version: [ Upside Down Cake 14]

  • Specific to simulators: [No]

@lawmicha
Copy link
Contributor

Hi @shivprakash86, thanks for opening this issue, we'll investigate and provide an update when we can.

@mattcreaser mattcreaser added bug Something isn't working s3 Issues with the AWS Android SDK for Simple Storage Service (S3). labels Jul 22, 2024
@mattcreaser
Copy link
Member

mattcreaser commented Jul 22, 2024

I believe the TransferService needs to pass the FOREGROUND_SERVICE_TYPE_DATA_SYNC flag to startForeground to be compliant with new API 34 requirements. We also need to add the FOREGROUND_SERVICE_DATA_SYNC permission to the manifest file.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    startForeground(ongoingNotificationId, userProvidedNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
} else {
    startForeground(ongoingNotificationId, userProvidedNotification);
}

@mattcreaser mattcreaser reopened this Jul 22, 2024
@mattcreaser mattcreaser self-assigned this Jul 22, 2024
@shivprakash86
Copy link
Author

I believe the TransferService needs to pass the FOREGROUND_SERVICE_TYPE_DATA_SYNC flag to startForeground to be compliant with new API 34 requirements. We also need to add the FOREGROUND_SERVICE_DATA_SYNC permission to the manifest file.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    startForeground(ongoingNotificationId, userProvidedNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
} else {
    startForeground(ongoingNotificationId, userProvidedNotification);
}

I think this change should be in your s3 SDK TransferService class onStartCommand method

@mattcreaser
Copy link
Member

👍 That's exactly right @shivprakash86. We'll update this very soon for a release next week.

@shivprakash86
Copy link
Author

@mattcreaser Thanks we are waiting.

@mattcreaser
Copy link
Member

The fix has been merged and we will prioritize getting it released soon. Please note the additional changes you will need to make to your AndroidManifest.xml file noted in the PR description:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>

    <application>
        <service
            android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
            android:foregroundServiceType="dataSync" />

    </application>

@shivprakash86
Copy link
Author

@mattcreaser Yes .

@shivprakash86
Copy link
Author

@mattcreaser is this release above issue?

@mattcreaser
Copy link
Member

Hey @shivprakash86 sorry that no one updated this issue, but this fix was released in version 2.76.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-release Code has been merged but pending release s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

No branches or pull requests

3 participants