Skip to content

Commit a53b128

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.40
1 parent 3839354 commit a53b128

File tree

66 files changed

+784
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+784
-52
lines changed

QCloudCosXml/cos-android-base/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
minSdkVersion 15
77
targetSdkVersion 28
88

9-
versionCode 50939
10-
versionName '5.9.37'
9+
versionCode 50940
10+
versionName '5.9.38'
1111

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

QCloudCosXml/cos-android-base/src/main/java/com/tencent/cos/xml/CosTrackSonarService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Context;
77

88
import com.tencent.cos.xml.base.BuildConfig;
9+
import com.tencent.qcloud.core.logger.COSLogger;
910
import com.tencent.qcloud.network.sonar.NetworkSonar;
1011
import com.tencent.qcloud.network.sonar.NetworkSonarCallback;
1112
import com.tencent.qcloud.network.sonar.SonarRequest;
@@ -158,6 +159,9 @@ public void onFinish(List<SonarResult> results) {
158159
// 至少探测到一种网络情况才上报
159160
if(params.containsKey("dns_ip") || params.containsKey("ping_ip") || params.containsKey("traceroute_ip")){
160161
QCloudTrackService.getInstance().report(eventCode, params);
162+
if(!periodic){
163+
COSLogger.iProbe("FailSonar", params.toString());
164+
}
161165
}
162166
}
163167
}

QCloudCosXml/cos-android-base/src/main/java/com/tencent/cos/xml/CosXmlBaseService.java

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import androidx.annotation.NonNull;
2929
import androidx.annotation.Nullable;
3030

