diff options
-rw-r--r-- | core/api/current.txt | 2 | ||||
-rw-r--r-- | core/java/android/app/Service.java | 8 | ||||
-rw-r--r-- | core/java/android/content/pm/ServiceInfo.java | 46 | ||||
-rw-r--r-- | core/res/res/values/attrs_manifest.xml | 3 |
4 files changed, 41 insertions, 18 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index bc9f10fc7a1a..787370abf2b7 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6969,6 +6969,7 @@ package android.app { method @Deprecated public void onStart(android.content.Intent, int); method public int onStartCommand(android.content.Intent, int, int); method public void onTaskRemoved(android.content.Intent); + method public void onTimeout(int); method public void onTrimMemory(int); method public boolean onUnbind(android.content.Intent); method public final void startForeground(int, android.app.Notification); @@ -12475,6 +12476,7 @@ package android.content.pm { field @Deprecated public static final int FOREGROUND_SERVICE_TYPE_NONE = 0; // 0x0 field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_PHONE_CALL}, anyOf={android.Manifest.permission.MANAGE_OWN_CALLS}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_PHONE_CALL = 4; // 0x4 field @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING = 512; // 0x200 + field public static final int FOREGROUND_SERVICE_TYPE_SHORT_SERVICE = 2048; // 0x800 field @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_SPECIAL_USE = 1073741824; // 0x40000000 field @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED = 1024; // 0x400 field public int flags; diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index 6d7a161d1687..3a7d483c69c3 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -1128,12 +1128,10 @@ 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. * - * TODO Implement it - * TODO Javadoc - * - * @param startId - * @hide + * @param startId the startId passed to {@link #onStartCommand(Intent, int, int)} when + * the service started. */ public void onTimeout(int startId) { } diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java index 9e6cf62f2397..7ea6733fa2ff 100644 --- a/core/java/android/content/pm/ServiceInfo.java +++ b/core/java/android/content/pm/ServiceInfo.java @@ -366,24 +366,48 @@ public class ServiceInfo extends ComponentInfo public static final int FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED = 1 << 10; /** - * Foreground service type corresponding to {@code shortService} in - * the {@link android.R.attr#foregroundServiceType} attribute. + * A foreground service type for "short-lived" services, which corresponds to + * {@code shortService} in the {@link android.R.attr#foregroundServiceType} attribute in the + * manifest. * - * TODO Implement it + * <p>Unlike other foreground service types, this type is not associated with a specific use + * case, and it will not require any special permissions + * (besides {@link Manifest.permission#FOREGROUND_SERVICE}). * - * TODO Expand the javadoc + * However, this type has the following restrictions. * - * This type is not associated with specific use cases unlike other types, but this has - * unique restrictions. * <ul> - * <li>Has a timeout - * <li>Cannot start other foreground services from this * <li> - * </ul> + * The type has a 1 minute timeout. + * A foreground service of this type must be stopped within the timeout by + * {@link android.app.Service#stopSelf), + * or {@link android.content.Context#stopService). + * {@link android.app.Service#stopForeground) will also work, which will demote the + * service to a "background" service, which will soon be stopped by the system. * - * @see Service#onTimeout + * <p>The system will <em>not</em> automatically stop it. * - * @hide + * <p>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. + * + * <li> + * A foreground service of this type cannot be made "sticky" + * (see {@link android.app.Service#START_STICKY}). That is, if an app is killed + * due to a crash or out-of memory while it's running a short foregorund-service, + * the system will not restart the service. + * <li> + * Other foreground services cannot be started from short foreground services. + * Unlike other foreground service types, when an app is running in the background + * while only having a "short" foreground service, it's not allowed to start + * other foreground services, due to the restriction describe here: + * <a href="/guide/components/foreground-services#background-start-restrictions> + * Restrictions on background starts + * </a> + * </ul> + * + * @see android.app.Service#onTimeout(int) */ public static final int FOREGROUND_SERVICE_TYPE_SHORT_SERVICE = 1 << 11; diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 6460007b52de..eb7034437423 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -1705,8 +1705,7 @@ --> <flag name="systemExempted" value="0x400" /> <!-- "Short service" foreground service type. See - TODO: Change it to a real link - {@code android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE}. + {@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE}. for more details. --> <flag name="shortService" value="0x800" /> |