Merge "Unhide the "SHORT_SERVICE" FGS type."

This commit is contained in:
TreeHugger Robot
2022-12-01 08:05:18 +00:00
committed by Android (Google) Code Review
4 changed files with 41 additions and 18 deletions

View File

@@ -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;

View File

@@ -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) {
}

View File

@@ -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>
* 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.
*
* <p>The system will <em>not</em> automatically stop it.
*
* <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 Service#onTimeout
*
* @hide
* @see android.app.Service#onTimeout(int)
*/
public static final int FOREGROUND_SERVICE_TYPE_SHORT_SERVICE = 1 << 11;

View File

@@ -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" />