update app外场景禁止自动跳回

This commit is contained in:
gallonyin
2023-07-03 18:36:12 +08:00
parent 6d951e2227
commit c6eaa2ecb2
4 changed files with 57 additions and 30 deletions

View File

@@ -9,8 +9,8 @@ android {
applicationId "org.yameida.worktool" applicationId "org.yameida.worktool"
minSdkVersion 24 minSdkVersion 24
targetSdkVersion 30 targetSdkVersion 30
versionCode 26041 versionCode 26042
versionName "2.6.4" versionName "2.6.4.2"
} }
buildTypes { buildTypes {

View File

@@ -112,7 +112,7 @@ fun getRoot(): AccessibilityNodeInfo {
* 获取前台窗口 * 获取前台窗口
* @param ignoreCheck false 必须等待前台为企业微信 true 直接返回当前前台窗口 * @param ignoreCheck false 必须等待前台为企业微信 true 直接返回当前前台窗口
*/ */
fun getRoot(ignoreCheck: Boolean): AccessibilityNodeInfo { fun getRoot(ignoreCheck: Boolean, share: Boolean = false): AccessibilityNodeInfo {
while (true) { while (true) {
val tempRoot = WeworkController.weworkService.rootInActiveWindow val tempRoot = WeworkController.weworkService.rootInActiveWindow
val root = WeworkController.weworkService.rootInActiveWindow val root = WeworkController.weworkService.rootInActiveWindow
@@ -139,16 +139,19 @@ fun getRoot(ignoreCheck: Boolean): AccessibilityNodeInfo {
error("点击关闭应用ANR") error("点击关闭应用ANR")
} }
} }
WeworkController.weworkService.currentPackage = root.packageName?.toString() ?: "" //app外场景禁止自动跳回(分享文件)
if (System.currentTimeMillis() % 30 == 0L) { if (!share) {
error("当前不在企业微信: ${root.packageName}") WeworkController.weworkService.currentPackage = root.packageName?.toString() ?: ""
if (!FloatWindowHelper.isPause) { if (System.currentTimeMillis() % 30 == 0L) {
ToastUtils.show("当前不在企业微信: ${root.packageName}\n尝试跳转到企业微信") error("当前不在企业微信: ${root.packageName}")
Utils.getApp().packageManager.getLaunchIntentForPackage(Constant.PACKAGE_NAMES) if (!FloatWindowHelper.isPause) {
?.apply { ToastUtils.show("当前不在企业微信: ${root.packageName}\n尝试跳转到企业微信")
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK Utils.getApp().packageManager.getLaunchIntentForPackage(Constant.PACKAGE_NAMES)
Utils.getApp().startActivity(this) ?.apply {
} this.flags = Intent.FLAG_ACTIVITY_NEW_TASK
Utils.getApp().startActivity(this)
}
}
} }
} }
if (ignoreCheck) { if (ignoreCheck) {

View File

@@ -434,11 +434,19 @@ object WeworkOperationImpl {
AccessibilityUtil.performClick(imageViewList[1]) AccessibilityUtil.performClick(imageViewList[1])
val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "以原文件分享", "用其他应用打开") val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "以原文件分享", "用其他应用打开")
AccessibilityUtil.performClick(shareFileButton) AccessibilityUtil.performClick(shareFileButton)
var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事")
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
if (shareToWorkButton == null) {
LogUtils.e("未找到发送给同事: $objectName")
if (retryCount > 0) {
return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1)
}
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList)
return false
}
AccessibilityUtil.performClick(shareToWorkButton) AccessibilityUtil.performClick(shareToWorkButton)
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage)
val time = System.currentTimeMillis() val time = System.currentTimeMillis()
var currentTime = time var currentTime = time
@@ -448,7 +456,7 @@ object WeworkOperationImpl {
LogUtils.e("尝试手势点击!!!!!") LogUtils.e("尝试手势点击!!!!!")
AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton)
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
} else { } else {
break break
} }
@@ -682,11 +690,19 @@ object WeworkOperationImpl {
newFile.writeBytes(body.bytes()) newFile.writeBytes(body.bytes())
LogUtils.i("文件存储本地成功 $filePath") LogUtils.i("文件存储本地成功 $filePath")
ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile)
var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事")
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
if (shareToWorkButton == null) {
LogUtils.e("未找到发送给同事: $objectName")
if (retryCount > 0) {
return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1)
}
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList)
return false
}
AccessibilityUtil.performClick(shareToWorkButton) AccessibilityUtil.performClick(shareToWorkButton)
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage)
val time = System.currentTimeMillis() val time = System.currentTimeMillis()
var currentTime = time var currentTime = time
@@ -696,7 +712,7 @@ object WeworkOperationImpl {
LogUtils.e("尝试手势点击!!!!!") LogUtils.e("尝试手势点击!!!!!")
AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton)
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
} else { } else {
break break
} }
@@ -742,11 +758,19 @@ object WeworkOperationImpl {
newFile.writeBytes(EncodeUtils.base64Decode(fileBase64)) newFile.writeBytes(EncodeUtils.base64Decode(fileBase64))
LogUtils.i("文件存储本地成功 $filePath") LogUtils.i("文件存储本地成功 $filePath")
ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile)
var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事")
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
if (shareToWorkButton == null) {
LogUtils.e("未找到发送给同事: $objectName")
if (retryCount > 0) {
return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1)
}
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList)
return false
}
AccessibilityUtil.performClick(shareToWorkButton) AccessibilityUtil.performClick(shareToWorkButton)
sleep(Constant.POP_WINDOW_INTERVAL) sleep(Constant.POP_WINDOW_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage)
val time = System.currentTimeMillis() val time = System.currentTimeMillis()
var currentTime = time var currentTime = time
@@ -756,7 +780,7 @@ object WeworkOperationImpl {
LogUtils.e("尝试手势点击!!!!!") LogUtils.e("尝试手势点击!!!!!")
AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton)
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事")
} else { } else {
break break
} }

View File

@@ -640,7 +640,7 @@ object AccessibilityUtil {
if (result != null) return result if (result != null) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -693,7 +693,7 @@ object AccessibilityUtil {
if (result != null) return result if (result != null) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -765,7 +765,7 @@ object AccessibilityUtil {
if (result.size >= minSize) return result if (result.size >= minSize) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -830,7 +830,7 @@ object AccessibilityUtil {
if (result.size >= minSize) return result if (result.size >= minSize) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -891,7 +891,7 @@ object AccessibilityUtil {
if (result != null) return result if (result != null) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -961,7 +961,7 @@ object AccessibilityUtil {
if (result.size >= minSize) return result if (result.size >= minSize) return result
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -1287,7 +1287,7 @@ object AccessibilityUtil {
findOnceByText(node, *textList, exact = exact, desc = desc) ?: return true findOnceByText(node, *textList, exact = exact, desc = desc) ?: return true
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }
@@ -1313,7 +1313,7 @@ object AccessibilityUtil {
findOnceByClazz(node, *clazzList) ?: return true findOnceByClazz(node, *clazzList) ?: return true
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
if (root) { if (root) {
node = getRoot(true) node = getRoot(true, share = true)
} else { } else {
node.refresh() node.refresh()
} }