diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-02-28 01:48:02 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-02-28 01:48:02 +0000 |
| commit | 79c8d6623b36a6fcccdef0cda8e68d42a094e989 (patch) | |
| tree | 0a3588cb88ef5f319468d219bb311f1e91647b87 /core/java | |
| parent | 3d6fff4db68173fd13b672aebfca2a03b3fb0a7f (diff) | |
| parent | fb72b990511b4546f0e89a1a0c7e44d13d7858dc (diff) | |
Merge "Add API Service.getForegroundServiceType()"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/IActivityManager.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/app/Service.java | 27 |
2 files changed, 27 insertions, 1 deletions
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 780dd630d834..5cbb59976c5a 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -204,6 +204,7 @@ interface IActivityManager { void setProcessImportant(in IBinder token, int pid, boolean isForeground, String reason); void setServiceForeground(in ComponentName className, in IBinder token, int id, in Notification notification, int flags, int foregroundServiceType); + int getForegroundServiceType(in ComponentName className, in IBinder token); boolean moveActivityTaskToBack(in IBinder token, boolean nonRoot); void getMemoryInfo(out ActivityManager.MemoryInfo outInfo); List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState(); diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index f116e133e338..1f91b3f431a1 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; import android.content.pm.ServiceInfo.ForegroundServiceType; import android.content.res.Configuration; import android.os.Build; @@ -733,7 +734,7 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac * {@link android.R.attr#foregroundServiceType} flags. * @throws IllegalArgumentException if param foregroundServiceType is not subset of manifest * attribute {@link android.R.attr#foregroundServiceType}. - * @see {@link android.content.pm.ServiceInfo} for the set of FOREGROUND_SERVICE_TYPE flags. + * @see android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MANIFEST */ public final void startForeground(int id, @NonNull Notification notification, @ForegroundServiceType int foregroundServiceType) { @@ -775,6 +776,30 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac } /** + * If the service has become a foreground service by calling + * {@link #startForeground(int, Notification)} + * or {@link #startForeground(int, Notification, int)}, {@link #getForegroundServiceType()} + * returns the current foreground service type. + * + * <p>If there is no foregroundServiceType specified + * in manifest, {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_NONE} is returned. </p> + * + * <p>If the service is not a foreground service, + * {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_NONE} is returned.</p> + * + * @return current foreground service type flags. + */ + public final @ForegroundServiceType int getForegroundServiceType() { + int ret = ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE; + try { + ret = mActivityManager.getForegroundServiceType( + new ComponentName(this, mClassName), mToken); + } catch (RemoteException ex) { + } + return ret; + } + + /** * Print the Service's state into the given stream. This gets invoked if * you run "adb shell dumpsys activity service <yourservicename>" * (note that for this command to work, the service must be running, and |
