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
27 changes: 25 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android-sdk.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.android.tools.build:gradle:1.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
21 changes: 14 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ android {
}

dependencies {
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'com.loopj.android:android-async-http:1.4.+'
compile 'com.qiniu:happy-dns:0.1.+'
// compile 'com.android.support:appcompat-v7:21.0.3'
compile fileTree(include: ['*.jar'], dir: 'libs')
}

task releaseJar(type: Copy, dependsOn: 'build') {
from('build/intermediates/bundles/release')
into('../releases')
include('classes.jar')
rename('classes.jar', 'qiniu-android-sdk-' + version + '.jar')
task releaseJar(type:Jar, dependsOn: 'build') {
//指定生成的jar名
baseName 'qiniu-android-sdk-' + version
//从哪里打包class文件
from('build/intermediates/classes/release/com/qiniu/android/dns/')
//打包到jar后的目录结构
into('com/qiniu/android/dns/')
//去掉不需要打包的目录和文件
exclude('test/', 'BuildConfig.class', 'R.class')
//去掉R$开头的文件
exclude{ it.name.startsWith('R$');}
}

android.libraryVariants.all { variant ->
def name = variant.buildType.name
def task = project.tasks.create "jar${name.capitalize()}", Jar
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.exclude '**/R.*', '**/R$*.*'
task.exclude '**/R.*', '**/R$*.*', '**/BuildConfig.class'
artifacts.add('archives', task);
}

Expand Down
33 changes: 17 additions & 16 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -25,9 +27,9 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand All @@ -36,12 +38,12 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
Expand All @@ -63,7 +65,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -83,13 +84,13 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
<orderEntry type="library" exported="" name="happy-dns-0.1.1" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.7" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void testNoComplete() {
public void testIpBack() throws Throwable {

Configuration c = new Configuration.Builder()
.zone(new Zone("upwelcome.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp))
.zone(new Zone("upwelcome.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.build();
UploadManager uploadManager2 = new UploadManager(c);
final String expectKey = "你好;\"\r\n\r\n\r\n";
Expand Down Expand Up @@ -328,7 +328,7 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPortBackup() throws Throwable {
Configuration c = new Configuration.Builder()
.zone(new Zone("upload.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp))
.zone(new Zone("upload.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.upPort(9999)
.build();
UploadManager uploadManager2 = new UploadManager(c);
Expand Down Expand Up @@ -372,7 +372,7 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testDnsHijacking() throws Throwable {
Configuration c = new Configuration.Builder()
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp))
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.build();
UploadManager uploadManager2 = new UploadManager(c);
final String expectKey = "你好;\"\r\n\r\n\r\n";
Expand Down
3 changes: 1 addition & 2 deletions library/src/androidTest/java/com/qiniu/android/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ protected void setUp() throws Exception {

@SmallTest
public void testPost1() throws Throwable {

httpManager.postData("http://www.baidu.com", "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -44,7 +43,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
}, null, false);

try {
signal.await(60, TimeUnit.SECONDS); // wait for callback
signal.await(6000, TimeUnit.SECONDS); // wait for callback
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private void templateHijack(int size) throws Throwable {
final File f = TempFile.createFile(size);

Configuration c = new Configuration.Builder()
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp))
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup,
Zone.zone0.upIp, Zone.zone0.upIp2))
.build();
UploadManager uploadManager = new UploadManager(c);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.qiniu.android.http;

import com.loopj.android.http.AsyncHttpClient;
import com.qiniu.android.dns.DnsManager;

import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.params.BasicHttpParams;

/**
* Created by bailong on 15/7/4.
*/
public final class AsyncHttpClientMod extends AsyncHttpClient {
static final ThreadLocal<DnsManager> local = new ThreadLocal<>();
static final ThreadLocal<String> ip = new ThreadLocal<>();
private final DnsManager dns;

private AsyncHttpClientMod(DnsManager dns) {
this.dns = dns;
}

public static AsyncHttpClientMod create(DnsManager dns) {
local.set(dns);
AsyncHttpClientMod a = new AsyncHttpClientMod(dns);
local.remove();
return a;
}

//在父类构造函数中调用
@Override
protected ClientConnectionManager createConnectionManager(SchemeRegistry schemeRegistry, BasicHttpParams httpParams) {
DnsManager d = dns == null ? local.get() : dns;
return new ThreadSafeClientConnManager(httpParams, schemeRegistry, d);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*/
public final class ByteArrayEntity extends AbstractHttpEntity implements Cloneable {

private static final int progressStep = 8 * 1024;
private final byte[] b;
private final int off, len;
private final ProgressHandler progressHandler;
private final CancellationHandler cancellationHandler;
private static final int progressStep = 8 * 1024;

public ByteArrayEntity(final byte[] b, ProgressHandler h, CancellationHandler c) {
this(b, 0, b.length, h, c);
}

public ByteArrayEntity(final byte[] b, final int off, final int len, ProgressHandler h, CancellationHandler c) {
public ByteArrayEntity(final byte[] b, final int off, final int len, ProgressHandler h, CancellationHandler c) {
super();
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) < 0) || ((off + len) > b.length)) {
Expand Down Expand Up @@ -50,9 +50,9 @@ public InputStream getContent() {
return new ByteArrayInputStream(this.b, this.off, this.len);
}

// @Override
// @Override
public void writeTo(final OutputStream outStream) throws IOException {
if(progressHandler != null || cancellationHandler != null){
if (progressHandler != null || cancellationHandler != null) {
writeWithNotify(outStream);
} else {
outStream.write(this.b, this.off, this.len);
Expand All @@ -63,7 +63,7 @@ public void writeTo(final OutputStream outStream) throws IOException {
private void writeWithNotify(final OutputStream outStream) throws IOException {
int off = 0;
while (off < this.len) {
if(cancellationHandler != null && cancellationHandler.isCancelled()) {
if (cancellationHandler != null && cancellationHandler.isCancelled()) {
try {
outStream.close();
} catch (Exception e) {
Expand All @@ -74,7 +74,7 @@ private void writeWithNotify(final OutputStream outStream) throws IOException {
int left = this.len - off;
int len = left < progressStep ? left : progressStep;
outStream.write(this.b, this.off + off, len);
if(progressHandler != null) {
if (progressHandler != null) {
progressHandler.onProgress(off, this.len);
}
off += len;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public interface CancellationHandler {
*/
boolean isCancelled();

public static class CancellationException extends IOException {

class CancellationException extends IOException {
}
}
Loading