diff --git a/api/current.txt b/api/current.txt index f7060f341ace7..01ff469e22816 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 @@ -11724,12 +11725,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 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; } @@ -53234,7 +53243,7 @@ package android.webkit { method public abstract boolean getDomStorageEnabled(); method public abstract java.lang.String getFantasyFontFamily(); method public abstract java.lang.String getFixedFontFamily(); - method public abstract int getForceDarkMode(); + method public int getForceDarkMode(); method public abstract boolean getJavaScriptCanOpenWindowsAutomatically(); method public abstract boolean getJavaScriptEnabled(); method public abstract android.webkit.WebSettings.LayoutAlgorithm getLayoutAlgorithm(); @@ -53281,7 +53290,7 @@ package android.webkit { method public abstract deprecated void setEnableSmoothTransition(boolean); method public abstract void setFantasyFontFamily(java.lang.String); method public abstract void setFixedFontFamily(java.lang.String); - method public abstract void setForceDarkMode(int); + method public void setForceDarkMode(int); method public abstract deprecated void setGeolocationDatabasePath(java.lang.String); method public abstract void setGeolocationEnabled(boolean); method public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean); diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index 16f6bdaa43131..5fa8526b5a24b 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -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.

* + *

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 + *

+ * * @param id The identifier for this notification as per * {@link NotificationManager#notify(int, Notification) * NotificationManager.notify(int, Notification)}; must not be 0. @@ -700,7 +707,7 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac } catch (RemoteException ex) { } } - + /** * Synonym for {@link #stopForeground(int)}. * @param removeNotification If true, the {@link #STOP_FOREGROUND_REMOVE} flag diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index ac18dca749509..d0de9a1d2a762 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -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, diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java index ad2c72274c070..8300c0c8d472d 100644 --- a/core/java/android/content/pm/ServiceInfo.java +++ b/core/java/android/content/pm/ServiceInfo.java @@ -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 sync 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 mediaPlay 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 phoneCall 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 location 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 deviceCompanion 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 ongoingProcess 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) { diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 089c59f3a09f5..854582b213402 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -1394,6 +1394,29 @@ + + + + + + + + + + + + + + + + + + +