am b633615e: Merge "Fix reporting of wakelocks to battery stats." into mnc-dev

* commit 'b633615ea6940f2806f8378c909a3d29a5265f9a':
  Fix reporting of wakelocks to battery stats.
This commit is contained in:
Jeff Brown
2015-06-22 19:37:20 +00:00
committed by Android Git Automerger
2 changed files with 67 additions and 34 deletions

View File

@@ -95,6 +95,9 @@ final class Notifier {
private final Intent mScreenOffIntent; private final Intent mScreenOffIntent;
private final Intent mScreenBrightnessBoostIntent; private final Intent mScreenBrightnessBoostIntent;
// True if the device should suspend when the screen is off due to proximity.
private final boolean mSuspendWhenScreenOffDueToProximityConfig;
// The current interactive state. This is set as soon as an interactive state // The current interactive state. This is set as soon as an interactive state
// transition begins so as to capture the reason that it happened. At some point // transition begins so as to capture the reason that it happened. At some point
// this state will propagate to the pending state then eventually to the // this state will propagate to the pending state then eventually to the
@@ -143,6 +146,9 @@ final class Notifier {
mScreenBrightnessBoostIntent.addFlags( mScreenBrightnessBoostIntent.addFlags(
Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
mSuspendWhenScreenOffDueToProximityConfig = context.getResources().getBoolean(
com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
// Initialize interactive state for battery stats. // Initialize interactive state for battery stats.
try { try {
mBatteryStats.noteInteractive(true); mBatteryStats.noteInteractive(true);
@@ -161,13 +167,14 @@ final class Notifier {
+ ", workSource=" + workSource); + ", workSource=" + workSource);
} }
try {
final int monitorType = getBatteryStatsWakeLockMonitorType(flags); final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
boolean unimportantForLogging = (flags&PowerManager.UNIMPORTANT_FOR_LOGGING) != 0 if (monitorType >= 0) {
&& ownerUid == Process.SYSTEM_UID; try {
final boolean unimportantForLogging = ownerUid == Process.SYSTEM_UID
&& (flags & PowerManager.UNIMPORTANT_FOR_LOGGING) != 0;
if (workSource != null) { if (workSource != null) {
mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag, historyTag, mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag,
monitorType, unimportantForLogging); historyTag, monitorType, unimportantForLogging);
} else { } else {
mBatteryStats.noteStartWakelock(ownerUid, ownerPid, tag, historyTag, mBatteryStats.noteStartWakelock(ownerUid, ownerPid, tag, historyTag,
monitorType, unimportantForLogging); monitorType, unimportantForLogging);
@@ -179,6 +186,7 @@ final class Notifier {
// Ignore // Ignore
} }
} }
}
/** /**
* Called when a wake lock is changing. * Called when a wake lock is changing.
@@ -188,17 +196,19 @@ final class Notifier {
int newFlags, String newTag, String newPackageName, int newOwnerUid, int newFlags, String newTag, String newPackageName, int newOwnerUid,
int newOwnerPid, WorkSource newWorkSource, String newHistoryTag) { int newOwnerPid, WorkSource newWorkSource, String newHistoryTag) {
if (workSource != null && newWorkSource != null) {
final int monitorType = getBatteryStatsWakeLockMonitorType(flags); final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
final int newMonitorType = getBatteryStatsWakeLockMonitorType(newFlags); final int newMonitorType = getBatteryStatsWakeLockMonitorType(newFlags);
boolean unimportantForLogging = (newFlags&PowerManager.UNIMPORTANT_FOR_LOGGING) != 0 if (workSource != null && newWorkSource != null
&& newOwnerUid == Process.SYSTEM_UID; && monitorType >= 0 && newMonitorType >= 0) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "onWakeLockChanging: flags=" + newFlags + ", tag=\"" + newTag Slog.d(TAG, "onWakeLockChanging: flags=" + newFlags + ", tag=\"" + newTag
+ "\", packageName=" + newPackageName + "\", packageName=" + newPackageName
+ ", ownerUid=" + newOwnerUid + ", ownerPid=" + newOwnerPid + ", ownerUid=" + newOwnerUid + ", ownerPid=" + newOwnerPid
+ ", workSource=" + newWorkSource); + ", workSource=" + newWorkSource);
} }
final boolean unimportantForLogging = newOwnerUid == Process.SYSTEM_UID
&& (newFlags & PowerManager.UNIMPORTANT_FOR_LOGGING) != 0;
try { try {
mBatteryStats.noteChangeWakelockFromSource(workSource, ownerPid, tag, historyTag, mBatteryStats.noteChangeWakelockFromSource(workSource, ownerPid, tag, historyTag,
monitorType, newWorkSource, newOwnerPid, newTag, newHistoryTag, monitorType, newWorkSource, newOwnerPid, newTag, newHistoryTag,
@@ -225,13 +235,15 @@ final class Notifier {
+ ", workSource=" + workSource); + ", workSource=" + workSource);
} }
try {
final int monitorType = getBatteryStatsWakeLockMonitorType(flags); final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
if (monitorType >= 0) {
try {
if (workSource != null) { if (workSource != null) {
mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag, historyTag, mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag,
monitorType); historyTag, monitorType);
} else { } else {
mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag, historyTag, monitorType); mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag,
historyTag, monitorType);
mAppOps.finishOperation(AppOpsManager.getToken(mAppOps), mAppOps.finishOperation(AppOpsManager.getToken(mAppOps),
AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName); AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName);
} }
@@ -239,14 +251,34 @@ final class Notifier {
// Ignore // Ignore
} }
} }
}
private static int getBatteryStatsWakeLockMonitorType(int flags) { private int getBatteryStatsWakeLockMonitorType(int flags) {
switch (flags & PowerManager.WAKE_LOCK_LEVEL_MASK) { switch (flags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
case PowerManager.PARTIAL_WAKE_LOCK: case PowerManager.PARTIAL_WAKE_LOCK:
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
return BatteryStats.WAKE_TYPE_PARTIAL; return BatteryStats.WAKE_TYPE_PARTIAL;
default:
case PowerManager.SCREEN_DIM_WAKE_LOCK:
case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
return BatteryStats.WAKE_TYPE_FULL; return BatteryStats.WAKE_TYPE_FULL;
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
if (mSuspendWhenScreenOffDueToProximityConfig) {
return -1;
}
return BatteryStats.WAKE_TYPE_PARTIAL;
case PowerManager.DRAW_WAKE_LOCK:
return BatteryStats.WAKE_TYPE_DRAW;
case PowerManager.DOZE_WAKE_LOCK:
// Doze wake locks are an internal implementation detail of the
// communication between dream manager service and power manager
// service. They have no additive battery impact.
return -1;
default:
return -1;
} }
} }

View File

@@ -970,6 +970,7 @@ public final class PowerManagerService extends SystemService
case PowerManager.SCREEN_BRIGHT_WAKE_LOCK: case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
case PowerManager.FULL_WAKE_LOCK: case PowerManager.FULL_WAKE_LOCK:
case PowerManager.DOZE_WAKE_LOCK: case PowerManager.DOZE_WAKE_LOCK:
case PowerManager.DRAW_WAKE_LOCK:
return true; return true;
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK: case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK: