背景:
? ? ? ?android系统优化电池使用,在应用退到后台后会判断应用是否还在使用cpu,如果在指定时间内使用cpu到一定程度就会杀进程,报ActivityManager: Killing 9553:com.oushang.screen/1000 (adj 700): excessive cpu 56840 during 300080 dur=623325 limit=10这个错。车机需要排除排除这种情况下杀carlink进程,在checkExcessivePowerUsageLocked种修改如下:
第一次修改:
diff --git a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java b/frameworks/base/services/core/jav
index f3531c4..b7a7927 100755
--- a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -24657,7 +24657,11 @@ public class ActivityManagerService extends IActivityManager.Stub
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
} else if (checkDur <= (mConstants.POWER_CHECK_INTERVAL*3)) {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
- } else {
+ } else if ((app.info.packageName.equals("com.oushang.screen"))
+ && (checkDur <= (mConstants.POWER_CHECK_INTERVAL*12))) {
+ Slog.d(TAG,"~~~zjy screen delay 1 hour");
+ cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
+ } else {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_4;
}
if (((cputimeUsed*100)/uptimeSince) >= cpuLimit) {
后面发现不行,主要是进入这个条件 checkDur <= (mConstants.POWER_CHECK_INTERVAL*3)之后,直接就开始杀进程,后面优化内容如下:
--- a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -24656,14 +24656,22 @@ public class ActivityManagerService extends IActivityManager.Stub
|| app.setProcState <= ActivityManager.PROCESS_STATE_HOME) {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
} else if (checkDur <= (mConstants.POWER_CHECK_INTERVAL*3)) {
- cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
- } else if ((app.info.packageName.equals("com.oushang.screen"))
- && (checkDur <= (mConstants.POWER_CHECK_INTERVAL*12))) {
+ Slog.d(TAG,"~~~zjy screen delay POWER_CHECK_INTERVAL*3"+",packageName:"+app.info.packageName);
+ if (app.info.packageName.equals("com.oushang.screen")) {
+ Slog.d(TAG,"~~~zjy screen delay 1 hour");
+ cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
+ } else {
+ cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
+ }
+ } else if ((app.info.packageName.equals("com.oushang.screen"))
+ && (checkDur < (mConstants.POWER_CHECK_INTERVAL*12))) {
Slog.d(TAG,"~~~zjy screen delay 1 hour");
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
} else {
+ Slog.d(TAG,"~~~zjy screen delay POWER_CHECK_MAX_CPU_4"+",packageName:"+app.info.packageName);
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_4;
}
+ Slog.d(TAG, "~~~zjy screen delay cputimeUsed:"+cputimeUsed*100+",uptimeSince:"+uptimeSince+",cpuLimit:"+cpuLimit+
if (((cputimeUsed*100)/uptimeSince) >= cpuLimit) {
synchronized (stats) {
stats.reportExcessiveCpuLocked(app.info.uid, app.processName,
修改后的内容如下:
// What is the limit for this process?
int cpuLimit;
long checkDur = curUptime - app.whenUnimportant;
if (checkDur <= mConstants.POWER_CHECK_INTERVAL) {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_1;
} else if (checkDur <= (mConstants.POWER_CHECK_INTERVAL*2)
|| app.setProcState <= ActivityManager.PROCESS_STATE_HOME) {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
} else if (checkDur <= (mConstants.POWER_CHECK_INTERVAL*3)) {
Slog.d(TAG,"~~~zjy screen delay POWER_CHECK_INTERVAL*3"+",packageName:"+app.info.packageName);
if (app.info.packageName.equals("com.oushang.screen")) {
Slog.d(TAG,"~~~zjy screen delay 1 hour");
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
} else {
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_3;
}
} else if ((app.info.packageName.equals("com.oushang.screen"))
&& (checkDur < (mConstants.POWER_CHECK_INTERVAL*12))) {
Slog.d(TAG,"~~~zjy screen delay 1 hour");
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_2;
} else {
Slog.d(TAG,"~~~zjy screen delay POWER_CHECK_MAX_CPU_4"+",packageName:"+app.info.packageName);
cpuLimit = mConstants.POWER_CHECK_MAX_CPU_4;
}
Slog.d(TAG, "~~~zjy screen delay cputimeUsed:"+cputimeUsed*100+",uptimeSince:"+uptimeSince+",cpuLimit:"+cpuLimit+",checkDur:"+checkDur);
if (((cputimeUsed*100)/uptimeSince) >= cpuLimit) {
synchronized (stats) {
stats.reportExcessiveCpuLocked(app.info.uid, app.processName,
uptimeSince, cputimeUsed);
}
|