From b8dcbeeff12bd3c51deeb87db79fce67073c6bd0 Mon Sep 17 00:00:00 2001 From: Hui Yu Date: Thu, 14 Feb 2019 13:50:01 -0800 Subject: [PATCH] Add IntDef annotation to parameter foregroundServiceType. For methods Service.startForeground(int, Notification, int). Also add IntDef annotation on return value of ServiceInfo.getForegroundServiceType(). Change-Id: I3f0df5ff44dfb1b0cf2150d6e40d39ac0cd2b2b5 Fix: 124331268 Test: NA. --- core/java/android/app/Service.java | 3 ++- core/java/android/content/pm/ServiceInfo.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index 87bf5ed7db65a..f116e133e3381 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -27,6 +27,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; +import android.content.pm.ServiceInfo.ForegroundServiceType; import android.content.res.Configuration; import android.os.Build; import android.os.IBinder; @@ -735,7 +736,7 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac * @see {@link android.content.pm.ServiceInfo} for the set of FOREGROUND_SERVICE_TYPE flags. */ public final void startForeground(int id, @NonNull Notification notification, - int foregroundServiceType) { + @ForegroundServiceType int foregroundServiceType) { try { mActivityManager.setServiceForeground( new ComponentName(this, mClassName), mToken, id, diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java index 60475de351cf5..4a2f800552f67 100644 --- a/core/java/android/content/pm/ServiceInfo.java +++ b/core/java/android/content/pm/ServiceInfo.java @@ -151,6 +151,7 @@ public class ServiceInfo extends ComponentInfo * @hide */ @IntDef(flag = true, prefix = { "FOREGROUND_SERVICE_TYPE_" }, value = { + FOREGROUND_SERVICE_TYPE_MANIFEST, FOREGROUND_SERVICE_TYPE_NONE, FOREGROUND_SERVICE_TYPE_DATA_SYNC, FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK, @@ -180,10 +181,10 @@ public class ServiceInfo extends ComponentInfo } /** - * Return the current foreground service type. - * @return the current foreground service type. + * Return foreground service type specified in the manifest.. + * @return foreground service type specified in the manifest. */ - public int getForegroundServiceType() { + public @ForegroundServiceType int getForegroundServiceType() { return mForegroundServiceType; }