31-
import com.tencent.cos.xml.base.BuildConfig;
3231
import com.tencent.cos.xml.common.ClientErrorCode;
3332
import com.tencent.cos.xml.common.VersionInfo;
3433
import com.tencent.cos.xml.exception.CosXmlClientException;
@@ -70,9 +69,7 @@
7069
import com.tencent.qcloud.core.http.QCloudHttpClient;
7170
import com.tencent.qcloud.core.http.QCloudHttpRequest;
7271
import com.tencent.qcloud.core.http.QCloudHttpRetryHandler;
73-
import com.tencent.qcloud.core.logger.AndroidLogcatAdapter;
74-
import com.tencent.qcloud.core.logger.FileLogAdapter;
75-
import com.tencent.qcloud.core.logger.QCloudLogger;
72+
import com.tencent.qcloud.core.logger.COSLogger;
7673
import com.tencent.qcloud.core.task.QCloudTask;
7774
import com.tencent.qcloud.core.task.RetryStrategy;
7875
import com.tencent.qcloud.core.task.TaskExecutors;
@@ -141,14 +138,11 @@ public CosXmlBaseService(Context context, CosXmlServiceConfig configuration,
141138
* @param configuration cos android SDK 服务配置{@link CosXmlServiceConfig}
142139
*/
143140
public CosXmlBaseService(Context context, CosXmlServiceConfig configuration) {
144-
if(configuration.isDebuggable() && !BuildConfig.DEBUG){
145-
FileLogAdapter fileLogAdapter = FileLogAdapter.getInstance(context, "QLog");
146-
QCloudLogger.addAdapter(fileLogAdapter);
147-
}
148-
if(configuration.isDebuggable()){
149-
AndroidLogcatAdapter logcatAdapter = new AndroidLogcatAdapter();
150-
QCloudLogger.addAdapter(logcatAdapter);
151-
}
141+
ContextHolder.setContext(context);
142+
143+
// 为了保持之前configuration.isDebuggable()对日志的控制
144+
COSLogger.enableLogcat(configuration.isDebuggable());
145+
COSLogger.enableLogFile(configuration.isDebuggable());
152146

153147
CosTrackService.init(context.getApplicationContext(), IS_CLOSE_REPORT, BRIDGE);
154148

@@ -157,7 +151,6 @@ public CosXmlBaseService(Context context, CosXmlServiceConfig configuration) {
157151
TaskExecutors.initExecutor(configuration.getUploadMaxThreadCount(), configuration.getDownloadMaxThreadCount());
158152

159153
setNetworkClient(configuration);
160-
ContextHolder.setContext(context);
161154
}
162155

163156
public QCloudCredentialProvider getCredentialProvider() {
@@ -211,7 +204,6 @@ private void init(QCloudHttpClient.Builder builder, CosXmlServiceConfig configur
211204
if(qCloudHttpRetryHandler != null){
212205
builder.setQCloudHttpRetryHandler(qCloudHttpRetryHandler);
213206
}
214-
builder.enableDebugLog(configuration.isDebuggable());
215207
if(configuration.getCustomizeNetworkClient() != null){
216208
builder.setNetworkClient(configuration.getCustomizeNetworkClient());
217209
} else {
@@ -245,7 +237,6 @@ public void setNetworkClient(CosXmlServiceConfig configuration){
245237
client.addVerifiedHost("*." + configuration.getEndpointSuffix());
246238
client.addVerifiedHost("*." + configuration.getEndpointSuffix(
247239
configuration.getRegion(), true));
248-
client.setDebuggable(configuration.isDebuggable());
249240
}
250241

251242
/**
@@ -930,21 +921,15 @@ public String getUserAgent(@Nullable String networkClientType) {
930921
* 获取 SDK 日志信息
931922
*/
932923
public File[] getLogFiles(int limit) {
933-
FileLogAdapter fileLogAdapter = QCloudLogger.getAdapter(FileLogAdapter.class);
934-
if (fileLogAdapter != null) {
935-
return fileLogAdapter.getLogFilesDesc(limit);
936-
}
937-
return null;
924+
return COSLogger.getLogFiles(limit);
938925
}
939926

940927
private void logRequestMetrics(CosXmlRequest cosXmlRequest){
941-
if(config.isDebuggable()) {
942-
if (cosXmlRequest.getMetrics() != null) {
943-
QCloudLogger.i(
944-
QCloudHttpClient.HTTP_LOG_TAG,
945-
cosXmlRequest.getMetrics().toString()
946-
);
947-
}
928+
if (cosXmlRequest.getMetrics() != null) {
929+
COSLogger.iNetwork(
930+
QCloudHttpClient.HTTP_LOG_TAG,
931+
cosXmlRequest.getMetrics().toString()
932+
);
948933
}
949934
}
950935
}

QCloudCosXml/cos-android/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ dependencies {
154154
// androidTestImplementation 'android.arch.persistence.room:rxjava2:2.1.1'
155155
androidTestImplementation "androidx.room:room-rxjava2:2.5.1"
156156

157-
// androidTestImplementation 'com.tencentcloudapi.cls:tencentcloud-cls-sdk-android:1.0.5'
157+
androidTestImplementation('com.tencentcloudapi.cls:tencentcloud-cls-sdk-android:1.0.5') {
158+
exclude group: 'com.google.code.gson', module: 'gson'
159+
}
158160
androidTestImplementation 'com.google.guava:guava:27.0.1-android'
159161

160162
androidTestImplementation 'org.dhatim:fastexcel:0.18.4'
@@ -234,7 +236,7 @@ uploadArchives {
234236
repositories.mavenDeployer {
235237
pom.project {
236238
groupId 'com.qcloud.cos'
237-
artifactId 'cos-android-nobeacon'
239+
artifactId 'cos-android'
238240
version cosSdkVersionName
239241
packaging 'aar'
240242
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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.cos.xml.common;
24+
25+
import android.os.Environment;
26+
import android.util.Log;
27+
28+
import androidx.test.ext.junit.runners.AndroidJUnit4;
29+
30+
import com.tencent.cos.xml.CosXmlServiceConfig;
31+
import com.tencent.cos.xml.CosXmlSimpleService;
32+
import com.tencent.cos.xml.core.ServiceFactory;
33+
import com.tencent.cos.xml.core.TestConst;
34+
import com.tencent.cos.xml.core.TestLocker;
35+
import com.tencent.cos.xml.core.TestUtils;
36+
import com.tencent.cos.xml.exception.CosXmlClientException;
37+
import com.tencent.cos.xml.exception.CosXmlServiceException;
38+
import com.tencent.cos.xml.listener.CosXmlResultListener;
39+
import com.tencent.cos.xml.model.CosXmlRequest;
40+
import com.tencent.cos.xml.model.CosXmlResult;
41+
import com.tencent.cos.xml.model.PresignedUrlRequest;
42+
import com.tencent.cos.xml.model.object.GetObjectRequest;
43+
import com.tencent.cos.xml.transfer.COSXMLDownloadTask;
44+
import com.tencent.cos.xml.transfer.TransferConfig;
45+
import com.tencent.cos.xml.transfer.TransferManager;
46+
import com.tencent.qcloud.core.logger.QCloudLogger;
47+
48+
import org.junit.Test;
49+
import org.junit.runner.RunWith;
50+
51+
import java.io.File;
52+
import java.io.FileOutputStream;
53+
import java.io.InputStream;
54+
import java.net.HttpURLConnection;
55+
import java.net.URL;
56+
57+
/**
58+
*
59+
* <p>
60+
* Created by jordanqin on 2020/12/29.
61+
* Copyright 2010-2020 Tencent Cloud. All Rights Reserved.
62+
*/
63+
@RunWith(AndroidJUnit4.class)
64+
public class SpecialCharactersTest {
65+
private String bucket = "0-a-1253960454";
66+
private String cosKey = "sentences/Cambridge_IELTS_Series/0+Cambridge A16~IETLS_A16_T1_Part_2.mp3";
67+
68+
private CosXmlSimpleService getCosXmlService() {
69+
CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
70+
.isHttps(true)
71+
.setDebuggable(true)
72+
.setConnectionTimeout(4000)
73+
.setSocketTimeout(4000)
74+
.setTransferThreadControl(false)
75+
.setUploadMaxThreadCount(10)
76+
.setDownloadMaxThreadCount(36)
77+
.setRegion("ap-nanjing")
78+
.builder();
79+
return ServiceFactory.INSTANCE.newService(cosXmlServiceConfig);
80+
}
81+
82+
private TransferManager getTransferManager() {
83+
TransferConfig transferConfig = new TransferConfig.Builder()
84+
.setDivisionForUpload(2 * 1024 * 1024)
85+
.setSliceSizeForUpload(1024 * 1024)
86+
.setVerifyCRC64(true)
87+
.setSliceSizeForCopy(5242880)
88+
.setDividsionForCopy(5242880)
89+
.build();
90+
Log.d(TestConst.UT_TAG, String.valueOf(transferConfig.getDivisionForCopy()));
91+
return new TransferManager(getCosXmlService(), transferConfig);
92+
}
93+
94+
@Test public void testPresignedDownload() {
95+
PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(bucket, cosKey);
96+
presignedUrlRequest.setRequestMethod("GET");
97+
presignedUrlRequest.setSignKeyTime(3600);
98+
presignedUrlRequest.addNoSignHeader("Host");
99+
try {
100+
String signUrl = getCosXmlService().getPresignedURL(presignedUrlRequest);
101+
Log.i("QCloudTest", signUrl);
102+
new Thread(() -> {
103+
String localPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/wechat.png";
104+
downloadFile(signUrl, localPath);
105+
}).start();
106+
TestUtils.sleep(5000);
107+
} catch (CosXmlClientException clientException) {
108+
QCloudLogger.i("QCloudTest", clientException.getMessage());
109+
clientException.printStackTrace();
110+
}
111+
}
112+
public void downloadFile(String fileUrl, String localPath) {
113+
int retryCount = 0;
114+
boolean success = false;
115+
while (!success && retryCount < 3) {
116+
HttpURLConnection connection = null;
117+
InputStream input = null;
118+
FileOutputStream output = null;
119+
try {
120+
URL url = new URL(fileUrl);
121+
connection = (HttpURLConnection) url.openConnection();
122+
connection.connect();
123+
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
124+
if (connection.getResponseCode() >= 500) {
125+
retryCount++;
126+
continue;
127+
} else {
128+
throw new RuntimeException("Server returned HTTP " + connection.getResponseCode()
129+
+ " " + connection.getResponseMessage());
130+
}
131+
}
132+
input = connection.getInputStream();
133+
output = new FileOutputStream(localPath);
134+
byte data[] = new byte[4096];
135+
int count;
136+
while ((count = input.read(data)) != -1) {
137+
output.write(data, 0, count);
138+
}
139+
success = true;
140+
} catch (Exception e) {
141+
retryCount++;
142+
} finally {
143+
try {
144+
if (output != null)
145+
output.close();
146+
if (input != null)
147+
input.close();
148+
} catch (Exception ignored) {
149+
}
150+
if (connection != null)
151+
connection.disconnect();
152+
}
153+
}
154+
if (!success) {
155+
throw new RuntimeException("Failed to download file after 3 attempts");
156+
}
157+
}
158+
159+
@Test public void testSmallDownload() {
160+
TransferManager transferManager = getTransferManager();
161+
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket,
162+
cosKey,
163+
TestUtils.localParentPath());
164+
COSXMLDownloadTask downloadTask = transferManager.download(TestUtils.getContext(),
165+
getObjectRequest);
166+
final TestLocker testLocker = new TestLocker();
167+
downloadTask.setCosXmlResultListener(new CosXmlResultListener() {
168+
@Override
169+
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
170+
File file = new File(getObjectRequest.getDownloadPath());
171+
TestUtils.print("download file size:"+file.length());
172+
testLocker.release();
173+
}
174+
175+
@Override
176+
public void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {
177+
TestUtils.printError(TestUtils.getCosExceptionMessage(clientException, serviceException));
178+
testLocker.release();
179+
}
180+
});
181+
testLocker.lock();
182+
TestUtils.assertCOSXMLTaskSuccess(downloadTask);
183+
}
184+
}

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/core/ServiceFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public CosXmlSimpleService newDefaultService() {
5757
.setDownloadMaxThreadCount(36)
5858
.setRegion(TestConst.PERSIST_BUCKET_REGION)
5959
.builder();
60-
6160
return newService(cosXmlServiceConfig);
6261
}
6362

0 commit comments

Comments
 (0)