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
d58a3b8a
authored
Jun 03, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
9384cf62
1c3df0fa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
1 deletions
+138
-1
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
+5
-0
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
+54
-0
app/src/main/java/com/bgycc/smartcanteen/entity/CommandShell.java
+78
-0
app/src/main/java/com/bgycc/smartcanteen/utils/DangerousUtils.java
+1
-1
智慧食堂开发文档.docx
+0
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
View file @
d58a3b8a
...
...
@@ -17,6 +17,7 @@ public class CommandHelper {
private
static
final
String
APP_UPDATE
=
"CONFIG_UPDATE"
;
private
static
final
String
CONFIG_WIFI
=
"CONFIG_WIFI"
;
private
static
final
String
CONFIG_LOG
=
"CONFIG_LOG"
;
private
static
final
String
EXEC_SHELL
=
"EXEC_SHELL"
;
// 设备指令白名单
private
static
final
Set
<
String
>
COMMAND_WHITELIST
=
new
HashSet
<
String
>()
{
...
...
@@ -25,6 +26,7 @@ public class CommandHelper {
add
(
APP_UPDATE
);
add
(
CONFIG_WIFI
);
add
(
CONFIG_LOG
);
add
(
EXEC_SHELL
);
}
};
...
...
@@ -68,6 +70,9 @@ public class CommandHelper {
case
CONFIG_WIFI:
workerClass
=
WifiConfigCommandWorker
.
class
;
break
;
case
EXEC_SHELL:
workerClass
=
ShellCommandWorker
.
class
;
break
;
}
if
(
workerClass
!=
null
)
{
Data
inputData
=
CommandWorker
.
createBaseData
(
gson
.
toJson
(
command
),
deviceSN
);
...
...
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
0 → 100644
View file @
d58a3b8a
package
com
.
bgycc
.
smartcanteen
.
command
;
import
android.content.Context
;
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
)
{
super
(
context
,
workerParams
);
this
.
commandShell
=
gson
.
fromJson
(
command
.
getData
(),
CommandShell
.
class
);
}
@NonNull
@Override
public
Result
doWork
()
{
if
(
commandShell
.
getData
()
==
null
)
{
return
failed
(
"shell指令非法"
);
}
CommandShell
.
CommandShellData
data
=
commandShell
.
getData
();
byte
[]
decryptAES
=
EncryptUtils
.
decryptHexStringAES
(
data
.
getShell
(),
KEY
.
getBytes
(),
TRANSFORMATION
,
IV
.
getBytes
());
final
String
shell
=
new
String
(
decryptAES
);
inProgress
(
"开始执行shell: "
+
shell
);
LogUtils
.
d
(
TAG
,
"执行shell: "
+
shell
);
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
();
}
}
app/src/main/java/com/bgycc/smartcanteen/entity/CommandShell.java
0 → 100644
View file @
d58a3b8a
package
com
.
bgycc
.
smartcanteen
.
entity
;
import
java.util.Objects
;
public
class
CommandShell
{
private
String
action
;
private
CommandShellData
data
;
public
String
getAction
()
{
return
action
;
}
public
void
setAction
(
String
action
)
{
this
.
action
=
action
;
}
public
CommandShellData
getData
()
{
return
data
;
}
public
void
setData
(
CommandShellData
data
)
{
this
.
data
=
data
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CommandShell
that
=
(
CommandShell
)
o
;
return
Objects
.
equals
(
action
,
that
.
action
)
&&
Objects
.
equals
(
data
,
that
.
data
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
action
,
data
);
}
@Override
public
String
toString
()
{
return
"CommandShell{"
+
"action='"
+
action
+
'\''
+
", data="
+
data
+
'}'
;
}
public
static
class
CommandShellData
{
private
String
shell
;
public
String
getShell
()
{
return
shell
;
}
public
void
setShell
(
String
shell
)
{
this
.
shell
=
shell
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CommandShellData
that
=
(
CommandShellData
)
o
;
return
Objects
.
equals
(
shell
,
that
.
shell
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
shell
);
}
@Override
public
String
toString
()
{
return
"CommandShellData{"
+
"shell='"
+
shell
+
'\''
+
'}'
;
}
}
}
app/src/main/java/com/bgycc/smartcanteen/utils/DangerousUtils.java
View file @
d58a3b8a
...
...
@@ -199,7 +199,7 @@ public class DangerousUtils {
return
true
;
}
p
rivate
static
boolean
isDeviceRooted
()
{
p
ublic
static
boolean
isDeviceRooted
()
{
String
su
=
"su"
;
String
[]
locations
=
{
"/system/bin/"
,
"/system/xbin/"
,
"/sbin/"
,
"/system/sd/xbin/"
,
"/system/bin/failsafe/"
,
"/data/local/xbin/"
,
"/data/local/bin/"
,
"/data/local/"
,
...
...
智慧食堂开发文档.docx
View file @
d58a3b8a
No preview for this file type
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