Use std::vector over Vector for InputFlinger (1/3)
Replace Vector<T> with std::vector<T>.
Bug: 112399697
Test: atest inputflinger_tests
Change-Id: I8baec68f7a684d97210077f3e387ca1096586a25
diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp
index bcb1ec5..1317620 100644
--- a/services/inputflinger/InputDispatcher.cpp
+++ b/services/inputflinger/InputDispatcher.cpp
@@ -524,10 +524,8 @@
sp<InputWindowHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId,
int32_t x, int32_t y, bool addOutsideTargets, bool addPortalWindows) {
// Traverse windows from front to back to find touched window.
- const Vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- sp<InputWindowHandle> windowHandle = windowHandles.itemAt(i);
+ const std::vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
+ for (const sp<InputWindowHandle>& windowHandle : windowHandles) {
const InputWindowInfo* windowInfo = windowHandle->getInfo();
if (windowInfo->displayId == displayId) {
int32_t flags = windowInfo->layoutParamsFlags;
@@ -859,7 +857,7 @@
}
// Identify targets.
- Vector<InputTarget> inputTargets;
+ std::vector<InputTarget> inputTargets;
int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime,
entry, inputTargets, nextWakeupTime);
if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
@@ -910,7 +908,7 @@
bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER;
// Identify targets.
- Vector<InputTarget> inputTargets;
+ std::vector<InputTarget> inputTargets;
bool conflictingPointerActions = false;
int32_t injectionResult;
@@ -946,11 +944,11 @@
ssize_t stateIndex = mTouchStatesByDisplay.indexOfKey(entry->displayId);
if (stateIndex >= 0) {
const TouchState& state = mTouchStatesByDisplay.valueAt(stateIndex);
- if (!state.portalWindows.isEmpty()) {
+ if (!state.portalWindows.empty()) {
// The event has gone through these portal windows, so we add monitoring targets of
// the corresponding displays as well.
for (size_t i = 0; i < state.portalWindows.size(); i++) {
- const InputWindowInfo* windowInfo = state.portalWindows.itemAt(i)->getInfo();
+ const InputWindowInfo* windowInfo = state.portalWindows[i]->getInfo();
addMonitoringTargetsLocked(inputTargets, windowInfo->portalToDisplayId,
-windowInfo->frameLeft, -windowInfo->frameTop);
}
@@ -1004,7 +1002,7 @@
}
void InputDispatcher::dispatchEventLocked(nsecs_t currentTime,
- EventEntry* eventEntry, const Vector<InputTarget>& inputTargets) {
+ EventEntry* eventEntry, const std::vector<InputTarget>& inputTargets) {
#if DEBUG_DISPATCH_CYCLE
ALOGD("dispatchEventToCurrentInputTargets");
#endif
@@ -1013,9 +1011,7 @@
pokeUserActivityLocked(eventEntry);
- for (size_t i = 0; i < inputTargets.size(); i++) {
- const InputTarget& inputTarget = inputTargets.itemAt(i);
-
+ for (const InputTarget& inputTarget : inputTargets) {
ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);
if (connectionIndex >= 0) {
sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
@@ -1181,7 +1177,7 @@
}
int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime,
- const EventEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime) {
+ const EventEntry* entry, std::vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime) {
int32_t injectionResult;
std::string reason;
@@ -1244,7 +1240,7 @@
}
int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
- const MotionEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
+ const MotionEntry* entry, std::vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
bool* outConflictingPointerActions) {
enum InjectionPermission {
INJECTION_PERMISSION_UNKNOWN,
@@ -1460,8 +1456,7 @@
// is at least one touched foreground window.
{
bool haveForegroundWindow = false;
- for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
- const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+ for (const TouchedWindow& touchedWindow : mTempTouchState.windows) {
if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
haveForegroundWindow = true;
if (! checkInjectionPermission(touchedWindow.windowHandle,
@@ -1491,8 +1486,7 @@
sp<InputWindowHandle> foregroundWindowHandle =
mTempTouchState.getFirstForegroundWindowHandle();
const int32_t foregroundWindowUid = foregroundWindowHandle->getInfo()->ownerUid;
- for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
- const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+ for (const TouchedWindow& touchedWindow : mTempTouchState.windows) {
if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
sp<InputWindowHandle> inputWindowHandle = touchedWindow.windowHandle;
if (inputWindowHandle->getInfo()->ownerUid != foregroundWindowUid) {
@@ -1504,8 +1498,7 @@
}
// Ensure all touched foreground windows are ready for new input.
- for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
- const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+ for (const TouchedWindow& touchedWindow : mTempTouchState.windows) {
if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
// Check whether the window is ready for more input.
std::string reason = checkWindowReadyForMoreInputLocked(currentTime,
@@ -1528,10 +1521,9 @@
sp<InputWindowHandle> foregroundWindowHandle =
mTempTouchState.getFirstForegroundWindowHandle();
if (foregroundWindowHandle->getInfo()->hasWallpaper) {
- const Vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- sp<InputWindowHandle> windowHandle = windowHandles.itemAt(i);
+ const std::vector<sp<InputWindowHandle>> windowHandles =
+ getWindowHandlesLocked(displayId);
+ for (const sp<InputWindowHandle>& windowHandle : windowHandles) {
const InputWindowInfo* info = windowHandle->getInfo();
if (info->displayId == displayId
&& windowHandle->getInfo()->layoutParamsType
@@ -1549,8 +1541,7 @@
// Success! Output targets.
injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
- for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
- const TouchedWindow& touchedWindow = mTempTouchState.windows.itemAt(i);
+ for (const TouchedWindow& touchedWindow : mTempTouchState.windows) {
addWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.targetFlags,
touchedWindow.pointerIds, inputTargets);
}
@@ -1613,11 +1604,11 @@
uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
for (size_t i = 0; i < mTempTouchState.windows.size(); ) {
- TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i);
+ TouchedWindow& touchedWindow = mTempTouchState.windows[i];
if (touchedWindow.targetFlags & InputTarget::FLAG_SPLIT) {
touchedWindow.pointerIds.clearBit(pointerId);
if (touchedWindow.pointerIds.isEmpty()) {
- mTempTouchState.windows.removeAt(i);
+ mTempTouchState.windows.erase(mTempTouchState.windows.begin() + i);
continue;
}
}
@@ -1664,17 +1655,15 @@
}
void InputDispatcher::addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
- int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets) {
+ int32_t targetFlags, BitSet32 pointerIds, std::vector<InputTarget>& inputTargets) {
sp<InputChannel> inputChannel = getInputChannelLocked(windowHandle->getToken());
if (inputChannel == nullptr) {
ALOGW("Window %s already unregistered input channel", windowHandle->getName().c_str());
return;
}
- inputTargets.push();
-
const InputWindowInfo* windowInfo = windowHandle->getInfo();
- InputTarget& target = inputTargets.editTop();
+ InputTarget target;
target.inputChannel = inputChannel;
target.flags = targetFlags;
target.xOffset = - windowInfo->frameLeft;
@@ -1683,26 +1672,26 @@
target.windowXScale = windowInfo->windowXScale;
target.windowYScale = windowInfo->windowYScale;
target.pointerIds = pointerIds;
+ inputTargets.push_back(target);
}
-void InputDispatcher::addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets,
+void InputDispatcher::addMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets,
int32_t displayId, float xOffset, float yOffset) {
- std::unordered_map<int32_t, Vector<sp<InputChannel>>>::const_iterator it =
+ std::unordered_map<int32_t, std::vector<sp<InputChannel>>>::const_iterator it =
mMonitoringChannelsByDisplay.find(displayId);
if (it != mMonitoringChannelsByDisplay.end()) {
- const Vector<sp<InputChannel>>& monitoringChannels = it->second;
+ const std::vector<sp<InputChannel>>& monitoringChannels = it->second;
const size_t numChannels = monitoringChannels.size();
for (size_t i = 0; i < numChannels; i++) {
- inputTargets.push();
-
- InputTarget& target = inputTargets.editTop();
+ InputTarget target;
target.inputChannel = monitoringChannels[i];
target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
target.xOffset = xOffset;
target.yOffset = yOffset;
target.pointerIds.clear();
target.globalScaleFactor = 1.0f;
+ inputTargets.push_back(target);
}
} else {
// If there is no monitor channel registered or all monitor channel unregistered,
@@ -1735,10 +1724,8 @@
bool InputDispatcher::isWindowObscuredAtPointLocked(
const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const {
int32_t displayId = windowHandle->getInfo()->displayId;
- const Vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- sp<InputWindowHandle> otherHandle = windowHandles.itemAt(i);
+ const std::vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
+ for (const sp<InputWindowHandle>& otherHandle : windowHandles) {
if (otherHandle == windowHandle) {
break;
}
@@ -1756,11 +1743,9 @@
bool InputDispatcher::isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const {
int32_t displayId = windowHandle->getInfo()->displayId;
- const Vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
+ const std::vector<sp<InputWindowHandle>> windowHandles = getWindowHandlesLocked(displayId);
const InputWindowInfo* windowInfo = windowHandle->getInfo();
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- sp<InputWindowHandle> otherHandle = windowHandles.itemAt(i);
+ for (const sp<InputWindowHandle>& otherHandle : windowHandles) {
if (otherHandle == windowHandle) {
break;
}
@@ -2333,7 +2318,7 @@
void InputDispatcher::synthesizeCancelationEventsForMonitorsLocked (
const CancelationOptions& options) {
for (auto& it : mMonitoringChannelsByDisplay) {
- const Vector<sp<InputChannel>>& monitoringChannels = it.second;
+ const std::vector<sp<InputChannel>>& monitoringChannels = it.second;
const size_t numChannels = monitoringChannels.size();
for (size_t i = 0; i < numChannels; i++) {
synthesizeCancelationEventsForInputChannelLocked(monitoringChannels[i], options);
@@ -2358,11 +2343,11 @@
nsecs_t currentTime = now();
- Vector<EventEntry*> cancelationEvents;
+ std::vector<EventEntry*> cancelationEvents;
connection->inputState.synthesizeCancelationEvents(currentTime,
cancelationEvents, options);
- if (!cancelationEvents.isEmpty()) {
+ if (!cancelationEvents.empty()) {
#if DEBUG_OUTBOUND_EVENT_DETAILS
ALOGD("channel '%s' ~ Synthesized %zu cancelation events to bring channel back in sync "
"with reality: %s, mode=%d.",
@@ -2370,7 +2355,7 @@
options.reason, options.mode);
#endif
for (size_t i = 0; i < cancelationEvents.size(); i++) {
- EventEntry* cancelationEventEntry = cancelationEvents.itemAt(i);
+ EventEntry* cancelationEventEntry = cancelationEvents[i];
switch (cancelationEventEntry->type) {
case EventEntry::TYPE_KEY:
logOutboundKeyDetails("cancel - ",
@@ -3011,24 +2996,23 @@
}
}
-Vector<sp<InputWindowHandle>> InputDispatcher::getWindowHandlesLocked(int32_t displayId) const {
- std::unordered_map<int32_t, Vector<sp<InputWindowHandle>>>::const_iterator it =
+std::vector<sp<InputWindowHandle>> InputDispatcher::getWindowHandlesLocked(
+ int32_t displayId) const {
+ std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>::const_iterator it =
mWindowHandlesByDisplay.find(displayId);
if(it != mWindowHandlesByDisplay.end()) {
return it->second;
}
// Return an empty one if nothing found.
- return Vector<sp<InputWindowHandle>>();
+ return std::vector<sp<InputWindowHandle>>();
}
sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked(
const sp<IBinder>& windowHandleToken) const {
for (auto& it : mWindowHandlesByDisplay) {
- const Vector<sp<InputWindowHandle>> windowHandles = it.second;
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
+ const std::vector<sp<InputWindowHandle>> windowHandles = it.second;
+ for (const sp<InputWindowHandle>& windowHandle : windowHandles) {
if (windowHandle->getToken() == windowHandleToken) {
return windowHandle;
}
@@ -3039,11 +3023,9 @@
bool InputDispatcher::hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const {
for (auto& it : mWindowHandlesByDisplay) {
- const Vector<sp<InputWindowHandle>> windowHandles = it.second;
- size_t numWindows = windowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- if (windowHandles.itemAt(i)->getToken()
- == windowHandle->getToken()) {
+ const std::vector<sp<InputWindowHandle>> windowHandles = it.second;
+ for (const sp<InputWindowHandle>& handle : windowHandles) {
+ if (handle->getToken() == windowHandle->getToken()) {
if (windowHandle->getInfo()->displayId != it.first) {
ALOGE("Found window %s in display %" PRId32
", but it should belong to display %" PRId32,
@@ -3072,7 +3054,7 @@
* For focused handle, check if need to change and send a cancel event to previous one.
* For removed handle, check if need to send a cancel event if already in touch.
*/
-void InputDispatcher::setInputWindows(const Vector<sp<InputWindowHandle>>& inputWindowHandles,
+void InputDispatcher::setInputWindows(const std::vector<sp<InputWindowHandle>>& inputWindowHandles,
int32_t displayId, const sp<ISetInputWindowsListener>& setInputWindowsListener) {
#if DEBUG_FOCUS
ALOGD("setInputWindows displayId=%" PRId32, displayId);
@@ -3081,28 +3063,27 @@
std::scoped_lock _l(mLock);
// Copy old handles for release if they are no longer present.
- const Vector<sp<InputWindowHandle>> oldWindowHandles = getWindowHandlesLocked(displayId);
+ const std::vector<sp<InputWindowHandle>> oldWindowHandles =
+ getWindowHandlesLocked(displayId);
sp<InputWindowHandle> newFocusedWindowHandle = nullptr;
bool foundHoveredWindow = false;
- if (inputWindowHandles.isEmpty()) {
+ if (inputWindowHandles.empty()) {
// Remove all handles on a display if there are no windows left.
mWindowHandlesByDisplay.erase(displayId);
} else {
// Since we compare the pointer of input window handles across window updates, we need
// to make sure the handle object for the same window stays unchanged across updates.
- const Vector<sp<InputWindowHandle>>& oldHandles = mWindowHandlesByDisplay[displayId];
+ const std::vector<sp<InputWindowHandle>>& oldHandles =
+ mWindowHandlesByDisplay[displayId];
std::unordered_map<sp<IBinder>, sp<InputWindowHandle>, IBinderHash> oldHandlesByTokens;
- for (size_t i = 0; i < oldHandles.size(); i++) {
- const sp<InputWindowHandle>& handle = oldHandles.itemAt(i);
+ for (const sp<InputWindowHandle>& handle : oldHandles) {
oldHandlesByTokens[handle->getToken()] = handle;
}
- const size_t numWindows = inputWindowHandles.size();
- Vector<sp<InputWindowHandle>> newHandles;
- for (size_t i = 0; i < numWindows; i++) {
- const sp<InputWindowHandle>& handle = inputWindowHandles.itemAt(i);
+ std::vector<sp<InputWindowHandle>> newHandles;
+ for (const sp<InputWindowHandle>& handle : inputWindowHandles) {
if (!handle->updateInfo() || (getInputChannelLocked(handle->getToken()) == nullptr
&& handle->getInfo()->portalToDisplayId == ADISPLAY_ID_NONE)) {
ALOGE("Window handle %s has no registered input channel",
@@ -3127,8 +3108,7 @@
}
}
- for (size_t i = 0; i < newHandles.size(); i++) {
- const sp<InputWindowHandle>& windowHandle = newHandles.itemAt(i);
+ for (const sp<InputWindowHandle>& windowHandle : newHandles) {
// Set newFocusedWindowHandle to the top most focused window instead of the last one
if (!newFocusedWindowHandle && windowHandle->getInfo()->hasFocus
&& windowHandle->getInfo()->visible) {
@@ -3184,7 +3164,7 @@
if (stateIndex >= 0) {
TouchState& state = mTouchStatesByDisplay.editValueAt(stateIndex);
for (size_t i = 0; i < state.windows.size(); ) {
- TouchedWindow& touchedWindow = state.windows.editItemAt(i);
+ TouchedWindow& touchedWindow = state.windows[i];
if (!hasWindowHandleLocked(touchedWindow.windowHandle)) {
#if DEBUG_FOCUS
ALOGD("Touched window was removed: %s in display %" PRId32,
@@ -3198,7 +3178,7 @@
synthesizeCancelationEventsForInputChannelLocked(
touchedInputChannel, options);
}
- state.windows.removeAt(i);
+ state.windows.erase(state.windows.begin() + i);
} else {
++i;
}
@@ -3209,9 +3189,7 @@
// This ensures that unused input channels are released promptly.
// Otherwise, they might stick around until the window handle is destroyed
// which might not happen until the next GC.
- size_t numWindows = oldWindowHandles.size();
- for (size_t i = 0; i < numWindows; i++) {
- const sp<InputWindowHandle>& oldWindowHandle = oldWindowHandles.itemAt(i);
+ for (const sp<InputWindowHandle>& oldWindowHandle : oldWindowHandles) {
if (!hasWindowHandleLocked(oldWindowHandle)) {
#if DEBUG_FOCUS
ALOGD("Window went away: %s", oldWindowHandle->getName().c_str());
@@ -3415,7 +3393,7 @@
int32_t oldTargetFlags = touchedWindow.targetFlags;
BitSet32 pointerIds = touchedWindow.pointerIds;
- state.windows.removeAt(i);
+ state.windows.erase(state.windows.begin() + i);
int32_t newTargetFlags = oldTargetFlags
& (InputTarget::FLAG_FOREGROUND
@@ -3531,7 +3509,7 @@
dump += StringPrintf(INDENT2 "%d: down=%s, split=%s, deviceId=%d, source=0x%08x\n",
state.displayId, toString(state.down), toString(state.split),
state.deviceId, state.source);
- if (!state.windows.isEmpty()) {
+ if (!state.windows.empty()) {
dump += INDENT3 "Windows:\n";
for (size_t i = 0; i < state.windows.size(); i++) {
const TouchedWindow& touchedWindow = state.windows[i];
@@ -3543,10 +3521,10 @@
} else {
dump += INDENT3 "Windows: <none>\n";
}
- if (!state.portalWindows.isEmpty()) {
+ if (!state.portalWindows.empty()) {
dump += INDENT3 "Portal windows:\n";
for (size_t i = 0; i < state.portalWindows.size(); i++) {
- const sp<InputWindowHandle> portalWindowHandle = state.portalWindows.itemAt(i);
+ const sp<InputWindowHandle> portalWindowHandle = state.portalWindows[i];
dump += StringPrintf(INDENT4 "%zu: name='%s'\n",
i, portalWindowHandle->getName().c_str());
}
@@ -3558,12 +3536,12 @@
if (!mWindowHandlesByDisplay.empty()) {
for (auto& it : mWindowHandlesByDisplay) {
- const Vector<sp<InputWindowHandle>> windowHandles = it.second;
+ const std::vector<sp<InputWindowHandle>> windowHandles = it.second;
dump += StringPrintf(INDENT "Display: %" PRId32 "\n", it.first);
- if (!windowHandles.isEmpty()) {
+ if (!windowHandles.empty()) {
dump += INDENT2 "Windows:\n";
for (size_t i = 0; i < windowHandles.size(); i++) {
- const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
+ const sp<InputWindowHandle>& windowHandle = windowHandles[i];
const InputWindowInfo* windowInfo = windowHandle->getInfo();
dump += StringPrintf(INDENT3 "%zu: name='%s', displayId=%d, "
@@ -3600,7 +3578,7 @@
if (!mMonitoringChannelsByDisplay.empty()) {
for (auto& it : mMonitoringChannelsByDisplay) {
- const Vector<sp<InputChannel>>& monitoringChannels = it.second;
+ const std::vector<sp<InputChannel>>& monitoringChannels = it.second;
dump += StringPrintf(INDENT "MonitoringChannels in display %" PRId32 ":\n", it.first);
const size_t numChannels = monitoringChannels.size();
for (size_t i = 0; i < numChannels; i++) {
@@ -3754,9 +3732,9 @@
// Store monitor channel by displayId.
if (monitor) {
- Vector<sp<InputChannel>>& monitoringChannels =
+ std::vector<sp<InputChannel>>& monitoringChannels =
mMonitoringChannelsByDisplay[displayId];
- monitoringChannels.push(inputChannel);
+ monitoringChannels.push_back(inputChannel);
}
mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this);
@@ -3817,11 +3795,11 @@
void InputDispatcher::removeMonitorChannelLocked(const sp<InputChannel>& inputChannel) {
for (auto it = mMonitoringChannelsByDisplay.begin();
it != mMonitoringChannelsByDisplay.end(); ) {
- Vector<sp<InputChannel>>& monitoringChannels = it->second;
+ std::vector<sp<InputChannel>>& monitoringChannels = it->second;
const size_t numChannels = monitoringChannels.size();
for (size_t i = 0; i < numChannels; i++) {
if (monitoringChannels[i] == inputChannel) {
- monitoringChannels.removeAt(i);
+ monitoringChannels.erase(monitoringChannels.begin() + i);
break;
}
}
@@ -4495,13 +4473,12 @@
}
bool InputDispatcher::InputState::isNeutral() const {
- return mKeyMementos.isEmpty() && mMotionMementos.isEmpty();
+ return mKeyMementos.empty() && mMotionMementos.empty();
}
bool InputDispatcher::InputState::isHovering(int32_t deviceId, uint32_t source,
int32_t displayId) const {
- for (size_t i = 0; i < mMotionMementos.size(); i++) {
- const MotionMemento& memento = mMotionMementos.itemAt(i);
+ for (const MotionMemento& memento : mMotionMementos) {
if (memento.deviceId == deviceId
&& memento.source == source
&& memento.displayId == displayId
@@ -4527,7 +4504,7 @@
}
ssize_t index = findKeyMemento(entry);
if (index >= 0) {
- mKeyMementos.removeAt(index);
+ mKeyMementos.erase(mKeyMementos.begin() + index);
return true;
}
/* FIXME: We can't just drop the key up event because that prevents creating
@@ -4552,7 +4529,7 @@
case AKEY_EVENT_ACTION_DOWN: {
ssize_t index = findKeyMemento(entry);
if (index >= 0) {
- mKeyMementos.removeAt(index);
+ mKeyMementos.erase(mKeyMementos.begin() + index);
}
addKeyMemento(entry, flags);
return true;
@@ -4571,7 +4548,7 @@
case AMOTION_EVENT_ACTION_CANCEL: {
ssize_t index = findMotionMemento(entry, false /*hovering*/);
if (index >= 0) {
- mMotionMementos.removeAt(index);
+ mMotionMementos.erase(mMotionMementos.begin() + index);
return true;
}
#if DEBUG_OUTBOUND_EVENT_DETAILS
@@ -4585,7 +4562,7 @@
case AMOTION_EVENT_ACTION_DOWN: {
ssize_t index = findMotionMemento(entry, false /*hovering*/);
if (index >= 0) {
- mMotionMementos.removeAt(index);
+ mMotionMementos.erase(mMotionMementos.begin() + index);
}
addMotionMemento(entry, flags, false /*hovering*/);
return true;
@@ -4610,9 +4587,9 @@
// anything generating fallback events (e.g. DPad keys for joystick movements).
if (index >= 0) {
if (entry->pointerCoords[0].isEmpty()) {
- mMotionMementos.removeAt(index);
+ mMotionMementos.erase(mMotionMementos.begin() + index);
} else {
- MotionMemento& memento = mMotionMementos.editItemAt(index);
+ MotionMemento& memento = mMotionMementos[index];
memento.setPointers(entry);
}
} else if (!entry->pointerCoords[0].isEmpty()) {
@@ -4623,7 +4600,7 @@
return true;
}
if (index >= 0) {
- MotionMemento& memento = mMotionMementos.editItemAt(index);
+ MotionMemento& memento = mMotionMementos[index];
memento.setPointers(entry);
return true;
}
@@ -4638,7 +4615,7 @@
case AMOTION_EVENT_ACTION_HOVER_EXIT: {
ssize_t index = findMotionMemento(entry, true /*hovering*/);
if (index >= 0) {
- mMotionMementos.removeAt(index);
+ mMotionMementos.erase(mMotionMementos.begin() + index);
return true;
}
#if DEBUG_OUTBOUND_EVENT_DETAILS
@@ -4653,7 +4630,7 @@
case AMOTION_EVENT_ACTION_HOVER_MOVE: {
ssize_t index = findMotionMemento(entry, true /*hovering*/);
if (index >= 0) {
- mMotionMementos.removeAt(index);
+ mMotionMementos.erase(mMotionMementos.begin() + index);
}
addMotionMemento(entry, flags, true /*hovering*/);
return true;
@@ -4666,7 +4643,7 @@
ssize_t InputDispatcher::InputState::findKeyMemento(const KeyEntry* entry) const {
for (size_t i = 0; i < mKeyMementos.size(); i++) {
- const KeyMemento& memento = mKeyMementos.itemAt(i);
+ const KeyMemento& memento = mKeyMementos[i];
if (memento.deviceId == entry->deviceId
&& memento.source == entry->source
&& memento.displayId == entry->displayId
@@ -4681,7 +4658,7 @@
ssize_t InputDispatcher::InputState::findMotionMemento(const MotionEntry* entry,
bool hovering) const {
for (size_t i = 0; i < mMotionMementos.size(); i++) {
- const MotionMemento& memento = mMotionMementos.itemAt(i);
+ const MotionMemento& memento = mMotionMementos[i];
if (memento.deviceId == entry->deviceId
&& memento.source == entry->source
&& memento.displayId == entry->displayId
@@ -4693,8 +4670,7 @@
}
void InputDispatcher::InputState::addKeyMemento(const KeyEntry* entry, int32_t flags) {
- mKeyMementos.push();
- KeyMemento& memento = mKeyMementos.editTop();
+ KeyMemento memento;
memento.deviceId = entry->deviceId;
memento.source = entry->source;
memento.displayId = entry->displayId;
@@ -4704,12 +4680,12 @@
memento.flags = flags;
memento.downTime = entry->downTime;
memento.policyFlags = entry->policyFlags;
+ mKeyMementos.push_back(memento);
}
void InputDispatcher::InputState::addMotionMemento(const MotionEntry* entry,
int32_t flags, bool hovering) {
- mMotionMementos.push();
- MotionMemento& memento = mMotionMementos.editTop();
+ MotionMemento memento;
memento.deviceId = entry->deviceId;
memento.source = entry->source;
memento.displayId = entry->displayId;
@@ -4720,6 +4696,7 @@
memento.setPointers(entry);
memento.hovering = hovering;
memento.policyFlags = entry->policyFlags;
+ mMotionMementos.push_back(memento);
}
void InputDispatcher::InputState::MotionMemento::setPointers(const MotionEntry* entry) {
@@ -4731,23 +4708,21 @@
}
void InputDispatcher::InputState::synthesizeCancelationEvents(nsecs_t currentTime,
- Vector<EventEntry*>& outEvents, const CancelationOptions& options) {
- for (size_t i = 0; i < mKeyMementos.size(); i++) {
- const KeyMemento& memento = mKeyMementos.itemAt(i);
+ std::vector<EventEntry*>& outEvents, const CancelationOptions& options) {
+ for (KeyMemento& memento : mKeyMementos) {
if (shouldCancelKey(memento, options)) {
- outEvents.push(new KeyEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime,
+ outEvents.push_back(new KeyEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime,
memento.deviceId, memento.source, memento.displayId, memento.policyFlags,
AKEY_EVENT_ACTION_UP, memento.flags | AKEY_EVENT_FLAG_CANCELED,
memento.keyCode, memento.scanCode, memento.metaState, 0, memento.downTime));
}
}
- for (size_t i = 0; i < mMotionMementos.size(); i++) {
- const MotionMemento& memento = mMotionMementos.itemAt(i);
+ for (const MotionMemento& memento : mMotionMementos) {
if (shouldCancelMotion(memento, options)) {
const int32_t action = memento.hovering ?
AMOTION_EVENT_ACTION_HOVER_EXIT : AMOTION_EVENT_ACTION_CANCEL;
- outEvents.push(new MotionEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime,
+ outEvents.push_back(new MotionEntry(SYNTHESIZED_EVENT_SEQUENCE_NUM, currentTime,
memento.deviceId, memento.source, memento.displayId, memento.policyFlags,
action, 0 /*actionButton*/, memento.flags, AMETA_NONE, 0 /*buttonState*/,
MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE,
@@ -4766,19 +4741,19 @@
void InputDispatcher::InputState::copyPointerStateTo(InputState& other) const {
for (size_t i = 0; i < mMotionMementos.size(); i++) {
- const MotionMemento& memento = mMotionMementos.itemAt(i);
+ const MotionMemento& memento = mMotionMementos[i];
if (memento.source & AINPUT_SOURCE_CLASS_POINTER) {
for (size_t j = 0; j < other.mMotionMementos.size(); ) {
- const MotionMemento& otherMemento = other.mMotionMementos.itemAt(j);
+ const MotionMemento& otherMemento = other.mMotionMementos[j];
if (memento.deviceId == otherMemento.deviceId
&& memento.source == otherMemento.source
&& memento.displayId == otherMemento.displayId) {
- other.mMotionMementos.removeAt(j);
+ other.mMotionMementos.erase(other.mMotionMementos.begin() + j);
} else {
j += 1;
}
}
- other.mMotionMementos.push(memento);
+ other.mMotionMementos.push_back(memento);
}
}
}
@@ -4940,7 +4915,7 @@
}
for (size_t i = 0; i < windows.size(); i++) {
- TouchedWindow& touchedWindow = windows.editItemAt(i);
+ TouchedWindow& touchedWindow = windows[i];
if (touchedWindow.windowHandle == windowHandle) {
touchedWindow.targetFlags |= targetFlags;
if (targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
@@ -4951,19 +4926,17 @@
}
}
- windows.push();
-
- TouchedWindow& touchedWindow = windows.editTop();
+ TouchedWindow touchedWindow;
touchedWindow.windowHandle = windowHandle;
touchedWindow.targetFlags = targetFlags;
touchedWindow.pointerIds = pointerIds;
+ windows.push_back(touchedWindow);
}
void InputDispatcher::TouchState::addPortalWindow(const sp<InputWindowHandle>& windowHandle) {
size_t numWindows = portalWindows.size();
for (size_t i = 0; i < numWindows; i++) {
- sp<InputWindowHandle> portalWindowHandle = portalWindows.itemAt(i);
- if (portalWindowHandle == windowHandle) {
+ if (portalWindows[i] == windowHandle) {
return;
}
}
@@ -4972,8 +4945,8 @@
void InputDispatcher::TouchState::removeWindow(const sp<InputWindowHandle>& windowHandle) {
for (size_t i = 0; i < windows.size(); i++) {
- if (windows.itemAt(i).windowHandle == windowHandle) {
- windows.removeAt(i);
+ if (windows[i].windowHandle == windowHandle) {
+ windows.erase(windows.begin() + i);
return;
}
}
@@ -4981,8 +4954,8 @@
void InputDispatcher::TouchState::removeWindowByToken(const sp<IBinder>& token) {
for (size_t i = 0; i < windows.size(); i++) {
- if (windows.itemAt(i).windowHandle->getToken() == token) {
- windows.removeAt(i);
+ if (windows[i].windowHandle->getToken() == token) {
+ windows.erase(windows.begin() + i);
return;
}
}
@@ -4990,21 +4963,21 @@
void InputDispatcher::TouchState::filterNonAsIsTouchWindows() {
for (size_t i = 0 ; i < windows.size(); ) {
- TouchedWindow& window = windows.editItemAt(i);
+ TouchedWindow& window = windows[i];
if (window.targetFlags & (InputTarget::FLAG_DISPATCH_AS_IS
| InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER)) {
window.targetFlags &= ~InputTarget::FLAG_DISPATCH_MASK;
window.targetFlags |= InputTarget::FLAG_DISPATCH_AS_IS;
i += 1;
} else {
- windows.removeAt(i);
+ windows.erase(windows.begin() + i);
}
}
}
sp<InputWindowHandle> InputDispatcher::TouchState::getFirstForegroundWindowHandle() const {
for (size_t i = 0; i < windows.size(); i++) {
- const TouchedWindow& window = windows.itemAt(i);
+ const TouchedWindow& window = windows[i];
if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
return window.windowHandle;
}
@@ -5015,8 +4988,7 @@
bool InputDispatcher::TouchState::isSlippery() const {
// Must have exactly one foreground window.
bool haveSlipperyForegroundWindow = false;
- for (size_t i = 0; i < windows.size(); i++) {
- const TouchedWindow& window = windows.itemAt(i);
+ for (const TouchedWindow& window : windows) {
if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
if (haveSlipperyForegroundWindow
|| !(window.windowHandle->getInfo()->layoutParamsFlags