Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#Changelog
## 8.3.2(2021-08-09)
* dns 缓存增加最大有效时间配置
* 网络状态检测可关闭


## 8.3.1(2021-07-12)
* 兼容支持 Android 4.x ( API level 14+ ),使用 Android4.x 对应 okhttp 版本请调整至 3.12.+
* 支持 okhttp 4.9
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ https://github.com/qiniudemo/qiniu-lab-android
| 7.0.7 | Android 2.2+ | android-async-http 1.4.8 |

### 注意
* 推荐使用最新版:8.3.1
* 推荐使用最新版:8.3.2
* AndroidNetwork.getMobileDbm()可以获取手机信号强度,需要如下权限(API>=18时生效)
```
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testFile() throws Throwable {
}

public void testMultiFile() throws Throwable {
Temp[] ts = new Temp[]{templateFile(400, 0.2), templateFile(700, 0.2), templateFile(1024, 0.51), templateFile(4 * 1024, 0.5), templateFile(8 * 1024 + 1, 0.6)};
Temp[] ts = new Temp[]{templateFile(400, 0.01), templateFile(700, 0.02), templateFile(1024, 0.02), templateFile(4 * 1024, 0.02), templateFile(8 * 1024 + 1, 0.2)};
checkTemp(ts, "testFile");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testReuploadV1() {
String key = "android_concurrent_resume_reupload_v1_" + size + "k";
try {
File file = TempFile.createFile(size, key);
reuploadUploadTest((long) (size * 0.7), file, key, configuration, null);
reuploadUploadTest((long) (size * 0.5), file, key, configuration, null);
TempFile.remove(file);
} catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testReuploadV1() {
String key = "android_resume_reupload_v1_" + size + "k";
try {
File file = TempFile.createFile(size, key);
reuploadUploadTest((long) (size * 0.7), file, key, configuration, null);
reuploadUploadTest((long) (size * 0.5), file, key, configuration, null);
TempFile.remove(file);
} catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,37 @@ public boolean shouldWait() {
TempFile.remove(tempFile);
}

public void test_600k() throws Throwable {
template(600, 0.7);
public void test_4M1K() throws Throwable {
template(4 * 1024 + 1, 0.5);

}

public void test700k() throws Throwable {
template(700, 0.1);
public void test5M() throws Throwable {
template(5 * 1024, 0.51);
}

public void test1M() throws Throwable {
template(1024, 0.51);
public void test_5M1K() throws Throwable {
template(5 * 1024 + 1, 0.5);

}

public void test_4M1K() throws Throwable {
template(4 * 1024 + 1, 0.5);
public void test8M() throws Throwable {
template(8 * 1024, 0.51);
}

public void test_8M1K() throws Throwable {
template(8 * 1024 + 1, 0.5);

}

public void test10M() throws Throwable {
template(10 * 1024, 0.51);
}

public void test_10M1K() throws Throwable {
template(10 * 1024 + 1, 0.5);

}

public void testLastModify() throws IOException {
File f = File.createTempFile("qiniutest", "b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public String toJson(){
public static final String RequestKeyPrefetchedBefore = "prefetched_before";
public static final String RequestKeyPrefetchedErrorMessage = "prefetched_error_message";
public static final String RequestKeyNetworkMeasuring = "network_measuring";
public static final String RequestKeyPerceptiveSpeed = "perceptive_speed";

// 分块上传统计⽇志
public static final String BlockKeyLogType = "log_type";
Expand All @@ -102,6 +103,7 @@ public String toJson(){
public static final String BlockKeyOsVersion = "os_version";
public static final String BlockKeySDKName = "sdk_name";
public static final String BlockKeySDKVersion = "sdk_version";
public static final String BlockKeyPerceptiveSpeed = "perceptive_speed";


// 上传质量统计
Expand All @@ -113,6 +115,7 @@ public String toJson(){
public static final String QualityKeyTotalElapsedTime = "total_elapsed_time";
public static final String QualityKeyRequestsCount = "requests_count";
public static final String QualityKeyRegionsCount = "regions_count";
public static final String QualityKeyFileSize = "file_size";
public static final String QualityKeyBytesSent = "bytes_sent";
public static final String QualityKeyCloudType = "cloud_type";
public static final String QualityKeyErrorType = "error_type";
Expand All @@ -121,6 +124,7 @@ public String toJson(){
public static final String QualityKeyOsVersion = "os_version";
public static final String QualityKeySDKName = "sdk_name";
public static final String QualityKeySDKVersion = "sdk_version";
public static final String QualityKeyPerceptiveSpeed = "perceptive_speed";

public static String requestReportStatusCode(ResponseInfo responseInfo){
if (responseInfo == null){
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/qiniu/android/common/AutoZone.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qiniu.android.common;

import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.http.dns.DnsPrefetchTransaction;
import com.qiniu.android.http.request.RequestTransaction;
import com.qiniu.android.http.metrics.UploadRegionRequestMetrics;
import com.qiniu.android.storage.UpToken;
Expand Down Expand Up @@ -44,6 +45,14 @@ public List<String> getUcServerList() {
}
}

private String[] getUcServerArray() {
if (ucServer != null) {
return new String[]{ucServer};
} else {
return new String[]{Config.preQueryHost00, Config.preQueryHost01};
}
}

@Override
public ZonesInfo getZonesInfo(UpToken token) {
if (token == null) {
Expand Down Expand Up @@ -75,6 +84,7 @@ public void preQuery(final UpToken token, final QueryHandler completeHandler) {
return;
}

DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(getUcServerArray());

try {
SingleFlight.perform(cacheKey, new SingleFlight.ActionHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


public final class Constants {
public static final String VERSION = "8.3.1";
public static final String VERSION = "8.3.2";

public static final String UTF_8 = "utf-8";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@

import org.json.JSONObject;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ConnectChecker {

private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
private static SingleFlight<UploadSingleRequestMetrics> singleFlight = new SingleFlight<>();

public static boolean isConnected(UploadSingleRequestMetrics metrics) {
Expand Down Expand Up @@ -81,9 +87,6 @@ public void complete(UploadSingleRequestMetrics metrics) {
synchronized (checkStatus) {
checkStatus.completeCount += 1;
}
if (isHostConnected) {
checkStatus.isConnected = true;
}
if (isHostConnected || checkStatus.completeCount == checkStatus.totalCount) {
synchronized (checkStatus) {
if (checkStatus.isCompleted) {
Expand All @@ -106,13 +109,40 @@ public void complete(UploadSingleRequestMetrics metrics) {

private static void checkHost(final String host, final CheckCompleteHandler completeHandler) {

Request request = new Request(host, Request.HttpMethodHEAD, null, null, GlobalConfiguration.getInstance().connectCheckTimeout);
final boolean[] hasCallback = {false};
int timeout = GlobalConfiguration.getInstance().connectCheckTimeout;

final UploadSingleRequestMetrics timeoutMetrics = new UploadSingleRequestMetrics();
timeoutMetrics.start();
executorService.schedule(new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (this) {
if (hasCallback[0]) {
return null;
}
hasCallback[0] = true;
}
timeoutMetrics.end();
completeHandler.complete(timeoutMetrics);
return null;
}
}, timeout, TimeUnit.SECONDS);

Request request = new Request(host, Request.HttpMethodHEAD, null, null, timeout);
SystemHttpClient client = new SystemHttpClient();

LogUtil.i("== checkHost:" + host);
client.request(request, true, null, null, new IRequestClient.RequestClientCompleteHandler() {
@Override
public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) {
synchronized (this) {
if (hasCallback[0]) {
return;
}
hasCallback[0] = true;
}

LogUtil.i("== checkHost:" + host + " responseInfo:" + responseInfo);
completeHandler.complete(metrics);
}
Expand All @@ -128,7 +158,6 @@ private static class CheckStatus {
private int totalCount = 0;
private int completeCount = 0;
private boolean isCompleted = false;
private boolean isConnected = false;
}

private static class CheckResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.qiniu.android.http.dns;

import com.qiniu.android.storage.GlobalConfiguration;
import com.qiniu.android.utils.Utils;

import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -93,4 +96,20 @@ public String getSourceValue() {
public Long getTimestampValue() {
return timestampValue;
}

boolean isValid() {
if (timestampValue == null || ipValue == null || ipValue.length() == 0) {
return false;
}
int maxTTL = GlobalConfiguration.getInstance().dnsCacheMaxTTL;
return (Utils.currentTimestamp() / 1000) < timestampValue + maxTTL;
}

boolean needRefresh() {
if (timestampValue == null || ttlValue == null || ipValue == null || ipValue.length() == 0) {
return false;
}
int ttl = ttlValue.intValue();
return (Utils.currentTimestamp() / 1000) > timestampValue + ttl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ public void run() {
return true;
}

public static synchronized boolean addDnsCheckAndPrefetchTransaction(final String[] hosts) {
if (!DnsPrefetcher.getInstance().isDnsOpen()) {
return false;
}

if (hosts == null || hosts.length == 0) {
return false;
}

TransactionManager manager = TransactionManager.getInstance();
TransactionManager.Transaction loadDns = new TransactionManager.Transaction(null, 0, new Runnable() {
@Override
public void run() {
DnsPrefetcher.getInstance().addPreFetchHosts(hosts);
}
});
manager.addTransaction(loadDns);
return true;
}


public static synchronized boolean setDnsCheckWhetherCachedValidTransactionAction() {
if (!DnsPrefetcher.getInstance().isDnsOpen()) {
Expand Down
Loading