MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / resolvePageAndGetSpecifiedAction

Method resolvePageAndGetSpecifiedAction

native/events/Preference.cpp:116–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114 }
115
116 ActionPtr Preference::resolvePageAndGetSpecifiedAction(const std::string &activity,
117 const ElementPtr &rootXML) {
118 if (nullptr != rootXML)
119 this->resolvePage(activity, rootXML);
120
121 // resolve action
122 ActionPtr returnAction = nullptr;
123 if (this->_currentActions.empty()) {
124 for (const CustomEventPtr &customEvent: this->_customEvents) {
125 float eventRate = randomInt(0, 10) / 10.0;
126 BLOG("customEvent activities %s, page event is %s, event times %d , rate is %f/%f",
127 customEvent->activity.c_str(),
128 activity.c_str(), customEvent->times, eventRate, customEvent->prob);
129 if (eventRate < customEvent->prob &&
130 customEvent->times > 0 &&
131 customEvent->activity == activity) {
132 if (!this->_currentActions.empty()) {
133 std::queue<ActionPtr> emptyActions;
134 this->_currentActions.swap(emptyActions);
135 BLOG("custom event clear happened when another event matched");
136 }
137 BLOG("custom event matched: %s actions size: %d", activity.c_str(),
138 (int) customEvent->actions.size());
139 for (const auto &matchedAction: customEvent->actions) {
140 this->_currentActions.push(matchedAction);
141 }
142 customEvent->times--;
143 }
144 }
145 }
146 if (!this->_currentActions.empty()) {
147 BLOG("check custom action queue");
148 auto frontAction = this->_currentActions.front();
149 this->_currentActions.pop();
150 if (frontAction->getActionType() >= ActionType::CLICK &&
151 frontAction->getActionType() <= ActionType::SCROLL_RIGHT_LEFT) {
152 // android action type
153 auto customAction = std::dynamic_pointer_cast<CustomAction>(frontAction);
154 if (rootXML && !this->patchActionBounds(customAction, rootXML)) {
155 return nullptr; // do nothing when action match failed
156 }
157 BLOG("custom action %s happened", customAction->xpath->toString().c_str());
158 BLOG("custom action: %s happened", customAction->toString().c_str());
159 return customAction;
160 }
161 }
162 return returnAction;
163 }
164
165 /// Used for get the bounding boxes of the specified actions
166 /// \param action The action specified by users, need to query its bounding box from XML tree

Callers 1

getOperateOptMethod · 0.80

Calls 9

resolvePageMethod · 0.95
patchActionBoundsMethod · 0.95
randomIntFunction · 0.85
emptyMethod · 0.80
getActionTypeMethod · 0.80
c_strMethod · 0.45
swapMethod · 0.45
sizeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected