Skip to content

Commit f8e4b8e

Browse files
committed
make it more stronger with error handle
1 parent 6720bf8 commit f8e4b8e

File tree

2 files changed

+99
-60
lines changed

2 files changed

+99
-60
lines changed

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/callback/DefaultCheckCB.java

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ public void setBuilder (UpdateBuilder builder) {
2727

2828
@Override
2929
public void onCheckStart() {
30-
if (checkCB != null) {
31-
checkCB.onCheckStart();
30+
try {
31+
if (checkCB != null) {
32+
checkCB.onCheckStart();
33+
}
34+
} catch (Throwable t) {
35+
onCheckError(t);
3236
}
3337
}
3438

@@ -38,69 +42,88 @@ public void onCheckStart() {
3842
*/
3943
@Override
4044
public void hasUpdate(Update update) {
41-
if (checkCB != null) {
42-
checkCB.hasUpdate(update);
45+
try {
46+
if (checkCB != null) {
47+
checkCB.hasUpdate(update);
48+
}
49+
50+
if (!builder.getStrategy().isShowUpdateDialog(update)) {
51+
Updater.getInstance().downUpdate(update,builder);
52+
return;
53+
}
54+
55+
Activity current = ActivityManager.get().topActivity();
56+
57+
DialogCreator creator = builder.getUpdateDialogCreator();
58+
creator.setBuilder(builder);
59+
creator.setCheckCB(builder.getCheckCB());
60+
Dialog dialog = creator.create(update,current);
61+
SafeDialogOper.safeShowDialog(dialog);
62+
63+
release();
64+
} catch (Throwable t) {
65+
onCheckError(t);
4366
}
44-
45-
if (!builder.getStrategy().isShowUpdateDialog(update)) {
46-
Updater.getInstance().downUpdate(update,builder);
47-
return;
48-
}
49-
50-
Activity current = ActivityManager.get().topActivity();
51-
52-
DialogCreator creator = builder.getUpdateDialogCreator();
53-
creator.setBuilder(builder);
54-
creator.setCheckCB(builder.getCheckCB());
55-
Dialog dialog = creator.create(update,current);
56-
SafeDialogOper.safeShowDialog(dialog);
57-
58-
release();
5967
}
6068

6169
/**
6270
* Receive and pass no_update event send by {@link UpdateWorker#sendNoUpdate()}
6371
*/
6472
@Override
6573
public void noUpdate() {
66-
if (checkCB != null) {
67-
checkCB.noUpdate();
74+
try {
75+
if (checkCB != null) {
76+
checkCB.noUpdate();
77+
}
78+
release();
79+
} catch (Throwable t) {
80+
onCheckError(t);
6881
}
6982

70-
release();
7183
}
7284

7385
/**
7486
* Receive and pass check_error event send by {@link UpdateWorker#sendOnErrorMsg(Throwable)}
7587
*/
7688
@Override
7789
public void onCheckError(Throwable t) {
78-
if (checkCB != null) {
79-
checkCB.onCheckError(t);
90+
try {
91+
if (checkCB != null) {
92+
checkCB.onCheckError(t);
93+
}
94+
} catch (Throwable ignore) {
95+
ignore.printStackTrace();
96+
} finally {
97+
release();
8098
}
81-
82-
release();
8399
}
84100

85101
/**
86102
* will be never invoke
87103
*/
88104
@Override
89105
public void onUserCancel() {
90-
if (checkCB != null) {
91-
checkCB.onUserCancel();
106+
try {
107+
if (checkCB != null) {
108+
checkCB.onUserCancel();
109+
}
110+
release();
111+
} catch (Throwable t) {
112+
onCheckError(t);
92113
}
93114

94-
release();
95115
}
96116

97117
@Override
98118
public void onCheckIgnore(Update update) {
99-
if (checkCB != null) {
100-
checkCB.onCheckIgnore(update);
119+
try {
120+
if (checkCB != null) {
121+
checkCB.onCheckIgnore(update);
122+
}
123+
release();
124+
} catch (Throwable t) {
125+
onCheckError(t);
101126
}
102-
103-
release();
104127
}
105128

106129
@Override

updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/callback/DefaultDownloadCB.java

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ public void setUpdate(Update update) {
4747
*/
4848
@Override
4949
public void onUpdateStart() {
50-
if (downloadCB != null) {
51-
downloadCB.onUpdateStart();
52-
}
53-
innerCB = getInnerCB();
54-
if (innerCB != null) {
55-
innerCB.onUpdateStart();
50+
try {
51+
if (downloadCB != null) {
52+
downloadCB.onUpdateStart();
53+
}
54+
innerCB = getInnerCB();
55+
if (innerCB != null) {
56+
innerCB.onUpdateStart();
57+
}
58+
} catch (Throwable t) {
59+
onUpdateError(t);
5660
}
5761
}
5862

@@ -73,17 +77,21 @@ private UpdateDownloadCB getInnerCB() {
7377
*/
7478
@Override
7579
public void onUpdateComplete(File file) {
76-
if (downloadCB != null) {
77-
downloadCB.onUpdateComplete(file);
78-
}
80+
try {
81+
if (downloadCB != null) {
82+
downloadCB.onUpdateComplete(file);
83+
}
7984

80-
if (innerCB != null) {
81-
innerCB.onUpdateComplete(file);
82-
}
85+
if (innerCB != null) {
86+
innerCB.onUpdateComplete(file);
87+
}
8388

84-
showInstallDialogIfNeed(file);
89+
showInstallDialogIfNeed(file);
8590

86-
release();
91+
release();
92+
} catch (Throwable t) {
93+
onUpdateError(t);
94+
}
8795
}
8896

8997
public void showInstallDialogIfNeed(File file) {
@@ -106,29 +114,37 @@ public void showInstallDialogIfNeed(File file) {
106114
*/
107115
@Override
108116
public void onUpdateProgress(long current,long total) {
109-
if (downloadCB != null) {
110-
downloadCB.onUpdateProgress(current,total);
117+
try {
118+
if (downloadCB != null) {
119+
downloadCB.onUpdateProgress(current,total);
120+
}
121+
122+
if (innerCB != null) {
123+
innerCB.onUpdateProgress(current,total);
124+
}
125+
} catch (Throwable t) {
126+
onUpdateError(t);
111127
}
112128

113-
if (innerCB != null) {
114-
innerCB.onUpdateProgress(current,total);
115-
}
116129
}
117130

118131
/**
119132
* Receive and pass download_error event send by {@link DownloadWorker#sendUpdateError(Throwable)}
120133
*/
121134
@Override
122135
public void onUpdateError(Throwable t) {
123-
if (downloadCB != null) {
124-
downloadCB.onUpdateError(t);
125-
}
126-
127-
if (innerCB != null) {
128-
innerCB.onUpdateError(t);
136+
try {
137+
if (downloadCB != null) {
138+
downloadCB.onUpdateError(t);
139+
}
140+
if (innerCB != null) {
141+
innerCB.onUpdateError(t);
142+
}
143+
} catch (Throwable ignore) {
144+
ignore.printStackTrace();
145+
} finally {
146+
release();
129147
}
130-
131-
release();
132148
}
133149

134150
@Override

0 commit comments

Comments
 (0)