diff --git a/app/build.gradle b/app/build.gradle index f6c6988280..7ca3254bc2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -403,6 +403,7 @@ dependencies { apply from: "./functions/crashreport.gradle" apply from: "./functions/widgets.gradle" apply from: "./functions/tts.gradle" + apply from: "./functions/httpdns.gradle" } android.applicationVariants.all { variant -> diff --git a/app/functions/httpdns.gradle b/app/functions/httpdns.gradle new file mode 100644 index 0000000000..ad62f966ef --- /dev/null +++ b/app/functions/httpdns.gradle @@ -0,0 +1,27 @@ +// 基础服务:仅比亚迪渠道用sdk方式实现,其他都基于apk基础服务 + +project.dependencies { + if (Boolean.valueOf(RELEASE)) { + bydautoImplementation rootProject.ext.dependencies.httpdnsnoop + d82xImplementation rootProject.ext.dependencies.httpdnsnoop + em1Implementation rootProject.ext.dependencies.httpdnsnoop + d8xxImplementation rootProject.ext.dependencies.httpdnsnoop + d80xImplementation rootProject.ext.dependencies.httpdnsnoop + em4Implementation rootProject.ext.dependencies.httpdnsnoop + e8xxImplementation rootProject.ext.dependencies.httpdnsnoop + f8xxImplementation rootProject.ext.dependencies.httpdnstencent + f80xImplementation rootProject.ext.dependencies.httpdnstencent + em3Implementation rootProject.ext.dependencies.httpdnsnoop + } else { + bydautoImplementation project(':foudations:httpdns-noop') + d82xImplementation project(':foudations:httpdns-noop') + em1Implementation project(':foudations:httpdns-noop') + d8xxImplementation project(':foudations:httpdns-noop') + d80xImplementation project(':foudations:httpdns-noop') + em4Implementation project(':foudations:httpdns-noop') + e8xxImplementation project(':foudations:httpdns-noop') + f8xxImplementation project(':foudations:httpdns-tencent') + f80xImplementation project(':foudations:httpdns-tencent') + em3Implementation project(':foudations:httpdns-noop') + } +} \ No newline at end of file diff --git a/config.gradle b/config.gradle index 7b8a4a7ef9..7fb6aa63da 100644 --- a/config.gradle +++ b/config.gradle @@ -2,20 +2,18 @@ ext { time = "" kotlin_version = "1.4.10" android = [ -// applicationId : "com.mogo.launcher", -// zhidadoApplicationId: "com.zhidao.launcher", -launcherApplicationId : "com.mogo.launcher", -independentApplicationId : "com.mogo.launcher.app", -fLauncherApplicationId : "com.mogo.launcher.f", -bydautoIndependentApplicationId: "com.mogo.launcher.app.bydauto", -fLauncherAmapApiValue : "aa2c8a0547378ead2f9a37762d9dd179", -bydautoIndependentApiValue : "b1e1d527b02a493913c50985827c943a", -commonLauncherAmapApiValue : "a36b9f7b086fa3951bb35338a5a06dd3", -commonIndependentAmapApiValue : "1c3fbc5f5e183619ffb1e7bc01e6751f", -compileSdkVersion : 28, -buildToolsVersion : "29.0.2", -minSdkVersion : 19, -targetSdkVersion : 22, + launcherApplicationId : "com.mogo.launcher", + independentApplicationId : "com.mogo.launcher.app", + fLauncherApplicationId : "com.mogo.launcher.f", + bydautoIndependentApplicationId: "com.mogo.launcher.app.bydauto", + fLauncherAmapApiValue : "aa2c8a0547378ead2f9a37762d9dd179", + bydautoIndependentApiValue : "b1e1d527b02a493913c50985827c943a", + commonLauncherAmapApiValue : "a36b9f7b086fa3951bb35338a5a06dd3", + commonIndependentAmapApiValue : "1c3fbc5f5e183619ffb1e7bc01e6751f", + compileSdkVersion : 28, + buildToolsVersion : "29.0.2", + minSdkVersion : 19, + targetSdkVersion : 22, ] dependencies = [ // androidx @@ -216,6 +214,11 @@ targetSdkVersion : 22, ttsnoop : "com.mogo.tts:tts-noop:${TTS_NOOP_VERSION}", mogomodulemachinevision : "com.mogo.module:module-machine-vision:${MOGO_MODULES_MVISION_VERSION}", + + + httpdnsbase : "com.mogo.httpdns:httpdns-base:${HTTPDNS_BASE_VERSION}", + httpdnsnoop : "com.mogo.httpdns:httpdns-noop:${HTTPDNS_NOOP_VERSION}", + httpdnstencent : "com.mogo.httpdns:httpdns-tencent:${HTTPDNS_TENCENT_VERSION}", ] } \ No newline at end of file diff --git a/foudations/httpdns-base/.gitignore b/foudations/httpdns-base/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/foudations/httpdns-base/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/foudations/httpdns-base/build.gradle b/foudations/httpdns-base/build.gradle new file mode 100644 index 0000000000..ef8743f6a9 --- /dev/null +++ b/foudations/httpdns-base/build.gradle @@ -0,0 +1,37 @@ +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 rootProject.ext.dependencies.arouter + annotationProcessor rootProject.ext.dependencies.aroutercompiler + + if (Boolean.valueOf(RELEASE)) { + api rootProject.ext.dependencies.mogoutils + } else { + api project(':foudations:mogo-utils') + } +} + +apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() \ No newline at end of file diff --git a/foudations/httpdns-base/consumer-rules.pro b/foudations/httpdns-base/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/foudations/httpdns-base/gradle.properties b/foudations/httpdns-base/gradle.properties new file mode 100644 index 0000000000..c2f7baa9af --- /dev/null +++ b/foudations/httpdns-base/gradle.properties @@ -0,0 +1,3 @@ +GROUP=com.mogo.httpdns +POM_ARTIFACT_ID=httpdns-base +VERSION_CODE=1 \ No newline at end of file diff --git a/foudations/httpdns-base/proguard-rules.pro b/foudations/httpdns-base/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/foudations/httpdns-base/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-base/src/main/AndroidManifest.xml b/foudations/httpdns-base/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..eb5f8d96b8 --- /dev/null +++ b/foudations/httpdns-base/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/foudations/httpdns-base/src/main/java/com/mogo/httpdns/HttpDnsConst.java b/foudations/httpdns-base/src/main/java/com/mogo/httpdns/HttpDnsConst.java new file mode 100644 index 0000000000..3cfdd526cc --- /dev/null +++ b/foudations/httpdns-base/src/main/java/com/mogo/httpdns/HttpDnsConst.java @@ -0,0 +1,13 @@ +package com.mogo.httpdns; + +public +/** + * @author congtaowang + * @since 2020/11/18 + * + * 描述 + */ +class HttpDnsConst { + + public static final String PATH = "/httpdns/api"; +} diff --git a/foudations/httpdns-base/src/main/java/com/mogo/httpdns/IMogoHttpDns.java b/foudations/httpdns-base/src/main/java/com/mogo/httpdns/IMogoHttpDns.java new file mode 100644 index 0000000000..eb32dbc99c --- /dev/null +++ b/foudations/httpdns-base/src/main/java/com/mogo/httpdns/IMogoHttpDns.java @@ -0,0 +1,16 @@ +package com.mogo.httpdns; + +import com.alibaba.android.arouter.facade.template.IProvider; +import com.mogo.utils.network.HttpDns; + +public +/** + * @author congtaowang + * @since 2020/11/18 + * + * http 请求做http dns转换 + */ +interface IMogoHttpDns extends IProvider { + + HttpDns dns(); +} diff --git a/foudations/httpdns-noop/.gitignore b/foudations/httpdns-noop/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/foudations/httpdns-noop/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/foudations/httpdns-noop/build.gradle b/foudations/httpdns-noop/build.gradle new file mode 100644 index 0000000000..da3ed76d3b --- /dev/null +++ b/foudations/httpdns-noop/build.gradle @@ -0,0 +1,36 @@ +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 rootProject.ext.dependencies.arouter + annotationProcessor rootProject.ext.dependencies.aroutercompiler + if (Boolean.valueOf(RELEASE)) { + implementation rootProject.ext.dependencies.httpdnsbase + } else { + implementation project(':foudations:httpdns-base') + } +} + +apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() \ No newline at end of file diff --git a/foudations/httpdns-noop/consumer-rules.pro b/foudations/httpdns-noop/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/foudations/httpdns-noop/gradle.properties b/foudations/httpdns-noop/gradle.properties new file mode 100644 index 0000000000..1d02951301 --- /dev/null +++ b/foudations/httpdns-noop/gradle.properties @@ -0,0 +1,3 @@ +GROUP=com.mogo.httpdns +POM_ARTIFACT_ID=httpdns-noop +VERSION_CODE=1 \ No newline at end of file diff --git a/foudations/httpdns-noop/proguard-rules.pro b/foudations/httpdns-noop/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/foudations/httpdns-noop/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-noop/src/main/AndroidManifest.xml b/foudations/httpdns-noop/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..7bfbfbae9a --- /dev/null +++ b/foudations/httpdns-noop/src/main/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/foudations/httpdns-noop/src/main/java/com/mogo/httpdns/noop/HttpDnsNoop.java b/foudations/httpdns-noop/src/main/java/com/mogo/httpdns/noop/HttpDnsNoop.java new file mode 100644 index 0000000000..22912e8f6f --- /dev/null +++ b/foudations/httpdns-noop/src/main/java/com/mogo/httpdns/noop/HttpDnsNoop.java @@ -0,0 +1,29 @@ +package com.mogo.httpdns.noop; + +import android.content.Context; + +import com.alibaba.android.arouter.facade.annotation.Route; +import com.mogo.httpdns.HttpDnsConst; +import com.mogo.httpdns.IMogoHttpDns; +import com.mogo.utils.network.HttpDns; + +public +/** + * @author congtaowang + * @since 2020/11/18 + * + * 描述 + */ +@Route( path = HttpDnsConst.PATH ) +class HttpDnsNoop implements IMogoHttpDns { + + @Override + public HttpDns dns() { + return null; + } + + @Override + public void init( Context context ) { + + } +} diff --git a/foudations/httpdns-tencent/build.gradle b/foudations/httpdns-tencent/build.gradle index 61aa3f2e5f..57ca60da7c 100644 --- a/foudations/httpdns-tencent/build.gradle +++ b/foudations/httpdns-tencent/build.gradle @@ -25,7 +25,16 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.mogo.tencent.httpdns:android-httpdns:+@aar" - implementation "com.mogo.tencent.beacon:android-beacon:+@jar" + implementation rootProject.ext.dependencies.arouter + annotationProcessor rootProject.ext.dependencies.aroutercompiler + + if (Boolean.valueOf(RELEASE)) { + implementation rootProject.ext.dependencies.httpdnsbase + implementation rootProject.ext.dependencies.mogocommons + } else { + implementation project(':foudations:httpdns-base') + implementation project(':foudations:mogo-commons') + } } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() \ No newline at end of file diff --git a/foudations/httpdns-tencent/libs/beacon-android-release-3.1.2-cover.jar b/foudations/httpdns-tencent/libs/beacon-android-release-3.1.2-cover.jar new file mode 100755 index 0000000000..d384c8a23d Binary files /dev/null and b/foudations/httpdns-tencent/libs/beacon-android-release-3.1.2-cover.jar differ diff --git a/foudations/httpdns-tencent/src/main/AndroidManifest.xml b/foudations/httpdns-tencent/src/main/AndroidManifest.xml index f209606808..a30884aeb4 100644 --- a/foudations/httpdns-tencent/src/main/AndroidManifest.xml +++ b/foudations/httpdns-tencent/src/main/AndroidManifest.xml @@ -10,4 +10,10 @@ + + + + + + \ No newline at end of file diff --git a/foudations/httpdns-tencent/src/main/java/com/mogo/httpdns/tencent/TencentHttpDns.java b/foudations/httpdns-tencent/src/main/java/com/mogo/httpdns/tencent/TencentHttpDns.java new file mode 100644 index 0000000000..2e6210405c --- /dev/null +++ b/foudations/httpdns-tencent/src/main/java/com/mogo/httpdns/tencent/TencentHttpDns.java @@ -0,0 +1,79 @@ +package com.mogo.httpdns.tencent; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Bundle; + +import com.alibaba.android.arouter.facade.annotation.Route; +import com.mogo.commons.debug.DebugConfig; +import com.mogo.httpdns.HttpDnsConst; +import com.mogo.httpdns.IMogoHttpDns; +import com.mogo.utils.logger.Logger; +import com.mogo.utils.network.HttpDns; +import com.tencent.msdk.dns.MSDKDnsResolver; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/11/18 + * + * 描述 + */ +@Route( path = HttpDnsConst.PATH ) +class TencentHttpDns implements IMogoHttpDns, HttpDns { + + private static final String TAG = "TencentHttpDns"; + + @Override + public HttpDns dns() { + return this; + } + + @Override + public List< InetAddress > lookup( String hostname ) throws UnknownHostException { + String ips = MSDKDnsResolver.getInstance().getAddrByName( hostname ); + Logger.d( TAG, hostname ); + String[] ipArr = ips.split( ";" ); + if ( 0 == ipArr.length ) { + return Collections.emptyList(); + } + List< InetAddress > inetAddressList = new ArrayList<>( ipArr.length ); + for ( String ip : ipArr ) { + if ( "0".equals( ip ) ) { + continue; + } + try { + InetAddress inetAddress = InetAddress.getByName( ip ); + inetAddressList.add( inetAddress ); + } catch ( UnknownHostException ignored ) { + Logger.e( TAG, ignored, "lookup invoked." ); + } + } + return inetAddressList; + } + + @Override + public void init( Context context ) { + final ApplicationInfo appInfo; + try { + appInfo = context.getPackageManager().getApplicationInfo( context.getPackageName(), PackageManager.GET_META_DATA ); + Bundle configBundle = appInfo.metaData; + MSDKDnsResolver.getInstance().init( context.getApplicationContext(), + configBundle.getString( "HTTP_DNS_APP_KEY" ), + configBundle.getString( "HTTP_DNS_ID" ), + configBundle.getString( "HTTP_DNS_KEY" ), + DebugConfig.isDebug(), + 1_000 + ); + } catch ( PackageManager.NameNotFoundException e ) { + e.printStackTrace(); + } + } +} diff --git a/foudations/mogo-commons/build.gradle b/foudations/mogo-commons/build.gradle index 35c862662d..790d2b2598 100644 --- a/foudations/mogo-commons/build.gradle +++ b/foudations/mogo-commons/build.gradle @@ -46,10 +46,12 @@ dependencies { implementation rootProject.ext.dependencies.mogoutils api rootProject.ext.dependencies.ttsbase implementation rootProject.ext.dependencies.skinsupport + implementation rootProject.ext.dependencies.httpdnsbase } else { implementation project(":foudations:mogo-utils") api project(":tts:tts-base") implementation project(":skin:mogo-skin-support") + implementation project(":foudations:httpdns-base") } api 'org.greenrobot:eventbus:3.1.1' } diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java index b5b577a813..168deb143a 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java @@ -18,14 +18,11 @@ import com.mogo.commons.network.Constants; import com.mogo.commons.network.ParamsUtil; import com.mogo.commons.network.X509TrustManagerImpl; import com.mogo.commons.storage.SpStorage; +import com.mogo.httpdns.IMogoHttpDns; import com.mogo.utils.ThreadPoolService; -import com.mogo.utils.TipDrawable; import com.mogo.utils.TipToast; import com.mogo.utils.network.NetConfig; import com.mogo.utils.storage.SharedPrefsMgr; -import com.zhidao.account.sdk.AccountClientManager; -import com.zhidao.account.sdk.callback.TicketInfoCallback; -import com.zhidao.account.sdk.network.NetEnvironManager; import java.io.IOException; import java.security.SecureRandom; @@ -149,6 +146,8 @@ public class AbsMogoApplication extends Application { } catch ( Exception e ) { } + IMogoHttpDns dns = ARouter.getInstance().navigation( IMogoHttpDns.class ); + NetConfig.instance().setSignaturePrefix( Constants.SIGN_PREFIX ) .setPublicParams( ParamsUtil.getStaticParams() ) .setHostnameVerifier( new AllAllowedHostnameVerifier() ) @@ -163,6 +162,7 @@ public class AbsMogoApplication extends Application { return chain.proceed( request ); } } ) + .setHttpDns( dns.dns() ) .setLoggable( DebugConfig.isDebug() ); } } 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 index 26d720b828..bdb83166ff 100644 --- 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 @@ -9,7 +9,7 @@ public * @author congtaowang * @since 2020/11/18 * - * 描述 + * 将HOST转换为HttpDNS的ip */ interface HttpDns { 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 4cb81038f4..f7f2afea91 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 @@ -164,7 +164,8 @@ public final class NetConfig { return httpDns; } - public void setHttpDns( HttpDns httpDns ) { + public NetConfig setHttpDns( HttpDns httpDns ) { this.httpDns = httpDns; + return this; } } diff --git a/gradle.properties b/gradle.properties index 8d681026ad..a059dec4fe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -109,6 +109,8 @@ MAP_CUSTOM_VERSION=1.2.1.9 MOGO_MODULES_MVISION_VERSION=1.0.0 # httpdns HTTPDNS_TENCENT_VERSION = 1.0.0 +HTTPDNS_BASE_VERSION = 1.0.0 +HTTPDNS_NOOP_VERSION = 1.0.0 ######## 外部依赖引用 # 车聊聊 diff --git a/settings.gradle b/settings.gradle index 7644c16aef..c9209949dc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,6 @@ +include ':foudations:httpdns-base' include ':foudations:httpdns-tencent' +include ':foudations:httpdns-noop' include ':modules:mogo-modules-mvision' include ':foudations:mogo-base-websocket-sdk' include ':tts:tts-base'