Skip to content

Commit 3ae4f72

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.14
1 parent 4167e05 commit 3ae4f72

File tree

346 files changed

+22792
-1471
lines changed

Some content is hidden

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

346 files changed

+22792
-1471
lines changed

QCloudCosXml/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildscript {
3030
}
3131

3232
repositories {
33-
mavenLocal()
33+
// mavenLocal()
3434
mavenCentral()
3535
maven { url "https://mirrors.tencent.com/repository/maven/tencent_public" }
3636
maven { url "https://mirrors.tencent.com/repository/maven/qmsp-oaid2" }
@@ -51,7 +51,7 @@ buildscript {
5151

5252
allprojects {
5353
repositories {
54-
mavenLocal()
54+
// mavenLocal()
5555
mavenCentral()
5656
maven { url "https://mirrors.tencent.com/repository/maven/tencent_public" }
5757
maven { url "https://mirrors.tencent.com/repository/maven/qmsp-oaid2" }

QCloudCosXml/cos-android-base/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ dependencies {
7171

7272
api project(':foundation')
7373

74-
compileOnly 'com.tencent.beacon:beacon-android-release:4.2.80.6:official@aar'
75-
compileOnly 'com.tencent.qimei:qimei:1.2.13.1'
74+
compileOnly files(
75+
'libs/beacon-android-release-4.2.80.6-official.aar',
76+
'libs/qimei-1.2.13.1.aar',
77+
'libs/qimei-core-1.2.13.1-normal.aar',
78+
'libs/qmsp-oaid2-1.0.4.aar'
79+
)
7680
}
7781

7882
static String quotWrapper(key) {
Binary file not shown.
1.15 KB
Binary file not shown.
Binary file not shown.
54.5 KB
Binary file not shown.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void reportDownloadTaskServiceException(CosXmlRequest request, QCloudServ
168168
// private String cosDownloadName(boolean cse) {
169169
// return cse? "COSDownloadTask-CSE" : "COSDownloadTask";
170170
// }
171-
171+
172172
// public void reportCOSUploadTaskSuccess(CosXmlRequest request, boolean cse) {
173173
// // 只需要一个 PutObjectRequest 壳,带上 HttpTaskMetrics 信息
174174
// reportRequestSuccess(EVENT_CODE_UPLOAD, request,
@@ -431,8 +431,7 @@ private Map<String, String> parseDnsParams(CosXmlRequest request) {
431431
List<InetAddress> dns = null;
432432
try {
433433
dns = ConnectionRepository.getInstance().getDnsRecord(host);
434-
} catch (UnknownHostException e) {
435-
e.printStackTrace();
434+
} catch (UnknownHostException ignored) {
436435
}
437436
params.put("ips", flatDns(taskMetrics.getConnectAddress(), dns));
438437
return params;

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.content.Context;
2626
import android.text.TextUtils;
2727

28+
import androidx.annotation.NonNull;
29+
2830
import com.tencent.cos.xml.base.BuildConfig;
2931
import com.tencent.cos.xml.common.ClientErrorCode;
3032
import com.tencent.cos.xml.exception.CosXmlClientException;
@@ -47,9 +49,10 @@
4749
import com.tencent.cos.xml.utils.StringUtils;
4850
import com.tencent.cos.xml.utils.URLEncodeUtils;
4951
import com.tencent.qcloud.core.auth.QCloudCredentialProvider;
50-
import com.tencent.qcloud.core.auth.QCloudLifecycleCredentials;
52+
import com.tencent.qcloud.core.auth.QCloudCredentials;
5153
import com.tencent.qcloud.core.auth.QCloudSelfSigner;
5254
import com.tencent.qcloud.core.auth.QCloudSigner;
55+
import com.tencent.qcloud.core.auth.ScopeLimitCredentialProvider;
5356
import com.tencent.qcloud.core.auth.SignerFactory;
5457
import com.tencent.qcloud.core.auth.StaticCredentialProvider;
5558
import com.tencent.qcloud.core.common.QCloudClientException;
@@ -80,7 +83,6 @@
8083
import java.util.HashSet;
8184
import java.util.LinkedList;
8285
import java.util.List;
83-
import java.util.Locale;
8486
import java.util.Map;
8587
import java.util.Set;
8688
import java.util.concurrent.Executor;
@@ -147,6 +149,8 @@ public CosXmlBaseService(Context context, CosXmlServiceConfig configuration) {
147149
BeaconService.init(context.getApplicationContext(), IS_CLOSE_BEACON, BRIDGE);
148150
appCachePath = context.getApplicationContext().getFilesDir().getPath();
149151

152+
TaskExecutors.initExecutor(configuration.getUploadMaxThreadCount(), configuration.getDownloadMaxThreadCount());
153+
150154
setNetworkClient(configuration);
151155
ContextHolder.setContext(context);
152156
}
@@ -247,6 +251,15 @@ public void addCustomerDNS(String domainName, String[] ipList) throws CosXmlClie
247251
}
248252
}
249253

254+
/**
255+
* 添加自定义 DNS 解析器
256+
* 支持添加多个,会顺序解析获取
257+
* @param dnsFetch DNS 解析器
258+
*/
259+
public void addCustomerDNSFetch(@NonNull QCloudHttpClient.QCloudDnsFetch dnsFetch){
260+
client.addDnsFetch(dnsFetch);
261+
}
262+
250263
@Deprecated
251264
public void addVerifiedHost(String hostName) {
252265
client.addVerifiedHost(hostName);
@@ -262,14 +275,6 @@ public void setDomain(String domain) {
262275
this.requestDomain = domain;
263276
}
264277

265-
protected String getRequestHostHeader(CosXmlRequest request) {
266-
267-
String bucket = config.getBucket(request.getBucket());
268-
String region = !TextUtils.isEmpty(request.getRegion()) ? request.getRegion() :
269-
config.getRegion();
270-
return String.format(Locale.ENGLISH, "%s.cos.%s.myqcloud.com", bucket, region);
271-
}
272-
273278
protected String getRequestHost(CosXmlRequest request) throws CosXmlClientException {
274279

275280

@@ -416,6 +421,8 @@ protected <T1 extends CosXmlRequest, T2 extends CosXmlResult> T2 execute(T1 cosX
416421

417422
httpTask = client.resolveRequest(httpRequest, credentialProvider);
418423
httpTask.setTransferThreadControl(config.isTransferThreadControl());
424+
httpTask.setUploadMaxThreadCount(config.getUploadMaxThreadCount());
425+
httpTask.setDownloadMaxThreadCount(config.getDownloadMaxThreadCount());
419426
cosXmlRequest.setTask(httpTask);
420427

421428
setProgressListener(cosXmlRequest, httpTask, false);
@@ -475,6 +482,8 @@ public void onFailure(QCloudClientException clientException, QCloudServiceExcept
475482
httpTask = client.resolveRequest(httpRequest, credentialProvider);
476483

477484
httpTask.setTransferThreadControl(config.isTransferThreadControl());
485+
httpTask.setUploadMaxThreadCount(config.getUploadMaxThreadCount());
486+
httpTask.setDownloadMaxThreadCount(config.getDownloadMaxThreadCount());
478487

479488
cosXmlRequest.setTask(httpTask);
480489

@@ -564,11 +573,19 @@ public String getAccessUrl(CosXmlRequest cosXmlRequest) {
564573
public String getPresignedURL(CosXmlRequest cosXmlRequest) throws CosXmlClientException {
565574
try {
566575
//step1: obtain sign, contain token if it exist.
567-
QCloudLifecycleCredentials qCloudLifecycleCredentials = (QCloudLifecycleCredentials) credentialProvider.getCredentials();
576+
// 根据 provider 类型判断是否需要传入 credential scope
577+
QCloudCredentials credentials;
578+
if (credentialProvider instanceof ScopeLimitCredentialProvider) {
579+
credentials = ((ScopeLimitCredentialProvider) credentialProvider).getCredentials(
580+
cosXmlRequest.getSTSCredentialScope(config));
581+
} else {
582+
credentials = credentialProvider.getCredentials();
583+
}
584+
568585
QCloudSigner signer = SignerFactory.getSigner(signerTypeCompat(signerType, cosXmlRequest));
569586

570587
QCloudHttpRequest request = buildHttpRequest(cosXmlRequest, null);
571-
signer.sign(request, qCloudLifecycleCredentials);
588+
signer.sign(request, credentials);
572589
String sign = request.header(HttpConstants.Header.AUTHORIZATION);
573590
String token = request.header("x-cos-security-token");
574591
if(!TextUtils.isEmpty(token)){

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

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.tencent.cos.xml.common.VersionInfo;
3232
import com.tencent.qcloud.core.http.QCloudHttpRetryHandler;
3333
import com.tencent.qcloud.core.task.RetryStrategy;
34+
import com.tencent.qcloud.core.task.TaskExecutors;
3435

3536
import java.util.HashMap;
3637
import java.util.HashSet;
@@ -68,50 +69,52 @@ public class CosXmlServiceConfig implements Parcelable {
6869
*/
6970
public static final String DEFAULT_USER_AGENT = VersionInfo.getUserAgent();
7071

71-
private String protocol;
72-
private String userAgent;
73-
private String userAgentExtended;
72+
private final String protocol;
73+
private final String userAgent;
74+
private final String userAgentExtended;
7475

75-
private String region;
76-
private String appid;
76+
private final String region;
77+
private final String appid;
7778

78-
private String host;
79-
private int port;
80-
private String endpointSuffix;
79+
private final String host;
80+
private final int port;
81+
private final String endpointSuffix;
8182

82-
private boolean isDebuggable;
83+
private final boolean isDebuggable;
8384

84-
private RetryStrategy retryStrategy;
85-
private QCloudHttpRetryHandler qCloudHttpRetryHandler;
85+
private final RetryStrategy retryStrategy;
86+
private final QCloudHttpRetryHandler qCloudHttpRetryHandler;
8687

87-
private int connectionTimeout;
88-
private int socketTimeout;
88+
private final int connectionTimeout;
89+
private final int socketTimeout;
8990

90-
private Executor executor;
91+
private final Executor executor;
9192

92-
private Executor observeExecutor;
93+
private final Executor observeExecutor;
9394

94-
private boolean isQuic;
95+
private final boolean isQuic;
9596

9697
private List<String> prefetchHosts;
9798

98-
private Map<String, List<String>> commonHeaders;
99+
private final Map<String, List<String>> commonHeaders;
99100

100-
private Set<String> noSignHeaders;
101+
private final Set<String> noSignHeaders;
101102

102-
private boolean dnsCache;
103+
private final boolean dnsCache;
103104

104105
private String hostFormat = DEFAULT_HOST_FORMAT;
105106

106107
private String hostHeaderFormat = null;
107108

108-
private boolean bucketInPath; // path style
109+
private final boolean bucketInPath; // path style
109110

110-
private boolean accelerate; //
111+
private final boolean accelerate; //
111112

112-
private boolean signInUrl; //
113+
private final boolean signInUrl; //
113114

114-
private boolean transferThreadControl = true;
115+
private final boolean transferThreadControl;
116+
private final int uploadMaxThreadCount;
117+
private final int downloadMaxThreadCount;
115118

116119
public CosXmlServiceConfig(Builder builder) {
117120
this.protocol = builder.protocol;
@@ -148,6 +151,8 @@ public CosXmlServiceConfig(Builder builder) {
148151
this.dnsCache = builder.dnsCache;
149152
this.signInUrl = builder.signInUrl;
150153
this.transferThreadControl = builder.transferThreadControl;
154+
this.uploadMaxThreadCount = builder.uploadMaxThreadCount;
155+
this.downloadMaxThreadCount = builder.downloadMaxThreadCount;
151156
}
152157

153158
public Builder newBuilder() {
@@ -410,6 +415,14 @@ public boolean isTransferThreadControl() {
410415
return transferThreadControl;
411416
}
412417

418+
public int getUploadMaxThreadCount() {
419+
return uploadMaxThreadCount;
420+
}
421+
422+
public int getDownloadMaxThreadCount() {
423+
return downloadMaxThreadCount;
424+
}
425+
413426
@Deprecated
414427
public String getEndpointSuffix() {
415428
return getEndpointSuffix(region, false);
@@ -608,13 +621,17 @@ public final static class Builder {
608621
private boolean signInUrl;
609622

610623
private boolean transferThreadControl = true;
624+
private int uploadMaxThreadCount;
625+
private int downloadMaxThreadCount;
611626

612627
public Builder() {
613628
protocol = HTTPS_PROTOCOL;
614629
userAgent = DEFAULT_USER_AGENT;
615630
isDebuggable = false;
616631
retryStrategy = RetryStrategy.DEFAULT;
617632
bucketInPath = false;
633+
uploadMaxThreadCount = TaskExecutors.DEFAULT_UPLOAD_THREAD_COUNT;
634+
downloadMaxThreadCount = TaskExecutors.DEFAULT_DOWNLOAD_THREAD_COUNT;
618635
}
619636

620637
public Builder(CosXmlServiceConfig config) {
@@ -652,6 +669,8 @@ public Builder(CosXmlServiceConfig config) {
652669

653670
signInUrl = config.signInUrl;
654671
transferThreadControl = config.transferThreadControl;
672+
uploadMaxThreadCount = config.uploadMaxThreadCount;
673+
downloadMaxThreadCount = config.downloadMaxThreadCount;
655674
}
656675

657676
/**
@@ -676,11 +695,32 @@ public Builder setSocketTimeout(int socketTimeoutMills) {
676695
return this;
677696
}
678697

698+
/**
699+
* 设置传输时是否进行线程并发控制
700+
* @param transferThreadControl 是否进行线程并发控制
701+
*/
679702
public Builder setTransferThreadControl(boolean transferThreadControl) {
680703
this.transferThreadControl = transferThreadControl;
681704
return this;
682705
}
683706

707+
/**
708+
* 设置上传时线程并发的最大值
709+
* @param uploadMaxThreadCount 线程并发的最大值
710+
*/
711+
public Builder setUploadMaxThreadCount(int uploadMaxThreadCount) {
712+
this.uploadMaxThreadCount = uploadMaxThreadCount;
713+
return this;
714+
}
715+
716+
/**
717+
* 设置下载时线程并发的最大值
718+
* @param downloadMaxThreadCount 线程并发的最大值
719+
*/
720+
public Builder setDownloadMaxThreadCount(int downloadMaxThreadCount) {
721+
this.downloadMaxThreadCount = downloadMaxThreadCount;
722+
return this;
723+
}
684724

685725
/**
686726
* 设置是否 Https 协议,默认为 Https

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.text.TextUtils;
2626

2727
import com.tencent.cos.xml.CosXmlServiceConfig;
28+
import com.tencent.cos.xml.common.ClientErrorCode;
2829
import com.tencent.cos.xml.exception.CosXmlClientException;
2930
import com.tencent.cos.xml.utils.URLEncodeUtils;
3031
import com.tencent.qcloud.core.auth.COSXmlSignSourceProvider;
@@ -38,10 +39,12 @@
3839
import com.tencent.qcloud.core.http.RequestBodySerializer;
3940
import com.tencent.qcloud.core.task.QCloudTask;
4041

42+
import org.xmlpull.v1.XmlPullParserException;
43+
44+
import java.io.IOException;
4145
import java.util.ArrayList;
4246
import java.util.HashSet;
4347
import java.util.LinkedHashMap;
44-
import java.util.LinkedList;
4548
import java.util.List;
4649
import java.util.Map;
4750
import java.util.Set;
@@ -229,7 +232,22 @@ public Map<String, List<String>> getRequestHeaders(){
229232
* @return 请求体
230233
* @throws CosXmlClientException 客户异常
231234
*/
232-
public abstract RequestBodySerializer getRequestBody() throws CosXmlClientException;
235+
public RequestBodySerializer getRequestBody() throws CosXmlClientException{
236+
try {
237+
return xmlBuilder();
238+
} catch (XmlPullParserException e) {
239+
throw new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(), e);
240+
} catch (IOException e) {
241+
throw new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(), e);
242+
}
243+
}
244+
245+
/**
246+
* 收拢xml解析
247+
*/
248+
protected RequestBodySerializer xmlBuilder() throws XmlPullParserException, IOException, CosXmlClientException {
249+
throw new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(), "xmlBuilder empty implementation");
250+
}
233251

234252
/**
235253
* sdk 参数校验
@@ -418,8 +436,11 @@ public void setSignSourceProvider(QCloudSignSourceProvider cosXmlSignSourceProvi
418436
*/
419437
public STSCredentialScope[] getSTSCredentialScope(CosXmlServiceConfig config) {
420438
String action = "name/cos:" + getClass().getSimpleName().replace("Request", "");
421-
STSCredentialScope scope = new STSCredentialScope(action, config.getBucket(bucket),
422-
config.getRegion(), getPath(config));
439+
STSCredentialScope scope = new STSCredentialScope(
440+
action,
441+
config.getBucket(bucket),
442+
this.getRegion() == null ? config.getRegion() : this.getRegion(),
443+
getPath(config));
423444
return scope.toArray();
424445
}
425446

0 commit comments

Comments
 (0)