Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53f8439d authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Unhide the "SHORT_SERVICE" FGS type.

Bug: 257270313
cts-coverage-bug: 260748204
Test: manual test with a test app.
Change-Id: I2e40b26a971c777971c28fb733ef9e72766c04c7
parent 82f57548
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6968,6 +6968,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);
@@ -12441,6 +12442,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;
+3 −5
Original line number Diff line number Diff line
@@ -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) {
    }
+35 −11
Original line number Diff line number Diff line
@@ -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;

+1 −2
Original line number Diff line number Diff line
@@ -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" />