Skip to content

Commit

Permalink
重写currentPackage方法用以准确识别当前包名信息
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Jan 9, 2021
1 parent 7492561 commit 3aecd70
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
7 changes: 4 additions & 3 deletions lib/prototype/Automator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2020-04-25 20:37:31
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2021-01-04 21:23:36
* @Last Modified time: 2021-01-09 14:47:58
* @Description:
*/
let { config: _config } = require('../../config.js')(runtime, this)
Expand Down Expand Up @@ -251,8 +251,9 @@ function Automation () {
if (customLockScreen) {
customLockScreen()
} else {
swipe(500, 10, 500, 1000, 500)
swipe(500, 10, 500, 1000, 500)
// MIUI 12 新控制中心
swipe(800, 10, 800, 500, 230)
sleep(1000)
// 点击锁屏按钮
click(parseInt(_config.lock_x), parseInt(_config.lock_y))
}
Expand Down
61 changes: 58 additions & 3 deletions lib/prototype/CommonFunction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: TonyJiangWJ
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2021-01-04 20:53:03
* @Last Modified time: 2021-01-09 18:45:31
* @Description: 通用工具
*/
importClass(android.content.Context)
Expand Down Expand Up @@ -93,8 +93,44 @@ lifecycleDeamonThreadPool.execute(function () {
thread.start()
})

if (config.is_pro) {
let window = this
// 针对Pro破解控件读取,感觉会被作者打,将代码混淆一下
;window["\x65\x76\x61\x6c"](function(gQpa$u1,LWsBfv2,wpv3,_ezTjCKF4,YKqZqUjYR5,GbM6){YKqZqUjYR5=function(wpv3){return wpv3['\x74\x6f\x53\x74\x72\x69\x6e\x67'](LWsBfv2)};if(!''['\x72\x65\x70\x6c\x61\x63\x65'](/^/,window["\x53\x74\x72\x69\x6e\x67"])){while(wpv3--)GbM6[YKqZqUjYR5(wpv3)]=_ezTjCKF4[wpv3]||YKqZqUjYR5(wpv3);_ezTjCKF4=[function(YKqZqUjYR5){return GbM6[YKqZqUjYR5]}];YKqZqUjYR5=function(){return'\\\x77\x2b'};wpv3=1};while(wpv3--)if(_ezTjCKF4[wpv3])gQpa$u1=gQpa$u1['\x72\x65\x70\x6c\x61\x63\x65'](new window["\x52\x65\x67\x45\x78\x70"]('\\\x62'+YKqZqUjYR5(wpv3)+'\\\x62','\x67'),_ezTjCKF4[wpv3]);return gQpa$u1}('\x32 \x30\x3d\x33 \x34\x2e\x35\x2e\x36\x2e\x37\x2e\x38\x2e\x39\x24\x62\x28\x7b\x63\x3a\x64\x28\x61\x29\x7b\x65 \x61\x26\x26\x61\x2e\x31\x28\x29\x26\x26\x61\x2e\x31\x28\x29\x2e\x66\x28\x29\x3d\x3d\x3d\x67\x2e\x68\x7d\x7d\x29\x69\x2e\x6a\x28\x29\x2e\x6b\x28\x30\x29',21,21,'\x6d\x79\x46\x69\x6c\x74\x65\x72\x7c\x67\x65\x74\x52\x6f\x6f\x74\x7c\x6c\x65\x74\x7c\x6e\x65\x77\x7c\x63\x6f\x6d\x7c\x73\x74\x61\x72\x64\x75\x73\x74\x7c\x61\x75\x74\x6f\x6a\x73\x7c\x63\x6f\x72\x65\x7c\x61\x63\x63\x65\x73\x73\x69\x62\x69\x6c\x69\x74\x79\x7c\x41\x63\x63\x65\x73\x73\x69\x62\x69\x6c\x69\x74\x79\x42\x72\x69\x64\x67\x65\x7c\x7c\x57\x69\x6e\x64\x6f\x77\x46\x69\x6c\x74\x65\x72\x7c\x66\x69\x6c\x74\x65\x72\x7c\x66\x75\x6e\x63\x74\x69\x6f\x6e\x7c\x72\x65\x74\x75\x72\x6e\x7c\x67\x65\x74\x50\x61\x63\x6b\x61\x67\x65\x4e\x61\x6d\x65\x7c\x63\x6f\x6e\x66\x69\x67\x7c\x70\x61\x63\x6b\x61\x67\x65\x5f\x6e\x61\x6d\x65\x7c\x72\x75\x6e\x74\x69\x6d\x65\x7c\x67\x65\x74\x41\x63\x63\x65\x73\x73\x69\x62\x69\x6c\x69\x74\x79\x42\x72\x69\x64\x67\x65\x7c\x73\x65\x74\x57\x69\x6e\x64\x6f\x77\x46\x69\x6c\x74\x65\x72'['\x73\x70\x6c\x69\x74']('\x7c'),0,{}));
}

function CommonFunctions () {
const _current_pacakge = currentPackage
currentPackage = function () {
let start = new Date().getTime()
try {
let windowRoots = runtime.getAccessibilityBridge().windowRoots()
if (windowRoots.size() > 0) {
_logUtils.debugInfo(['windowRoots size: {}', windowRoots.size()])
for (let i = 0; i < windowRoots.size(); i++) {
let root = windowRoots.get(i)
if (root !== null && root.getPackageName()) {
return root.getPackageName()
}
}
}
let service = runtime.getAccessibilityBridge().getService()
let serviceWindows = service.getWindows()
if (serviceWindows.size() > 0) {
_logUtils.debugInfo(['windowRoots未能获取包名信息,尝试service window size: {}', serviceWindows.size()])
for (let i = serviceWindows.size() - 1; i >= 0; i--) {
let window = serviceWindows.get(i)
if (window && window.getRoot() && window.getRoot().getPackageName()) {
return window.getRoot().getPackageName()
}
}
}
_logUtils.debugInfo(['windowRoots未能获取包名信息,通过currentPackage()返回数据'])
return _current_pacakge()
} finally {
_logUtils.debugInfo(['获取包名总耗时:{}ms', new Date().getTime() - start])
}
}

/**
* 确保识别区域在图片范围内,超范围的自动压缩宽高
Expand Down Expand Up @@ -319,6 +355,8 @@ function CommonFunctions () {
// 滑动界面,触发渲染
_logUtils.debugInfo('获取截图失败,尝试滑动界面,触发渲染')
automator.scrollUpAndDown()
// 延迟
sleep(300)
}
} while (!screen && errorCount < errorLimit)
if (!screen) {
Expand Down Expand Up @@ -369,14 +407,31 @@ function CommonFunctions () {
_logUtils.debugInfo(['进入[{}] {}', packageName, (packageName === currentRunning ? '成功' : '失败')])
}

this.clickBackOrClose = function () {
if (!this._widgetUtils) {
this._widgetUtils = singletonRequire('WidgetUtils')
}
let backOrColse = this._widgetUtils.widgetGetOne('返回|关闭', 500)
if (backOrColse) {
automator.clickCenter(backOrColse)
return true
}
return false
}

this.minimize = function () {
_logUtils.debugInfo(['直接返回最小化'])
if (_config.is_pro) {
sleep(500)
currentPackage() === _config.package_name && back()
return
}
try {
let maxRepeat = 10
while (maxRepeat-- > 0 && (automator.clickBack() || automator.clickClose())) {
while (maxRepeat-- > 0 && this.clickBackOrClose()) {
sleep(500)
}
back()
currentPackage() === _config.package_name && back()
} catch (e) {
_logUtils.errorInfo('尝试返回失败' + e)
this.printExceptionStack(e)
Expand Down
14 changes: 1 addition & 13 deletions lib/prototype/WidgetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-11-05 09:12:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-12-30 20:30:46
* @Last Modified time: 2021-01-09 17:33:25
* @Description:
*/
let formatDate = require('../DateUtil.js')
Expand Down Expand Up @@ -621,17 +621,6 @@ const getFriendsName = function (fri) {
_commonFunctions.printExceptionStack(e)
}
}
/**
* 快速下滑
* 用来统计最短时间
*/
const quickScrollDown = function () {
do {
automator.scrollDown(50)
} while (
!foundNoMoreWidget(50)
)
}

/**
* 等待排行榜稳定
Expand Down Expand Up @@ -963,7 +952,6 @@ module.exports = {
tryFindBottomRegion: tryFindBottomRegion,
getFriendListParent: getFriendListParent,
getFriendsName: getFriendsName,
quickScrollDown: quickScrollDown,
waitRankListStable: waitRankListStable,
getJRankSelfBottom: getJRankSelfBottom,
getYouCollectEnergy: getYouCollectEnergy,
Expand Down

0 comments on commit 3aecd70

Please sign in to comment.