Mitigation of Android 15 background

From Engineering Client Portal

Mitigation of Android 15 background network access restrictions

Observation

On devices running Android 15 and 16, ping HTTP requests consistently fail while the application is in a background state. These failed pings currently undergo five retry attempts, which consistently result in a 404 error response. Once the retry limit is reached, the failed requests are purged from the pending database table. The OS's aggressive background restrictions prevent the SDK from establishing a stable network handshake.

Root Cause

Below writeup has been taken directly from the official Android developer documentation which states that -

“In Android 15, apps that start a network request outside of a valid process lifecycle receive an exception. Typically, an UnknownHostException or other socket-related IOException. Network requests that happen outside of a valid lifecycle are usually due to apps unknowingly continuing a network request even after the app is no longer active.

To mitigate this exception, ensure your network requests are lifecycle aware and cancelled upon leaving a valid process lifecycle by using lifecycle aware components. If it is important that the network request should happen even when the user leaves the application, consider scheduling the network request using WorkManager or continue a user visible task using Foreground Service.”

Conclusion Of Background Behaviour Changes

Starting with Android 15, the system has introduced stricter limitations on background network access! So we have transitioned our background operations to use the WorkManager API, which is now a required dependency. Without the WorkManager library, background network calls may be blocked or fail silently, leading to data loss on devices running Android 15 or later.

WorkManager Integration (Client Side)

Client apps must add the WorkManager library once they have integrated version 10.2.0.0 of the AppSDK. Starting with this version, the WorkManager library is a mandatory dependency and missing it will fail the AppSDK initialization.

The AppSDK will flash the below error message to the console -

“AppApi initialize failed! Starting with Android 15, the system has introduced stricter limitations on background network access! So we have transitioned our background operations to use the WorkManager API, which is now a required dependency. Without the WorkManager library, background network calls may be blocked or fail silently, leading to data synchronization issues on newer devices. Please add the androidx.work:work-runtime dependency to your project's build.gradle file“


Note: Please add the androidx.work:work-runtime dependency to the project's build.gradle file.