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
8c787126
authored
Mar 13, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复UpdateCommandHandler单例在已初始化后再次调用不刷新下载地址的问题
parent
568f96b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
+15
-6
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandHandler.java
+15
-6
No files found.
app/src/main/java/com/bgycc/smartcanteen/command/UpdateCommandHandler.java
View file @
8c787126
...
@@ -60,12 +60,12 @@ public class UpdateCommandHandler extends CommandHandler {
...
@@ -60,12 +60,12 @@ public class UpdateCommandHandler extends CommandHandler {
synchronized
(
UpdateCommandHandler
.
class
)
{
synchronized
(
UpdateCommandHandler
.
class
)
{
if
(
instance
==
null
)
{
if
(
instance
==
null
)
{
instance
=
new
UpdateCommandHandler
(
command
,
gson
,
callback
);
instance
=
new
UpdateCommandHandler
(
command
,
gson
,
callback
);
}
else
{
instance
.
init
(
command
,
gson
,
callback
);
}
}
}
}
}
}
else
{
// 当callback发生变化时,重新设置
instance
.
init
(
command
,
gson
,
callback
);
if
(!
callback
.
equals
(
instance
.
commandProgressCallback
))
{
instance
.
commandProgressCallback
=
callback
;
}
}
return
instance
;
return
instance
;
}
}
...
@@ -88,6 +88,15 @@ public class UpdateCommandHandler extends CommandHandler {
...
@@ -88,6 +88,15 @@ public class UpdateCommandHandler extends CommandHandler {
FileUtils
.
delete
(
updateApk
);
FileUtils
.
delete
(
updateApk
);
}
}
private
void
init
(
Command
command
,
Gson
gson
,
CommandProgressCallback
callback
)
{
this
.
command
=
command
;
this
.
gson
=
gson
;
this
.
commandProgressCallback
=
callback
;
this
.
commandUpdate
=
gson
.
fromJson
(
command
.
getData
(),
CommandUpdate
.
class
);
this
.
updateApk
=
new
File
(
Utils
.
getApp
().
getCacheDir
(),
UPDATE_APK
);
FileUtils
.
delete
(
updateApk
);
}
@Override
@Override
public
synchronized
CommandResponse
run
()
{
public
synchronized
CommandResponse
run
()
{
if
(
start
)
{
if
(
start
)
{
...
@@ -154,14 +163,14 @@ public class UpdateCommandHandler extends CommandHandler {
...
@@ -154,14 +163,14 @@ public class UpdateCommandHandler extends CommandHandler {
AppUtils
.
AppInfo
info
=
AppUtils
.
getApkInfo
(
updateApk
);
AppUtils
.
AppInfo
info
=
AppUtils
.
getApkInfo
(
updateApk
);
if
(
info
==
null
||
!
info
.
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
if
(
info
==
null
||
!
info
.
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
FileUtils
.
delete
(
updateApk
);
FileUtils
.
delete
(
updateApk
);
LogUtils
.
w
(
TAG
,
"更新包包名非法
"
);
LogUtils
.
w
(
TAG
,
"更新包包名非法
: "
+
(
info
==
null
?
"null"
:
info
.
getPackageName
())
);
idle
(
""
,
0
);
idle
(
""
,
0
);
start
=
false
;
start
=
false
;
return
;
return
;
}
}
if
(
info
.
getVersionCode
()
==
BuildConfig
.
VERSION_CODE
)
{
if
(
info
.
getVersionCode
()
==
BuildConfig
.
VERSION_CODE
)
{
FileUtils
.
delete
(
updateApk
);
FileUtils
.
delete
(
updateApk
);
LogUtils
.
w
(
TAG
,
"
更新包已安装"
);
LogUtils
.
w
(
TAG
,
"
当前版本: "
+
BuildConfig
.
VERSION_CODE
+
", 安装包版本: "
+
info
.
getVersionCode
()
);
}
else
if
(
info
.
getVersionCode
()
<
BuildConfig
.
VERSION_CODE
)
{
}
else
if
(
info
.
getVersionCode
()
<
BuildConfig
.
VERSION_CODE
)
{
FileUtils
.
delete
(
updateApk
);
FileUtils
.
delete
(
updateApk
);
LogUtils
.
d
(
TAG
,
"不允许安装低版本"
);
LogUtils
.
d
(
TAG
,
"不允许安装低版本"
);
...
...
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