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

Method loadActions

native/events/Preference.cpp:572–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570 }
571
572 void Preference::loadActions() {
573 std::string fileContent = loadFileContent(ActionConfigFilePath);
574 if (fileContent.empty())
575 return;
576 BLOG("loading actions : %s", ActionConfigFilePath.c_str());
577 try {
578 ::nlohmann::json actionEvents = ::nlohmann::json::parse(fileContent);
579 for (const ::nlohmann::json &actionEvent: actionEvents) {
580 CustomEventPtr customEvent = std::make_shared<CustomEvent>();
581 customEvent->prob = static_cast<float>(getJsonValue<float>(actionEvent, "prob", 1));
582 customEvent->times = getJsonValue<int>(actionEvent, "times", 1);
583 customEvent->activity = getJsonValue<std::string>(actionEvent, "activity", "");
584 BLOG("loading event %s", customEvent->activity.c_str());
585 ::nlohmann::json actions = getJsonValue<::nlohmann::json>(actionEvent, "actions",
586 ::nlohmann::json());
587 for (const ::nlohmann::json &action: actions) {
588 std::string actionTypeString = getJsonValue<std::string>(action, "action", "");
589 auto customAction = std::make_shared<CustomAction>(
590 stringToActionType(actionTypeString));
591 std::string xPathString = getJsonValue<std::string>(action, "xpath", "");
592 BLOG("loading action %s", xPathString.c_str());
593 customAction->xpath = std::make_shared<Xpath>(xPathString);
594 customAction->text = getJsonValue<std::string>(action, "text", "");
595 customAction->clearText = getJsonValue<bool>(action, "clearText", false);
596 customAction->throttle = getJsonValue<int>(action, "throttle", 1000);
597 customAction->waitTime = getJsonValue<int>(action, "wait", 0);
598 customAction->adbInput = getJsonValue<bool>(action, "useAdbInput", false);
599 customAction->allowFuzzing = false;
600 if (customAction->getActionType() == ActionType::SHELL_EVENT) {
601 customAction->command = getJsonValue<std::string>(actions, "command", "");
602 }
603 BLOG("loading action %s", xPathString.c_str());
604 customEvent->actions.push_back(customAction);
605 }
606 this->_customEvents.push_back(customEvent);
607 }
608 } catch (nlohmann::json::exception &ex) {
609 BLOGE("parse actions error happened: id,%d: %s", ex.id, ex.what());
610 }
611 }
612
613 void Preference::loadBlackWidgets() {
614 std::string fileContent = fastbotx::Preference::loadFileContent(BlackWidgetFilePath);

Callers

nothing calls this directly

Calls 7

parseFunction · 0.85
stringToActionTypeFunction · 0.85
emptyMethod · 0.80
getActionTypeMethod · 0.80
push_backMethod · 0.80
whatMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected