diff options
| -rw-r--r-- | core/java/android/os/Process.java | 7 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 29 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ProcessList.java | 8 |
3 files changed, 39 insertions, 5 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index a9508dad154f..7ce7c9237815 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -422,6 +422,13 @@ public class Process { **/ public static final int THREAD_GROUP_RT_APP = 6; + /** + * Thread group for bound foreground services that should + * have additional CPU restrictions during screen off + * @hide + **/ + public static final int THREAD_GROUP_RESTRICTED = 7; + public static final int SIGNAL_QUIT = 3; public static final int SIGNAL_KILL = 9; public static final int SIGNAL_USR1 = 10; diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index ec862f315cfc..d1cd58448535 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -95,6 +95,7 @@ import static android.os.Process.SIGNAL_USR1; import static android.os.Process.SYSTEM_UID; import static android.os.Process.THREAD_GROUP_BG_NONINTERACTIVE; import static android.os.Process.THREAD_GROUP_DEFAULT; +import static android.os.Process.THREAD_GROUP_RESTRICTED; import static android.os.Process.THREAD_GROUP_TOP_APP; import static android.os.Process.THREAD_PRIORITY_BACKGROUND; import static android.os.Process.THREAD_PRIORITY_FOREGROUND; @@ -13067,6 +13068,7 @@ public class ActivityManagerService extends IActivityManager.Stub mHandler.obtainMessage(DISPATCH_SCREEN_AWAKE_MSG, isAwake ? 1 : 0, 0) .sendToTarget(); } + updateOomAdjLocked(); } } @@ -18056,6 +18058,9 @@ public class ActivityManagerService extends IActivityManager.Stub case ProcessList.SCHED_GROUP_TOP_APP: schedGroup = 'T'; break; + case ProcessList.SCHED_GROUP_RESTRICTED: + schedGroup = 'R'; + break; default: schedGroup = '?'; break; @@ -22881,8 +22886,8 @@ public class ActivityManagerService extends IActivityManager.Stub app.curSchedGroup = ProcessList.SCHED_GROUP_TOP_APP; app.adjType = "pers-top-activity"; } else if (app.hasTopUi) { + // sched group/proc state adjustment is below app.systemNoUi = false; - app.curSchedGroup = ProcessList.SCHED_GROUP_TOP_APP; app.adjType = "pers-top-ui"; } else if (activitiesSize > 0) { for (int j = 0; j < activitiesSize; j++) { @@ -22893,7 +22898,15 @@ public class ActivityManagerService extends IActivityManager.Stub } } if (!app.systemNoUi) { - app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT_UI; + if (mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE) { + // screen on, promote UI + app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT_UI; + app.curSchedGroup = ProcessList.SCHED_GROUP_TOP_APP; + } else { + // screen off, restrict UI scheduling + app.curProcState = ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE; + app.curSchedGroup = ProcessList.SCHED_GROUP_RESTRICTED; + } } return (app.curAdj=app.maxAdj); } @@ -23751,6 +23764,15 @@ public class ActivityManagerService extends IActivityManager.Stub } } + // Put bound foreground services in a special sched group for additional + // restrictions on screen off + if (procState >= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE && + mWakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE) { + if (schedGroup > ProcessList.SCHED_GROUP_RESTRICTED) { + schedGroup = ProcessList.SCHED_GROUP_RESTRICTED; + } + } + // Do final modification to adj. Everything we do between here and applying // the final setAdj must be done in this function, because we will also use // it when computing the final cached adj later. Note that we don't need to @@ -24173,6 +24195,9 @@ public class ActivityManagerService extends IActivityManager.Stub case ProcessList.SCHED_GROUP_TOP_APP_BOUND: processGroup = THREAD_GROUP_TOP_APP; break; + case ProcessList.SCHED_GROUP_RESTRICTED: + processGroup = THREAD_GROUP_RESTRICTED; + break; default: processGroup = THREAD_GROUP_DEFAULT; break; diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index bf7aef9ecc65..784d62e51966 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -128,13 +128,15 @@ public final class ProcessList { // Activity manager's version of Process.THREAD_GROUP_BG_NONINTERACTIVE static final int SCHED_GROUP_BACKGROUND = 0; + // Activity manager's version of Process.THREAD_GROUP_RESTRICTED + static final int SCHED_GROUP_RESTRICTED = 1; // Activity manager's version of Process.THREAD_GROUP_DEFAULT - static final int SCHED_GROUP_DEFAULT = 1; + static final int SCHED_GROUP_DEFAULT = 2; // Activity manager's version of Process.THREAD_GROUP_TOP_APP - static final int SCHED_GROUP_TOP_APP = 2; + static final int SCHED_GROUP_TOP_APP = 3; // Activity manager's version of Process.THREAD_GROUP_TOP_APP // Disambiguate between actual top app and processes bound to the top app - static final int SCHED_GROUP_TOP_APP_BOUND = 3; + static final int SCHED_GROUP_TOP_APP_BOUND = 4; // The minimum number of cached apps we want to be able to keep around, // without empty apps being able to push them out of memory. |