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
82fbbeb1
authored
May 20, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
4189ff05
ce425b44
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
185 additions
and
92 deletions
+185
-92
app/src/main/java/com/bgycc/smartcanteen/command/LogCommandWorker.java
+5
-5
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandWorker.java
+1
-1
app/src/main/java/com/bgycc/smartcanteen/device/DeviceFeatures.java
+15
-0
app/src/main/java/com/bgycc/smartcanteen/device/QUADDevice.java
+32
-0
app/src/main/java/com/bgycc/smartcanteen/device/TPSDevice.java
+30
-0
app/src/main/java/com/bgycc/smartcanteen/installer/DefaultInstaller.java
+40
-0
app/src/main/java/com/bgycc/smartcanteen/installer/QUADInstaller.java
+15
-0
app/src/main/java/com/bgycc/smartcanteen/installer/TPSInstaller.java
+22
-48
app/src/main/java/com/bgycc/smartcanteen/qrcode/DefaultQRCodeScan.java
+2
-1
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
+0
-20
app/src/main/java/com/bgycc/smartcanteen/utils/DeviceProxy.java
+23
-17
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/LogCommandWorker.java
View file @
82fbbeb1
...
...
@@ -14,8 +14,6 @@ import com.blankj.utilcode.util.LogUtils;
import
com.blankj.utilcode.util.PathUtils
;
import
com.blankj.utilcode.util.ZipUtils
;
import
org.jetbrains.annotations.NotNull
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
...
...
@@ -149,15 +147,14 @@ public class LogCommandWorker extends CommandWorker {
return
zip
;
}
@NotNull
private
File
getLogDirByType
(
String
logType
)
{
File
logDir
;
if
(
logType
.
equals
(
BOOT_LOG
))
{
logDir
=
new
File
(
DeviceProxy
.
getSystemLogDir
()
);
logDir
=
DeviceProxy
.
systemLogDir
(
);
}
else
{
logDir
=
new
File
(
LogUtils
.
getConfig
().
getDir
());
}
LogUtils
.
d
(
TAG
,
"待上传日志文件类型: "
+
logType
);
LogUtils
.
d
(
TAG
,
"待上传日志文件类型: "
+
logType
+
", 日志文件夹路径: "
+
(
logDir
!=
null
?
logDir
:
"null"
)
);
return
logDir
;
}
...
...
@@ -177,6 +174,9 @@ public class LogCommandWorker extends CommandWorker {
}
private
boolean
copyTargetFiles
(
File
src
,
File
descDir
)
{
if
(
src
==
null
||
descDir
==
null
)
{
return
true
;
}
FileFilter
filter
=
file
->
{
Date
date
=
new
Date
(
file
.
lastModified
());
return
date
.
after
(
startTime
)
&&
date
.
before
(
endTime
);
...
...
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandWorker.java
View file @
82fbbeb1
...
...
@@ -154,7 +154,7 @@ public class UpdateCommandWorker extends CommandWorker {
inProgress
(
"不允许安装低版本"
);
}
else
{
LogUtils
.
d
(
TAG
,
"开始安装更新包: "
+
updateApk
.
getAbsolutePath
());
if
(
DeviceProxy
.
updateApp
(
updateApk
))
{
if
(
DeviceProxy
.
updateApp
(
getApplicationContext
(),
updateApk
))
{
inProgress
(
"开始安装"
);
}
else
{
inProgress
(
"安装文件权限修改失败"
);
...
...
app/src/main/java/com/bgycc/smartcanteen/device/DeviceFeatures.java
0 → 100644
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
device
;
import
android.content.Context
;
import
com.bgycc.smartcanteen.qrcode.IQRCodeScan
;
import
java.io.File
;
public
interface
DeviceFeatures
{
IQRCodeScan
createQRCodeScan
()
throws
Exception
;
File
systemLogDir
();
boolean
updateApp
(
Context
context
,
File
updateApk
);
}
app/src/main/java/com/bgycc/smartcanteen/device/QUADDevice.java
0 → 100644
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
device
;
import
android.content.Context
;
import
com.bgycc.smartcanteen.installer.QUADInstaller
;
import
com.bgycc.smartcanteen.qrcode.DefaultQRCodeScan
;
import
com.bgycc.smartcanteen.qrcode.IQRCodeScan
;
import
com.blankj.utilcode.util.PathUtils
;
import
com.telpo.tps550.api.DeviceAlreadyOpenException
;
import
java.io.File
;
import
java.io.IOException
;
public
class
QUADDevice
implements
DeviceFeatures
{
private
static
final
String
SYSTEM_LOG_DIR_NAME
=
"boot_log"
;
private
static
final
String
PORT
=
"/dev/ttyS6"
;
@Override
public
IQRCodeScan
createQRCodeScan
()
throws
IOException
,
DeviceAlreadyOpenException
{
return
new
DefaultQRCodeScan
(
PORT
);
}
@Override
public
File
systemLogDir
()
{
return
new
File
(
PathUtils
.
getExternalStoragePath
()
+
File
.
separator
+
SYSTEM_LOG_DIR_NAME
);
}
@Override
public
boolean
updateApp
(
Context
context
,
File
updateApk
)
{
return
new
QUADInstaller
().
install
(
context
,
updateApk
);
}
}
app/src/main/java/com/bgycc/smartcanteen/device/TPSDevice.java
0 → 100644
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
device
;
import
android.content.Context
;
import
com.bgycc.smartcanteen.installer.TPSInstaller
;
import
com.bgycc.smartcanteen.qrcode.DefaultQRCodeScan
;
import
com.bgycc.smartcanteen.qrcode.IQRCodeScan
;
import
com.telpo.tps550.api.DeviceAlreadyOpenException
;
import
java.io.File
;
import
java.io.IOException
;
public
class
TPSDevice
implements
DeviceFeatures
{
private
static
final
String
PORT
=
"/dev/ttyS0"
;
@Override
public
IQRCodeScan
createQRCodeScan
()
throws
IOException
,
DeviceAlreadyOpenException
{
return
new
DefaultQRCodeScan
(
PORT
);
}
@Override
public
File
systemLogDir
()
{
return
null
;
}
@Override
public
boolean
updateApp
(
Context
context
,
File
updateApk
)
{
return
new
TPSInstaller
().
install
(
context
,
updateApk
);
}
}
app/src/main/java/com/bgycc/smartcanteen/installer/DefaultInstaller.java
0 → 100644
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
installer
;
import
android.content.Context
;
import
android.os.Build
;
import
com.blankj.utilcode.util.LogUtils
;
import
java.io.File
;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
@SuppressWarnings
(
"all"
)
public
abstract
class
DefaultInstaller
{
protected
static
final
String
ARG_PATH
=
"arg_path"
;
protected
static
final
String
ARG_COMPONENT
=
"arg_package"
;
// assets文件夹中守护进程apk名称
protected
static
final
String
DAEMON_APK_NAME
=
"Daemon.apk"
;
// 守护package name
protected
static
final
String
DAEMON_PACKAGE_NAME
=
"com.bgycc.smartcanteen.daemon"
;
// 守护服务类名称
protected
static
final
String
DAEMON_SERVICE_NAME
=
"com.bgycc.smartcanteen.daemon.DaemonService"
;
public
final
boolean
install
(
Context
context
,
File
updateApk
)
{
String
model
=
Build
.
MODEL
;
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
M
)
{
// 6.0以下安装包需要修改权限才能安装
try
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
"chmod 755 "
+
updateApk
);
p
.
waitFor
();
LogUtils
.
d
(
TAG
,
"安装文件权限修改成功"
);
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"安装文件权限修改失败"
);
return
false
;
}
}
return
installActual
(
context
,
updateApk
);
}
public
abstract
boolean
installActual
(
Context
context
,
File
updateApk
);
}
app/src/main/java/com/bgycc/smartcanteen/installer/QUADInstaller.java
0 → 100644
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
installer
;
import
android.content.Context
;
import
com.blankj.utilcode.util.AppUtils
;
import
java.io.File
;
public
class
QUADInstaller
extends
DefaultInstaller
{
@Override
public
boolean
installActual
(
Context
context
,
File
updateApk
)
{
AppUtils
.
installApp
(
updateApk
);
return
true
;
}
}
app/src/main/java/com/bgycc/smartcanteen/
utils/InstallManag
er.java
→
app/src/main/java/com/bgycc/smartcanteen/
installer/TPSInstall
er.java
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
utils
;
package
com
.
bgycc
.
smartcanteen
.
installer
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Build
;
import
com.bgycc.smartcanteen.BuildConfig
;
import
com.bgycc.smartcanteen.activity.MainActivity
;
import
com.bgycc.smartcanteen.utils.DangerousUtils
;
import
com.blankj.utilcode.util.AppUtils
;
import
com.blankj.utilcode.util.FileUtils
;
import
com.blankj.utilcode.util.LogUtils
;
...
...
@@ -19,30 +20,9 @@ import java.io.InputStream;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
public
class
InstallManager
{
private
static
final
String
ARG_PATH
=
"arg_path"
;
private
static
final
String
ARG_COMPONENT
=
"arg_package"
;
// assets文件夹中守护进程apk名称
private
static
final
String
DAEMON_APK_NAME
=
"Daemon.apk"
;
// 守护package name
private
static
final
String
DAEMON_PACKAGE_NAME
=
"com.bgycc.smartcanteen.daemon"
;
// 守护服务类名称
private
static
final
String
DAEMON_SERVICE_NAME
=
"com.bgycc.smartcanteen.daemon.DaemonService"
;
public
static
boolean
install
(
File
updateApk
)
{
String
model
=
Build
.
MODEL
;
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
M
)
{
// 6.0以下安装包需要修改权限才能安装
try
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
"chmod 755 "
+
updateApk
);
p
.
waitFor
();
LogUtils
.
d
(
TAG
,
"安装文件权限修改成功"
);
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"安装文件权限修改失败"
);
return
false
;
}
}
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_TPS
))
{
public
class
TPSInstaller
extends
DefaultInstaller
{
@Override
public
boolean
installActual
(
Context
context
,
File
updateApk
)
{
// 检查守护进程的安装情况,及其安装版本
if
(!
AppUtils
.
isAppInstalled
(
DAEMON_PACKAGE_NAME
))
{
LogUtils
.
d
(
TAG
,
"守护app未安装,从assets复制并进行安装"
);
...
...
@@ -59,27 +39,8 @@ public class InstallManager {
}
}
}
startDaemonForInstall
(
updateApk
);
startDaemonForInstall
(
context
,
updateApk
);
return
true
;
}
else
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_QUAD
))
{
AppUtils
.
installApp
(
updateApk
);
return
true
;
}
else
{
throw
new
RuntimeException
(
"不明设备型号: "
+
model
);
}
}
private
static
void
copyDaemonApkToTarget
(
File
daemonApk
)
throws
IOException
{
InputStream
is
=
Utils
.
getApp
().
getAssets
().
open
(
DAEMON_APK_NAME
);
FileOutputStream
fos
=
new
FileOutputStream
(
daemonApk
);
byte
[]
buffer
=
new
byte
[
1024
];
int
byteCount
;
while
((
byteCount
=
is
.
read
(
buffer
))
!=
-
1
)
{
fos
.
write
(
buffer
,
0
,
byteCount
);
}
fos
.
flush
();
is
.
close
();
fos
.
close
();
}
private
static
boolean
installDaemonFromAssets
(
boolean
update
)
{
...
...
@@ -101,7 +62,20 @@ public class InstallManager {
return
false
;
}
private
static
void
startDaemonForInstall
(
File
updateApk
)
{
private
static
void
copyDaemonApkToTarget
(
File
daemonApk
)
throws
IOException
{
InputStream
is
=
Utils
.
getApp
().
getAssets
().
open
(
DAEMON_APK_NAME
);
FileOutputStream
fos
=
new
FileOutputStream
(
daemonApk
);
byte
[]
buffer
=
new
byte
[
1024
];
int
byteCount
;
while
((
byteCount
=
is
.
read
(
buffer
))
!=
-
1
)
{
fos
.
write
(
buffer
,
0
,
byteCount
);
}
fos
.
flush
();
is
.
close
();
fos
.
close
();
}
private
static
void
startDaemonForInstall
(
Context
context
,
File
updateApk
)
{
LogUtils
.
d
(
TAG
,
"启动守护app进行更新操作"
);
ComponentName
componentName
=
new
ComponentName
(
DAEMON_PACKAGE_NAME
,
DAEMON_SERVICE_NAME
);
Intent
intent
=
new
Intent
();
...
...
@@ -109,6 +83,6 @@ public class InstallManager {
intent
.
putExtra
(
ARG_COMPONENT
,
BuildConfig
.
APPLICATION_ID
+
File
.
separator
+
MainActivity
.
class
.
getName
());
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
setComponent
(
componentName
);
Utils
.
getApp
()
.
startService
(
intent
);
context
.
startService
(
intent
);
}
}
app/src/main/java/com/bgycc/smartcanteen/qrcode/DefaultQRCodeScan.java
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.telpo.tps550.api.DeviceAlreadyOpenException
;
import
com.telpo.tps550.api.serial.Serial
;
import
java.io.IOException
;
...
...
@@ -13,7 +14,7 @@ public class DefaultQRCodeScan implements IQRCodeScan {
private
Serial
serial
;
private
InputStream
serialPortIS
;
public
DefaultQRCodeScan
(
String
portPath
)
throws
Exception
{
public
DefaultQRCodeScan
(
String
portPath
)
throws
IOException
,
DeviceAlreadyOpen
Exception
{
serial
=
new
Serial
(
portPath
,
115200
,
0
);
this
.
serialPortIS
=
serial
.
getInputStream
();
}
...
...
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
deleted
100644 → 0
View file @
4189ff05
package
com
.
bgycc
.
smartcanteen
.
qrcode
;
import
android.os.Build
;
import
com.bgycc.smartcanteen.utils.DeviceProxy
;
public
class
QRCodeScanFactory
{
private
static
final
String
TPS_PORT
=
"/dev/ttyS0"
;
private
static
final
String
QUAD_PORT
=
"/dev/ttyS6"
;
public
static
IQRCodeScan
create
()
throws
Exception
{
String
model
=
Build
.
MODEL
;
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_TPS
))
{
return
new
DefaultQRCodeScan
(
TPS_PORT
);
}
else
if
(
model
.
contains
(
DeviceProxy
.
DEVICE_MODEL_QUAD
))
{
return
new
DefaultQRCodeScan
(
QUAD_PORT
);
}
else
{
throw
new
RuntimeException
(
"不明设备型号: "
+
model
);
}
}
}
app/src/main/java/com/bgycc/smartcanteen/utils/DeviceProxy.java
View file @
82fbbeb1
package
com
.
bgycc
.
smartcanteen
.
utils
;
import
android.content.Context
;
import
android.os.Build
;
import
com.bgycc.smartcanteen.device.DeviceFeatures
;
import
com.bgycc.smartcanteen.device.QUADDevice
;
import
com.bgycc.smartcanteen.device.TPSDevice
;
import
com.bgycc.smartcanteen.qrcode.IQRCodeScan
;
import
com.bgycc.smartcanteen.qrcode.QRCodeScanFactory
;
import
com.blankj.utilcode.util.PathUtils
;
import
java.io.File
;
...
...
@@ -13,26 +15,30 @@ import java.io.File;
* 设计该代理类目的是为了增加设备时,务必在下面所有方法的实际执行里进行适配
*/
public
class
DeviceProxy
{
public
static
final
String
DEVICE_MODEL_TPS
=
"TPS"
;
public
static
final
String
DEVICE_MODEL_QUAD
=
"QUAD"
;
private
static
final
String
QUAD_SYSTEM_LOG
=
"boot_log"
;
private
static
final
String
DEVICE_MODEL_TPS
=
"TPS"
;
private
static
final
String
DEVICE_MODEL_QUAD
=
"QUAD"
;
public
static
IQRCodeScan
createQRCodeScan
()
throws
Exception
{
return
QRCodeScanFactory
.
create
();
}
public
static
boolean
updateApp
(
File
updateApk
)
{
return
InstallManager
.
install
(
updateApk
);
}
public
static
String
getSystemLogDir
()
{
private
static
DeviceFeatures
deviceImpl
;
static
{
String
model
=
Build
.
MODEL
;
if
(
model
.
contains
(
DEVICE_MODEL_TPS
))
{
return
PathUtils
.
getExternalStoragePath
()
+
File
.
separator
+
QUAD_SYSTEM_LOG
;
deviceImpl
=
new
TPSDevice
()
;
}
else
if
(
model
.
contains
(
DEVICE_MODEL_QUAD
))
{
return
PathUtils
.
getExternalStoragePath
()
+
File
.
separator
+
QUAD_SYSTEM_LOG
;
deviceImpl
=
new
QUADDevice
()
;
}
else
{
return
PathUtils
.
getExternalStoragePath
()
+
File
.
separator
+
QUAD_SYSTEM_LOG
;
deviceImpl
=
new
TPSDevice
();
}
}
public
static
IQRCodeScan
createQRCodeScan
()
throws
Exception
{
return
deviceImpl
.
createQRCodeScan
();
}
public
static
boolean
updateApp
(
Context
context
,
File
updateApk
)
{
return
deviceImpl
.
updateApp
(
context
,
updateApk
);
}
public
static
File
systemLogDir
()
{
return
deviceImpl
.
systemLogDir
();
}
}
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