Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BYLAppRobot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuyang
BYLAppRobot
Commits
0dbc9c45
Commit
0dbc9c45
authored
Oct 24, 2018
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加程序前台判断逻辑,修复启动问题
parent
eb964c2f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
16 deletions
+63
-16
MainActivity.kt
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
+28
-6
Task.kt
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
+14
-2
AdbUtil.kt
app/src/main/java/com/duolebo/blyrobot/util/AdbUtil.kt
+1
-1
AppUtil.kt
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
+20
-0
activity_main.xml
app/src/main/res/layout/activity_main.xml
+0
-7
No files found.
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
View file @
0dbc9c45
...
...
@@ -65,22 +65,39 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
startRobotService
()
startBtn
.
setOnClickListener
{
startRobot
()
}
stopBtn
.
setOnClickListener
{
stopRobot
()
toggle
()
}
startBtn
.
requestFocus
()
requestAppList
()
refreshBtn
.
setOnClickListener
{
this
.
appInfoAdapter
.
clear
()
requestAppList
()
}
}
private
fun
toggle
()
{
// 暂时测试用
if
(
TaskManager
.
instance
.
isRunning
)
{
stopRobot
()
startBtn
.
isEnabled
=
false
startBtn
.
postDelayed
({
startBtn
.
isEnabled
=
true
startBtn
.
text
=
"启动"
},
3000
)
}
else
{
startRobot
()
startBtn
.
isEnabled
=
false
startBtn
.
postDelayed
({
startBtn
.
isEnabled
=
true
startBtn
.
text
=
"停止"
},
3000
)
}
}
private
fun
requestAppList
()
{
apkInfoProtocol
=
GetAppInfoProtocol
(
this
,
Config
.
instance
)
this
.
dataHandler
=
AppBaseHandler
(
this
)
...
...
@@ -139,7 +156,7 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
override
fun
onProtocolSucceed
(
protocol
:
IProtocol
?)
{
if
(
protocol
is
GetAppInfoProtocol
)
{
this
.
appInfoData
=
protocol
.
data
this
.
appInfoData
=
protocol
.
data
as
AppInfoData
this
.
appInfoAdapter
.
setData
(
appInfoData
.
apkInfos
)
this
.
appInfoAdapter
.
notifyDataSetChanged
()
...
...
@@ -179,6 +196,11 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
this
.
dataList
.
addAll
(
dataList
)
}
fun
clear
()
{
this
.
dataList
.
clear
()
notifyDataSetChanged
()
}
override
fun
getView
(
position
:
Int
,
convertView
:
View
?,
parent
:
ViewGroup
):
View
{
var
itemView
:
AppConfigListItem
if
(
convertView
==
null
)
{
...
...
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
View file @
0dbc9c45
...
...
@@ -97,7 +97,12 @@ class Task : IAppBaseCallback {
// }
// 频道轮询处理
try
{
val
success
=
this
.
processChannels
()
// 尝试两次
if
(!
success
)
{
this
.
reset
()
this
.
processChannels
()
}
// 上传图片
this
.
uploadImage
()
this
.
status
=
"4"
...
...
@@ -162,7 +167,7 @@ class Task : IAppBaseCallback {
}
}
private
fun
processChannels
()
{
private
fun
processChannels
()
:
Boolean
{
Log
.
i
(
TAG
,
"processChannels"
)
step
()
for
(
i
in
1
until
this
.
apkInfo
.
channelCount
)
{
...
...
@@ -170,8 +175,15 @@ class Task : IAppBaseCallback {
this
.
channelIndex
=
i
capture
(
apkInfo
.
captureDelay
)
AdbUtil
.
sendMultiKey
(
this
.
apkInfo
.
channelKeyEvent
)
if
(!
AppUtil
.
isAppBackground
(
context
,
this
.
apkInfo
.
packageName
))
{
return
false
}
step
()
}
return
true
}
private
fun
step
()
{
...
...
app/src/main/java/com/duolebo/blyrobot/util/AdbUtil.kt
View file @
0dbc9c45
...
...
@@ -205,7 +205,7 @@ object AdbUtil {
val
keyEvents
=
ArrayList
<
EmulateKey
>()
val
keys
=
keyPath
.
split
(
Constants
.
SLASH
)
for
(
stepKey
in
keys
)
{
var
delay
=
"
1
"
var
delay
=
"
2
"
if
(
Constants
.
VERTICAL_BAR
in
stepKey
)
{
val
params
=
stepKey
.
split
(
Constants
.
VERTICAL_BAR
)
delay
=
params
[
1
]
...
...
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
View file @
0dbc9c45
package
com.duolebo.blyrobot.util
import
android.app.ActivityManager
import
android.content.Context
import
android.text.TextUtils
import
java.net.Inet4Address
...
...
@@ -12,6 +13,9 @@ import android.content.pm.PackageManager
import
android.os.Build
import
android.os.Environment
import
java.util.regex.Pattern
import
android.app.ActivityManager.RunningAppProcessInfo
object
AppUtil
{
...
...
@@ -168,4 +172,20 @@ object AppUtil {
return
sdcardAbsPath
}
fun
isAppBackground
(
context
:
Context
,
packageName
:
String
):
Boolean
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
return
AdbUtil
.
isAppActive
(
packageName
)
}
val
activityManager
=
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
)
as
ActivityManager
val
appProcesses
=
activityManager
.
runningAppProcesses
for
(
appProcess
in
appProcesses
)
{
if
(
appProcess
.
processName
==
packageName
)
{
return
appProcess
.
importance
==
RunningAppProcessInfo
.
IMPORTANCE_BACKGROUND
}
}
return
false
}
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
0dbc9c45
...
...
@@ -27,13 +27,6 @@
android:layout_height=
"wrap_content"
android:text=
"启动"
/>
<Button
android:id=
"@+id/stopBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"10dp"
android:text=
"停止"
/>
<Button
android:id=
"@+id/refreshBtn"
android:layout_width=
"wrap_content"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment