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

Commit af4fcdcb authored by Hui Yu's avatar Hui Yu Committed by Android (Google) Code Review
Browse files

Merge "Add manifest service attribute foregroundServiceType"

parents 88d90e98 1ea85520
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -644,6 +644,7 @@ package android {
    field public static final int forceHasOverlappingRendering = 16844065; // 0x1010521
    field public static final int foreground = 16843017; // 0x1010109
    field public static final int foregroundGravity = 16843264; // 0x1010200
    field public static final int foregroundServiceType = 16844191; // 0x101059f
    field public static final int foregroundTint = 16843885; // 0x101046d
    field public static final int foregroundTintMode = 16843886; // 0x101046e
    field public static final int format = 16843013; // 0x1010105
@@ -11755,12 +11756,20 @@ package android.content.pm {
    ctor public ServiceInfo(android.content.pm.ServiceInfo);
    method public int describeContents();
    method public void dump(android.util.Printer, java.lang.String);
    method public int getForegroundServiceType();
    field public static final android.os.Parcelable.Creator<android.content.pm.ServiceInfo> CREATOR;
    field public static final int FLAG_EXTERNAL_SERVICE = 4; // 0x4
    field public static final int FLAG_ISOLATED_PROCESS = 2; // 0x2
    field public static final int FLAG_SINGLE_USER = 1073741824; // 0x40000000
    field public static final int FLAG_STOP_WITH_TASK = 1; // 0x1
    field public static final int FLAG_USE_APP_ZYGOTE = 8; // 0x8
    field public static final int FOREGROUND_SERVICE_TYPE_DEVICE_COMPANION = 5; // 0x5
    field public static final int FOREGROUND_SERVICE_TYPE_LOCATION = 4; // 0x4
    field public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PLAY = 2; // 0x2
    field public static final int FOREGROUND_SERVICE_TYPE_ONGOING_PROCESS = 6; // 0x6
    field public static final int FOREGROUND_SERVICE_TYPE_PHONE_CALL = 3; // 0x3
    field public static final int FOREGROUND_SERVICE_TYPE_SYNC = 1; // 0x1
    field public static final int FOREGROUND_SERVICE_TYPE_UNSPECIFIED = 0; // 0x0
    field public int flags;
    field public java.lang.String permission;
  }
+8 −1
Original line number Diff line number Diff line
@@ -685,6 +685,13 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
     * the permission {@link android.Manifest.permission#FOREGROUND_SERVICE} in order to use
     * this API.</p>
     *
     * <p>To use this API, apps targeting API {@link android.os.Build.VERSION_CODES#Q} or later must
     * specify the foreground service type using attribute
     * {@link android.R.attr#foregroundServiceType} in service element of manifest file, otherwise
     * a SecurityException is thrown when this API is called. Apps targeting API older than
     * {@link android.os.Build.VERSION_CODES#Q} do not need to specify the foreground service type
     * </p>
     *
     * @param id The identifier for this notification as per
     * {@link NotificationManager#notify(int, Notification)
     * NotificationManager.notify(int, Notification)}; must not be 0.
+4 −0
Original line number Diff line number Diff line
@@ -5380,6 +5380,10 @@ public class PackageParser {
        s.info.splitName =
                sa.getNonConfigurationString(R.styleable.AndroidManifestService_splitName, 0);

        s.info.mForegroundServiceType = sa.getInt(
                com.android.internal.R.styleable.AndroidManifestService_foregroundServiceType,
                ServiceInfo.FOREGROUND_SERVICE_TYPE_UNSPECIFIED);

        s.info.flags = 0;
        if (sa.getBoolean(
                com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
+88 −0
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package android.content.pm;

import android.annotation.IntDef;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Printer;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Information you can retrieve about a particular application
 * service. This corresponds to information collected from the
@@ -94,6 +98,81 @@ public class ServiceInfo extends ComponentInfo
     */
    public int flags;

    /**
     * The default foreground service type if not been set in manifest file.
     */
    public static final int FOREGROUND_SERVICE_TYPE_UNSPECIFIED = 0;

    /**
     * Constant corresponding to <code>sync</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * Data(photo, file, account) upload/download, backup/restore, import/export, fetch,
     * transfer over network between device and cloud.
     */
    public static final int FOREGROUND_SERVICE_TYPE_SYNC = 1;

    /**
     * Constant corresponding to <code>mediaPlay</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * Music, video, news or other media play.
     */
    public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PLAY = 2;

    /**
     * Constant corresponding to <code>phoneCall</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * Ongoing phone call or video conference.
     */
    public static final int FOREGROUND_SERVICE_TYPE_PHONE_CALL = 3;

    /**
     * Constant corresponding to <code>location</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * GPS, map, navigation location update.
     */
    public static final int FOREGROUND_SERVICE_TYPE_LOCATION = 4;

    /**
     * Constant corresponding to <code>deviceCompanion</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * Auto, bluetooth, TV or other devices connection, monitoring and interaction.
     */
    public static final int FOREGROUND_SERVICE_TYPE_DEVICE_COMPANION = 5;

    /**
     * Constant corresponding to <code>ongoingProcess</code> in
     * the {@link android.R.attr#foregroundServiceType} attribute.
     * Process that should not be interrupted, including installation, setup, photo
     * compression etc.
     */
    public static final int FOREGROUND_SERVICE_TYPE_ONGOING_PROCESS = 6;

    /**
     * The enumeration of values for foreground service type.
     * The foreground service type is set in {@link android.R.attr#foregroundServiceType}
     * attribute.
     * @hide
     */
    @IntDef(flag = false, prefix = { "FOREGROUND_SERVICE_TYPE_" }, value = {
            FOREGROUND_SERVICE_TYPE_UNSPECIFIED,
            FOREGROUND_SERVICE_TYPE_SYNC,
            FOREGROUND_SERVICE_TYPE_MEDIA_PLAY,
            FOREGROUND_SERVICE_TYPE_PHONE_CALL,
            FOREGROUND_SERVICE_TYPE_LOCATION,
            FOREGROUND_SERVICE_TYPE_DEVICE_COMPANION,
            FOREGROUND_SERVICE_TYPE_ONGOING_PROCESS
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ForegroundServiceType {}

    /**
     * The type of foreground service, set in
     * {@link android.R.attr#foregroundServiceType} attribute, one value in
     * {@link ForegroundServiceType}
     * @hide
     */
    public @ForegroundServiceType int mForegroundServiceType = FOREGROUND_SERVICE_TYPE_UNSPECIFIED;

    public ServiceInfo() {
    }

@@ -101,6 +180,15 @@ public class ServiceInfo extends ComponentInfo
        super(orig);
        permission = orig.permission;
        flags = orig.flags;
        mForegroundServiceType = orig.mForegroundServiceType;
    }

    /**
     * Return the current foreground service type.
     * @return the current foreground service type.
     */
    public int getForegroundServiceType() {
        return mForegroundServiceType;
    }

    public void dump(Printer pw, String prefix) {
+25 −0
Original line number Diff line number Diff line
@@ -1394,6 +1394,29 @@

    <attr name="usesNonSdkApi" format="boolean" />

    <!-- Specify the type of foreground service. Apps targeting API
     {@link android.os.Build.VERSION_CODES#Q} or later must specify foreground service type,
     otherwise a SecurityException is thrown when
     {@link android.app.Service#startForeground(int, Notification)} on this service is called.
    -->
    <attr name="foregroundServiceType">
        <!-- Data (photo, file, account) upload/download, backup/restore, import/export, fetch,
        transfer over network between device and cloud.  -->
        <enum name="sync" value="1" />
        <!-- Music, video, news or other media play. -->
        <enum name="mediaPlay" value="2" />
        <!-- Ongoing phone call or video conference. -->
        <enum name="phoneCall" value="3" />
        <!-- GPS, map, navigation location update. -->
        <enum name="location" value="4" />
        <!-- Auto, bluetooth, TV or other devices connection, monitoring and interaction. -->
        <enum name="deviceCompanion" value="5" />
        <!-- Process that should not be interrupted, including installation, setup, photo
        compression etc. -->
        <enum name="ongoingProcess" value="6" />
    </attr>


    <!-- The <code>manifest</code> tag is the root of an
         <code>AndroidManifest.xml</code> file,
         describing the contents of an Android package (.apk) file.  One
@@ -2242,6 +2265,8 @@
             recommended to measure memory usage under typical workloads to determine
             whether it makes sense to use this flag. -->
        <attr name="useAppZygote" format="boolean" />
        <!-- If this is a foreground service, specify its category. -->
        <attr name="foregroundServiceType" />
    </declare-styleable>

    <!-- The <code>receiver</code> tag declares an
Loading