Skip to content

Commit e74719f

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.7
1 parent 9a2bc98 commit e74719f

File tree

11 files changed

+225
-85
lines changed

11 files changed

+225
-85
lines changed

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

Lines changed: 68 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
import com.tencent.beacon.core.info.BeaconPubParams;
3131
import com.tencent.beacon.event.open.BeaconReport;
32-
import com.tencent.cos.xml.base.BuildConfig;
3332
import com.tencent.cos.xml.common.ClientErrorCode;
33+
import com.tencent.cos.xml.base.BuildConfig;
3434
import com.tencent.cos.xml.exception.CosXmlClientException;
3535
import com.tencent.cos.xml.exception.CosXmlServiceException;
3636
import com.tencent.cos.xml.model.CosXmlRequest;
@@ -42,6 +42,7 @@
4242
import com.tencent.qcloud.core.common.QCloudClientException;
4343
import com.tencent.qcloud.core.common.QCloudServiceException;
4444
import com.tencent.qcloud.core.http.ConnectionRepository;
45+
import com.tencent.qcloud.core.http.HttpConstants;
4546
import com.tencent.qcloud.core.http.HttpRequest;
4647
import com.tencent.qcloud.core.http.HttpTask;
4748
import com.tencent.qcloud.core.http.HttpTaskMetrics;
@@ -90,22 +91,27 @@ public class BeaconService {
9091
public static final String EVENT_PARAMS_NODE_GET = "GetObjectRequest";
9192

9293
private Context applicationContext;
93-
private CosXmlServiceConfig config;
9494
private static BeaconService instance;
9595

96-
private BeaconService(Context applicationContext, CosXmlServiceConfig config) {
96+
//是否关闭灯塔上报
97+
private boolean isCloseBeacon;
98+
//上报桥接来源
99+
private String bridge;
100+
101+
private BeaconService(Context applicationContext) {
97102
this.applicationContext = applicationContext;
98-
this.config = config;
99103
}
100104

101105
/**
102106
* 初始化
103107
*/
104-
public static void init(Context applicationContext, CosXmlServiceConfig serviceConfig) {
108+
public static void init(Context applicationContext, boolean isCloseBeacon, String bridge) {
105109
synchronized (BeaconService.class) {
106110
if (instance == null) {
107-
instance = new BeaconService(applicationContext, serviceConfig);
108-
TrackService.init(applicationContext, APP_KEY, IS_DEBUG, serviceConfig.isCloseBeacon());
111+
instance = new BeaconService(applicationContext);
112+
instance.isCloseBeacon = isCloseBeacon;
113+
instance.bridge = bridge;
114+
TrackService.init(applicationContext, APP_KEY, IS_DEBUG, isCloseBeacon);
109115
}
110116
}
111117
}
@@ -482,7 +488,8 @@ private Map<String, String> parsePerfParams(@Nullable HttpTaskMetrics taskMetric
482488
params.put("http_full", String.valueOf(taskMetrics.fullTaskTookTime()));
483489
params.put("size", String.valueOf(taskMetrics.requestBodyByteCount() + taskMetrics.responseBodyByteCount()));
484490
params.put("retry_times", String.valueOf(taskMetrics.getRetryCount()));
485-
491+
//TODO dathub已经不能编辑上报字段 待升级datahub3.0
492+
// params.put("is_clock_skewed_retry", String.valueOf(taskMetrics.isClockSkewedRetry()));
486493
return params;
487494
}
488495

@@ -496,6 +503,8 @@ private Map<String, String> parseSimplePerfParams(@Nullable HttpTaskMetrics task
496503
params.put("took_time", String.valueOf(taskMetrics.httpTaskFullTime()));
497504
params.put("size", String.valueOf(taskMetrics.requestBodyByteCount() + taskMetrics.responseBodyByteCount()));
498505
params.put("retry_times", String.valueOf(taskMetrics.getRetryCount()));
506+
//TODO dathub已经不能编辑上报字段 待升级datahub3.0
507+
// params.put("is_clock_skewed_retry", String.valueOf(taskMetrics.isClockSkewedRetry()));
499508
return params;
500509
}
501510

@@ -534,6 +543,14 @@ private Map<String, String> parseUrlParams(CosXmlRequest request) {
534543
!TextUtils.isEmpty(((ObjectRequest) request).getCosPath())) {
535544
params.put("request_path", ((ObjectRequest) request).getCosPath());
536545
}
546+
if(request.getHttpTask() != null){
547+
if(request.getHttpTask().request() != null){
548+
String ua = request.getHttpTask().request().header(HttpConstants.Header.USER_AGENT);
549+
if(!TextUtils.isEmpty(ua)) {
550+
params.put("user_agent", ua);
551+
}
552+
}
553+
}
537554
return params;
538555
}
539556

@@ -567,7 +584,7 @@ private String parseEventCode(CosXmlRequest request) {
567584
}
568585

569586
private void report(String eventCode, Map<String, String> params) {
570-
if(config.isCloseBeacon() || !TrackService.isIncludeBeacon()) return;
587+
if(isCloseBeacon || !TrackService.isIncludeBeacon()) return;
571588
TrackService.getInstance().track(APP_KEY, eventCode, params);
572589
}
573590

@@ -586,44 +603,44 @@ public void reportError(String source, Exception e) {
586603
report(EVENT_CODE_ERROR, params);
587604
}
588605

589-
private Map<String, String> getBaseServiceParams(CosXmlRequest cosXmlRequest, long tookTime, boolean isSuccess) {
590-
Map<String, String> params = getCommonParams();
591-
592-
params.put("result", isSuccess ? EVENT_PARAMS_SUCCESS : EVENT_PARAMS_FAILURE);
593-
params.put("took_time", String.valueOf(tookTime));
594-
params.put("name", cosXmlRequest.getClass().getSimpleName());
595-
params.put("region", TextUtils.isEmpty(cosXmlRequest.getRegion()) ? this.config.getRegion() : cosXmlRequest.getRegion());
596-
params.put("accelerate", cosXmlRequest.isSupportAccelerate() ? "Y" : "N");
597-
598-
if (!isSuccess) {
599-
HttpTaskMetrics metrics = cosXmlRequest.getMetrics();
600-
if (metrics != null) {
601-
params.put("http_dns", String.valueOf(metrics.dnsLookupTookTime()));
602-
params.put("http_connect", String.valueOf(metrics.connectTookTime()));
603-
params.put("http_secure_connect", String.valueOf(metrics.secureConnectTookTime()));
604-
params.put("http_md5", String.valueOf(metrics.calculateMD5STookTime()));
605-
params.put("http_sign", String.valueOf(metrics.signRequestTookTime()));
606-
params.put("http_read_header", String.valueOf(metrics.readResponseHeaderTookTime()));
607-
params.put("http_read_body", String.valueOf(metrics.readResponseBodyTookTime()));
608-
params.put("http_write_header", String.valueOf(metrics.writeRequestHeaderTookTime()));
609-
params.put("http_write_body", String.valueOf(metrics.writeRequestBodyTookTime()));
610-
params.put("http_full", String.valueOf(metrics.fullTaskTookTime()));
611-
}
612-
613-
String host = cosXmlRequest.getRequestHost(this.config);
614-
if (host != null) {
615-
params.put("host", host);
616-
try {
617-
List<InetAddress> ips = ConnectionRepository.getInstance().getDnsRecord(host);
618-
params.put("ips", flatInetAddressList(ips));
619-
} catch (UnknownHostException e) {
620-
e.printStackTrace();
621-
}
622-
}
623-
}
624-
625-
return params;
626-
}
606+
// private Map<String, String> getBaseServiceParams(CosXmlRequest cosXmlRequest, long tookTime, boolean isSuccess) {
607+
// Map<String, String> params = getCommonParams();
608+
//
609+
// params.put("result", isSuccess ? EVENT_PARAMS_SUCCESS : EVENT_PARAMS_FAILURE);
610+
// params.put("took_time", String.valueOf(tookTime));
611+
// params.put("name", cosXmlRequest.getClass().getSimpleName());
612+
// params.put("region", TextUtils.isEmpty(cosXmlRequest.getRegion()) ? this.config.getRegion() : cosXmlRequest.getRegion());
613+
// params.put("accelerate", cosXmlRequest.isSupportAccelerate() ? "Y" : "N");
614+
//
615+
// if (!isSuccess) {
616+
// HttpTaskMetrics metrics = cosXmlRequest.getMetrics();
617+
// if (metrics != null) {
618+
// params.put("http_dns", String.valueOf(metrics.dnsLookupTookTime()));
619+
// params.put("http_connect", String.valueOf(metrics.connectTookTime()));
620+
// params.put("http_secure_connect", String.valueOf(metrics.secureConnectTookTime()));
621+
// params.put("http_md5", String.valueOf(metrics.calculateMD5STookTime()));
622+
// params.put("http_sign", String.valueOf(metrics.signRequestTookTime()));
623+
// params.put("http_read_header", String.valueOf(metrics.readResponseHeaderTookTime()));
624+
// params.put("http_read_body", String.valueOf(metrics.readResponseBodyTookTime()));
625+
// params.put("http_write_header", String.valueOf(metrics.writeRequestHeaderTookTime()));
626+
// params.put("http_write_body", String.valueOf(metrics.writeRequestBodyTookTime()));
627+
// params.put("http_full", String.valueOf(metrics.fullTaskTookTime()));
628+
// }
629+
//
630+
// String host = cosXmlRequest.getRequestHost(this.config);
631+
// if (host != null) {
632+
// params.put("host", host);
633+
// try {
634+
// List<InetAddress> ips = ConnectionRepository.getInstance().getDnsRecord(host);
635+
// params.put("ips", flatInetAddressList(ips));
636+
// } catch (UnknownHostException e) {
637+
// e.printStackTrace();
638+
// }
639+
// }
640+
// }
641+
//
642+
// return params;
643+
// }
627644

628645
private String flatInetAddressList(@Nullable List<InetAddress> ips) {
629646
if (ips == null) {
@@ -671,14 +688,17 @@ private Map<String, String> getUploadParams(String region, boolean isSuccess) {
671688
* @return 公共参数
672689
*/
673690
private Map<String, String> getCommonParams() {
674-
if(config.isCloseBeacon() || !TrackService.isIncludeBeacon()) return new HashMap<>();
691+
if(isCloseBeacon || !TrackService.isIncludeBeacon()) return new HashMap<>();
675692

676693
Map<String, String> params = new HashMap<>();
677694
BeaconPubParams pubParams = BeaconReport.getInstance().getCommonParams(applicationContext);
678695
params.put("boundle_id", pubParams.getBoundleId());
679696
params.put("network_type", pubParams.getNetworkType());
680697
params.put("cossdk_version", com.tencent.cos.xml.base.BuildConfig.VERSION_NAME);
681698
params.put("cossdk_version_code", String.valueOf(com.tencent.cos.xml.base.BuildConfig.VERSION_CODE));
699+
if(!TextUtils.isEmpty(bridge)) {
700+
params.put("bridge", bridge);
701+
}
682702
return params;
683703
}
684704

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
public class CosXmlBaseService implements BaseCosXml {
9797
private static final String TAG = "CosXmlBaseService";
9898

99+
/**
100+
* 是否关闭灯塔上报
101+
*/
102+
public static boolean IS_CLOSE_BEACON;
103+
/**
104+
* 桥接来源
105+
*/
106+
public static String BRIDGE;
107+
99108
protected volatile QCloudHttpClient client;
100109
protected QCloudCredentialProvider credentialProvider;
101110
protected String tag = "CosXml";
@@ -136,7 +145,7 @@ public CosXmlBaseService(Context context, CosXmlServiceConfig configuration) {
136145
QCloudLogger.addAdapter(logcatAdapter);
137146
}
138147

139-
BeaconService.init(context.getApplicationContext(), configuration);
148+
BeaconService.init(context.getApplicationContext(), IS_CLOSE_BEACON, BRIDGE);
140149
appCachePath = context.getApplicationContext().getFilesDir().getPath();
141150

142151
setNetworkClient(configuration);

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class CosXmlServiceConfig implements Parcelable {
6969

7070
private String protocol;
7171
private String userAgent;
72+
private String userAgentExtended;
7273

7374
private String region;
7475
private String appid;
@@ -78,7 +79,6 @@ public class CosXmlServiceConfig implements Parcelable {
7879
private String endpointSuffix;
7980

8081
private boolean isDebuggable;
81-
private boolean isCloseBeacon;
8282

8383
private RetryStrategy retryStrategy;
8484
private QCloudHttpRetryHandler qCloudHttpRetryHandler;
@@ -115,8 +115,8 @@ public class CosXmlServiceConfig implements Parcelable {
115115
public CosXmlServiceConfig(Builder builder) {
116116
this.protocol = builder.protocol;
117117
this.userAgent = builder.userAgent;
118+
this.userAgentExtended = builder.userAgentExtended;
118119
this.isDebuggable = builder.isDebuggable;
119-
this.isCloseBeacon = builder.isCloseBeacon;
120120

121121
this.appid = builder.appid;
122122
this.region = builder.region;
@@ -166,7 +166,11 @@ public String getProtocol() {
166166
* @return UserAgent
167167
*/
168168
public String getUserAgent() {
169-
return userAgent;
169+
if(TextUtils.isEmpty(userAgentExtended)){
170+
return userAgent;
171+
} else {
172+
return userAgent + "-" + userAgentExtended;
173+
}
170174
}
171175

172176
/**
@@ -479,10 +483,6 @@ public boolean isDebuggable() {
479483
return isDebuggable;
480484
}
481485

482-
public boolean isCloseBeacon() {
483-
return isCloseBeacon;
484-
}
485-
486486
public int getSocketTimeout() {
487487
return socketTimeout;
488488
}
@@ -521,7 +521,6 @@ public void writeToParcel(Parcel dest, int flags) {
521521
dest.writeString(protocol);
522522
dest.writeString(region);
523523
dest.writeInt(isDebuggable ? 1 : 0);
524-
dest.writeInt(isCloseBeacon ? 1 : 0);
525524
}
526525

527526
private CosXmlServiceConfig(Parcel in) {
@@ -552,6 +551,7 @@ public final static class Builder {
552551

553552
private String protocol;
554553
private String userAgent;
554+
private String userAgentExtended;
555555

556556
private String region;
557557
private String appid;
@@ -562,7 +562,6 @@ public final static class Builder {
562562
private boolean bucketInPath;
563563

564564
private boolean isDebuggable;
565-
private boolean isCloseBeacon;
566565

567566
private RetryStrategy retryStrategy;
568567
private QCloudHttpRetryHandler qCloudHttpRetryHandler;
@@ -592,7 +591,6 @@ public Builder() {
592591
protocol = HTTPS_PROTOCOL;
593592
userAgent = DEFAULT_USER_AGENT;
594593
isDebuggable = false;
595-
isCloseBeacon = false;
596594
retryStrategy = RetryStrategy.DEFAULT;
597595
bucketInPath = false;
598596
}
@@ -610,7 +608,6 @@ public Builder(CosXmlServiceConfig config) {
610608
bucketInPath = config.bucketInPath;
611609

612610
isDebuggable = config.isDebuggable;
613-
isCloseBeacon = config.isCloseBeacon;
614611

615612
retryStrategy = config.retryStrategy;
616613
qCloudHttpRetryHandler = config.qCloudHttpRetryHandler;
@@ -684,7 +681,7 @@ public Builder isHttps(boolean isHttps) {
684681
* 和 ap-shanghai,那么最终的请求地址为 bucket-1250000000.ap-shanghai.tencent.com
685682
*
686683
* </>
687-
* 注意,这个设置不会影响 GetService 请求,GetService 请求 Host 通过 {@link CosXmlService#setServiceDomain(String)} 设置
684+
* 注意,这个设置不会影响 GetService 请求,GetService 请求 Host 通过 {@link CosXmlBaseService#setDomain(String)} 设置
688685
*
689686
* @param hostFormat host 格式化字符串
690687
* @return Builder 对象
@@ -786,17 +783,6 @@ public Builder setDebuggable(boolean isDebuggable) {
786783
return this;
787784
}
788785

789-
/**
790-
* 是否关闭上报灯塔
791-
*
792-
* @param isCloseBeacon 是否关闭上报灯塔
793-
* @return Builder 对象
794-
*/
795-
public Builder setCloseBeacon(boolean isCloseBeacon) {
796-
this.isCloseBeacon = isCloseBeacon;
797-
return this;
798-
}
799-
800786
/**
801787
* 是否将签名放在 URL 中,默认放在 Header 中
802788
*
@@ -881,6 +867,15 @@ public Builder enableQuic(boolean isEnable){
881867
return this;
882868
}
883869

870+
/**
871+
* 设置ua拓展参数
872+
* @param userAgentExtended ua拓展参数()会拼接在ua后面
873+
*/
874+
public Builder setUserAgentExtended(String userAgentExtended) {
875+
this.userAgentExtended = userAgentExtended;
876+
return this;
877+
}
878+
884879
/**
885880
* 是否开启 DNS 解析缓存,开启后,将 DNS 解析的结果缓存在本地,
886881
* 当系统 DNS 解析失败后,会使用本地缓存的 DNS 结果

QCloudCosXml/cos-android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ dependencies {
129129
if(includeBeacon){
130130
embed('com.tencent.beacon:beacon-android-release:4.2.80.6:official@aar') {
131131
exclude(group:'com.android.support', module:'support-annotations')
132+
exclude(group:'androidx.annotation', module:'annotation')
132133
}
133134
embed('com.tencent.qimei:qimei:1.2.13.1') {
134135
exclude(group:'com.android.support', module:'support-annotations')
136+
exclude(group:'androidx.annotation', module:'annotation')
135137
}
136138
} else {
137139
compileOnly 'com.tencent.beacon:beacon-android-release:4.2.80.6:official@aar'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ protected QCloudLifecycleCredentials fetchNewCredentials()
7676
JSONTokener jsonParser = new JSONTokener(jsonStr);
7777
JSONObject data = (JSONObject) jsonParser.nextValue();
7878
JSONObject credentials = data.getJSONObject("credentials");
79-
// return new SessionQCloudCredentials(credentials.getString("tmpSecretId"), credentials.getString("tmpSecretKey"),
80-
// credentials.getString("sessionToken"), data.getLong("startTime"), data.getLong("expiredTime"));
8179
return new SessionQCloudCredentials(credentials.getString("tmpSecretId"), credentials.getString("tmpSecretKey"),
82-
credentials.getString("sessionToken"), data.getLong("expiredTime"));
80+
credentials.getString("sessionToken"), data.getLong("startTime"), data.getLong("expiredTime"));
81+
// return new SessionQCloudCredentials(credentials.getString("tmpSecretId"), credentials.getString("tmpSecretKey"),
82+
// credentials.getString("sessionToken"), data.getLong("expiredTime"));
8383
} catch (JSONException ex) {
8484
throw new QCloudClientException(ex);
8585
}

0 commit comments

Comments
 (0)