Skip to content

Commit a6d3c7d

Browse files
committed
update qcloud sdk to 1.5.33
1 parent f41d7ae commit a6d3c7d

File tree

10 files changed

+189
-14
lines changed

10 files changed

+189
-14
lines changed

QCloudFoundation/foundation/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
minSdkVersion 15
88
targetSdkVersion 28
99

10-
versionCode 10531
11-
versionName "1.5.31"
10+
versionCode 10533
11+
versionName "1.5.33"
1212

1313
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1414

@@ -36,7 +36,7 @@ android {
3636

3737
dependencies {
3838
// implementation fileTree(dir: 'libs', include: ['*.jar'])
39-
api 'com.squareup.okhttp3:okhttp:3.11.0'
39+
api 'com.squareup.okhttp3:okhttp:3.12.1'
4040
api 'com.parse.bolts:bolts-tasks:1.4.0'
4141

4242
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
@@ -46,6 +46,8 @@ dependencies {
4646
testCompileOnly 'org.mockito:mockito-core:1.10.19'
4747

4848
compileOnly 'androidx.appcompat:appcompat:1.0.0'
49+
50+
compileOnly 'com.tencent.qcloud:beacon-android-release:4.1.13'
4951
}
5052

5153
project.extensions.add('artifactId', 'qcloud-foundation')

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/HttpRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737

3838
import okhttp3.CacheControl;
39+
import okhttp3.Headers;
3940
import okhttp3.HttpUrl;
4041
import okhttp3.MediaType;
4142
import okhttp3.Request;
@@ -331,6 +332,23 @@ public Builder<T> addHeaders(Map<String, List<String>> headers) {
331332
return this;
332333
}
333334

335+
public Builder<T> addHeadersUnsafeNonAscii(Map<String, List<String>> headers) {
336+
if (headers != null) {
337+
Headers.Builder headerBuilder = new Headers.Builder();
338+
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
339+
String name = entry.getKey();
340+
for (String value : entry.getValue()) {
341+
if (name != null && value != null) {
342+
headerBuilder.addUnsafeNonAscii(name, value);
343+
addHeaderNameValue(this.headers, name, value);
344+
}
345+
}
346+
}
347+
requestBuilder.headers(headerBuilder.build());
348+
}
349+
return this;
350+
}
351+
334352
public Builder<T> removeHeader(String name) {
335353
requestBuilder.removeHeader(name);
336354
headers.remove(name);

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/HttpTask.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ protected HttpResult<T> execute() throws QCloudClientException, QCloudServiceExc
236236
e.printStackTrace();
237237
}
238238
}
239+
240+
if (httpRequest.getRequestBody() instanceof StreamingRequestBody) {
241+
((StreamingRequestBody) httpRequest.getRequestBody()).release();
242+
}
243+
239244
metrics.onTaskEnd();
240245
}
241246
}

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/HttpTaskMetrics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ synchronized public HttpTaskMetrics merge(HttpTaskMetrics taskMetrics) {
294294
@Override
295295
public String toString() {
296296
return new StringBuilder().append("Http Metrics: \n")
297+
.append("domain : ").append(domainName).append("\n")
298+
.append("dns : ").append(connectAddress != null ? connectAddress.getHostAddress() : "null").append("\n")
297299
.append("fullTaskTookTime : ").append(fullTaskTookTime()).append("\n")
298300
.append("calculateMD5STookTime : ").append(calculateMD5STookTime()).append("\n")
299301
.append("signRequestTookTime : ").append(signRequestTookTime()).append("\n")

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/QCloudHttpClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ public Builder() {
251251

252252
public Builder setConnectionTimeout(int connectionTimeout) {
253253
if (connectionTimeout < 3 * 1000) {
254-
throw new IllegalArgumentException("connection timeout must be larger than 10 seconds.");
254+
throw new IllegalArgumentException("connection timeout must be larger than 3 seconds.");
255255
}
256256
this.connectionTimeout = connectionTimeout;
257257
return this;
258258
}
259259

260260
public Builder setSocketTimeout(int socketTimeout) {
261261
if (socketTimeout < 3 * 1000) {
262-
throw new IllegalArgumentException("socket timeout must be larger than 10 seconds.");
262+
throw new IllegalArgumentException("socket timeout must be larger than 3 seconds.");
263263
}
264264
this.socketTimeout = socketTimeout;
265265
return this;

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/QCloudHttpRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
package com.tencent.qcloud.core.http;
2424

25-
2625
import com.tencent.qcloud.core.auth.QCloudSignSourceProvider;
2726
import com.tencent.qcloud.core.auth.QCloudSigner;
2827
import com.tencent.qcloud.core.auth.STSCredentialScope;

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/StreamingRequestBody.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class StreamingRequestBody extends RequestBody implements ProgressBody, Q
6767

6868
protected CountingSink countingSink;
6969

70+
private boolean deleteFileWhenComplete = false;
71+
7072
public void setProgressListener(QCloudProgressListener progressListener) {
7173
this.progressListener = progressListener;
7274
}
@@ -115,7 +117,7 @@ static StreamingRequestBody steam(InputStream inputStream, File tmpFile, String
115117
requestBody.file = tmpFile;
116118
requestBody.offset = offset < 0 ? 0 : offset;
117119
requestBody.requiredLength = length;
118-
120+
requestBody.deleteFileWhenComplete = true;
119121
return requestBody;
120122
}
121123

@@ -293,4 +295,14 @@ public String onGetMd5() throws IOException {
293295
if(inputStream != null)Util.closeQuietly(inputStream);
294296
}
295297
}
298+
299+
//
300+
public void release() {
301+
if (deleteFileWhenComplete) {
302+
if (file != null) {
303+
file.delete();
304+
}
305+
}
306+
307+
}
296308
}

QCloudFoundation/foundation/src/main/java/com/tencent/qcloud/core/http/interceptor/RetryInterceptor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ Response processRequest(Chain chain, Request request, HttpTask task) throws IOEx
207207
} else if (shouldRetry(request, response, attempts, task.getWeight(), startTime, e, statusCode) && !task.isCanceled()) {
208208
QCloudLogger.i(HTTP_LOG_TAG, "%s failed for %s, code is %d", request, e, statusCode);
209209
retryStrategy.onTaskEnd(false, e);
210-
if (response != null && response.body() != null) {
211-
response.close();
212-
}
213-
214210
} else {
215211
QCloudLogger.i(HTTP_LOG_TAG, "%s ends for %s, code is %d", request, e, statusCode);
216212
break;
@@ -331,7 +327,6 @@ private int getHostReliable(String host) {
331327

332328

333329
private boolean shouldRetry(Request request, Response response, int attempts, int weight, long startTime, IOException e, int statusCode) {
334-
335330
if (isUserCancelled(e)) {
336331
return false;
337332
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright (c) 2010-2020 Tencent Cloud. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package com.tencent.qcloud.core.track;
24+
25+
import android.content.Context;
26+
import com.tencent.beacon.event.open.BeaconConfig;
27+
import com.tencent.beacon.event.open.BeaconEvent;
28+
import com.tencent.beacon.event.open.BeaconReport;
29+
import com.tencent.beacon.event.open.EventResult;
30+
import com.tencent.beacon.event.open.EventType;
31+
import com.tencent.qcloud.core.logger.QCloudLogger;
32+
import com.tencent.qcloud.core.util.QCloudStringUtils;
33+
34+
import java.util.Map;
35+
36+
/**
37+
* 灯塔服务
38+
*/
39+
public class TrackService {
40+
41+
private static final String TAG = "TrackService";
42+
private static String beaconKey;
43+
private static boolean debug = false;
44+
private Context context;
45+
private static TrackService instance;
46+
47+
private TrackService(Context context) {
48+
this.context = context.getApplicationContext();
49+
}
50+
51+
/**
52+
* 初始化
53+
*/
54+
public static void init(Context context, String beaconKey, boolean debug) {
55+
synchronized (TrackService.class) {
56+
if (instance == null) {
57+
instance = new TrackService(context);
58+
TrackService.beaconKey = beaconKey;
59+
TrackService.debug = debug;
60+
if(isIncludeBeacon()) {
61+
BeaconConfig.Builder builder = BeaconConfig.builder()
62+
.auditEnable(false)
63+
.bidEnable(false)
64+
.qmspEnable(false)
65+
.pagePathEnable(false)
66+
.setNormalPollingTime(30000);
67+
try {
68+
builder.collectMACEnable(false)
69+
.collectIMEIEnable(false)
70+
.collectAndroidIdEnable(false)
71+
.collectProcessInfoEnable(false);
72+
} catch (NoSuchMethodError error) {
73+
//APP使用了标准版的灯塔SDK builder不支持collectXXX
74+
}
75+
BeaconConfig config = builder.build();
76+
77+
BeaconReport beaconReport = BeaconReport.getInstance();
78+
beaconReport.setLogAble(debug);//是否打开日志
79+
try {
80+
beaconReport.setCollectMac(false); //该项设为false即关闭采集Mac功能
81+
beaconReport.setCollectAndroidID(false); //该项设为false即关闭采集AndroidId功能
82+
beaconReport.setCollectImei(false); //该项设为false即关闭采集IMEI和IMSI的功能
83+
beaconReport.setCollectProcessInfo(false); //该项设为false即关闭采集processInfo功能
84+
} catch (NoSuchMethodError error) {
85+
}
86+
beaconReport.start(context, beaconKey, config);
87+
//某些灯塔sdk版本,start之前setCollectMac等无效
88+
try {
89+
beaconReport.setCollectMac(false); //该项设为false即关闭采集Mac功能
90+
beaconReport.setCollectAndroidID(false); //该项设为false即关闭采集AndroidId功能
91+
beaconReport.setCollectImei(false); //该项设为false即关闭采集IMEI和IMSI的功能
92+
beaconReport.setCollectProcessInfo(false); //该项设为false即关闭采集processInfo功能
93+
} catch (NoSuchMethodError error) {
94+
}
95+
}
96+
}
97+
}
98+
}
99+
100+
public static TrackService getInstance() {
101+
return instance;
102+
}
103+
104+
105+
public void track(String beaconKey, String eventCode, Map<String, String> params) {
106+
if(!isIncludeBeacon()) return;
107+
String trackBeaconKey = TrackService.beaconKey;
108+
if (beaconKey != null) {
109+
trackBeaconKey = beaconKey;
110+
}
111+
BeaconEvent.Builder builder = BeaconEvent.builder()
112+
.withAppKey(trackBeaconKey)
113+
.withCode(eventCode)
114+
.withType(EventType.NORMAL)
115+
.withParams(params);
116+
try {
117+
builder.withIsSimpleParams(true);
118+
} catch (NoSuchMethodError error) {
119+
//APP使用了标准版的灯塔SDK 不支持withIsSimpleParams
120+
}
121+
EventResult result = BeaconReport.getInstance().report(builder.build());
122+
if (debug) {
123+
StringBuilder mapAsString = new StringBuilder("{");
124+
for (String key : params.keySet()) {
125+
mapAsString.append(key + "=" + params.get(key) + ", ");
126+
}
127+
mapAsString.delete(mapAsString.length() - 2, mapAsString.length()).append("}");
128+
QCloudLogger.i(TAG, "eventCode: %s, params: %s => result{ eventID: %s, errorCode: %d, errorMsg: %s}",
129+
eventCode, mapAsString, result.eventID, result.errorCode, result.errMsg);
130+
}
131+
}
132+
133+
134+
private static boolean isIncludeBeacon(){
135+
try {
136+
Class.forName("com.tencent.beacon.event.open.BeaconReport");
137+
return true;
138+
} catch (ClassNotFoundException e){
139+
return false;
140+
}
141+
}
142+
}

QCloudFoundation/quic/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ android {
3131
minSdkVersion 15
3232
targetSdkVersion 27
3333

34-
versionCode 10531
34+
versionCode 10533
3535

36-
versionName "1.5.31"
36+
versionName "1.5.33"
3737

3838
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3939

0 commit comments

Comments
 (0)