Use const reference when not modifying objects
Before we can refactor to use shared_ptr, we should make ownership clear
by only using reference and const reference in places that don't care
about the ownership model of the object (and when the object is not
nullable).
Bug: none
Test: none
Change-Id: If794e2e1403b31d44524ef88b71c167215fafe46
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 90cc5c6..58404a2 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -363,7 +363,7 @@
// Poke user activity for this event.
if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {
- pokeUserActivityLocked(mPendingEvent);
+ pokeUserActivityLocked(*mPendingEvent);
}
// Get ready to dispatch the event.
@@ -404,14 +404,14 @@
case EventEntry::TYPE_KEY: {
KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);
if (isAppSwitchDue) {
- if (isAppSwitchKeyEvent(typedEntry)) {
+ if (isAppSwitchKeyEvent(*typedEntry)) {
resetPendingAppSwitchLocked(true);
isAppSwitchDue = false;
} else if (dropReason == DropReason::NOT_DROPPED) {
dropReason = DropReason::APP_SWITCH;
}
}
- if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, typedEntry)) {
+ if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, *typedEntry)) {
dropReason = DropReason::STALE;
}
if (dropReason == DropReason::NOT_DROPPED && mNextUnblockedEvent) {
@@ -426,7 +426,7 @@
if (dropReason == DropReason::NOT_DROPPED && isAppSwitchDue) {
dropReason = DropReason::APP_SWITCH;
}
- if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, typedEntry)) {
+ if (dropReason == DropReason::NOT_DROPPED && isStaleEvent(currentTime, *typedEntry)) {
dropReason = DropReason::STALE;
}
if (dropReason == DropReason::NOT_DROPPED && mNextUnblockedEvent) {
@@ -443,7 +443,7 @@
if (done) {
if (dropReason != DropReason::NOT_DROPPED) {
- dropInboundEventLocked(mPendingEvent, dropReason);
+ dropInboundEventLocked(*mPendingEvent, dropReason);
}
mLastDropReason = dropReason;
@@ -462,16 +462,16 @@
// Optimize app switch latency.
// If the application takes too long to catch up then we drop all events preceding
// the app switch key.
- KeyEntry* keyEntry = static_cast<KeyEntry*>(entry);
+ const KeyEntry& keyEntry = static_cast<const KeyEntry&>(*entry);
if (isAppSwitchKeyEvent(keyEntry)) {
- if (keyEntry->action == AKEY_EVENT_ACTION_DOWN) {
+ if (keyEntry.action == AKEY_EVENT_ACTION_DOWN) {
mAppSwitchSawKeyDown = true;
- } else if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
+ } else if (keyEntry.action == AKEY_EVENT_ACTION_UP) {
if (mAppSwitchSawKeyDown) {
#if DEBUG_APP_SWITCH
ALOGD("App switch is pending!");
#endif
- mAppSwitchDueTime = keyEntry->eventTime + APP_SWITCH_TIMEOUT;
+ mAppSwitchDueTime = keyEntry.eventTime + APP_SWITCH_TIMEOUT;
mAppSwitchSawKeyDown = false;
needWake = true;
}
@@ -591,7 +591,7 @@
}
}
-void InputDispatcher::dropInboundEventLocked(EventEntry* entry, DropReason dropReason) {
+void InputDispatcher::dropInboundEventLocked(const EventEntry& entry, DropReason dropReason) {
const char* reason;
switch (dropReason) {
case DropReason::POLICY:
@@ -626,15 +626,15 @@
}
}
- switch (entry->type) {
+ switch (entry.type) {
case EventEntry::TYPE_KEY: {
CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason);
synthesizeCancelationEventsForAllConnectionsLocked(options);
break;
}
case EventEntry::TYPE_MOTION: {
- MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
- if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
+ const MotionEntry& motionEntry = static_cast<const MotionEntry&>(entry);
+ if (motionEntry.source & AINPUT_SOURCE_CLASS_POINTER) {
CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, reason);
synthesizeCancelationEventsForAllConnectionsLocked(options);
} else {
@@ -651,10 +651,10 @@
keyCode == AKEYCODE_APP_SWITCH;
}
-bool InputDispatcher::isAppSwitchKeyEvent(KeyEntry* keyEntry) {
- return !(keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) && isAppSwitchKeyCode(keyEntry->keyCode) &&
- (keyEntry->policyFlags & POLICY_FLAG_TRUSTED) &&
- (keyEntry->policyFlags & POLICY_FLAG_PASS_TO_USER);
+bool InputDispatcher::isAppSwitchKeyEvent(const KeyEntry& keyEntry) {
+ return !(keyEntry.flags & AKEY_EVENT_FLAG_CANCELED) && isAppSwitchKeyCode(keyEntry.keyCode) &&
+ (keyEntry.policyFlags & POLICY_FLAG_TRUSTED) &&
+ (keyEntry.policyFlags & POLICY_FLAG_PASS_TO_USER);
}
bool InputDispatcher::isAppSwitchPendingLocked() {
@@ -673,8 +673,8 @@
#endif
}
-bool InputDispatcher::isStaleEvent(nsecs_t currentTime, EventEntry* entry) {
- return currentTime - entry->eventTime >= STALE_EVENT_TIMEOUT;
+bool InputDispatcher::isStaleEvent(nsecs_t currentTime, const EventEntry& entry) {
+ return currentTime - entry.eventTime >= STALE_EVENT_TIMEOUT;
}
bool InputDispatcher::haveCommandsLocked() const {
@@ -837,7 +837,7 @@
entry->dispatchInProgress = true;
- logOutboundKeyDetails("dispatchKey - ", entry);
+ logOutboundKeyDetails("dispatchKey - ", *entry);
}
// Handle case where the policy asked us to try again later last time.
@@ -858,7 +858,7 @@
std::unique_ptr<CommandEntry> commandEntry = std::make_unique<CommandEntry>(
&InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible);
sp<InputWindowHandle> focusedWindowHandle =
- getValueByKey(mFocusedWindowHandlesByDisplay, getTargetDisplayId(entry));
+ getValueByKey(mFocusedWindowHandlesByDisplay, getTargetDisplayId(*entry));
if (focusedWindowHandle != nullptr) {
commandEntry->inputChannel = getInputChannelLocked(focusedWindowHandle->getToken());
}
@@ -887,7 +887,7 @@
// Identify targets.
std::vector<InputTarget> inputTargets;
int32_t injectionResult =
- findFocusedWindowTargetsLocked(currentTime, entry, inputTargets, nextWakeupTime);
+ findFocusedWindowTargetsLocked(currentTime, *entry, inputTargets, nextWakeupTime);
if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
return false;
}
@@ -898,21 +898,21 @@
}
// Add monitor channels from event's or focused display.
- addGlobalMonitoringTargetsLocked(inputTargets, getTargetDisplayId(entry));
+ addGlobalMonitoringTargetsLocked(inputTargets, getTargetDisplayId(*entry));
// Dispatch the key.
dispatchEventLocked(currentTime, entry, inputTargets);
return true;
}
-void InputDispatcher::logOutboundKeyDetails(const char* prefix, const KeyEntry* entry) {
+void InputDispatcher::logOutboundKeyDetails(const char* prefix, const KeyEntry& entry) {
#if DEBUG_OUTBOUND_EVENT_DETAILS
ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, displayId=%" PRId32 ", "
"policyFlags=0x%x, action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, "
"metaState=0x%x, repeatCount=%d, downTime=%" PRId64,
- prefix, entry->eventTime, entry->deviceId, entry->source, entry->displayId,
- entry->policyFlags, entry->action, entry->flags, entry->keyCode, entry->scanCode,
- entry->metaState, entry->repeatCount, entry->downTime);
+ prefix, entry.eventTime, entry.deviceId, entry.source, entry.displayId, entry.policyFlags,
+ entry.action, entry.flags, entry.keyCode, entry.scanCode, entry.metaState,
+ entry.repeatCount, entry.downTime);
#endif
}
@@ -923,7 +923,7 @@
if (!entry->dispatchInProgress) {
entry->dispatchInProgress = true;
- logOutboundMotionDetails("dispatchMotion - ", entry);
+ logOutboundMotionDetails("dispatchMotion - ", *entry);
}
// Clean up if dropping the event.
@@ -944,12 +944,12 @@
if (isPointerEvent) {
// Pointer event. (eg. touchscreen)
injectionResult =
- findTouchedWindowTargetsLocked(currentTime, entry, inputTargets, nextWakeupTime,
+ findTouchedWindowTargetsLocked(currentTime, *entry, inputTargets, nextWakeupTime,
&conflictingPointerActions);
} else {
// Non touch event. (eg. trackball)
injectionResult =
- findFocusedWindowTargetsLocked(currentTime, entry, inputTargets, nextWakeupTime);
+ findFocusedWindowTargetsLocked(currentTime, *entry, inputTargets, nextWakeupTime);
}
if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
return false;
@@ -968,7 +968,7 @@
}
// Add monitor channels from event's or focused display.
- addGlobalMonitoringTargetsLocked(inputTargets, getTargetDisplayId(entry));
+ addGlobalMonitoringTargetsLocked(inputTargets, getTargetDisplayId(*entry));
if (isPointerEvent) {
ssize_t stateIndex = mTouchStatesByDisplay.indexOfKey(entry->displayId);
@@ -996,33 +996,32 @@
return true;
}
-void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionEntry* entry) {
+void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionEntry& entry) {
#if DEBUG_OUTBOUND_EVENT_DETAILS
ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, displayId=%" PRId32
", policyFlags=0x%x, "
"action=0x%x, actionButton=0x%x, flags=0x%x, "
"metaState=0x%x, buttonState=0x%x,"
"edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRId64,
- prefix, entry->eventTime, entry->deviceId, entry->source, entry->displayId,
- entry->policyFlags, entry->action, entry->actionButton, entry->flags, entry->metaState,
- entry->buttonState, entry->edgeFlags, entry->xPrecision, entry->yPrecision,
- entry->downTime);
+ prefix, entry.eventTime, entry.deviceId, entry.source, entry.displayId, entry.policyFlags,
+ entry.action, entry.actionButton, entry.flags, entry.metaState, entry.buttonState,
+ entry.edgeFlags, entry.xPrecision, entry.yPrecision, entry.downTime);
- for (uint32_t i = 0; i < entry->pointerCount; i++) {
+ for (uint32_t i = 0; i < entry.pointerCount; i++) {
ALOGD(" Pointer %d: id=%d, toolType=%d, "
"x=%f, y=%f, pressure=%f, size=%f, "
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
"orientation=%f",
- i, entry->pointerProperties[i].id, entry->pointerProperties[i].toolType,
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
- entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
+ i, entry.pointerProperties[i].id, entry.pointerProperties[i].toolType,
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+ entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
}
#endif
}
@@ -1036,7 +1035,7 @@
ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true
- pokeUserActivityLocked(eventEntry);
+ pokeUserActivityLocked(*eventEntry);
for (const InputTarget& inputTarget : inputTargets) {
sp<Connection> connection = getConnectionLocked(inputTarget.inputChannel);
@@ -1053,7 +1052,7 @@
}
int32_t InputDispatcher::handleTargetsNotReadyLocked(
- nsecs_t currentTime, const EventEntry* entry,
+ nsecs_t currentTime, const EventEntry& entry,
const sp<InputApplicationHandle>& applicationHandle,
const sp<InputWindowHandle>& windowHandle, nsecs_t* nextWakeupTime, const char* reason) {
if (applicationHandle == nullptr && windowHandle == nullptr) {
@@ -1103,7 +1102,7 @@
}
if (currentTime >= mInputTargetWaitTimeoutTime) {
- onANRLocked(currentTime, applicationHandle, windowHandle, entry->eventTime,
+ onANRLocked(currentTime, applicationHandle, windowHandle, entry.eventTime,
mInputTargetWaitStartTime, reason);
// Force poll loop to wake up immediately on next iteration once we get the
@@ -1175,21 +1174,21 @@
* then it should be dispatched to that display. Otherwise, the event goes to the focused display.
* Focused display is the display that the user most recently interacted with.
*/
-int32_t InputDispatcher::getTargetDisplayId(const EventEntry* entry) {
+int32_t InputDispatcher::getTargetDisplayId(const EventEntry& entry) {
int32_t displayId;
- switch (entry->type) {
+ switch (entry.type) {
case EventEntry::TYPE_KEY: {
- const KeyEntry* typedEntry = static_cast<const KeyEntry*>(entry);
- displayId = typedEntry->displayId;
+ const KeyEntry& keyEntry = static_cast<const KeyEntry&>(entry);
+ displayId = keyEntry.displayId;
break;
}
case EventEntry::TYPE_MOTION: {
- const MotionEntry* typedEntry = static_cast<const MotionEntry*>(entry);
- displayId = typedEntry->displayId;
+ const MotionEntry& motionEntry = static_cast<const MotionEntry&>(entry);
+ displayId = motionEntry.displayId;
break;
}
default: {
- ALOGE("Unsupported event type '%" PRId32 "' for target display.", entry->type);
+ ALOGE("Unsupported event type '%" PRId32 "' for target display.", entry.type);
return ADISPLAY_ID_NONE;
}
}
@@ -1197,7 +1196,7 @@
}
int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime,
- const EventEntry* entry,
+ const EventEntry& entry,
std::vector<InputTarget>& inputTargets,
nsecs_t* nextWakeupTime) {
int32_t injectionResult;
@@ -1230,7 +1229,7 @@
}
// Check permissions.
- if (!checkInjectionPermission(focusedWindowHandle, entry->injectionState)) {
+ if (!checkInjectionPermission(focusedWindowHandle, entry.injectionState)) {
injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
goto Failed;
}
@@ -1264,7 +1263,7 @@
}
int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
- const MotionEntry* entry,
+ const MotionEntry& entry,
std::vector<InputTarget>& inputTargets,
nsecs_t* nextWakeupTime,
bool* outConflictingPointerActions) {
@@ -1277,8 +1276,8 @@
// For security reasons, we defer updating the touch state until we are sure that
// event injection will be allowed.
- int32_t displayId = entry->displayId;
- int32_t action = entry->action;
+ int32_t displayId = entry.displayId;
+ int32_t action = entry.action;
int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
// Update the touch state as needed based on the properties of the touch event.
@@ -1298,14 +1297,14 @@
bool isSplit = mTempTouchState.split;
bool switchedDevice = mTempTouchState.deviceId >= 0 && mTempTouchState.displayId >= 0 &&
- (mTempTouchState.deviceId != entry->deviceId ||
- mTempTouchState.source != entry->source || mTempTouchState.displayId != displayId);
+ (mTempTouchState.deviceId != entry.deviceId || mTempTouchState.source != entry.source ||
+ mTempTouchState.displayId != displayId);
bool isHoverAction = (maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE ||
maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER ||
maskedAction == AMOTION_EVENT_ACTION_HOVER_EXIT);
bool newGesture = (maskedAction == AMOTION_EVENT_ACTION_DOWN ||
maskedAction == AMOTION_EVENT_ACTION_SCROLL || isHoverAction);
- const bool isFromMouse = entry->source == AINPUT_SOURCE_MOUSE;
+ const bool isFromMouse = entry.source == AINPUT_SOURCE_MOUSE;
bool wrongDevice = false;
if (newGesture) {
bool down = maskedAction == AMOTION_EVENT_ACTION_DOWN;
@@ -1323,8 +1322,8 @@
}
mTempTouchState.reset();
mTempTouchState.down = down;
- mTempTouchState.deviceId = entry->deviceId;
- mTempTouchState.source = entry->source;
+ mTempTouchState.deviceId = entry.deviceId;
+ mTempTouchState.source = entry.source;
mTempTouchState.displayId = displayId;
isSplit = false;
} else if (switchedDevice && maskedAction == AMOTION_EVENT_ACTION_MOVE) {
@@ -1348,11 +1347,11 @@
int32_t pointerIndex = getMotionEventActionPointerIndex(action);
// Always dispatch mouse events to cursor position.
if (isFromMouse) {
- x = int32_t(entry->xCursorPosition);
- y = int32_t(entry->yCursorPosition);
+ x = int32_t(entry.xCursorPosition);
+ y = int32_t(entry.yCursorPosition);
} else {
- x = int32_t(entry->pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_X));
- y = int32_t(entry->pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_Y));
+ x = int32_t(entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_X));
+ y = int32_t(entry.pointerCoords[pointerIndex].getAxisValue(AMOTION_EVENT_AXIS_Y));
}
bool isDown = maskedAction == AMOTION_EVENT_ACTION_DOWN;
sp<InputWindowHandle> newTouchedWindowHandle =
@@ -1410,7 +1409,7 @@
// Update the temporary touch state.
BitSet32 pointerIds;
if (isSplit) {
- uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
+ uint32_t pointerId = entry.pointerProperties[pointerIndex].id;
pointerIds.markBit(pointerId);
}
mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
@@ -1432,10 +1431,10 @@
}
// Check whether touches should slip outside of the current foreground window.
- if (maskedAction == AMOTION_EVENT_ACTION_MOVE && entry->pointerCount == 1 &&
+ if (maskedAction == AMOTION_EVENT_ACTION_MOVE && entry.pointerCount == 1 &&
mTempTouchState.isSlippery()) {
- int32_t x = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X));
- int32_t y = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));
+ int32_t x = int32_t(entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X));
+ int32_t y = int32_t(entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));
sp<InputWindowHandle> oldTouchedWindowHandle =
mTempTouchState.getFirstForegroundWindowHandle();
@@ -1469,7 +1468,7 @@
BitSet32 pointerIds;
if (isSplit) {
- pointerIds.markBit(entry->pointerProperties[0].id);
+ pointerIds.markBit(entry.pointerProperties[0].id);
}
mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
}
@@ -1507,7 +1506,7 @@
for (const TouchedWindow& touchedWindow : mTempTouchState.windows) {
if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
haveForegroundWindow = true;
- if (!checkInjectionPermission(touchedWindow.windowHandle, entry->injectionState)) {
+ if (!checkInjectionPermission(touchedWindow.windowHandle, entry.injectionState)) {
injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
injectionPermission = INJECTION_PERMISSION_DENIED;
goto Failed;
@@ -1613,7 +1612,7 @@
Failed:
// Check injection permission once and for all.
if (injectionPermission == INJECTION_PERMISSION_UNKNOWN) {
- if (checkInjectionPermission(nullptr, entry->injectionState)) {
+ if (checkInjectionPermission(nullptr, entry.injectionState)) {
injectionPermission = INJECTION_PERMISSION_GRANTED;
} else {
injectionPermission = INJECTION_PERMISSION_DENIED;
@@ -1642,8 +1641,8 @@
mTempTouchState.reset();
if (maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER ||
maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE) {
- mTempTouchState.deviceId = entry->deviceId;
- mTempTouchState.source = entry->source;
+ mTempTouchState.deviceId = entry.deviceId;
+ mTempTouchState.source = entry.source;
mTempTouchState.displayId = displayId;
}
} else if (maskedAction == AMOTION_EVENT_ACTION_UP ||
@@ -1662,7 +1661,7 @@
// One pointer went up.
if (isSplit) {
int32_t pointerIndex = getMotionEventActionPointerIndex(action);
- uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
+ uint32_t pointerId = entry.pointerProperties[pointerIndex].id;
for (size_t i = 0; i < mTempTouchState.windows.size();) {
TouchedWindow& touchedWindow = mTempTouchState.windows[i];
@@ -1822,7 +1821,7 @@
std::string InputDispatcher::checkWindowReadyForMoreInputLocked(
nsecs_t currentTime, const sp<InputWindowHandle>& windowHandle,
- const EventEntry* eventEntry, const char* targetType) {
+ const EventEntry& eventEntry, const char* targetType) {
// If the window is paused then keep waiting.
if (windowHandle->getInfo()->paused) {
return StringPrintf("Waiting because the %s window is paused.", targetType);
@@ -1854,7 +1853,7 @@
}
// Ensure that the dispatch queues aren't too far backed up for this event.
- if (eventEntry->type == EventEntry::TYPE_KEY) {
+ if (eventEntry.type == EventEntry::TYPE_KEY) {
// If the event is a key event, then we must wait for all previous events to
// complete before delivering it because previous events may have the
// side-effect of transferring focus to a different window and we want to
@@ -1926,7 +1925,7 @@
}
}
-void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
+void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) {
int32_t displayId = getTargetDisplayId(eventEntry);
sp<InputWindowHandle> focusedWindowHandle =
getValueByKey(mFocusedWindowHandlesByDisplay, displayId);
@@ -1941,21 +1940,21 @@
}
int32_t eventType = USER_ACTIVITY_EVENT_OTHER;
- switch (eventEntry->type) {
+ switch (eventEntry.type) {
case EventEntry::TYPE_MOTION: {
- const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry);
- if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) {
+ const MotionEntry& motionEntry = static_cast<const MotionEntry&>(eventEntry);
+ if (motionEntry.action == AMOTION_EVENT_ACTION_CANCEL) {
return;
}
- if (MotionEvent::isTouchEvent(motionEntry->source, motionEntry->action)) {
+ if (MotionEvent::isTouchEvent(motionEntry.source, motionEntry.action)) {
eventType = USER_ACTIVITY_EVENT_TOUCH;
}
break;
}
case EventEntry::TYPE_KEY: {
- const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry);
- if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) {
+ const KeyEntry& keyEntry = static_cast<const KeyEntry&>(eventEntry);
+ if (keyEntry.flags & AKEY_EVENT_FLAG_CANCELED) {
return;
}
eventType = USER_ACTIVITY_EVENT_BUTTON;
@@ -1965,7 +1964,7 @@
std::unique_ptr<CommandEntry> commandEntry =
std::make_unique<CommandEntry>(&InputDispatcher::doPokeUserActivityLockedInterruptible);
- commandEntry->eventTime = eventEntry->eventTime;
+ commandEntry->eventTime = eventEntry.eventTime;
commandEntry->userActivityEventType = eventType;
postCommandLocked(std::move(commandEntry));
}
@@ -2003,8 +2002,8 @@
if (inputTarget->flags & InputTarget::FLAG_SPLIT) {
ALOG_ASSERT(eventEntry->type == EventEntry::TYPE_MOTION);
- MotionEntry* originalMotionEntry = static_cast<MotionEntry*>(eventEntry);
- if (inputTarget->pointerIds.count() != originalMotionEntry->pointerCount) {
+ const MotionEntry& originalMotionEntry = static_cast<const MotionEntry&>(*eventEntry);
+ if (inputTarget->pointerIds.count() != originalMotionEntry.pointerCount) {
MotionEntry* splitMotionEntry =
splitMotionEvent(originalMotionEntry, inputTarget->pointerIds);
if (!splitMotionEntry) {
@@ -2013,7 +2012,7 @@
if (DEBUG_FOCUS) {
ALOGD("channel '%s' ~ Split motion event.",
connection->getInputChannelName().c_str());
- logOutboundMotionDetails(" ", splitMotionEntry);
+ logOutboundMotionDetails(" ", *splitMotionEntry);
}
enqueueDispatchEntriesLocked(currentTime, connection, splitMotionEntry, inputTarget);
splitMotionEntry->release();
@@ -2086,9 +2085,9 @@
// Apply target flags and update the connection's input state.
switch (eventEntry->type) {
case EventEntry::TYPE_KEY: {
- KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
- dispatchEntry->resolvedAction = keyEntry->action;
- dispatchEntry->resolvedFlags = keyEntry->flags;
+ const KeyEntry& keyEntry = static_cast<const KeyEntry&>(*eventEntry);
+ dispatchEntry->resolvedAction = keyEntry.action;
+ dispatchEntry->resolvedFlags = keyEntry.flags;
if (!connection->inputState.trackKey(keyEntry, dispatchEntry->resolvedAction,
dispatchEntry->resolvedFlags)) {
@@ -2103,7 +2102,7 @@
}
case EventEntry::TYPE_MOTION: {
- MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
+ const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*eventEntry);
if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_OUTSIDE;
} else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT) {
@@ -2115,11 +2114,11 @@
} else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER) {
dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_DOWN;
} else {
- dispatchEntry->resolvedAction = motionEntry->action;
+ dispatchEntry->resolvedAction = motionEntry.action;
}
if (dispatchEntry->resolvedAction == AMOTION_EVENT_ACTION_HOVER_MOVE &&
- !connection->inputState.isHovering(motionEntry->deviceId, motionEntry->source,
- motionEntry->displayId)) {
+ !connection->inputState.isHovering(motionEntry.deviceId, motionEntry.source,
+ motionEntry.displayId)) {
#if DEBUG_DISPATCH_CYCLE
ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: filling in missing hover enter "
"event",
@@ -2128,7 +2127,7 @@
dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER;
}
- dispatchEntry->resolvedFlags = motionEntry->flags;
+ dispatchEntry->resolvedFlags = motionEntry.flags;
if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) {
dispatchEntry->resolvedFlags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
}
@@ -2147,7 +2146,7 @@
return; // skip the inconsistent event
}
- dispatchPointerDownOutsideFocus(motionEntry->source, dispatchEntry->resolvedAction,
+ dispatchPointerDownOutsideFocus(motionEntry.source, dispatchEntry->resolvedAction,
inputTarget->inputChannel->getToken());
break;
@@ -2509,11 +2508,12 @@
switch (cancelationEventEntry->type) {
case EventEntry::TYPE_KEY:
logOutboundKeyDetails("cancel - ",
- static_cast<KeyEntry*>(cancelationEventEntry));
+ static_cast<const KeyEntry&>(*cancelationEventEntry));
break;
case EventEntry::TYPE_MOTION:
logOutboundMotionDetails("cancel - ",
- static_cast<MotionEntry*>(cancelationEventEntry));
+ static_cast<const MotionEntry&>(
+ *cancelationEventEntry));
break;
}
@@ -2545,7 +2545,7 @@
}
}
-MotionEntry* InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry,
+MotionEntry* InputDispatcher::splitMotionEvent(const MotionEntry& originalMotionEntry,
BitSet32 pointerIds) {
ALOG_ASSERT(pointerIds.value != 0);
@@ -2553,19 +2553,19 @@
PointerProperties splitPointerProperties[MAX_POINTERS];
PointerCoords splitPointerCoords[MAX_POINTERS];
- uint32_t originalPointerCount = originalMotionEntry->pointerCount;
+ uint32_t originalPointerCount = originalMotionEntry.pointerCount;
uint32_t splitPointerCount = 0;
for (uint32_t originalPointerIndex = 0; originalPointerIndex < originalPointerCount;
originalPointerIndex++) {
const PointerProperties& pointerProperties =
- originalMotionEntry->pointerProperties[originalPointerIndex];
+ originalMotionEntry.pointerProperties[originalPointerIndex];
uint32_t pointerId = uint32_t(pointerProperties.id);
if (pointerIds.hasBit(pointerId)) {
splitPointerIndexMap[splitPointerCount] = originalPointerIndex;
splitPointerProperties[splitPointerCount].copyFrom(pointerProperties);
splitPointerCoords[splitPointerCount].copyFrom(
- originalMotionEntry->pointerCoords[originalPointerIndex]);
+ originalMotionEntry.pointerCoords[originalPointerIndex]);
splitPointerCount += 1;
}
}
@@ -2583,13 +2583,13 @@
return nullptr;
}
- int32_t action = originalMotionEntry->action;
+ int32_t action = originalMotionEntry.action;
int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
if (maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN ||
maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
int32_t originalPointerIndex = getMotionEventActionPointerIndex(action);
const PointerProperties& pointerProperties =
- originalMotionEntry->pointerProperties[originalPointerIndex];
+ originalMotionEntry.pointerProperties[originalPointerIndex];
uint32_t pointerId = uint32_t(pointerProperties.id);
if (pointerIds.hasBit(pointerId)) {
if (pointerIds.count() == 1) {
@@ -2613,19 +2613,19 @@
}
MotionEntry* splitMotionEntry =
- new MotionEntry(originalMotionEntry->sequenceNum, originalMotionEntry->eventTime,
- originalMotionEntry->deviceId, originalMotionEntry->source,
- originalMotionEntry->displayId, originalMotionEntry->policyFlags,
- action, originalMotionEntry->actionButton, originalMotionEntry->flags,
- originalMotionEntry->metaState, originalMotionEntry->buttonState,
- originalMotionEntry->classification, originalMotionEntry->edgeFlags,
- originalMotionEntry->xPrecision, originalMotionEntry->yPrecision,
- originalMotionEntry->xCursorPosition,
- originalMotionEntry->yCursorPosition, originalMotionEntry->downTime,
+ new MotionEntry(originalMotionEntry.sequenceNum, originalMotionEntry.eventTime,
+ originalMotionEntry.deviceId, originalMotionEntry.source,
+ originalMotionEntry.displayId, originalMotionEntry.policyFlags, action,
+ originalMotionEntry.actionButton, originalMotionEntry.flags,
+ originalMotionEntry.metaState, originalMotionEntry.buttonState,
+ originalMotionEntry.classification, originalMotionEntry.edgeFlags,
+ originalMotionEntry.xPrecision, originalMotionEntry.yPrecision,
+ originalMotionEntry.xCursorPosition,
+ originalMotionEntry.yCursorPosition, originalMotionEntry.downTime,
splitPointerCount, splitPointerProperties, splitPointerCoords, 0, 0);
- if (originalMotionEntry->injectionState) {
- splitMotionEntry->injectionState = originalMotionEntry->injectionState;
+ if (originalMotionEntry.injectionState) {
+ splitMotionEntry->injectionState = originalMotionEntry.injectionState;
splitMotionEntry->injectionState->refCount += 1;
}
@@ -4476,7 +4476,7 @@
entry->downTime, entry->eventTime);
}
-void InputDispatcher::updateDispatchStatistics(nsecs_t currentTime, const EventEntry* entry,
+void InputDispatcher::updateDispatchStatistics(nsecs_t currentTime, const EventEntry& entry,
int32_t injectionResult,
nsecs_t timeSpentWaitingForApplication) {
// TODO Write some statistics about how long we spend waiting.