httpdns 2

This commit is contained in:
wangcongtao
2020-11-18 15:12:24 +08:00
parent ac6c217507
commit 9c0d4a0181
28 changed files with 351 additions and 21 deletions

View File

@@ -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 ->

View File

@@ -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')
}
}

View File

@@ -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}",
]
}

1
foudations/httpdns-base/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -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()

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.httpdns
POM_ARTIFACT_ID=httpdns-base
VERSION_CODE=1

View File

@@ -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

View File

@@ -0,0 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.httpdns.base">
</manifest>

View File

@@ -0,0 +1,13 @@
package com.mogo.httpdns;
public
/**
* @author congtaowang
* @since 2020/11/18
*
* 描述
*/
class HttpDnsConst {
public static final String PATH = "/httpdns/api";
}

View File

@@ -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();
}

1
foudations/httpdns-noop/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -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()

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.httpdns
POM_ARTIFACT_ID=httpdns-noop
VERSION_CODE=1

View File

@@ -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

View File

@@ -0,0 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.httpdns.noop">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- 用于获取手机imei码进行数据上报非必须 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 灯塔 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

View File

@@ -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 ) {
}
}

View File

@@ -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()

View File

@@ -10,4 +10,10 @@
<!-- 灯塔 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
<meta-data android:name="HTTP_DNS_APP_KEY" android:value="0I00093F244N42WU"/>
<meta-data android:name="HTTP_DNS_ID" android:value="2742"/>
<meta-data android:name="HTTP_DNS_KEY" android:value="7Pplkaua"/>
</application>
</manifest>

View File

@@ -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();
}
}
}

View File

@@ -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'
}

View File

@@ -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() );
}
}

View File

@@ -9,7 +9,7 @@ public
* @author congtaowang
* @since 2020/11/18
*
* 描述
* 将HOST转换为HttpDNS的ip
*/
interface HttpDns {

View File

@@ -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;
}
}

View File

@@ -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
######## 外部依赖引用
# 车聊聊

View File

@@ -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'