Skip to content

Commit dbd2a01

Browse files
authored
Merge pull request #324 from sxci/fix_record_condition
Fix record condition
2 parents 5217ee5 + fa8165b commit dbd2a01

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

library/src/main/java/com/qiniu/android/collect/Config.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public final class Config {
3737
* 默认使用当前应用的缓存目录: getCacheDir()
3838
*/
3939
public static String recordDir = null;
40+
41+
static {
42+
try {
43+
recordDir = ContextGetter.applicationContext().getCacheDir().getAbsolutePath();
44+
} catch (Throwable e) {
45+
e.fillInStackTrace();
46+
}
47+
}
48+
4049
/**
4150
* 记录上传信息文件最大值,单位:字节。
4251
* <p>
@@ -62,14 +71,6 @@ public final class Config {
6271
*/
6372
public static int interval = 10;
6473

65-
static {
66-
try {
67-
recordDir = ContextGetter.applicationContext().getCacheDir().getAbsolutePath();
68-
} catch (Throwable e) {
69-
e.fillInStackTrace();
70-
}
71-
}
72-
7374
/**
7475
* 当网络切换到 wifi 下,切换到此设置
7576
*/

library/src/main/java/com/qiniu/android/collect/UploadInfoCollector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.qiniu.android.collect;
22

3-
43
import com.qiniu.android.http.UserAgent;
54
import com.qiniu.android.storage.UpToken;
65

@@ -198,7 +197,7 @@ public void run() {
198197
singleServer.submit(taskRecord);
199198

200199
// 少几次上传没有影响
201-
if (Config.isUpload && upToken != UpToken.NULL) {
200+
if (Config.isUpload && !UpToken.isInvalid(upToken)) {
202201
Runnable taskUpload = new Runnable() {
203202
@Override
204203
public void run() {

library/src/main/java/com/qiniu/android/http/ResponseInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static ResponseInfo create(final JSONObject json, final int statusCode, f
129129
final String ip = _ip.substring(Math.max(0, _ip.indexOf("/") + 1));
130130
ResponseInfo res = new ResponseInfo(json, statusCode, reqId, xlog, xvia, host, path, ip,
131131
port, duration, sent, error, upToken, totalSize);
132-
if (Config.isRecord || upToken != null) {
132+
if (Config.isRecord) {
133133
final String _timeStamp = res.timeStamp + "";
134134
UploadInfoCollector.handleHttp(upToken,
135135
// 延迟序列化.如果判断不记录,则不执行序列化

library/src/main/java/com/qiniu/android/storage/UpToken.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public static UpToken parse(String token) {
4949
return new UpToken(obj.optString("returnUrl"), token, t[0]);
5050
}
5151

52+
public static boolean isInvalid(UpToken token) {
53+
return token == null || token == NULL;
54+
}
55+
5256
public String toString() {
5357
return token;
5458
}

library/src/main/java/com/qiniu/android/storage/UploadManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static boolean areInvalidArg(final String key, byte[] data, File f, Stri
5555
ResponseInfo info = null;
5656
if (message != null) {
5757
info = ResponseInfo.invalidArgument(message, decodedToken);
58-
} else if (decodedToken == UpToken.NULL || decodedToken == null) {
58+
} else if (UpToken.isInvalid(decodedToken)) {
5959
info = ResponseInfo.invalidToken("invalid token");
6060
} else if ((f != null && f.length() == 0) || (data != null && data.length == 0)) {
6161
info = ResponseInfo.zeroSize(decodedToken);
@@ -82,7 +82,7 @@ private static ResponseInfo areInvalidArg(final String key, byte[] data, File f,
8282
return ResponseInfo.invalidArgument(message, decodedToken);
8383
}
8484

85-
if (decodedToken == UpToken.NULL || decodedToken == null) {
85+
if (UpToken.isInvalid(decodedToken)) {
8686
return ResponseInfo.invalidToken("invalid token");
8787
}
8888

0 commit comments

Comments
 (0)