Deprecate the DATA_SYNC FGS type.
The DATA_SYNC foreground service type will be deprecated starting from
Android version V. This does not affect any functionality and only logs
a warning message, giving developers a heads up that an exception will
be thrown if this type continues to be used in a future release.
Bug: 297095631
Test: atest ActivityManagerForegroundServiceTypeTest
Change-Id: Iba0590104d5ab6e7bcbd019693652408a1fdb26e
diff --git a/core/api/current.txt b/core/api/current.txt
index 97f078b..02872d2 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -13478,7 +13478,7 @@
field public static final int FLAG_USE_APP_ZYGOTE = 8; // 0x8
field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_CAMERA}, anyOf={android.Manifest.permission.CAMERA}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_CAMERA = 64; // 0x40
field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE}, anyOf={android.Manifest.permission.BLUETOOTH_ADVERTISE, android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.CHANGE_NETWORK_STATE, android.Manifest.permission.CHANGE_WIFI_STATE, android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, android.Manifest.permission.NFC, android.Manifest.permission.TRANSMIT_IR, android.Manifest.permission.UWB_RANGING}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE = 16; // 0x10
- field @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_DATA_SYNC, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1; // 0x1
+ field @Deprecated @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_DATA_SYNC, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1; // 0x1
field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_HEALTH}, anyOf={android.Manifest.permission.ACTIVITY_RECOGNITION, android.Manifest.permission.BODY_SENSORS, android.Manifest.permission.HIGH_SAMPLING_RATE_SENSORS}) public static final int FOREGROUND_SERVICE_TYPE_HEALTH = 256; // 0x100
field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_LOCATION}, anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_LOCATION = 8; // 0x8
field public static final int FOREGROUND_SERVICE_TYPE_MANIFEST = -1; // 0xffffffff
diff --git a/core/java/android/app/ForegroundServiceTypePolicy.java b/core/java/android/app/ForegroundServiceTypePolicy.java
index d1e517b..7e06735 100644
--- a/core/java/android/app/ForegroundServiceTypePolicy.java
+++ b/core/java/android/app/ForegroundServiceTypePolicy.java
@@ -62,6 +62,7 @@
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
+import android.os.Build;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
@@ -127,10 +128,14 @@
* The FGS type enforcement:
* deprecating the {@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC}.
*
+ * <p>Starting a FGS with this type from apps with targetSdkVersion
+ * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} or later will result in a warning
+ * in the log.
+ *
* @hide
*/
@ChangeId
- @Disabled
+ @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
@Overridable
public static final long FGS_TYPE_DATA_SYNC_DEPRECATION_CHANGE_ID = 255039210L;
diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java
index 5b0cee7..9c6aab4 100644
--- a/core/java/android/content/pm/ServiceInfo.java
+++ b/core/java/android/content/pm/ServiceInfo.java
@@ -163,12 +163,25 @@
* Because of this, developers must make sure to stop the foreground service even if
* {@link android.app.Service#onTimeout(int, int)} is not called on such versions.
*
- * @see android.app.Service#onTimeout(int, int)
+ * <p>Apps targeting API level {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} and
+ * later should <b>NOT</b> use this type: calling
+ * {@link android.app.Service#startForeground(int, android.app.Notification, int)} with
+ * this type on devices running {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} is
+ * still allowed, but it may throw an {@link android.app.InvalidForegroundServiceTypeException}
+ * in future platform releases.
+ *
+ * <p class="note">
+ * Use the {@link android.app.job.JobInfo.Builder#setUserInitiated(boolean)} API for
+ * user-initiated, network data transfers.
+ *
+ * @deprecated Use {@link android.app.job.JobInfo.Builder} APIs or alternate FGS types
+ * (like {@link #FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING}) applicable to your use-case.
*/
@RequiresPermission(
value = Manifest.permission.FOREGROUND_SERVICE_DATA_SYNC,
conditional = true
)
+ @Deprecated
public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 << 0;
/**
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 4741012..647bccf 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1618,13 +1618,15 @@
<!-- Data (photo, file, account) upload/download, backup/restore, import/export, fetch,
transfer over network between device and cloud.
- <p>For apps with <code>targetSdkVersion</code>
- {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and above, this type should NOT
- be used: calling
- {@link android.app.Service#startForeground(int, android.app.Notification, int)} with
- this type on devices running {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}
- is still allowed, but calling it with this type on devices running future platform
- releases may get a {@link android.app.InvalidForegroundServiceTypeException}.
+ <p><b>THIS TYPE IS DEPRECATED.</b>
+ <p><em>Note: For apps with <code>targetSdkVersion</code>
+ {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, this type should
+ <b>NOT</b> be used: calling
+ {@link android.app.Service#startForeground(int, android.app.Notification, int)}
+ with this type on devices running
+ {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} is still allowed, but it may
+ throw an {@link android.app.InvalidForegroundServiceTypeException} in future platform
+ releases.</em>
-->
<flag name="dataSync" value="0x01" />
<!-- Music, video, news or other media play.