Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1c3df0fa
authored
Jun 03, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复一个因为shell立即执行导致任务未完成而不断循环的问题
parent
df2f1314
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
+14
-5
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
View file @
1c3df0fa
...
...
@@ -6,17 +6,23 @@ import androidx.annotation.NonNull;
import
androidx.work.WorkerParameters
;
import
com.bgycc.smartcanteen.entity.CommandShell
;
import
com.bgycc.smartcanteen.executor.SCTaskExecutor
;
import
com.bgycc.smartcanteen.utils.DangerousUtils
;
import
com.blankj.utilcode.util.EncryptUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.ShellUtils
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
public
class
ShellCommandWorker
extends
CommandWorker
{
private
static
final
String
KEY
=
"sc_shell"
;
private
static
final
String
TRANSFORMATION
=
"DES/CBC/PKCS5Padding"
;
private
static
final
String
IV
=
"12345678"
;
// shell指令需要在其他线程延迟执行(先让任务被标记为成功,否则可能会引发异常)
private
static
final
long
EXEC_DELAY
=
500
;
private
CommandShell
commandShell
;
public
ShellCommandWorker
(
@NonNull
Context
context
,
@NonNull
WorkerParameters
workerParams
)
{
...
...
@@ -33,13 +39,16 @@ public class ShellCommandWorker extends CommandWorker {
}
CommandShell
.
CommandShellData
data
=
commandShell
.
getData
();
byte
[]
decryptAES
=
EncryptUtils
.
decryptHexStringAES
(
data
.
getShell
(),
KEY
.
getBytes
(),
TRANSFORMATION
,
IV
.
getBytes
());
String
shell
=
new
String
(
decryptAES
);
final
String
shell
=
new
String
(
decryptAES
);
inProgress
(
"开始执行shell: "
+
shell
);
LogUtils
.
d
(
TAG
,
"执行shell: "
+
shell
);
ShellUtils
.
CommandResult
result
=
ShellUtils
.
execCmd
(
shell
,
DangerousUtils
.
isDeviceRooted
());
LogUtils
.
d
(
TAG
,
"shell执行结果: "
+
result
.
result
+
"\nsuccess: "
+
result
.
successMsg
+
"\nerror: "
+
result
.
errorMsg
);
SCTaskExecutor
.
getInstance
()
.
schedule
(()
->
{
ShellUtils
.
CommandResult
result
=
ShellUtils
.
execCmd
(
shell
,
DangerousUtils
.
isDeviceRooted
());
LogUtils
.
d
(
TAG
,
"shell执行结果: "
+
result
.
result
+
"\nsuccess: "
+
result
.
successMsg
+
"\nerror: "
+
result
.
errorMsg
);
},
EXEC_DELAY
,
TimeUnit
.
MILLISECONDS
);
return
success
();
}
}
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