Comments (2)
修改上述提到的问题后,仍然有发现黑控件不生效的情况,通过走查日志发现另一个可能的代码逻辑问题。
在日志中看到配置中的多个 black widget,在 native 层日志均有打印识别到,但是在运行到实际判断 point 是否位于黑控件区域时,却打印 Rects: 1 ,即当前Activity中仅保存有一个黑控件区域,这与配置中的多个黑控件不符,因此导致黑控件不生效。
- 通过走查代码发现,在处理黑控件时逻辑如下
void Preference::resolveBlackWidgets(const ElementPtr &rootXML, const std::string &activity) {
// black widgets
if (!this->_blackWidgetActions.empty()) {
for (const CustomActionPtr &blackWidgetAction: this->_blackWidgetActions) {
if (!activity.empty() && blackWidgetAction->activity != activity)
continue;
XpathPtr xpath = blackWidgetAction->xpath;
// read the bounds of black widget from the config
std::vector<float> bounds = blackWidgetAction->bounds;
bool hasBoundingBox = bounds.size() >= 4;
if (nullptr == this->_rootScreenSize) {
BLOGE("black widget match failed %s", "No root node in current page");
return;
}
if (hasBoundingBox && bounds[1] <= 1.1 && bounds[3] <= 1.1) {
int rootWidth = this->_rootScreenSize->right;// - rootSize->left;
int rootHeight = this->_rootScreenSize->bottom;// - rootSize->top;
bounds[0] = bounds[0] * static_cast<float>(rootWidth);
bounds[1] = bounds[1] * static_cast<float>(rootHeight);
bounds[2] = bounds[2] * static_cast<float>(rootWidth);
bounds[3] = bounds[3] * static_cast<float>(rootHeight);
}
bool xpathExistsInPage;
std::vector<ElementPtr> xpathElements;
if (xpath) {
this->findMatchedElements(xpathElements, xpath, rootXML);
BDLOG("find black widget %s %d", xpath->toString().c_str(),
(int) xpathElements.size());
}
xpathExistsInPage = xpath && !xpathElements.empty();
std::vector<RectPtr> cachedRects; // cache black widgets
if (xpathExistsInPage && !hasBoundingBox) {
BLOG("black widget xpath %s, has no bounds matched %d nodes",
xpath->toString().c_str(), (int) xpathElements.size());
for (const auto &matchedElement: xpathElements) {
BLOG("black widget, delete node: %s depends xpath",
matchedElement->getResourceID().c_str());
cachedRects.push_back(matchedElement->getBounds());
matchedElement->deleteElement();
}
}
else if (xpathExistsInPage || (!xpath && hasBoundingBox)) {
RectPtr rejectRect = std::make_shared<Rect>(bounds[0], bounds[1], bounds[2],
bounds[3]);
cachedRects.push_back(rejectRect);
std::vector<ElementPtr> elementsInRejectRect;
rootXML->recursiveElements([&rejectRect](const ElementPtr &child) -> bool {
return rejectRect->contains(child->getBounds()->center());
}, elementsInRejectRect);
BLOG("black widget xpath %s, with bounds matched %d nodes",
xpath ? xpath->toString().c_str() : "none",
(int) elementsInRejectRect.size());
for (const auto &elementInRejectRect: elementsInRejectRect) {
if (elementInRejectRect) {
BLOG("black widget, delete node: %s depends xpath",
elementInRejectRect->getResourceID().c_str());
elementInRejectRect->deleteElement();
}
}
}
this->_cachedBlackWidgetRects[activity] = cachedRects;
}
}
}
以上代码中,在 for 循环内定义了一个变量 std::vector<float> bounds = blackWidgetAction->bounds;
,并在当前for 循环结束时,将识别到的cachedRects 赋值给 _cachedBlackWidgetRects Map 中的 activity 对应的值,这样导致在循环结束后,只有最后一个黑控件的区域被保存在 _cachedBlackWidgetRects 中,因此导致黑控件不生效。
解决方案
修改 resolveBlackWidgets 函数,将 cachedRects 定义在 for 在 for 循环外部,这样在循环结束后,所有的黑控件区域都会被保存在 _cachedBlackWidgetRects 中,代码如下
void Preference::resolveBlackWidgets(const ElementPtr &rootXML, const std::string &activity) {
// black widgets
if (!this->_blackWidgetActions.empty()) {
std::vector<RectPtr> cachedRects; // cache black widgets
for (const CustomActionPtr &blackWidgetAction: this->_blackWidgetActions) {
// ... ...
}
this->_cachedBlackWidgetRects[activity] = cachedRects;
}
}
能力有限,无法肯定该问题定位是否准确,并且修改有效,劳烦项目管理员百忙之后可以抽时间审查一下,万分感谢
from fastbot_android.
你好,后面这部分修改 是否已存在于你第一个问题提供的 so包链接中?
from fastbot_android.
Related Issues (20)
- reuseModel 中存在重复数据
- Is there a way to pause execution?
- fastbot停留在某个页面事件很长并提前停止运行 HOT 1
- How to debug the application
- 多次执行是reuse模型读取文件时报错 HOT 1
- 黑白名单不生效 HOT 1
- app卡屏
- A15报错 HOT 3
- max.xpath.actions 不生效 HOT 4
- Android V执行Fastbot报错 HOT 4
- None
- max.widget.black不生效 HOT 1
- max.xpath.actions配置没有跑到
- 大佬能出下FastBot的Debug的方式吗?是不是要做一些代码改造才可以调试。
- errors on Quest 3
- 应用防止截图
- java.lang.IncompatibleClassChangeError
- java.io.FileNotFoundException: /data/system/theme_config/theme_compatibility.xml
- 编译monkeyq.jar时报错UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: Java heap space
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastbot_android.