summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-01-20 02:55:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-01-20 02:55:30 +0000
commit4c0659f5313bcc70be704a3808af9e670f467ee6 (patch)
tree94da0aa44a73285c1dd6c5c41f201c6078dd8dbf /core/java/android
parent596915de30f53312eb9d3176f6b558943967c9b6 (diff)
parent42a386b7717300bf6d75cbd3b4f7ad00f294be0d (diff)
Merge "Enable background restrictions"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ContextImpl.java23
-rw-r--r--core/java/android/app/IActivityManager.aidl3
-rw-r--r--core/java/android/app/NotificationManager.java35
-rw-r--r--core/java/android/content/Context.java21
-rw-r--r--core/java/android/content/ContextWrapper.java15
-rw-r--r--core/java/android/content/pm/PackageManagerInternal.java5
6 files changed, 94 insertions, 8 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index d08bee507b77..b67e193f4f48 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -1385,7 +1385,14 @@ class ContextImpl extends Context {
@Override
public ComponentName startService(Intent service) {
warnIfCallingFromSystemProcess();
- return startServiceCommon(service, mUser);
+ return startServiceCommon(service, -1, null, mUser);
+ }
+
+ @Override
+ public ComponentName startServiceInForeground(Intent service,
+ int id, Notification notification) {
+ warnIfCallingFromSystemProcess();
+ return startServiceCommon(service, id, notification, mUser);
}
@Override
@@ -1396,16 +1403,24 @@ class ContextImpl extends Context {
@Override
public ComponentName startServiceAsUser(Intent service, UserHandle user) {
- return startServiceCommon(service, user);
+ return startServiceCommon(service, -1, null, user);
}
- private ComponentName startServiceCommon(Intent service, UserHandle user) {
+ @Override
+ public ComponentName startServiceInForegroundAsUser(Intent service,
+ int id, Notification notification, UserHandle user) {
+ return startServiceCommon(service, id, notification, user);
+ }
+
+ private ComponentName startServiceCommon(Intent service, int id, Notification notification,
+ UserHandle user) {
try {
validateServiceIntent(service);
service.prepareToLeaveProcess(this);
ComponentName cn = ActivityManager.getService().startService(
mMainThread.getApplicationThread(), service, service.resolveTypeIfNeeded(
- getContentResolver()), getOpPackageName(), user.getIdentifier());
+ getContentResolver()), id, notification, getOpPackageName(),
+ user.getIdentifier());
if (cn != null) {
if (cn.getPackageName().equals("!")) {
throw new SecurityException(
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index e143255bbd43..70b3f84a7ddb 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -128,7 +128,8 @@ interface IActivityManager {
void finishSubActivity(in IBinder token, in String resultWho, int requestCode);
PendingIntent getRunningServiceControlPanel(in ComponentName service);
ComponentName startService(in IApplicationThread caller, in Intent service,
- in String resolvedType, in String callingPackage, int userId);
+ in String resolvedType, int id, in Notification notification,
+ in String callingPackage, int userId);
int stopService(in IApplicationThread caller, in Intent service,
in String resolvedType, int userId);
int bindService(in IApplicationThread caller, in IBinder token, in Intent service,
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 3551691b18be..c0aae6df34fe 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -24,6 +24,7 @@ import android.annotation.TestApi;
import android.app.Notification.Builder;
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.graphics.drawable.Icon;
import android.net.Uri;
@@ -1085,4 +1086,38 @@ public class NotificationManager
default: return defValue;
}
}
+
+ /**
+ * Start a service directly into the "foreground service" state. Unlike
+ * {@link android.content.Context#startService(Intent)}, this method
+ * can be used from within background operations like broadcast receivers
+ * or scheduled jobs.
+ *
+ * @param service Description of the service to be stopped. The Intent must be either
+ * fully explicit (supplying a component name) or specify a specific package
+ * name it is targeted to.
+ * @param id The identifier for this notification as per
+ * {@link #notify(int, Notification) NotificationManager.notify(int, Notification)};
+ * must not be 0.
+ * @param notification The Notification to be displayed.
+ * @return If the service is being started or is already running, the
+ * {@link ComponentName} of the actual service that was started is
+ * returned; else if the service does not exist null is returned.
+ */
+ @Nullable
+ public ComponentName startServiceInForeground(Intent service,
+ int id, Notification notification) {
+ return mContext.startServiceInForeground(service, id, notification);
+ }
+
+ /**
+ * @hide like {@link #startServiceInForeground(Intent, int, Notification)}
+ * but for a specific user.
+ */
+ @Nullable
+ public ComponentName startServiceInForegroundAsUser(Intent service,
+ int id, Notification notification, UserHandle user) {
+ return mContext.startServiceInForegroundAsUser(service, id, notification, user);
+ }
+
}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index af5e64381bf1..b196c6409527 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -35,6 +35,7 @@ import android.annotation.UserIdInt;
import android.app.IApplicationThread;
import android.app.IServiceConnection;
import android.app.LoadedApk;
+import android.app.Notification;
import android.app.admin.DevicePolicyManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -2517,6 +2518,17 @@ public abstract class Context {
public abstract ComponentName startService(Intent service);
/**
+ * Start a service directly into the "foreground service" state. Unlike {@link #startService},
+ * this method can be used from within background operations like broadcast receivers
+ * or scheduled jobs. The API entry point for this is in NotificationManager in order to
+ * preserve appropriate public package layering.
+ * @hide
+ */
+ @Nullable
+ public abstract ComponentName startServiceInForeground(Intent service,
+ int id, Notification notification);
+
+ /**
* Request that a given application service be stopped. If the service is
* not running, nothing happens. Otherwise it is stopped. Note that calls
* to startService() are not counted -- this stops the service no matter
@@ -2547,9 +2559,18 @@ public abstract class Context {
/**
* @hide like {@link #startService(Intent)} but for a specific user.
*/
+ @Nullable
public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
/**
+ * @hide like {@link #startServiceInForeground(Intent, int, Notification)}
+ * but for a specific user.
+ */
+ @Nullable
+ public abstract ComponentName startServiceInForegroundAsUser(Intent service,
+ int id, Notification notification, UserHandle user);
+
+ /**
* @hide like {@link #stopService(Intent)} but for a specific user.
*/
public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index e437de0fb9ba..b131eccbe48a 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.IApplicationThread;
import android.app.IServiceConnection;
+import android.app.Notification;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
@@ -623,6 +624,13 @@ public class ContextWrapper extends Context {
return mBase.startService(service);
}
+ /** @hide */
+ @Override
+ public ComponentName startServiceInForeground(Intent service,
+ int id, Notification notification) {
+ return mBase.startServiceInForeground(service, id, notification);
+ }
+
@Override
public boolean stopService(Intent name) {
return mBase.stopService(name);
@@ -636,6 +644,13 @@ public class ContextWrapper extends Context {
/** @hide */
@Override
+ public ComponentName startServiceInForegroundAsUser(Intent service,
+ int id, Notification notification, UserHandle user) {
+ return mBase.startServiceInForegroundAsUser(service, id, notification, user);
+ }
+
+ /** @hide */
+ @Override
public boolean stopServiceAsUser(Intent name, UserHandle user) {
return mBase.stopServiceAsUser(name, user);
}
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java
index 62f38483250a..a1747c7d22b9 100644
--- a/core/java/android/content/pm/PackageManagerInternal.java
+++ b/core/java/android/content/pm/PackageManagerInternal.java
@@ -138,9 +138,8 @@ public abstract class PackageManagerInternal {
* @param userId The user under which to check.
*
* @return An {@link ApplicationInfo} containing information about the
- * package.
- * @throws NameNotFoundException if a package with the given name cannot be
- * found on the system.
+ * package, or {@code null} if no application exists with that
+ * package name.
*/
public abstract ApplicationInfo getApplicationInfo(String packageName, int userId);