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
de0b3030
Commit
de0b3030
authored
Sep 25, 2018
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task run
parent
a8ded119
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
108 additions
and
35 deletions
+108
-35
.gitignore
.gitignore
+0
-12
MainActivity.kt
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
+26
-2
Task.kt
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
+14
-4
BylRobotService.kt
...main/java/com/duolebo/blyrobot/service/BylRobotService.kt
+19
-6
TaskManager.kt
app/src/main/java/com/duolebo/blyrobot/tools/TaskManager.kt
+28
-1
AdbUtil.kt
app/src/main/java/com/duolebo/blyrobot/util/AdbUtil.kt
+2
-2
Constants.kt
app/src/main/java/com/duolebo/blyrobot/util/Constants.kt
+7
-3
CaptureWebServer.kt
...rc/main/java/com/duolebo/blyrobot/web/CaptureWebServer.kt
+1
-1
activity_main.xml
app/src/main/res/layout/activity_main.xml
+7
-0
build.gradle
build.gradle
+1
-1
gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+3
-3
No files found.
.gitignore
View file @
de0b3030
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
/captures
.externalNativeBuild
### Android template
# Built application files
*.apk
...
...
@@ -41,16 +39,6 @@ proguard/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks
...
...
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
View file @
de0b3030
...
...
@@ -6,22 +6,46 @@ import android.support.v4.content.LocalBroadcastManager
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
android.widget.Button
import
com.duolebo.blyrobot.service.BylRobotService
import
com.duolebo.blyrobot.util.Constants
class
MainActivity
:
AppCompatActivity
()
{
private
val
TAG
=
"MainActivity"
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
Log
.
i
(
""
,
"onCreate...."
)
Log
.
i
(
TAG
,
"onCreate...."
)
setContentView
(
R
.
layout
.
activity_main
)
startRobotService
()
val
startBtn
=
findViewById
<
Button
>(
R
.
id
.
startBtn
)
startBtn
.
setOnClickListener
{
startRobot
()
}
val
stopBtn
=
findViewById
<
Button
>(
R
.
id
.
stopBtn
)
stopBtn
.
setOnClickListener
{
stopRobot
()
}
startBtn
.
requestFocus
()
}
private
fun
startRobotService
()
{
startService
(
Intent
(
this
,
BylRobotService
::
class
.
java
))
}
private
fun
startRobot
()
{
val
intent
=
Intent
()
Log
.
i
(
TAG
,
"startRobot..."
)
val
intent
=
Intent
(
Constants
.
ACTION_LOCAL_SERVICE
)
intent
.
putExtra
(
Constants
.
KEY_CMD
,
Constants
.
CMD_START
)
LocalBroadcastManager
.
getInstance
(
this
).
sendBroadcast
(
intent
)
}
private
fun
stopRobot
()
{
val
intent
=
Intent
(
Constants
.
ACTION_LOCAL_SERVICE
)
intent
.
putExtra
(
Constants
.
KEY_CMD
,
Constants
.
CMD_STOP
)
LocalBroadcastManager
.
getInstance
(
this
).
sendBroadcast
(
intent
)
}
...
...
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
View file @
de0b3030
...
...
@@ -20,7 +20,7 @@ class Task {
private
var
launchDelay
=
15
private
var
context
:
Context
private
val
imageDateFormat
=
SimpleDateFormat
(
"yyyy_MM_dd_HH_mm_ss"
,
Locale
.
CHINA
)
var
proc
:
Process
?
=
null
var
proc
:
Process
?
=
null
constructor
(
context
:
Context
)
{
this
.
context
=
context
...
...
@@ -38,10 +38,14 @@ class Task {
fun
start
()
{
this
.
launchApp
()
stop
()
}
fun
finish
()
{
fun
stop
()
{
AdbUtil
.
stopApp
(
this
.
packageName
)
this
.
taskListener
?.
run
{
onComplete
()
}
}
fun
launchApp
(
reset
:
Boolean
=
true
)
{
...
...
@@ -49,7 +53,7 @@ class Task {
AdbUtil
.
resetApp
(
this
.
packageName
)
}
AdbUtil
.
launchApp
(
"
{$packageName}/{$launcher}
"
)
AdbUtil
.
launchApp
(
"
$packageName/$launcher
"
)
Thread
.
sleep
(
launchDelay
*
1000L
)
}
...
...
@@ -104,7 +108,7 @@ class Task {
fun
screenShot
()
{
val
time
=
imageDateFormat
.
format
(
Date
())
val
imagePath
=
this
.
imagePath
+
"/
{$
packageName}_$time.png"
val
imagePath
=
this
.
imagePath
+
"/
${
packageName}_$time.png"
AdbUtil
.
screenShot
(
imagePath
)
}
...
...
@@ -126,4 +130,10 @@ class Task {
}
}
var
taskListener
:
OnTaskListener
?
=
null
interface
OnTaskListener
{
fun
onComplete
()
}
}
\ No newline at end of file
app/src/main/java/com/duolebo/blyrobot/service/BylRobotService.kt
View file @
de0b3030
...
...
@@ -10,6 +10,7 @@ import android.os.IBinder
import
android.support.v4.content.LocalBroadcastManager
import
android.util.Log
import
com.duolebo.blyrobot.data.Task
import
com.duolebo.blyrobot.tools.TaskManager
import
com.duolebo.blyrobot.util.AdbUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Constants
...
...
@@ -22,17 +23,23 @@ class BylRobotService: Service() {
private
val
TAG
=
"BylRobotService"
private
var
timer
:
Timer
?
=
null
private
var
count
=
0
private
val
tasks
=
ArrayList
<
Task
>()
private
val
broadcastReceiver
=
object
:
BroadcastReceiver
()
{
override
fun
onReceive
(
p0
:
Context
?,
p1
:
Intent
?)
{
override
fun
onReceive
(
p0
:
Context
?,
intent
:
Intent
?)
{
if
(
intent
!=
null
)
{
val
cmd
=
intent
.
getStringExtra
(
Constants
.
KEY_CMD
)
when
(
cmd
)
{
Constants
.
CMD_START
->
loadTask
()
Constants
.
CMD_STOP
->
stopTask
()
}
loadTask
()
}
}
}
override
fun
onCreate
()
{
super
.
onCreate
()
initBroadcast
()
timer
=
Timer
()
timer
!!
.
schedule
(
object
:
TimerTask
()
{
...
...
@@ -50,16 +57,22 @@ class BylRobotService: Service() {
}
private
fun
initBroadcast
()
{
val
intentFilter
=
IntentFilter
(
Constants
.
BC_SERVICE
)
Log
.
i
(
TAG
,
"initBroadcast..."
)
val
intentFilter
=
IntentFilter
(
Constants
.
ACTION_LOCAL_SERVICE
)
LocalBroadcastManager
.
getInstance
(
this
).
registerReceiver
(
broadcastReceiver
,
intentFilter
)
}
private
fun
loadTask
()
{
Log
.
i
(
TAG
,
"loadTask..."
)
val
task
=
Task
(
this
)
task
.
from
(
JSONObject
(
AppUtil
.
readFromAssert
(
this
,
"test.json"
)))
tasks
.
add
(
task
)
TaskManager
.
instance
.
add
(
task
)
TaskManager
.
instance
.
start
()
}
private
fun
stopTask
()
{
TaskManager
.
instance
.
stop
()
}
private
fun
screenShot
()
{
Thread
(
Runnable
{
...
...
app/src/main/java/com/duolebo/blyrobot/tools/TaskManager.kt
View file @
de0b3030
package
com.duolebo.blyrobot.tools
import
android.util.Log
import
com.duolebo.blyrobot.data.Task
import
kotlin.collections.ArrayList
class
TaskManager
{
private
val
TAG
=
"TaskManager"
private
val
tasks
=
ArrayList
<
Task
>()
private
var
isRunning
=
false
private
var
currentTask
:
Task
?=
null
private
val
runnable
=
Runnable
{
while
(
isRunning
&&
tasks
.
size
>
0
)
{
currentTask
=
tasks
[
0
]
currentTask
!!
.
start
()
}
}
fun
add
(
task
:
Task
)
{
task
.
taskListener
=
object
:
Task
.
OnTaskListener
{
override
fun
onComplete
()
{
remove
(
task
)
}
}
this
.
tasks
.
add
(
task
)
}
...
...
@@ -29,10 +45,21 @@ class TaskManager {
}
fun
start
()
{
if
(
this
.
isRunning
)
{
Log
.
i
(
TAG
,
"is running"
)
return
}
this
.
isRunning
=
true
val
t
=
Thread
(
runnable
)
t
.
start
()
}
fun
stop
()
{
this
.
tasks
.
clear
()
this
.
isRunning
=
false
}
companion
object
{
val
instance
=
TaskManager
()
}
}
\ No newline at end of file
app/src/main/java/com/duolebo/blyrobot/util/AdbUtil.kt
View file @
de0b3030
...
...
@@ -247,11 +247,11 @@ object AdbUtil {
}
fun
resetApp
(
packageName
:
String
)
{
exeCmdEcho
(
"pm clear $packageName"
)
exeCmdEcho
(
"pm clear $packageName"
,
true
)
}
fun
launchApp
(
launchInfo
:
String
)
{
exeCmdEcho
(
"am start -n $launchInfo"
)
exeCmdEcho
(
"am start -n $launchInfo"
,
true
)
}
fun
stopApp
(
packageName
:
String
)
{
...
...
app/src/main/java/com/duolebo/blyrobot/util/Constants.kt
View file @
de0b3030
package
com.duolebo.blyrobot.util
object
Constants
{
val
KEY_URL
=
"url"
val
KEY_TIME
=
"time"
const
val
KEY_URL
=
"url"
const
val
KEY_TIME
=
"time"
const
val
KEY_CMD
=
"cmd"
const
val
CMD_START
=
"start"
const
val
CMD_STOP
=
"stop"
val
KEY_MAP
=
mapOf
(
"0"
to
"7"
,
...
...
@@ -34,5 +38,5 @@ object Constants {
const
val
LAUNCHER
=
"launcher"
const
val
LAUNCH_DELAY
=
"launchDelay"
const
val
BC_SERVICE
=
"broadcast
_service"
const
val
ACTION_LOCAL_SERVICE
=
"action_local
_service"
}
\ No newline at end of file
app/src/main/java/com/duolebo/blyrobot/web/CaptureWebServer.kt
View file @
de0b3030
...
...
@@ -92,7 +92,7 @@ class CaptureWebServer : NanoHTTPD {
val
appInfo
=
next
.
appInfo
if
(
appInfo
!=
null
)
{
val
appPackageName
=
appInfo
!!
.
pkgs
.
getAt
(
0
)
val
appPackageName
=
appInfo
.
pkgs
.
getAt
(
0
)
if
(
packageName
==
appPackageName
)
{
iterator
.
remove
()
continue
...
...
app/src/main/res/layout/activity_main.xml
View file @
de0b3030
...
...
@@ -15,6 +15,13 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"启动"
/>
<Button
android:id=
"@+id/stopBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"停止"
/>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
build.gradle
View file @
de0b3030
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
{
ext
.
kotlin_version
=
'1.2.
6
1'
ext
.
kotlin_version
=
'1.2.
7
1'
repositories
{
google
()
jcenter
()
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
de0b3030
#
Mon Jul 09 10:52:01
CST 2018
#
Tue Sep 25 09:27:36
CST 2018
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.4-all.zip
android.enableBuildCache
=
false
\ No newline at end of file
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-4.6-all.zip
android.enableBuildCache
=
false
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