diff options
| author | Amith Yamasani <yamasani@google.com> | 2019-03-20 22:49:43 -0700 |
|---|---|---|
| committer | Amith Yamasani <yamasani@google.com> | 2019-04-02 10:27:03 -0700 |
| commit | f235d0b53a0e33828ea23fe5aa7e668eaba3ce8b (patch) | |
| tree | c4a93cdf243f6875717734f8eeab34a0ff15cd1e /core/java/android | |
| parent | 825c933351dd4512fe9f8db849dfc1eac4738412 (diff) | |
Avoid elevating apps to high proc states on binding
For service and provider bindings from TOP and
FOREGROUND_SERVICE apps, don't elevate bound apps
to above BOUND_FOREGROUND_SERVICE.
For service bindings, it is possible to explicitly
request the binding to match the foreground app
such that the bound app can get similar privileges
of foreground permissions.
For instance, when a foreground service has a location
type, providers it binds to don't automatically get the
location privilege. On the other hand, sometimes apps
showing UI want to treat their dependencies also as if
they are showing UI.
This change does not affect the oom_adj calculation,
only the proc state calculation for bound processes.
New BIND_INCLUDE_CAPABILITIES flag can be used to restore old
behavior for bound services.
Introduces a new state PROCESS_STATE_BOUND_TOP
Bug: 128337543
Test: atest CtsAppTestCases:ActivityManagerProcessStateTest
Change-Id: I13733e7f43a78903299254bc110cd8f7a8db4c40
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 40 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 2 | ||||
| -rw-r--r-- | core/java/android/os/BatteryStats.java | 4 |
3 files changed, 27 insertions, 19 deletions
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 80b6349ca284..395c867de9d7 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -513,71 +513,75 @@ public class ActivityManager { /** @hide Process is hosting a foreground service with location type. */ public static final int PROCESS_STATE_FOREGROUND_SERVICE_LOCATION = 3; + /** @hide Process is bound to a TOP app. This is ranked below SERVICE_LOCATION so that + * it doesn't get the capability of location access while-in-use. */ + public static final int PROCESS_STATE_BOUND_TOP = 4; + /** @hide Process is hosting a foreground service. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4; + public static final int PROCESS_STATE_FOREGROUND_SERVICE = 5; /** @hide Process is hosting a foreground service due to a system binding. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 5; + public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 6; /** @hide Process is important to the user, and something they are aware of. */ - public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6; + public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 7; /** @hide Process is important to the user, but not something they are aware of. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7; + public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 8; /** @hide Process is in the background transient so we will try to keep running. */ - public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8; + public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 9; /** @hide Process is in the background running a backup/restore operation. */ - public static final int PROCESS_STATE_BACKUP = 9; + public static final int PROCESS_STATE_BACKUP = 10; /** @hide Process is in the background running a service. Unlike oom_adj, this level * is used for both the normal running in background state and the executing * operations state. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_SERVICE = 10; + public static final int PROCESS_STATE_SERVICE = 11; /** @hide Process is in the background running a receiver. Note that from the * perspective of oom_adj, receivers run at a higher foreground level, but for our * prioritization here that is not necessary and putting them below services means * many fewer changes in some process states as they receive broadcasts. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_RECEIVER = 11; + public static final int PROCESS_STATE_RECEIVER = 12; /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */ - public static final int PROCESS_STATE_TOP_SLEEPING = 12; + public static final int PROCESS_STATE_TOP_SLEEPING = 13; /** @hide Process is in the background, but it can't restore its state so we want * to try to avoid killing it. */ - public static final int PROCESS_STATE_HEAVY_WEIGHT = 13; + public static final int PROCESS_STATE_HEAVY_WEIGHT = 14; /** @hide Process is in the background but hosts the home activity. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_HOME = 14; + public static final int PROCESS_STATE_HOME = 15; /** @hide Process is in the background but hosts the last shown activity. */ - public static final int PROCESS_STATE_LAST_ACTIVITY = 15; + public static final int PROCESS_STATE_LAST_ACTIVITY = 16; /** @hide Process is being cached for later use and contains activities. */ @UnsupportedAppUsage - public static final int PROCESS_STATE_CACHED_ACTIVITY = 16; + public static final int PROCESS_STATE_CACHED_ACTIVITY = 17; /** @hide Process is being cached for later use and is a client of another cached * process that contains activities. */ - public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 17; + public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 18; /** @hide Process is being cached for later use and has an activity that corresponds * to an existing recent task. */ - public static final int PROCESS_STATE_CACHED_RECENT = 18; + public static final int PROCESS_STATE_CACHED_RECENT = 19; /** @hide Process is being cached for later use and is empty. */ - public static final int PROCESS_STATE_CACHED_EMPTY = 19; + public static final int PROCESS_STATE_CACHED_EMPTY = 20; /** @hide Process does not exist. */ - public static final int PROCESS_STATE_NONEXISTENT = 20; + public static final int PROCESS_STATE_NONEXISTENT = 21; // NOTE: If PROCESS_STATEs are added, then new fields must be added // to frameworks/base/core/proto/android/app/enums.proto and the following method must @@ -602,6 +606,8 @@ public class ActivityManager { return AppProtoEnums.PROCESS_STATE_PERSISTENT_UI; case PROCESS_STATE_TOP: return AppProtoEnums.PROCESS_STATE_TOP; + case PROCESS_STATE_BOUND_TOP: + return AppProtoEnums.PROCESS_STATE_BOUND_TOP; case PROCESS_STATE_FOREGROUND_SERVICE_LOCATION: case PROCESS_STATE_FOREGROUND_SERVICE: return AppProtoEnums.PROCESS_STATE_FOREGROUND_SERVICE; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index d7a2e1b80f84..af738da20621 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -427,7 +427,7 @@ public abstract class Context { * invisible background activities. This will impact the number of * recent activities the user can switch between without having them * restart. There is no guarantee this will be respected, as the system - * tries to balance such requests from one app vs. the importantance of + * tries to balance such requests from one app vs. the importance of * keeping other apps around. */ public static final int BIND_VISIBLE = 0x10000000; diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index b64fe007bcd9..00d522bae27f 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -16,6 +16,7 @@ package android.os; +import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP; import static android.app.ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE_LOCATION; import android.annotation.UnsupportedAppUsage; @@ -859,7 +860,8 @@ public abstract class BatteryStats implements Parcelable { */ public static final int[] CRITICAL_PROC_STATES = { PROCESS_STATE_TOP, - PROCESS_STATE_FOREGROUND_SERVICE_LOCATION, PROCESS_STATE_FOREGROUND_SERVICE, + PROCESS_STATE_FOREGROUND_SERVICE_LOCATION, + PROCESS_STATE_BOUND_TOP, PROCESS_STATE_FOREGROUND_SERVICE, PROCESS_STATE_FOREGROUND }; |
