summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/WindowManagerService.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/java/com/android/server/WindowManagerService.java')
-rw-r--r--services/java/com/android/server/WindowManagerService.java84
1 files changed, 76 insertions, 8 deletions
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 3e75db1..3fa5baf 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -179,6 +179,25 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
+ /** The minimum time between dispatching touch events. */
+ int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
+
+ // Last touch event time
+ long mLastTouchEventTime = 0;
+
+ // Last touch event type
+ int mLastTouchEventType = OTHER_EVENT;
+
+ // Time to wait before calling useractivity again. This saves CPU usage
+ // when we get a flood of touch events.
+ static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
+
+ // Last time we call user activity
+ long mLastUserActivityCallTime = 0;
+
+ // Last time we updated battery stats
+ long mLastBatteryStatsCallTime = 0;
+
private static final String SYSTEM_SECURE = "ro.secure";
/**
@@ -3694,9 +3713,20 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
// -------------------------------------------------------------
private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
- if (targetWin == null ||
- targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
- mPowerManager.userActivity(SystemClock.uptimeMillis(), false, eventType);
+ long curTime = SystemClock.uptimeMillis();
+
+ if (eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
+ if (mLastTouchEventType == eventType &&
+ (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
+ return;
+ }
+ mLastUserActivityCallTime = curTime;
+ mLastTouchEventType = eventType;
+ }
+
+ if (targetWin == null
+ || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
+ mPowerManager.userActivity(curTime, false, eventType, false);
}
}
@@ -3764,7 +3794,7 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
// events in such a way, since this means the user is moving the
// pointer without actually pressing down. All other cases should
// be atypical, so let's log them.
- if (ev.getAction() != MotionEvent.ACTION_MOVE) {
+ if (action != MotionEvent.ACTION_MOVE) {
Log.w(TAG, "No window to dispatch pointer action " + ev.getAction());
}
if (qev != null) {
@@ -3851,7 +3881,39 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
return false;
}
} //end if target
-
+
+ // TODO remove once we settle on a value or make it app specific
+ if (action == MotionEvent.ACTION_DOWN) {
+ int max_events_per_sec = 35;
+ try {
+ max_events_per_sec = Integer.parseInt(SystemProperties
+ .get("windowsmgr.max_events_per_sec"));
+ if (max_events_per_sec < 1) {
+ max_events_per_sec = 35;
+ }
+ } catch (NumberFormatException e) {
+ }
+ mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
+ }
+
+ /*
+ * Throttle events to minimize CPU usage when there's a flood of events
+ * e.g. constant contact with the screen
+ */
+ if (action == MotionEvent.ACTION_MOVE) {
+ long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
+ long now = SystemClock.uptimeMillis();
+ if (now < nextEventTime) {
+ try {
+ Thread.sleep(nextEventTime - now);
+ } catch (InterruptedException e) {
+ }
+ mLastTouchEventTime = nextEventTime;
+ } else {
+ mLastTouchEventTime = now;
+ }
+ }
+
synchronized(mWindowMap) {
if (qev != null && action == MotionEvent.ACTION_MOVE) {
mKeyWaiter.bindTargetWindowLocked(target,
@@ -4928,7 +4990,7 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
}
if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
mPowerManager.userActivity(event.when, false,
- LocalPowerManager.BUTTON_EVENT);
+ LocalPowerManager.BUTTON_EVENT, false);
}
if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
@@ -5088,11 +5150,17 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo
eventType = LocalPowerManager.OTHER_EVENT;
}
try {
- mBatteryStats.noteInputEvent();
+ long now = SystemClock.uptimeMillis();
+
+ if ((now - mLastBatteryStatsCallTime)
+ >= MIN_TIME_BETWEEN_USERACTIVITIES) {
+ mLastBatteryStatsCallTime = now;
+ mBatteryStats.noteInputEvent();
+ }
} catch (RemoteException e) {
// Ignore
}
- mPowerManager.userActivity(curTime, false, eventType);
+ mPowerManager.userActivity(curTime, false, eventType, false);
switch (ev.classType) {
case RawInputEvent.CLASS_KEYBOARD:
KeyEvent ke = (KeyEvent)ev.event;