diff --git a/foudations/httpdns-tencent/.gitignore b/foudations/httpdns-tencent/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/foudations/httpdns-tencent/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/foudations/httpdns-tencent/build.gradle b/foudations/httpdns-tencent/build.gradle new file mode 100644 index 0000000000..61aa3f2e5f --- /dev/null +++ b/foudations/httpdns-tencent/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.ext.android.compileSdkVersion + // buildToolsVersion rootProject.ext.android.buildToolsVersion + defaultConfig { + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode Integer.valueOf(VERSION_CODE) + versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION") + + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "com.mogo.tencent.httpdns:android-httpdns:+@aar" + implementation "com.mogo.tencent.beacon:android-beacon:+@jar" +} + +apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() \ No newline at end of file diff --git a/foudations/httpdns-tencent/consumer-rules.pro b/foudations/httpdns-tencent/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/foudations/httpdns-tencent/gradle.properties b/foudations/httpdns-tencent/gradle.properties new file mode 100644 index 0000000000..32c09bbf9b --- /dev/null +++ b/foudations/httpdns-tencent/gradle.properties @@ -0,0 +1,3 @@ +GROUP=com.mogo.httpdns +POM_ARTIFACT_ID=httpdns-tencent +VERSION_CODE=1 \ No newline at end of file diff --git a/foudations/httpdns-tencent/proguard-rules.pro b/foudations/httpdns-tencent/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/foudations/httpdns-tencent/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/foudations/httpdns-tencent/src/main/AndroidManifest.xml b/foudations/httpdns-tencent/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..f209606808 --- /dev/null +++ b/foudations/httpdns-tencent/src/main/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/network/HttpDns.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/HttpDns.java new file mode 100644 index 0000000000..26d720b828 --- /dev/null +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/HttpDns.java @@ -0,0 +1,17 @@ +package com.mogo.utils.network; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/11/18 + * + * 描述 + */ +interface HttpDns { + + List< InetAddress > lookup( String hostname ) throws UnknownHostException; +} diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/network/NetConfig.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/NetConfig.java index a0fe0af85f..4cb81038f4 100644 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/network/NetConfig.java +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/NetConfig.java @@ -46,6 +46,8 @@ public final class NetConfig { private SSLContext sslContext; + private HttpDns httpDns; + private NetConfig() { } @@ -157,4 +159,12 @@ public final class NetConfig { public synchronized void setSslContext( SSLContext sslContext ) { this.sslContext = sslContext; } + + public HttpDns getHttpDns() { + return httpDns; + } + + public void setHttpDns( HttpDns httpDns ) { + this.httpDns = httpDns; + } } diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/network/OkHttpFactory.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/OkHttpFactory.java index 02e05d5592..29497b44f7 100644 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/network/OkHttpFactory.java +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/network/OkHttpFactory.java @@ -1,8 +1,12 @@ package com.mogo.utils.network; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import okhttp3.Dns; import okhttp3.Interceptor; import okhttp3.OkHttpClient; @@ -45,6 +49,13 @@ public final class OkHttpFactory { builder.addNetworkInterceptor(networkInterceptor); } + HttpDns httpDns = NetConfig.instance().getHttpDns(); + if ( httpDns != null ) { + builder.dns( hostname -> { + return httpDns.lookup( hostname ); + } ); + } + sInstance = builder.build(); } } diff --git a/gradle.properties b/gradle.properties index e6f959c146..8d681026ad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -107,6 +107,8 @@ TTS_NOOP_VERSION=1.0.0 # 自研地图 MAP_CUSTOM_VERSION=1.2.1.9 MOGO_MODULES_MVISION_VERSION=1.0.0 +# httpdns +HTTPDNS_TENCENT_VERSION = 1.0.0 ######## 外部依赖引用 # 车聊聊 diff --git a/settings.gradle b/settings.gradle index 9d2abf0197..7644c16aef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ +include ':foudations:httpdns-tencent' include ':modules:mogo-modules-mvision' include ':foudations:mogo-base-websocket-sdk' include ':tts:tts-base'