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
47474660
authored
Apr 29, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除因重命名导致冗余的代码文件
parent
bbc3bf26
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
136 deletions
+0
-136
app/src/main/java/com/bgycc/smartcanteen/util/DangerousUtils.java
+0
-0
app/src/main/java/com/bgycc/smartcanteen/util/DeviceProxy.java
+0
-23
app/src/main/java/com/bgycc/smartcanteen/util/InstallManager.java
+0
-113
No files found.
app/src/main/java/com/bgycc/smartcanteen/util/DangerousUtils.java
deleted
100644 → 0
View file @
bbc3bf26
This diff is collapsed.
Click to expand it.
app/src/main/java/com/bgycc/smartcanteen/util/DeviceProxy.java
deleted
100644 → 0
View file @
bbc3bf26
package
com
.
bgycc
.
smartcanteen
.
util
;
import
com.bgycc.smartcanteen.qrcode.IQRCodeScan
;
import
com.bgycc.smartcanteen.qrcode.QRCodeScanFactory
;
import
java.io.File
;
/**
* 多设备相关方案的代理类 <br/>
* 设计该代理类目的是为了增加设备时,务必在下面所有方法的实际执行里进行适配
*/
public
class
DeviceProxy
{
public
static
final
String
DEVICE_MODEL_TPS
=
"TPS"
;
public
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
);
}
}
app/src/main/java/com/bgycc/smartcanteen/util/InstallManager.java
deleted
100644 → 0
View file @
bbc3bf26
package
com
.
bgycc
.
smartcanteen
.
util
;
import
android.content.ComponentName
;
import
android.content.Intent
;
import
android.os.Build
;
import
com.bgycc.smartcanteen.BuildConfig
;
import
com.bgycc.smartcanteen.activity.MainActivity
;
import
com.blankj.utilcode.util.AppUtils
;
import
com.blankj.utilcode.util.FileUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.PathUtils
;
import
com.blankj.utilcode.util.Utils
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
InstallManager
{
private
static
final
String
TAG
=
"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
))
{
// 检查守护进程的安装情况,及其安装版本
if
(!
AppUtils
.
isAppInstalled
(
DAEMON_PACKAGE_NAME
))
{
LogUtils
.
d
(
TAG
,
"守护app未安装,从assets复制并进行安装"
);
if
(
installDaemonFromAssets
(
false
))
{
return
DangerousUtils
.
installAppSilent
(
updateApk
);
}
}
else
{
// 若已安装,则检查是否需要更新
AppUtils
.
AppInfo
daemonAppInfo
=
AppUtils
.
getAppInfo
(
DAEMON_PACKAGE_NAME
);
if
(
daemonAppInfo
.
getVersionCode
()
<
BuildConfig
.
DaemonVersion
)
{
LogUtils
.
d
(
TAG
,
"当前守护app版本: "
+
daemonAppInfo
.
getVersionCode
()
+
", 最新版本: "
+
BuildConfig
.
DaemonVersion
);
if
(
installDaemonFromAssets
(
true
))
{
return
DangerousUtils
.
installAppSilent
(
updateApk
);
}
}
}
startDaemonForInstall
(
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
)
{
File
daemonApk
=
new
File
(
PathUtils
.
getExternalStoragePath
(),
DAEMON_APK_NAME
);
try
{
copyDaemonApkToTarget
(
daemonApk
);
boolean
result
=
DangerousUtils
.
installAppSilent
(
daemonApk
);
LogUtils
.
d
(
TAG
,
"守护app安装结果: "
+
result
);
if
(!
result
)
{
LogUtils
.
d
(
TAG
,
"守护app"
+
(
update
?
"更新"
:
"安装"
)
+
"失败,启动静默安装"
);
return
true
;
}
}
catch
(
IOException
e
)
{
LogUtils
.
d
(
TAG
,
update
?
"assets文件夹中未找到守护apk,或守护app复制失败,启动静默安装"
:
"新版app复制失败,启动静默安装"
,
e
);
return
true
;
}
finally
{
FileUtils
.
delete
(
daemonApk
);
}
return
false
;
}
private
static
void
startDaemonForInstall
(
File
updateApk
)
{
LogUtils
.
d
(
TAG
,
"启动守护app进行更新操作"
);
ComponentName
componentName
=
new
ComponentName
(
DAEMON_PACKAGE_NAME
,
DAEMON_SERVICE_NAME
);
Intent
intent
=
new
Intent
();
intent
.
putExtra
(
ARG_PATH
,
updateApk
.
getAbsolutePath
());
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
);
}
}
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