/**
* 检查apk主版本是否是8,如果不是会有异常发生
* 该函数可以在程序中调用,防止iec和apk版本不一致
* 适合版本 EC 8.2.0+
*/
function checkApkVersion8() {
return configWrapper.checkApkVersion8();
}
/**
* 检查apk主版本是否是9,如果不是会有异常发生
* 该函数可以在程序中调用,防止iec和apk版本不一致
* 适合版本 EC 9.1.0+
*/
function checkApkVersion9() {
return configWrapper.checkApkVersion9();
}
/**
* 读取JSON中的整型数据
*
* 运行环境: 无限制
*
* 兼容版本: Android 4.4 以上
* @param key 配置项目
* @return 整型 JSON中key对应的整型数据
*/
function readConfigInt(key) {
return configWrapper.getParamInt(key);
}
/**
* 取得配置的JSON
* @return {null|JSON} JSON数据
*/
function getConfigJSON() {
var d = configWrapper.getParams();
if (d == null || d == "") {
return null;
}
return JSON.parse(d);
}
function readConfigDouble(key) {
return configWrapper.getParamDouble(key);
}
function readConfigBoolean(key) {
return configWrapper.getParamBoolean(key);
}
/**
* 更新配置
* @param key 键
* @param value 值
* @return {boolean} true 成功,false失败
*/
function updateConfig(key, value) {
return configWrapper.updateConfig(key, value);
}
function readConfigLong(key) {
return configWrapper.getParamLong(key);
}
/**
* 读取JSON中的字符串数据
*
* 运行环境: 无限制
*
* 兼容版本: Android 4.4 以上
*
* @param key 配置项目
* @return string JSON中key对应的字符串数据
*/
function readConfigString(key) {
return javaString2string(configWrapper.getParamString(key));
}
/**
* 删除UI配置
*
* @param key 配置项目
* @return {bool} true 代表成功 false 代表失败
*/
function deleteConfig(key) {
return configWrapper.deleteConfig(key);
}
/**
* 是否是agent模式
* @return {boolean}
*/
function isAgentMode() {
if (configWrapper == null) {
return false;
}
return configWrapper.isAgentMode();
}
/**
* 是否是无障碍模式
* @return {boolean}
*/
function isAccMode() {
if (configWrapper == null) {
return false;
}
return configWrapper.isAccMode();
}
function isFastJs() {
if (configWrapper == null) {
return false;
}
//return configWrapper.isFastJs();
return false;
}
function isStableJs() {
if (configWrapper == null) {
return false;
}
//return configWrapper.isStableJs();
return true;
}
/**
* 节点选择器集合
* @constructor
*/
function S() {
this.selectors = [];
this.attr = {};
this.createSelector();
}
S.prototype.createSelector = function () {
this.attr = {};
this.selectors.push(this.attr);
};
/**
* 获取节点选择器集合的对象
* @return {S} 选择器对象
*/
S.get = function () {
return new S();
};
/**
* 获取节点信息
* @param timeout 超时时间
* @return {null|NodeInfo[]} 节点信息集合
*/
S.prototype.getNodeInfo = function (timeout) {
return getNodeInfo(this, timeout);
};
/**
* 通过选择器 获取第一个节点信息
* @param timeout 等待时间,单位是毫秒
* @return {null|NodeInfo} 对象或者null
*/
S.prototype.getOneNodeInfo = function (timeout) {
return getOneNodeInfo(this, timeout);
};
/**
* 创建一个子节点选择器
* @return {S} 选择器对象
*/
S.prototype.child = function () {
this.createSelector();
return this;
};
S.prototype.row = function (row) {
if (this.attr != null) {
this.attr["row"] = row;
}
return this;
};
S.prototype.column = function (column) {
if (this.attr != null) {
this.attr["column"] = column;
}
return this;
};
S.prototype.rowSpan = function (rowSpan) {
if (this.attr != null) {
this.attr["rowSpan"] = rowSpan;
}
return this;
};
S.prototype.columnSpan = function (columnSpan) {
if (this.attr != null) {
this.attr["columnSpan"] = columnSpan;
}
return this;
};
S.prototype.rowCount = function (rowCount) {
if (this.attr != null) {
this.attr["rowCount"] = rowCount;
}
return this;
};
S.prototype.columnCount = function (columnCount) {
if (this.attr != null) {
this.attr["columnCount"] = columnCount;
}
return this;
};
/**
* 按照属性 selected 进行选择
*
* @param selected true 或者 false
* @return {S} 节点选择器
*/
S.prototype.selected = function (selected) {
if (this.attr != null) {
this.attr["selected"] = selected;
}
return this;
};
/**
* 按照属性 visible 进行选择
*
* @param visible true 或者 false
* @return {S} 节点选择器
*/
S.prototype.visible = function (visible) {
if (this.attr != null) {
this.attr["visible"] = visible;
}
return this;
};
S.prototype.nid = function (nid) {
if (this.attr != null) {
this.attr["nid"] = nid;
}
return this;
};
/**
* 按照属性 focused 进行选择
*
* @param focused true 或者 false
* @return {S} 节点选择器
*/
S.prototype.focused = function (focused) {
if (this.attr != null) {
this.attr["focused"] = focused;
}
return this;
};
/**
* 按照属性 enabled 进行选择
*
* @param enabled true 或者 false
* @return {S} 节点选择器
*/
S.prototype.enabled = function (enabled) {
if (this.attr != null) {
this.attr["enabled"] = enabled;
}
return this;
};
/**
* 按照属性 focusable 进行选择
*
* @param focusable true 或者 false
* @return {S} 节点选择器
*/
S.prototype.focusable = function (focusable) {
if (this.attr != null) {
this.attr["focusable"] = focusable;
}
return this;
};
/**
* 按照属性 scrollable 进行选择
*
* @param scrollable true 或者 false
* @return {S} 节点选择器
*/
S.prototype.scrollable = function (scrollable) {
if (this.attr != null) {
this.attr["scrollable"] = scrollable;
}
return this;
};
/**
* 按照属性 long-clickable 进行选择
*
* @param longClickable true 或者 false
* @return {S} 节点选择器
*/
S.prototype.longClickable = function (longClickable) {
if (this.attr != null) {
this.attr["longClickable"] = longClickable;
}
return this;
};
/**
* 按照属性 clickable 进行选择
*
* @param clickable true 或者 false
* @return {S} 节点选择器
*/
S.prototype.clickable = function (clickable) {
if (this.attr != null) {
this.attr["clickable"] = clickable;
}
return this;
};
/**
* 按照属性 checked 进行选择
*
* @param checked true 或者 false
* @return {S} 节点选择器
*/
S.prototype.checked = function (checked) {
if (this.attr != null) {
this.attr["checked"] = checked;
}
return this;
};
/**
* 按照属性 checkable 进行选择
*
* @param checkable true 或者 false
* @return {S} 节点选择器
*/
S.prototype.checkable = function (checkable) {
if (this.attr != null) {
this.attr["checkable"] = checkable;
}
return this;
};
/**
* 按照属性 id 进行匹配
*
* @param id 字符串
* @return {S} 节点选择器
*/
S.prototype.id = function (id) {
if (this.attr != null) {
this.attr["id"] = id;
}
return this;
};
/**
* 按照属性 id 进行匹配, 支持正则
*
* @param id 字符串
* @return {S} 节点选择器
*/
S.prototype.idMatch = function (id) {
if (this.attr != null) {
this.attr["idMatch"] = id;
}
return this;
};
/**
* 按照属性 pkg 进行匹配
*
* @param pkg 字符串
* @return {S} 节点选择器
*/
S.prototype.pkg = function (pkg) {
if (this.attr != null) {
this.attr["pkg"] = pkg;
}
return this;
};
/**
* 按照属性 pkg 进行匹配,支持正则
*
* @param pkg 字符串
* @return {S} 节点选择器
*/
S.prototype.pkgMatch = function (pkg) {
if (this.attr != null) {
this.attr["pkgMatch"] = pkg;
}
return this;
};
/**
* 按照属性 desc 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.desc = function (value) {
if (this.attr != null) {
this.attr["desc"] = value;
}
return this;
};
/**
* 按照属性 desc 进行匹配,支持正则
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.descMatch = function (value) {
if (this.attr != null) {
this.attr["descMatch"] = value;
}
return this;
};
/**
* 按照属性 bounds 进行范围
*
* @param left 范围左边数值
* @param top 范围上边数值
* @param right 范围右边数值
* @param bottom 范围底边数值
* @return {S} 节点选择器
*/
S.prototype.bounds = function (left, top, right, bottom) {
if (this.attr != null) {
this.attr["bounds"] = left + "," + top + "," + right + "," + bottom;
}
return this;
};
/**
* 按照属性 text 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.text = function (value) {
if (this.attr != null) {
this.attr["text"] = value;
}
return this;
};
S.prototype.xpath = function (value) {
if (this.attr != null) {
this.attr["xpath"] = value;
}
return this;
};
/**
* 按照属性 text 进行匹配,支持正则
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.textMatch = function (value) {
if (this.attr != null) {
this.attr["textMatch"] = value;
}
return this;
};
/**
* 按照属性 clz 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.clz = function (value) {
if (this.attr != null) {
this.attr["clz"] = value;
}
return this;
};
/**
* 按照属性 clz 进行匹配,支持正则
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.clzMatch = function (value) {
if (this.attr != null) {
this.attr["clzMatch"] = value;
}
return this;
};
/**
* 按照属性 depth 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.depth = function (value) {
if (this.attr != null) {
this.attr["depth"] = value;
}
return this;
};
/**
* 按照属性 index 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.index = function (value) {
if (this.attr != null) {
this.attr["index"] = value;
}
return this;
};
/**
* 按照属性 drawingOrder 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.drawingOrder = function (value) {
if (this.attr != null) {
this.attr["drawingOrder"] = value;
}
return this;
};
/**
* 按照属性 childCount 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.childCount = function (value) {
if (this.attr != null) {
this.attr["childCount"] = value;
}
return this;
};
/**
* 按照属性 editable 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.editable = function (value) {
if (this.attr != null) {
this.attr["editable"] = value;
}
return this;
};
/**
* 按照属性 password 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.password = function (value) {
if (this.attr != null) {
this.attr["password"] = value;
}
return this;
};
/**
* 按照属性 dismissable 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.dismissable = function (value) {
if (this.attr != null) {
this.attr["dismissable"] = value;
}
return this;
};
/**
* 按照属性 multiLine 进行匹配
*
* @param value 字符串
* @return {S} 节点选择器
*/
S.prototype.multiLine = function (value) {
if (this.attr != null) {
this.attr["multiLine"] = value;
}
return this;
};
S.prototype.toJSONString = function () {
return JSON.stringify(this.selectors);
};
function NotificationInfo(javaNotification) {
this.seqId = null;
this.pkg = null;
this.text = null;
this.title = null;
this.subText = null;
this.infoText = null;
this.time = 0;
this.bigText = null;
this.titleBig = null;
this.summaryBig = null;
this.key = null;
if (javaNotification != null) {
this.seqId = javaNotification['seqId'];
this.pkg = javaNotification['pkg'];
this.text = javaNotification["text"];
this.title = javaNotification["title"];
this.subText = javaNotification["subText"];
this.tickerText = javaNotification["infoText"];
this.time = javaNotification["time"];
this.bigText = javaNotification["bigText"];
this.titleBig = javaNotification["titleBig"];
this.summaryBig = javaNotification["summaryBig"];
this.key = javaNotification["key"];
}
}
function ToastInfo(javaToast) {
this.pkg = null;
this.text = null;
this.time = 0;
if (javaToast != null) {
this.pkg = javaToast["pkg"];
this.text = javaToast["text"];
this.time = javaToast["time"];
}
}
function Point(javaPoint) {
this.x = 0;
this.y = 0;
if (javaPoint != null) {
this.x = javaPoint["x"];
this.y = javaPoint["y"];
}
}
Point.get = function () {
return new Point(null);
};
Point.jsonToObject = function (res) {
if (res == null || res == "") {
return null;
}
res = JSON.parse(res);
if (res == null) {
return null;
}
return new Point(res);
};
Point.prototype.setX = function (x) {
this.x = x;
return this;
};
Point.prototype.setY = function (y) {
this.y = y;
return this;
};
Point.prototype.toJSONString = function () {
return JSON.stringify(this);
};
function Rect(javaRect) {
this.top = 0;
this.bottom = 0;
this.left = 0;
this.right = 0;
this.similarity = 0;
if (javaRect != null) {
this.top = javaRect["top"];
this.bottom = javaRect["bottom"];
this.left = javaRect["left"];
this.right = javaRect["right"];
this.similarity = javaRect["similarity"];
}
}
/**
* 取得中间的坐标点
* @return {Point} 对象
*/
Rect.prototype.center = function () {
var p = new Point(null);
p.x = this.left + (this.right - this.left) / 2;
p.y = this.top + (this.bottom - this.top) / 2;
return p;
};
Rect.jsonToObject = function (res) {
if (res == null || res == "") {
return null;
}
res = JSON.parse(res);
if (res == null) {
return null;
}
return new Rect(res);
};
Rect.get = function () {
return new Rect(null);
};
Rect.prototype.setLeft = function (left) {
this.left = left;
return this;
};
Rect.prototype.setTop = function (top) {
this.top = top;
return this;
};
Rect.prototype.setRight = function (right) {
this.right = right;
return this;
};
Rect.prototype.setBottom = function (bottom) {
this.bottom = bottom;
return this;
};
Rect.prototype.toJSONString = function () {
return JSON.stringify(this);
};
function Match(javaMatch) {
this.point = null;
this.similarity = 0;
if (javaMatch != null) {
this.similarity = javaMatch["similarity"];
var d = javaMatch["point"];
if (d != null) {
this.point = new Point(d);
}
}
}
Match.prototype.toJSONString = function () {
return JSON.stringify(this);
};
function NodeInfo(javaNodeInfo) {
this.bounds = null;
this.visibleBounds = null;
this.childCount = 0;
this.clz = null;
this.desc = null;
this.pkg = null;
this.text = null;
this.checkable = false;
this.checked = false;
this.clickable = false;
this.enabled = false;
this.focusable = false;
this.focused = false;
this.longClickable = false;
this.scrollable = false;
this.selected = false;
this.id = null;
this.nid = null;
this.parentId = null;
this.index = 0;
this.depth = 0;
this.visible = false;
this.drawingOrder = 0;
this.editable = false;
this.password = false;
this.multiLine = false;
this.dismissable = false;
this.row = 0;
this.column = 0;
this.rowSpan = 0;
this.columnSpan = 0;
this.rowCount = 0;
this.columnCount = 0;
if (javaNodeInfo != null) {
if (javaNodeInfo["bounds"] != null) {
this.bounds = new Rect(javaNodeInfo["bounds"]);
}
if (javaNodeInfo["visibleBounds"] != null) {
this.visibleBounds = new Rect(javaNodeInfo["visibleBounds"]);
}
this.childCount = javaNodeInfo["childCount"];
this.row = javaNodeInfo["row"];
this.column = javaNodeInfo["column"];
this.rowSpan = javaNodeInfo["rowSpan"];
this.columnSpan = javaNodeInfo["columnSpan"];
this.rowCount = javaNodeInfo["rowCount"];
this.columnCount = javaNodeInfo["columnCount"];
this.clz = javaNodeInfo["clz"];
this.pkg = javaNodeInfo["pkg"];
this.desc = javaNodeInfo["desc"];
this.text = javaNodeInfo["text"];
this.checkable = javaNodeInfo["checkable"];
this.checked = javaNodeInfo["checked"];
this.clickable = javaNodeInfo["clickable"];
this.enabled = javaNodeInfo["enabled"];
this.focusable = javaNodeInfo["focusable"];
this.focused = javaNodeInfo["focused"];
this.longClickable = javaNodeInfo["longClickable"];
this.scrollable = javaNodeInfo["scrollable"];
this.selected = javaNodeInfo["selected"];
this.id = javaNodeInfo["id"];
this.nid = javaNodeInfo["nid"];
this.parentId = javaNodeInfo["parentId"];
this.index = javaNodeInfo["index"];
this.depth = javaNodeInfo["depth"];
this.drawingOrder = javaNodeInfo["drawingOrder"];
this.editable = javaNodeInfo["editable"];
this.password = javaNodeInfo["password"];
this.multiLine = javaNodeInfo["multiLine"];
this.dismissable = javaNodeInfo["dismissable"];
this.visible = javaNodeInfo["visible"];
}
}
/**
* 该节点的父级节点
* @return {null|NodeInfo} 对象 或者null
*/
NodeInfo.prototype.parent = function () {
return getNodeInfoParent(this);
};
/**
* 取得单个子节点
* @param index 子节点索引
* @return {null|NodeInfo} 对象 或者null
*/
NodeInfo.prototype.child = function (index) {
return getNodeInfoChild(this, index);
};
/**
* 取得所有子节点
* @return {null|NodeInfo[]} 节点集合
*/
NodeInfo.prototype.allChildren = function () {
return getNodeInfoAllChildren(this);
};
/**
* 当前节点的所有兄弟节点
* @return {null|NodeInfo[]} 节点集合
*/
NodeInfo.prototype.siblings = function () {
return getSiblingNodeInfo(this);
};
/**
* 在当前节点前面的兄弟节点
* @return {null|NodeInfo[]} 节点集合
*/
NodeInfo.prototype.previousSiblings = function () {
return getPreviousSiblingNodeInfo(this);
};
/**
* 点击中心点
* @return {boolean} true 成功
*/
NodeInfo.prototype.clickCenter = function () {
return clickCenter(this.bounds);
};
/**
* 通过选择器 获取第一个节点信息
* @param selectors 选择器
* @param timeout
* @return {null|NodeInfo} 对象或者null
*/
NodeInfo.prototype.getOneNodeInfo = function (selectors, timeout) {
if (isAccMode()) {
return acEvent.getOneNodeInfoForNode(this.nid, selectors, timeout);
} else if (isAgentMode()) {
return agentEvent.getOneNodeInfoForNode(this.nid, selectors, timeout);
}
return null;
};
/**
* 通过选择器 获取节点信息
* @param selectors 选择器
* @param timeout
* @return {null|NodeInfo[]} NodeInfo 数组
*/
NodeInfo.prototype.getNodeInfo = function (selectors, timeout) {
if (isAccMode()) {
return acEvent.getNodeInfoForNode(this.nid, selectors, timeout);
} else if (isAgentMode()) {
return agentEvent.getNodeInfoForNode(this.nid, selectors, timeout);
}
return null;
};
/**
* 在当前节点后面的兄弟节点
* @return {null|NodeInfo[]} 节点集合
*/
NodeInfo.prototype.nextSiblings = function () {
return getNextSiblingNodeInfo(this);
};
/**
* 点击节点
* @return boolean|布尔型 true 成功 ,false 失败
*/
NodeInfo.prototype.click = function () {
return clickRandomRect(this.bounds);
};
/**
* 无指针点击节点
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.clickEx = function () {
return clickExNodeInfo(this);
};
/**
* 聚焦
* @return {boolean}
*/
NodeInfo.prototype.setFocus = function () {
return setFocusNodeInfo(this);
};
/**
* 无指针长点击节点
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.longClickEx = function () {
return longClickExNodeInfo(this);
};
/**
* 向前滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollForward = function () {
return scrollForwardNodeInfo(this);
};
/**
* 向后滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollBackward = function () {
return scrollBackwardNodeInfo(this);
};
/**
* 向下滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollDown = function () {
return scrollDownNodeInfo(this);
};
/**
* 向上滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollUp = function () {
return scrollUpNodeInfo(this);
};
/**
* 向左滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollLeft = function () {
return scrollLeftNodeInfo(this);
};
/**
* 向右滚动
* @return {boolean} true 代表成功 false 代表失败
*/
NodeInfo.prototype.scrollRight = function () {
return scrollRightNodeInfo(this);
};
/**
* 对某个节点粘贴数据
* @param content 要输入的内容
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.pasteText = function (content) {
return pasteTextNodeInfo(this, content);
};
/**
* 长点击节点
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.longClick = function () {
return longClickRandomRect(this.bounds);
};
/**
* 对某个节点输入数据
* @param content 要输入的内容
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.inputText = function (content) {
return inputTextNodeInfo(this, content);
};
/**
* 使用输入法对某个节点输入数据,前提是已经设置本程序的输入法为默认输入法
* @param content 要输入的内容
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.imeInputText = function (content) {
return imeInputTextNodeInfo(this, content);
};
/**
* 使用输入法对某个节点输入数据,前提是已经设置本程序的输入法为默认输入法
* @param content 具体请看 KeyEvent.KEYCODE_*的值,例如66 = enter 67=del,84=SEARCH
* @return {boolean} true 成功 ,false 失败
*/
NodeInfo.prototype.imeInputKeyCode = function (content) {
return imeInputKeyCodeNodeInfo(this, content);
};
/**
* 清除节点文本数据
* @return {boolean} 布尔型| true代表成功
*/
NodeInfo.prototype.clearText = function () {
return clearTextFieldNodeInfo(this);
};
/**
* 该方法会刷新节点缓存
*/
NodeInfo.prototype.refresh = function () {
refreshNodeInfo(this);
};
/**
* 节点信息是否有效
*/
NodeInfo.prototype.isValid = function () {
return isValidNodeInfo(this);
};
NodeInfo.prototype.toJSONString = function () {
return JSON.stringify(this);
};
function AutoImage(uuid) {
this.uuid = uuid + "";
this.mat = false;
if (uuid != null && uuid != undefined) {
this.mat = uuid.indexOf("-mat") != -1;
}
}
AutoImage.prototype.toString = function () {
return JSON.stringify({"uuid": this.uuid, "mat": this.mat, "aiobj": true});
};
/**
* 点击文本
* @param text 文本
* @return {boolean}
*/
function clickText(text) {
if (isAccMode()) {
return acEvent.click(S.get().text(text));
} else if (isAgentMode()) {
return agentEvent.click(S.get().text(text));
}
return false;
}
/**
* 随机点击选择器的任意元素
* @param selectors 选择器对象
* @return {boolean}
*/
function clickRandom(selectors) {
if (isAccMode()) {
return acEvent.clickRandom(selectors);
} else if (isAgentMode()) {
return agentEvent.clickRandom(selectors);
}
return false;
}
/**
* 随机点击选择器的任意元素(无指针模式)
* @param selectors 选择器对象
* @return {boolean}
*/
function clickRandomEx(selectors) {
if (isAccMode()) {
return acEvent.clickRandomEx(selectors);
} else if (isAgentMode()) {
return agentEvent.clickRandomEx(selectors);
}
return false;
}
/**
* 随机点击区域中的坐标
* @param rect 区域对象
* @return {boolean}
*/
function clickRandomRect(rect) {
if (isAccMode()) {
return acEvent.clickRandomRect(rect);
} else if (isAgentMode()) {
return agentEvent.clickRandomRect(rect);
}
return false;
}
/**
* 随机长点击区域中的坐标
* @param rect 区域对象
* @return {boolean}
*/
function longClickRandomRect(rect) {
if (isAccMode()) {
return acEvent.longClickRandomRect(rect);
} else if (isAgentMode()) {
return agentEvent.longClickRandomRect(rect);
}
return false;
}
/**
* 点击选择器
* @param selectors 选择器对象
* @return {boolean}
*/
function click(selectors) {
if (isAccMode()) {
return acEvent.click(selectors);
} else if (isAgentMode()) {
return agentEvent.click(selectors);
}
return false;
}
/**
* 无指针模式点击选择器
* @param selectors 选择器对象
* @return {boolean}
*/
function clickEx(selectors) {
if (isAccMode()) {
return acEvent.clickEx(selectors);
} else if (isAgentMode()) {
return agentEvent.clickEx(selectors);
}
return false;
}
/**
* 设置节点聚焦
* @param selectors 选择器对象
* @return {boolean}
*/
function setFocus(selectors) {
if (isAccMode()) {
return acEvent.setFocus(selectors);
} else if (isAgentMode()) {
return agentEvent.setFocus(selectors);
}
return false;
}
/**
* 无指针模式长按选择器
* @param selectors 选择器对象
* @return {boolean}
*/
function longClickEx(selectors) {
if (isAccMode()) {
return acEvent.longClickEx(selectors);
} else if (isAgentMode()) {
return agentEvent.longClickEx(selectors);
}
return false;
}
/**
* 点击某个区域中心坐标点
* @param rect 区域
* @return {boolean} 布尔型 true 成功,false 失败
*/
function clickCenter(rect) {
if (isAccMode()) {
return acEvent.clickCenter(rect);
} else if (isAgentMode()) {
return agentEvent.clickCenter(rect);
}
return false;
}
/**
* 点击坐标
* @param x x坐标
* @param y y坐标
* @return {boolean}
*/
function clickPoint(x, y) {
if (isAccMode()) {
return acEvent.clickPoint(x, y);
} else if (isAgentMode()) {
return agentEvent.clickPoint(x, y);
}
return false;
}
/**
* 双击坐标
* @param x x坐标
* @param y y坐标
* @return {boolean}
*/
function doubleClickPoint(x, y) {
if (isAccMode()) {
return acEvent.doubleClickPoint(x, y);
} else if (isAgentMode()) {
return agentEvent.doubleClickPoint(x, y);
}
return false;
}
/**
* 长点击选择器
* @param selectors 选择器对象
* @return {boolean}
*/
function longClick(selectors) {
if (isAccMode()) {
return acEvent.longClick(selectors);
} else if (isAgentMode()) {
return agentEvent.longClick(selectors);
}
return false;
}
/**
* 长点击坐标
* @param x x坐标
* @param y y坐标
* @return {boolean}
*/
function longClickPoint(x, y) {
if (isAccMode()) {
return acEvent.longClickPoint(x, y);
} else if (isAgentMode()) {
return agentEvent.longClickPoint(x, y);
}
return false;
}
/**
* 获取选择器得到的文本数据
* @param selectors 选择器
* @return {null|string} 字符串集合
*/
function getText(selectors) {
if (isAccMode()) {
return acEvent.getText(selectors);
} else if (isAgentMode()) {
return agentEvent.getText(selectors);
}
return null;
}
/**
* 获取节点属性信息
* @param selectors 选择器
* @param attr 属性值,例如 text,className,更多的属性请参考NodeInfo对象属性
* @return {null|any[]} null|字符串数组|Rect对象数组
*/
function getNodeAttrs(selectors, attr) {
if (selectors == null || attr == null) {
return null;
}
var nodes = getNodeInfo(selectors, 0);
if (nodes == null || nodes.length <= 0) {
return null;
}
var x = [];
for (var i = 0; i < nodes.length; i++) {
var n = nodes[i];
try {
x.push(n[attr]);
} catch (e) {
}
}
return x;
}
/**
* 锁定当前节点,锁定后,后面就算界面刷新,但是节点还是老的信息,需要和releaseNode进行配合才能进行解锁
*/
function lockNode() {
if (isAccMode()) {
acEvent.lockNode();
} else if (isAgentMode()) {
agentEvent.lockNode();
}
}
/**
* 释放节点的锁,释放后,当界面刷新的时候,节点信息会变成最新的
*/
function releaseNode() {
if (isAccMode()) {
acEvent.releaseNode();
} else if (isAgentMode()) {
agentEvent.releaseNode();
}
}
/**
* 设置各种手势模式事件的操作类型,默认是异步,目前只对无障碍模式有效
* @param mode 1 代表异步,2代表同步
* @return {boolean} true代表成功 false代表失败
*/
function setGestureActionMode(mode) {
if (isAccMode()) {
return acEvent.setAccActionMode(mode);
}
return false;
}
/**
* 获取节点信息
* @param selectors 选择器
* @param timeout 超时时间,单位是毫秒
* @return {null|NodeInfo[]} NodeInfo 数组 节点信息集合
*/
function getNodeInfo(selectors, timeout) {
if (isAccMode()) {
return acEvent.getNodeInfo(selectors, timeout);
} else if (isAgentMode()) {
return agentEvent.getNodeInfo(selectors, timeout);
}
return null;
}
/**
* 通过Selector 判断元素是否存在
* @param selectors 选择器
* @return {boolean}
*/
function has(selectors) {
if (isAccMode()) {
return acEvent.has(selectors);
} else if (isAgentMode()) {
return agentEvent.has(selectors);
}
return false;
}
/**
* 通过Selector 判断并等待元素是否存
* @param selectors 选择器
* @param timeout 超时时间,单位毫秒
* @return {boolean}
*/
function waitExistNode(selectors, timeout) {
if (timeout <= 0) {
if (isAccMode()) {
return acEvent.has(selectors);
} else if (isAgentMode()) {
return agentEvent.has(selectors);
}
} else {
var x = thread.execSync(function () {
if (isAccMode()) {
return acEvent.has(selectors);
} else if (isAgentMode()) {
return agentEvent.has(selectors);
}
}, timeout);
if (x == null) {
return false;
}
return x;
}
}
/**
* 等待activity界面出现
* @param activity 界面名称
* @param timeout 超时时间,单位毫秒
* @return {boolean}
*/
function waitExistActivity(activity, timeout) {
if (activity == null) {
return false;
}
if (timeout <= 0) {
var s = getRunningActivity();
return s == activity;
} else {
return thread.execSync(function () {
var s = getRunningActivity();
return s == activity;
}, timeout);
}
}
/**
* 将元素节点变成XML
* @return {null|string} string|null
*/
function dumpXml() {
if (isAccMode()) {
return acEvent.dumpXml();
} else if (isAgentMode()) {
return agentEvent.dumpXml();
}
return null;
}
/**
* 将通知发射处理,相当于点击了通知栏
* @param seqId
* @return {boolean}
*/
function shotNotification(seqId) {
if (isAccMode()) {
return acEvent.shotNotification(seqId);
} else if (isAgentMode()) {
return agentEvent.shotNotification(seqId);
}
return false;
}
/**
* 将通知进行取消操作
* @param seqId
* @return {boolean}
*/
function cancelNotification(seqId) {
if (isAccMode()) {
return acEvent.cancelNotification(seqId);
} else if (isAgentMode()) {
return agentEvent.cancelNotification(seqId);
}
return false;
}
/**
*
* @param seqId
* @return {boolean}
*/
function ignoreNotification(seqId) {
if (isAccMode()) {
return acEvent.ignoreNotification(seqId);
} else if (isAgentMode()) {
return agentEvent.ignoreNotification(seqId);
}
return false;
}
/**
* 获取toast数据
* @param pkg 指定包名
* @param size 指定获取的条数
* @return {null|ToastInfo[]} null|ToastInfo数组
*/
function getLastToast(pkg, size) {
if (isAccMode()) {
return acEvent.getLastToast(pkg, size);
} else if (isAgentMode()) {
return agentEvent.getLastToast(pkg, size);
}
return null;
}
/**
* 获取最近通知栏对象
* @param pkg 指定包名
* @param size 指定获取的条数
* @return {null|NotificationInfo[]} 数组|null
*/
function getLastNotification(pkg, size) {
if (isAccMode()) {
return acEvent.getLastNotification(pkg, size);
} else if (isAgentMode()) {
return agentEvent.getLastNotification(pkg, size);
}
return null;
}
/**
* 请求监听状态栏的权限
*
* 运行环境: 无限制
*
* @param timeout 请求权限超时时间 单位是秒
* @return {boolean} true 代表请求权限成功,false代表失败
*/
function requestNotificationPermission(timeout) {
if (isAccMode()) {
return acEvent.requestNotificationPermission(timeout);
} else if (isAgentMode()) {
return agentEvent.requestNotificationPermission(timeout);
}
return null;
}
/**
* 检查是否含有状态栏监听权限
*
* 运行环境: 无限制
*
* 兼容版本: Android 5.0 以上
* @return {boolean} true 有权限,false 代表无权限
*/
function hasNotificationPermission() {
if (isAccMode()) {
return acEvent.hasNotificationPermission();
} else if (isAgentMode()) {
return agentEvent.hasNotificationPermission();
}
return null;
}
/**
* 取得当前运行的Activity类名
* @return {null|string}
*/
function getRunningActivity() {
if (isAccMode()) {
return acEvent.getRunningActivity();
} else if (isAgentMode()) {
return agentEvent.getRunningActivity();
}
return null;
}
/**
* 这个获取的不准,请使用 getCurrentRunningPkg 函数
* 取得当前运行的App包名
* @return {null|string}
*/
function getRunningPkg() {
if (isAccMode()) {
return acEvent.getRunningPkg();
} else if (isAgentMode()) {
return agentEvent.getRunningPkg();
}
return null;
}
/**
*
* 取得当前运行的App包名
* 这个是通过节点获取的,前提是需要打开自动化服务
* 适配EC 10.6.0+
* @return {null|string}
*/
function getCurrentRunningPkg() {
if (isAccMode()) {
return acEvent.getCurrentRunningPkg();
} else if (isAgentMode()) {
return agentEvent.getCurrentRunningPkg();
}
return null;
}
/**
*
* @return {boolean} 布尔型| true代表成功
*/
function home() {
if (isAccMode()) {
return acEvent.home();
} else if (isAgentMode()) {
return agentEvent.home();
}
return false;
}
/**
* 返回桌面2
* 适配EC 安卓 9.16.0+
* @return {boolean} true 代表成功
*/
function home2() {
importClass(android.content.Intent);
var intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(intent);
} catch (e) {
loge(e)
return false;
}
return true;
}
/**
* 分割屏幕
* @return {boolean} 布尔型| true代表成功
*/
function splitScreen() {
if (isAccMode()) {
return acEvent.splitScreen();
} else if (isAgentMode()) {
return agentEvent.splitScreen();
}
return false;
}
/**
* 模拟电源键
* @return {boolean} true 成功 false 失败
*/
function power() {
if (isAccMode()) {
return acEvent.power();
} else if (isAgentMode()) {
return agentEvent.power();
}
return false;
}
/**
* 打开快速设置
* @return {boolean} true 成功, else 失败
*/
function openQuickSettings() {
if (isAccMode()) {
return acEvent.openQuickSettings();
} else if (isAgentMode()) {
return agentEvent.openQuickSettings();
}
return false;
}
/**
* 打开通知栏
*
* @return {boolean} true 成功, else 失败
*/
function openNotification() {
if (isAccMode()) {
return acEvent.openNotification();
} else if (isAgentMode()) {
return agentEvent.openNotification();
}
return false;
}
/**
* 返回按键
* @return {boolean}
*/
function back() {
if (isAccMode()) {
return acEvent.back();
} else if (isAgentMode()) {
return agentEvent.back();
}
return false;
}
/**
* 最近APP任务按键
* @return {boolean}
*/
function recentApps() {
if (isAccMode()) {
return acEvent.recentApps();
} else if (isAgentMode()) {
return agentEvent.recentApps();
}
return false;
}
/**
* 当前是否是我们的输入法
* @return {boolean}
*/
function currentIsOurIme() {
if (isAccMode()) {
return acEvent.currentIsOurIme();
} else if (isAgentMode()) {
return agentEvent.currentIsOurIme();
}
return false;
}
/**
* 通过Selector输入数据
* @param selectors 选择器
* @param content 数据字符串
* @return {boolean}
*/
function inputText(selectors, content) {
if (isAccMode()) {
return acEvent.inputText(selectors, content);
} else if (isAgentMode()) {
return agentEvent.inputText(selectors, content);
}
return false;
}
/**
* 通过选择器粘贴数据
* @param selectors 选择器
* @param content 数据字符串
* @return {boolean}
*/
function pasteText(selectors, content) {
if (isAccMode()) {
return acEvent.pasteText(selectors, content);
} else if (isAgentMode()) {
return agentEvent.pasteText(selectors, content);
}
return false;
}
/**
* 使用输入法输入内容,前提是已经设置本程序的输入法为默认输入法
* 适合没有节点的情况,例如游戏等
* @param selectors 选择器,可以为空,如果为空,前提是输入框是聚焦的状态
* @param content 具体请看 KeyEvent.KEYCODE_*的值,例如66 = enter 67=del,84=SEARCH
* 特殊代码: 1000: 模拟搜索按键,1001: 模拟完成按键 1002:模拟go按键,1003:模拟下一个按键,1004:模拟上一个按键 1005:模拟发送按键
* @return {boolean}
*/
function imeInputText(selectors, content) {
if (selectors == null || selectors == undefined || selectors == "") {
return acEvent.imeInputText(selectors, content);
}
if (isAccMode()) {
return acEvent.imeInputText(selectors, content);
} else if (isAgentMode()) {
return agentEvent.imeInputText(selectors, content);
}
return false;
}
/**
* 使用输入法输入内容时,输入法键盘视图是否展示出来
* 前提:在EC 系统设置中,勾选了 显示输入法键盘
* 适配EC 9.18.0+
* @return {boolean}true代表视图展示 false代表未展示
*/
function imeInputViewShown() {
return acEventWrapper.imeInputViewShown();
};
/**
* 使用输入法输入内容,前提是已经设置本程序的输入法为默认输入法
* @param selectors 选择器
* @param content 整型,具体请看 KeyEvent.KEYCODE_*的值,例如66 = enter 67=del,84=SEARCH
* @return {boolean}
*/
function imeInputKeyCode(selectors, content) {
if (selectors == null || selectors == undefined || selectors == "") {
return acEvent.imeInputKeyCode(selectors, content);
}
if (isAccMode()) {
return acEvent.imeInputKeyCode(selectors, content);
} else if (isAgentMode()) {
return agentEvent.imeInputKeyCode(selectors, content);
}
return false;
}
/**
* 清除文本数据
* @param selectors 节点选择器
* @return {boolean} 布尔型| true代表成功
*/
function clearTextField(selectors) {
if (isAccMode()) {
return acEvent.clearTextField(selectors);
} else if (isAgentMode()) {
return agentEvent.clearTextField(selectors);
}
}
/**
* 通过选择器滑动节点
* @param selectors 节点选择器
* @param endX 结束的X坐标
* @param endY 结束的Y坐标
* @param duration 持续时长 单位毫秒
* @return {boolean} true 代表成功 false 代表失败
*/
function swipe(selectors, endX, endY, duration) {
if (isAccMode()) {
return acEvent.swipe(selectors, endX, endY, duration);
} else if (isAgentMode()) {
return agentEvent.swipe(selectors, endX, endY, duration);
}
return false;
}
/**
* 从一个坐标滑动到另一个坐标
* @param startX 起始坐标的X轴值
* @param startY 起始坐标的Y轴值
* @param endX 结束坐标的X轴值
* @param endY 结束坐标的Y轴值
* @param duration 持续时长 单位毫秒
* @return {boolean} true 滑动成功, false 滑动失败
*/
function swipeToPoint(startX, startY, endX, endY, duration) {
if (isAccMode()) {
return acEvent.swipeToPoint(startX, startY, endX, endY, duration);
} else if (isAgentMode()) {
return agentEvent.swipeToPoint(startX, startY, endX, endY, duration);
}
return false;
}
/**
* 通过选择器从下向上滑动
* @param selectors 节点选择器
* @param distance 滑动距离 单位是像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 滑动成功,false 滑动失败
*/
function swipeFromDownToUp(selectors, distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromDownToUp(selectors, distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromDownToUp(selectors, distance, duration);
}
return false;
}
/**
* 通过选择器从上向下滑动
* @param selectors 节点选择器
* @param distance 滑动距离 单位是像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 滑动成功,false 滑动失败
*/
function swipeFromUpToDown(selectors, distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromUpToDown(selectors, distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromUpToDown(selectors, distance, duration);
}
return false;
}
/**
* 通过选择器从右向左滑动
* @param selectors 节点选择器
* @param distance 滑动距离 单位是像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 滑动成功,false 滑动失败
*/
function swipeFromRightToLeft(selectors, distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromRightToLeft(selectors, distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromRightToLeft(selectors, distance, duration);
}
return false;
}
/**
* 通过选择器从左向右滑动
* @param selectors 节点选择器
* @param distance 滑动距离 单位是像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 滑动成功,false 滑动失败
*/
function swipeFromLeftToRight(selectors, distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromLeftToRight(selectors, distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromLeftToRight(selectors, distance, duration);
}
return false;
}
/**
* 向上滑动
* @param distance 滑动距离 单位像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 成功,false 失败
*/
function swipeFromDownToUpInScreen(distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromDownToUpInScreen(distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromDownToUpInScreen(distance, duration);
}
return false;
}
/**
* 向下滑动
* @param distance 滑动距离 单位像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 代表成功 false 代表失败
*/
function swipeFromUpToDownInScreen(distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromUpToDownInScreen(distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromUpToDownInScreen(distance, duration);
}
return false;
}
/**
* 向左滑动
* @param distance 滑动距离 单位像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 代表成功 false 代表失败
*/
function swipeFromRightToLeftInScreen(distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromRightToLeftInScreen(distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromRightToLeftInScreen(distance, duration);
}
return false;
}
/**
* 向右滑动
* @param distance 滑动距离 单位像素
* @param duration 持续时长 单位毫秒
* @return {boolean} true 代表成功 false 代表失败
*/
function swipeFromLeftToRightInScreen(distance, duration) {
if (isAccMode()) {
return acEvent.swipeFromLeftToRightInScreen(distance, duration);
} else if (isAgentMode()) {
return agentEvent.swipeFromLeftToRightInScreen(distance, duration);
}
return false;
}
/**
* 是否滚动到底部了,如果查不到元素也会返回false
* @param distance 滚动方向 UP,DOWN,LEFT,RIGHT
* @param selectors 选择器
* @return {boolean} false 代表未滚动到位,true 代表滚动完成了
*/
function isScrollEnd(distance, selectors) {
if (isAccMode()) {
return acEvent.isScrollEnd(distance, selectors);
} else if (isAgentMode()) {
return agentEvent.isScrollEnd(distance, selectors);
}
return false;
}
/**
*
执行从一个坐标到另一个坐标的拖动
* * @param startX 起始坐标的X轴值 * @param startY 起始坐标的Y轴值 * @param endX 结束坐标的X轴值 * @param endY 结束坐标的Y轴值 * @param duration 持续时长 单位毫秒 * @return {boolean} true 拖动成功, false 拖动失败 */ function drag(startX, startY, endX, endY, duration) { if (isAccMode()) { return acEvent.drag(startX, startY, endX, endY, duration); } else if (isAgentMode()) { return agentEvent.drag(startX, startY, endX, endY, duration); } return false; } /** * 通过选择器拖动某个元素到目标元素 * @param selectors 选择器 {@link S} * @param destObj 目标元素选择器 * @param duration 持续时长 单位毫秒 * @return {boolean} true 成功 false 失败 */ function dragTo(selectors, destObj, duration) { if (isAccMode()) { return acEvent.dragTo(selectors, destObj, duration); } else if (isAgentMode()) { return agentEvent.dragTo(selectors, destObj, duration); } return false; } /** * 通过选择器拖动某个元素到目标X Y 坐标 * @param selectors 原始元素选择器 * @param endX 目标 X 坐标 * @param endY 目标 Y 坐标 * @param duration 持续时长 单位毫秒 * @return {boolean} true 成功 false 失败 */ function dragToPoint(selectors, endX, endY, duration) { if (isAccMode()) { return acEvent.dragToPoint(selectors, endX, endY, duration); } else if (isAgentMode()) { return agentEvent.dragToPoint(selectors, endX, endY, duration); } return false; } /** * 请求展示浮窗的权限 *