diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index e48539791cc13..a1554572c7df4 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -1140,6 +1140,22 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac * Callback called on timeout for {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE}. * See {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE} for more details. * + *
If the foreground service of type + * {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE} + * doesn't finish even after it's timed out, + * the app will be declared an ANR after a short grace period of several seconds. + * + *
Note, even though + * {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE} + * was added + * on Android version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, + * it can be also used on + * on prior android versions (just like other new foreground service types can be used). + * However, because {@link android.app.Service#onTimeout(int)} did not exist on prior versions, + * it will never called on such versions. + * Because of this, developers must make sure to stop the foreground service even if + * {@link android.app.Service#onTimeout(int)} is not called on such versions. + * * @param startId the startId passed to {@link #onStartCommand(Intent, int, int)} when * the service started. */ diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java index f3209f9c7ea69..49d21dafbd5d4 100644 --- a/core/java/android/content/pm/ServiceInfo.java +++ b/core/java/android/content/pm/ServiceInfo.java @@ -401,8 +401,9 @@ public class ServiceInfo extends ComponentInfo * *
If the service isn't stopped within the timeout, * {@link android.app.Service#onTimeout(int)} will be called. - * If the service is still not stopped after the callback, - * the app will be declared an ANR. + * + *
If the service is still not stopped after the callback, + * the app will be declared an ANR after a short grace period of several seconds. * *
Note, even though + * {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE} + * was added + * on Android version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, + * it can be also used on + * on prior android versions (just like other new foreground service types can be used). + * However, because {@link android.app.Service#onTimeout(int)} did not exist on prior versions, + * it will never called on such versions. + * Because of this, developers must make sure to stop the foreground service even if + * {@link android.app.Service#onTimeout(int)} is not called on such versions. + * * @see android.app.Service#onTimeout(int) */ public static final int FOREGROUND_SERVICE_TYPE_SHORT_SERVICE = 1 << 11;