am b9b56954: Merge "Eliminate special battery calls by WindowManager" into jb-mr1-dev
* commit 'b9b56954ec5a242f7c4945942539106539f98ffb': Eliminate special battery calls by WindowManager
This commit is contained in:
@@ -267,13 +267,6 @@ public final class PowerManager {
|
|||||||
*/
|
*/
|
||||||
public static final int USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS = 1 << 0;
|
public static final int USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS = 1 << 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Special wake lock tag used for the wake lock in the Window Manager that handles the
|
|
||||||
* {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} flag.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final String KEEP_SCREEN_ON_FLAG_TAG = "KEEP_SCREEN_ON_FLAG";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to sleep reason code: Going to sleep due by user request.
|
* Go to sleep reason code: Going to sleep due by user request.
|
||||||
* @hide
|
* @hide
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Process;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.WorkSource;
|
import android.os.WorkSource;
|
||||||
@@ -117,19 +116,15 @@ final class Notifier {
|
|||||||
+ ", workSource=" + workSource);
|
+ ", workSource=" + workSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWakeLockAlreadyReportedToBatteryStats(tag, ownerUid)) {
|
try {
|
||||||
try {
|
final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
|
||||||
final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
|
if (workSource != null) {
|
||||||
if (workSource != null) {
|
mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag, monitorType);
|
||||||
mBatteryStats.noteStartWakelockFromSource(
|
} else {
|
||||||
workSource, ownerPid, tag, monitorType);
|
mBatteryStats.noteStartWakelock(ownerUid, ownerPid, tag, monitorType);
|
||||||
} else {
|
|
||||||
mBatteryStats.noteStartWakelock(
|
|
||||||
ownerUid, ownerPid, tag, monitorType);
|
|
||||||
}
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
// Ignore
|
|
||||||
}
|
}
|
||||||
|
} catch (RemoteException ex) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,30 +139,18 @@ final class Notifier {
|
|||||||
+ ", workSource=" + workSource);
|
+ ", workSource=" + workSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWakeLockAlreadyReportedToBatteryStats(tag, ownerUid)) {
|
try {
|
||||||
try {
|
final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
|
||||||
final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
|
if (workSource != null) {
|
||||||
if (workSource != null) {
|
mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag, monitorType);
|
||||||
mBatteryStats.noteStopWakelockFromSource(
|
} else {
|
||||||
workSource, ownerPid, tag, monitorType);
|
mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag, monitorType);
|
||||||
} else {
|
|
||||||
mBatteryStats.noteStopWakelock(
|
|
||||||
ownerUid, ownerPid, tag, monitorType);
|
|
||||||
}
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
// Ignore
|
|
||||||
}
|
}
|
||||||
|
} catch (RemoteException ex) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isWakeLockAlreadyReportedToBatteryStats(String tag, int uid) {
|
|
||||||
// The window manager already takes care of reporting battery stats associated
|
|
||||||
// with the use of the KEEP_SCREEN_ON_FLAG.
|
|
||||||
// TODO: Use a WorkSource to handle this situation instead of hardcoding it here.
|
|
||||||
return uid == Process.SYSTEM_UID
|
|
||||||
&& tag.equals(PowerManager.KEEP_SCREEN_ON_FLAG_TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getBatteryStatsWakeLockMonitorType(int flags) {
|
private static 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:
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ import android.os.SystemClock;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.TokenWatcher;
|
import android.os.TokenWatcher;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
|
import android.os.WorkSource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
@@ -923,7 +924,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
mContext.registerReceiver(mBroadcastReceiver, filter);
|
mContext.registerReceiver(mBroadcastReceiver, filter);
|
||||||
|
|
||||||
mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
|
mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
|
||||||
| PowerManager.ON_AFTER_RELEASE, PowerManager.KEEP_SCREEN_ON_FLAG_TAG);
|
| PowerManager.ON_AFTER_RELEASE, TAG);
|
||||||
mHoldingScreenWakeLock.setReferenceCounted(false);
|
mHoldingScreenWakeLock.setReferenceCounted(false);
|
||||||
|
|
||||||
mInputManager = new InputManagerService(context, mInputMonitor);
|
mInputManager = new InputManagerService(context, mInputMonitor);
|
||||||
@@ -7020,7 +7021,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
|
public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
|
||||||
public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9;
|
public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9;
|
||||||
public static final int WINDOW_FREEZE_TIMEOUT = 11;
|
public static final int WINDOW_FREEZE_TIMEOUT = 11;
|
||||||
public static final int HOLD_SCREEN_CHANGED = 12;
|
|
||||||
public static final int APP_TRANSITION_TIMEOUT = 13;
|
public static final int APP_TRANSITION_TIMEOUT = 13;
|
||||||
public static final int PERSIST_ANIMATION_SCALE = 14;
|
public static final int PERSIST_ANIMATION_SCALE = 14;
|
||||||
public static final int FORCE_GC = 15;
|
public static final int FORCE_GC = 15;
|
||||||
@@ -7041,8 +7042,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1;
|
public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1;
|
||||||
public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2;
|
public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2;
|
||||||
|
|
||||||
private Session mLastReportedHold;
|
|
||||||
|
|
||||||
public H() {
|
public H() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7294,33 +7293,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HOLD_SCREEN_CHANGED: {
|
|
||||||
Session oldHold;
|
|
||||||
Session newHold;
|
|
||||||
synchronized (mWindowMap) {
|
|
||||||
oldHold = mLastReportedHold;
|
|
||||||
newHold = (Session)msg.obj;
|
|
||||||
mLastReportedHold = newHold;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldHold != newHold) {
|
|
||||||
try {
|
|
||||||
if (oldHold != null) {
|
|
||||||
mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
|
|
||||||
"window",
|
|
||||||
BatteryStats.WAKE_TYPE_WINDOW);
|
|
||||||
}
|
|
||||||
if (newHold != null) {
|
|
||||||
mBatteryStats.noteStartWakelock(newHold.mUid, -1,
|
|
||||||
"window",
|
|
||||||
BatteryStats.WAKE_TYPE_WINDOW);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case APP_TRANSITION_TIMEOUT: {
|
case APP_TRANSITION_TIMEOUT: {
|
||||||
synchronized (mWindowMap) {
|
synchronized (mWindowMap) {
|
||||||
if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
|
if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
|
||||||
@@ -9134,7 +9106,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
// Finally update all input windows now that the window changes have stabilized.
|
// Finally update all input windows now that the window changes have stabilized.
|
||||||
mInputMonitor.updateInputWindowsLw(true /*force*/);
|
mInputMonitor.updateInputWindowsLw(true /*force*/);
|
||||||
|
|
||||||
setHoldScreenLocked(mInnerFields.mHoldScreen != null);
|
setHoldScreenLocked(mInnerFields.mHoldScreen);
|
||||||
if (!mDisplayFrozen) {
|
if (!mDisplayFrozen) {
|
||||||
if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) {
|
if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) {
|
||||||
mPowerManager.setScreenBrightnessOverrideFromWindowManager(-1);
|
mPowerManager.setScreenBrightnessOverrideFromWindowManager(-1);
|
||||||
@@ -9149,11 +9121,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
toBrightnessOverride(mInnerFields.mButtonBrightness));
|
toBrightnessOverride(mInnerFields.mButtonBrightness));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mInnerFields.mHoldScreen != mHoldingScreenOn) {
|
|
||||||
mHoldingScreenOn = mInnerFields.mHoldScreen;
|
|
||||||
Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, mInnerFields.mHoldScreen);
|
|
||||||
mH.sendMessage(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTurnOnScreen) {
|
if (mTurnOnScreen) {
|
||||||
if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
|
if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
|
||||||
@@ -9237,13 +9204,17 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void setHoldScreenLocked(final Session newHoldScreen) {
|
||||||
* Must be called with the main window manager lock held.
|
final boolean hold = newHoldScreen != null;
|
||||||
*/
|
|
||||||
void setHoldScreenLocked(boolean holding) {
|
if (hold && mHoldingScreenOn != newHoldScreen) {
|
||||||
boolean state = mHoldingScreenWakeLock.isHeld();
|
mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid));
|
||||||
if (holding != state) {
|
}
|
||||||
if (holding) {
|
mHoldingScreenOn = newHoldScreen;
|
||||||
|
|
||||||
|
final boolean state = mHoldingScreenWakeLock.isHeld();
|
||||||
|
if (hold != state) {
|
||||||
|
if (hold) {
|
||||||
mPolicy.screenOnStartedLw();
|
mPolicy.screenOnStartedLw();
|
||||||
mHoldingScreenWakeLock.acquire();
|
mHoldingScreenWakeLock.acquire();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user