删除 independent 依赖
This commit is contained in:
1
foudations/httpdns-tencent/.gitignore
vendored
1
foudations/httpdns-tencent/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,46 +0,0 @@
|
||||
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"
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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()
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.httpdns
|
||||
POM_ARTIFACT_ID=httpdns-tencent
|
||||
VERSION_CODE=1
|
||||
21
foudations/httpdns-tencent/proguard-rules.pro
vendored
21
foudations/httpdns-tencent/proguard-rules.pro
vendored
@@ -1,21 +0,0 @@
|
||||
# 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
|
||||
@@ -1,19 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.httpdns">
|
||||
|
||||
<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" />
|
||||
|
||||
<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>
|
||||
@@ -1,170 +0,0 @@
|
||||
package com.mogo.httpdns.tencent;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.utils.ThreadPoolService;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.tencent.msdk.dns.MSDKDnsResolver;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/11/18
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class HttpDnsIpsCache {
|
||||
|
||||
private static final String TAG = "HttpDnsIpsCache";
|
||||
|
||||
// 缓存过期时间
|
||||
public static final long INTERVAL_CACHE = 60 * 60 * 1000;
|
||||
|
||||
// 刷新缓存时间
|
||||
public static final long TTL = ( long ) ( INTERVAL_CACHE * 0.75 );
|
||||
|
||||
// 使用dns新域名
|
||||
public static final int MSG_DNS_FLUSH = 6000000;
|
||||
// ttl
|
||||
public static final int MSG_DNS_TTL = 6000001;
|
||||
|
||||
private final static Map< String, String > sCaches = new ConcurrentHashMap<>();
|
||||
private final static Map< String, String > sTTLCaches = new ConcurrentHashMap<>();
|
||||
|
||||
private final static Map< String, IHttpDnsTtlCallback > sTtlCallbacks = new ConcurrentHashMap<>();
|
||||
|
||||
private final static Handler sHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_DNS_FLUSH ) {
|
||||
flushNewDnsCache();
|
||||
postTtlCallback();
|
||||
loopDnsParse();
|
||||
} else if ( msg.what == MSG_DNS_TTL ) {
|
||||
parseHosts();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 将 ttl 消息回调
|
||||
*/
|
||||
static void postTtlCallback() {
|
||||
if ( sTtlCallbacks.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
Collection<IHttpDnsTtlCallback> callbacks = sTtlCallbacks.values();
|
||||
if (callbacks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for ( IHttpDnsTtlCallback callback : callbacks ) {
|
||||
if ( callback == null ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
callback.onTtl();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存域名
|
||||
*
|
||||
* @param host
|
||||
* @param ip
|
||||
*/
|
||||
static void cache( String host, String ip ) {
|
||||
sCaches.put( host, ip );
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中的域名
|
||||
*
|
||||
* @param host
|
||||
* @return
|
||||
*/
|
||||
static String getHttpDnsIps( String host ) {
|
||||
return sCaches.get( host );
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用新的 dns 缓存
|
||||
*/
|
||||
static void flushNewDnsCache() {
|
||||
sCaches.clear();
|
||||
sCaches.putAll( sTTLCaches );
|
||||
}
|
||||
|
||||
/**
|
||||
* ttl 到达后,刷新一遍 dns 域名
|
||||
*/
|
||||
static void loopDnsParse() {
|
||||
Logger.d( TAG, "使用新的dns列表" );
|
||||
sHandler.sendEmptyMessageDelayed( MSG_DNS_FLUSH, INTERVAL_CACHE );
|
||||
sHandler.sendEmptyMessageDelayed( MSG_DNS_TTL, TTL );
|
||||
}
|
||||
|
||||
/**
|
||||
* ttl 到期,刷新域名
|
||||
*/
|
||||
static void parseHosts() {
|
||||
Logger.d( TAG, "ttl 过期,刷新dns列表" );
|
||||
ThreadPoolService.execute( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set< String > hostSet = sCaches.keySet();
|
||||
if ( hostSet.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
for ( String host : hostSet ) {
|
||||
String newIp = parseHostFromHttpDns( host );
|
||||
if ( TextUtils.isEmpty( newIp ) ) {
|
||||
continue;
|
||||
}
|
||||
sTTLCaches.put( host, newIp );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用腾讯服务解析域名
|
||||
*
|
||||
* @param host
|
||||
* @return
|
||||
*/
|
||||
static String parseHostFromHttpDns( String host ) {
|
||||
String ips = MSDKDnsResolver.getInstance().getAddrByName( host );
|
||||
String[] ipArr = ips.split( ";" );
|
||||
if ( 0 == ipArr.length ) {
|
||||
return null;
|
||||
}
|
||||
for ( String ip : ipArr ) {
|
||||
if ( TextUtils.isEmpty( ip ) || TextUtils.equals( "0", ip ) ) {
|
||||
continue;
|
||||
}
|
||||
Logger.d( TAG, "parse: %s - %s", host, ip );
|
||||
return ip;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static void addHttpDnsTtlCallback( String host, IHttpDnsTtlCallback callback ) {
|
||||
sTtlCallbacks.put( host, callback );
|
||||
}
|
||||
|
||||
static void removeHttpDnsTtlCallback( String host ) {
|
||||
sTtlCallbacks.remove( host );
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.mogo.httpdns.tencent;
|
||||
|
||||
public class IHttpDnsTtlCallback {
|
||||
public void onTtl() {
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
package com.mogo.httpdns.tencent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.cloud.httpdns.listener.OnAddressChangedListener;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.httpdns.HttpDnsConst;
|
||||
import com.mogo.httpdns.IHttpDnsCallback;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.httpdns.HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_IM;
|
||||
import static com.mogo.httpdns.HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_WS;
|
||||
|
||||
|
||||
@Route( path = HttpDnsConst.PATH )
|
||||
public class TencentHttpDns implements IMogoHttpDns, HttpDns {
|
||||
|
||||
private static volatile boolean sInited = false;
|
||||
|
||||
private static final String TAG = "TencentHttpDns";
|
||||
|
||||
@Override
|
||||
public List< InetAddress > lookup( String hostname ) throws UnknownHostException {
|
||||
Logger.d( TAG, "需要dns解析" );
|
||||
String cacheIp = getCacheOrParseIpIfNecessary( hostname );
|
||||
if ( TextUtils.isEmpty( cacheIp ) ) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.asList( InetAddress.getAllByName( cacheIp ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCachedHttpDnsIps( String host,int type ) {
|
||||
String ip = HttpDnsIpsCache.getHttpDnsIps(host);
|
||||
if (ip == null) {
|
||||
return null;
|
||||
} else {
|
||||
return tailPort(ip, type);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCacheOrParseIpIfNecessary( String host ) {
|
||||
String cacheIp = HttpDnsIpsCache.getHttpDnsIps( host );
|
||||
if ( TextUtils.isEmpty( cacheIp ) ) {
|
||||
cacheIp = HttpDnsIpsCache.parseHostFromHttpDns( host );
|
||||
if ( !TextUtils.isEmpty( cacheIp ) ) {
|
||||
HttpDnsIpsCache.cache( host, cacheIp );
|
||||
}
|
||||
}
|
||||
return cacheIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHttpDnsIp( String host,int type, boolean useCache, IHttpDnsCallback callback ) {
|
||||
String cacheIp;
|
||||
if ( useCache ) {
|
||||
cacheIp = getCacheOrParseIpIfNecessary( host );
|
||||
} else {
|
||||
cacheIp = HttpDnsIpsCache.parseHostFromHttpDns( host );
|
||||
if ( !TextUtils.isEmpty( cacheIp ) ) {
|
||||
HttpDnsIpsCache.cache( host, cacheIp );
|
||||
}
|
||||
}
|
||||
if ( !TextUtils.isEmpty( cacheIp ) ) {
|
||||
if ( callback != null ) {
|
||||
callback.onParsed( tailPort(cacheIp,type) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( callback != null ) {
|
||||
callback.onParsed( null );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String syncGetHttpDns(String host, int type, boolean useCache) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addressChangedListener(OnAddressChangedListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Keep
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
if ( sInited ) {
|
||||
return;
|
||||
}
|
||||
MSDKDnsResolver.getInstance().init( context.getApplicationContext(),
|
||||
"0I00093F244N42WU",
|
||||
"2742",
|
||||
"7Pplkaua",
|
||||
DebugConfig.isDebug(),
|
||||
1_000
|
||||
);
|
||||
MSDKDnsResolver.getInstance().WGSetDnsOpenId( "1AE58PG9444E3G9L" );
|
||||
HttpDnsIpsCache.loopDnsParse();
|
||||
sInited = true;
|
||||
}
|
||||
|
||||
private String tailPort(String ip, int type) {
|
||||
switch (type) {
|
||||
case HTTP_DNS_ADDRESS_TYPE_WS:
|
||||
return ip + ":4004";
|
||||
case HTTP_DNS_ADDRESS_TYPE_IM:
|
||||
return ip + ":4002";
|
||||
default:
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
foudations/mogo-base-services-apk/.gitignore
vendored
1
foudations/mogo-base-services-apk/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,7 +0,0 @@
|
||||
## 基实现功能
|
||||
|
||||
基础服务apk实现对应功能:位置上报、长连接、passport
|
||||
|
||||
位置上报:com.zhidao.locationinfo
|
||||
长链:com.zhidao.socketservice
|
||||
passport:
|
||||
@@ -1,51 +0,0 @@
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
|
||||
api rootProject.ext.dependencies.socketsdk
|
||||
api rootProject.ext.dependencies.socketsdkconnsvrprotoco
|
||||
api rootProject.ext.dependencies.socketsdkprotobufjava
|
||||
implementation rootProject.ext.dependencies.accountsdk
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogocommons
|
||||
implementation rootProject.ext.dependencies.mogoserviceapi
|
||||
} else {
|
||||
implementation project(":foudations:mogo-utils")
|
||||
implementation project(":foudations:mogo-commons")
|
||||
implementation project(":services:mogo-service-api")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.base
|
||||
POM_ARTIFACT_ID=services-apk
|
||||
VERSION_CODE=1
|
||||
@@ -1,21 +0,0 @@
|
||||
# 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
|
||||
@@ -1,5 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.base.services.apk">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.mogo.base.services.locationinfo;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.service.locationinfo.IMogoLocationInfoService;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 位置服务
|
||||
*/
|
||||
@Keep
|
||||
class MogoLocationInfoServices implements IMogoLocationInfoService {
|
||||
|
||||
private static final String TAG = "MogoLocationInfoServices-apk";
|
||||
|
||||
private static volatile MogoLocationInfoServices sInstance;
|
||||
|
||||
private MogoLocationInfoServices() {
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static MogoLocationInfoServices getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MogoLocationInfoServices.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MogoLocationInfoServices();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideLocation( MogoLocation location ) {
|
||||
Logger.d( TAG, "apk - provideLocation" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Logger.d( TAG, "apk - start" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
Logger.d( TAG, "apk - stop" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
Logger.d( TAG, "apk - init" );
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.mogo.base.services.passport;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.service.passport.IMogoPassportManager;
|
||||
import com.mogo.service.passport.IMogoTicketCallback;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.account.sdk.AccountClientManager;
|
||||
import com.zhidao.account.sdk.BusinessType;
|
||||
import com.zhidao.account.sdk.Environment;
|
||||
import com.zhidao.account.sdk.callback.TicketInfoCallback;
|
||||
import com.zhidao.account.sdk.network.NetEnvironManager;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Keep
|
||||
class PassportManager implements IMogoPassportManager {
|
||||
|
||||
private static final String TAG = "PassportManager-apk";
|
||||
|
||||
private static volatile PassportManager sInstance;
|
||||
|
||||
private PassportManager() {
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static PassportManager getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( PassportManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new PassportManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTicket( final IMogoTicketCallback callback ) {
|
||||
getTicket( new TicketInfoCallback() {
|
||||
@Override
|
||||
public void onSuccess( String ticket ) {
|
||||
Logger.d( TAG, "success" );
|
||||
SpStorage.setTicket( ticket );
|
||||
if ( callback != null ) {
|
||||
callback.onTicketGot( ticket );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure( int code, String msg ) {
|
||||
Logger.d( TAG, "fail code= %s, msg=%s", code, msg );
|
||||
if ( callback != null ) {
|
||||
callback.onError( code, msg );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private static void getTicket( TicketInfoCallback callback ) {
|
||||
AccountClientManager.getTicket( callback );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
AccountClientManager.init( context.getApplicationContext(), getNetEnvironment(), BusinessType.toc_login, "os2.0-launcher" );
|
||||
}
|
||||
|
||||
private Environment getNetEnvironment() {
|
||||
int mode = DebugConfig.getNetMode();
|
||||
if ( mode == DebugConfig.NET_MODE_DEMO ) {
|
||||
// 演示环境用 qa 的
|
||||
mode = DebugConfig.NET_MODE_QA;
|
||||
}
|
||||
switch ( mode ) {
|
||||
case DebugConfig.NET_MODE_DEV:
|
||||
return Environment.dev;
|
||||
case DebugConfig.NET_MODE_DEMO:
|
||||
case DebugConfig.NET_MODE_QA:
|
||||
return Environment.qa;
|
||||
case DebugConfig.NET_MODE_RELEASE:
|
||||
default:
|
||||
return Environment.release;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
package com.mogo.base.services.socket;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.mogo.service.connection.IMogoMsgAckListener;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.connection.MsgBody;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
|
||||
import com.zhidao.socketsdk.manager.OnSocketAckCallback;
|
||||
import com.zhidao.socketsdk.manager.OnSocketReceiveCallback;
|
||||
import com.zhidao.socketsdk.manager.SocketConnManager;
|
||||
import com.zhidao.socketsdk.manager.SocketConnManagerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
* <p>
|
||||
* 长链实现:基于 netty
|
||||
*/
|
||||
@Keep
|
||||
public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallback, OnSocketAckCallback {
|
||||
|
||||
private static final String TAG = "SocketManager-apk";
|
||||
|
||||
public static final int MSG_PRODUCT_LINE = MogoCommon.Product.mogoBussiness_VALUE;
|
||||
private static final int MSG_HEADER_TYPE = MogoConnsvr.MsgType.mogoMsgTypeDispatchSvrNoRspReq_VALUE;
|
||||
|
||||
private static volatile SocketManager sInstance;
|
||||
|
||||
private SocketManager( Context context ) {
|
||||
mSocketConnManager = SocketConnManagerImpl.getInstance( context );
|
||||
mSocketConnManager.addSocketMessageCallback( this );
|
||||
mSocketConnManager.addSocketAckCallback( this );
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static SocketManager getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( SocketManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new SocketManager( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理消息分发
|
||||
* <p>
|
||||
* key - msgType
|
||||
*/
|
||||
private Map< Integer, List< IMogoOnMessageListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 管理消息回执
|
||||
* <p>
|
||||
* key - msgId
|
||||
*/
|
||||
private Map< Long, IMogoMsgAckListener > mAckListeners = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private SocketConnManager mSocketConnManager;
|
||||
public static final int MAX_CAP = 64; //保证充足的容量应对非常延时的推送
|
||||
private ArrayList< Long > mReceivedMsgId = new ArrayList<>( MAX_CAP );
|
||||
private int mCurrentIndex = 0;
|
||||
|
||||
@Override
|
||||
public void init( Context context, String appId ) {
|
||||
if ( mSocketConnManager != null ) {
|
||||
mSocketConnManager.init( appId );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived( byte[] content ) {
|
||||
onMessageReceived( content, 0);
|
||||
}
|
||||
|
||||
public void onMessageReceived( byte[] content, long msgId ) {
|
||||
try {
|
||||
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom( content );
|
||||
int msgType = payload.getMsgType();
|
||||
Logger.d( TAG, "received msg type = " + msgType );
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
Iterator< IMogoOnMessageListener > iterator = listeners.iterator();
|
||||
if ( msgId != 0 ) { //兼容老版本
|
||||
if ( mReceivedMsgId.contains( msgId ) ) { // 避免消息重发
|
||||
return;
|
||||
}
|
||||
cacheLastReceivedMsgId( msgId );
|
||||
}
|
||||
Object object = null;
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoOnMessageListener listener = iterator.next();
|
||||
if ( object == null ) {
|
||||
object = GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() );
|
||||
}
|
||||
if ( listener != null ) {
|
||||
Logger.d( TAG, "received msgId = %s, content = %s", msgId, payload.getPayload().toStringUtf8() );
|
||||
listener.onMsgReceived( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
Logger.e( TAG, e, "parse msg error." );
|
||||
}
|
||||
}
|
||||
|
||||
private void cacheLastReceivedMsgId( long msgId ) {
|
||||
if ( msgId == 0 ) {
|
||||
return;
|
||||
}
|
||||
synchronized ( this ){
|
||||
mReceivedMsgId.add( mCurrentIndex % MAX_CAP, msgId );
|
||||
mCurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck( byte[] headerBytes, byte[] payloadBytes ) {
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom( headerBytes );
|
||||
int msgType = header.getMsgType();
|
||||
String appId = header.getAppId();
|
||||
int productLine = header.getProductLine();
|
||||
long msgId = header.getMsgId();
|
||||
IMogoMsgAckListener listener = mAckListeners.remove( msgId );
|
||||
if ( listener != null ) {
|
||||
listener.onAck( msgId );
|
||||
}
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( mListeners.containsKey( msgType ) ) {
|
||||
Logger.w( TAG, "msgType %d is exist.", msgType );
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
mListeners.put( msgType, new ArrayList< IMogoOnMessageListener >() );
|
||||
}
|
||||
mListeners.get( msgType ).add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType ) {
|
||||
mListeners.remove( msgType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( listener == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
return;
|
||||
}
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && listeners.contains( listener ) ) {
|
||||
listeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg( MsgBody body, IMogoMsgAckListener listener ) {
|
||||
Logger.d( TAG, "sendMsg." );
|
||||
if ( mSocketConnManager != null ) {
|
||||
if ( mSocketConnManager.isConnected() ) {
|
||||
Logger.d( TAG, "isConnected." );
|
||||
final byte[] pb = convertToPBBytes( body.getMsgType(), objectToBytes( body.getContent() ) );
|
||||
mSocketConnManager.sendPayload(
|
||||
MSG_PRODUCT_LINE,
|
||||
pb,
|
||||
MSG_HEADER_TYPE,
|
||||
body.isAck(),
|
||||
body.getMsgId()
|
||||
);
|
||||
mAckListeners.put( body.getMsgId(), listener );
|
||||
} else {
|
||||
Logger.e( TAG, "sendMsg error, connect is lost." );
|
||||
}
|
||||
} else {
|
||||
Logger.e( TAG, "sendMsg error, client is null." );
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] objectToBytes( Object obj ) {
|
||||
String jsonStr = GsonUtil.jsonFromObject( obj );
|
||||
return jsonStr.getBytes();
|
||||
}
|
||||
|
||||
private byte[] convertToPBBytes( int msgType, byte[] payloadBytes ) {
|
||||
MogoConnsvr.Payload payloadData = MogoConnsvr.Payload.newBuilder()
|
||||
.setMsgType( msgType )
|
||||
.setPayload( ByteString.copyFrom( payloadBytes ) ).build();
|
||||
return payloadData.toByteArray();
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
mListeners.clear();
|
||||
mListeners = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
}
|
||||
}
|
||||
1
foudations/mogo-base-services-sdk/.gitignore
vendored
1
foudations/mogo-base-services-sdk/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,3 +0,0 @@
|
||||
## sdk实现功能
|
||||
|
||||
脱离基础服务apk实现对应功能:位置上报、长连接、passport
|
||||
@@ -1,53 +0,0 @@
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
// 上报位置
|
||||
implementation 'com.zhidao.locupload:loc-upload-sdk:1.1.7'
|
||||
// 长链
|
||||
implementation 'com.zhidao.socket:built-in-socket:1.0.17'
|
||||
// passport
|
||||
implementation 'com.zhidao.tcloginsdk:tclogin:1.1.3'
|
||||
|
||||
annotationProcessor 'com.elegant.spi:compiler:1.0.3'
|
||||
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogocommons
|
||||
implementation rootProject.ext.dependencies.mogoserviceapi
|
||||
} else {
|
||||
implementation project(":foudations:mogo-utils")
|
||||
implementation project(":foudations:mogo-commons")
|
||||
implementation project(":services:mogo-service-api")
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
@@ -1,2 +0,0 @@
|
||||
#-----MogoBaseServiceSdk-----
|
||||
-keep class com.mogo.base.services.locationinfo.MogoLocationSource.*{*;}
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.base
|
||||
POM_ARTIFACT_ID=services-sdk
|
||||
VERSION_CODE=1
|
||||
@@ -1,24 +0,0 @@
|
||||
# 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
|
||||
|
||||
#-----MogoBaseServiceSdk-----
|
||||
-keep class com.mogo.base.services.locationinfo.MogoLocationSource.*{*;}
|
||||
@@ -1,5 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.base.services">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.mogo.base.services;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
public abstract
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/7/23
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class BaseServicesConstants {
|
||||
|
||||
/**
|
||||
* 建立长链的通道ID
|
||||
*/
|
||||
@Keep
|
||||
public static final String SOCKET_CHANNEL_ID = "dataCrawler";
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.mogo.base.services.locationinfo;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.service.locationinfo.IMogoLocationInfoService;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.locupload.LocUploadConfig;
|
||||
import com.zhidao.locupload.LocUploadManager;
|
||||
|
||||
public
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 位置服务
|
||||
*/
|
||||
@Keep
|
||||
class MogoLocationInfoServices implements IMogoLocationInfoService {
|
||||
|
||||
private static final String TAG = "MogoLocationInfoServices-sdk";
|
||||
|
||||
private static volatile MogoLocationInfoServices sInstance;
|
||||
private MogoLocation mLocation;
|
||||
|
||||
private MogoLocationInfoServices() {
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static MogoLocationInfoServices getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MogoLocationInfoServices.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MogoLocationInfoServices();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideLocation( MogoLocation location ) {
|
||||
mLocation = location;
|
||||
Logger.d( TAG, "sdk - provideLocation" );
|
||||
}
|
||||
|
||||
public MogoLocation getLocation() {
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
LocUploadManager.getInstance().startUpload();
|
||||
Logger.d( TAG, "sdk - start" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
LocUploadManager.getInstance().stopUpload();
|
||||
Logger.d( TAG, "sdk - stop" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
LocUploadConfig.instance().
|
||||
setAppId( DebugConfig.getSocketAppId() ).
|
||||
setContext( context.getApplicationContext() ).
|
||||
setLoggable( DebugConfig.isDebug() ).
|
||||
setLocInterval( 2000L );
|
||||
Logger.d( TAG, "sdk - init" );
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.mogo.base.services.locationinfo;
|
||||
|
||||
import com.elegant.spi.annotations.Service;
|
||||
import com.zhidao.locupload.location.LocationServiceProvider;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Service( value = LocationServiceProvider.class )
|
||||
class MogoLocationSource extends LocationServiceProvider {
|
||||
|
||||
@Override
|
||||
public float getBearing() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getBearing();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAccuracy() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAccuracy();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProvider() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getProvider();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getSpeed();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAltitude() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAltitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAdCode() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAdCode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLocType() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLocType();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLatitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLongitude() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLongitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getTime();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCityCode() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getCityCode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCityName() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getCityName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGpsAccuracyStatus() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getGpsAccuracyStatus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSatellites() {
|
||||
if ( MogoLocationInfoServices.getInstance().getLocation() != null ) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getSatellite();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCarStatus() {
|
||||
// 常开状态
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.mogo.base.services.passport;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.service.passport.IMogoPassportManager;
|
||||
import com.mogo.service.passport.IMogoTicketCallback;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.accountsdk.manager.CarPadClientManagerImpl;
|
||||
import com.zhidao.accountsdk.manager.TicketInfoCallback;
|
||||
import com.zhidao.tcloginsdk.LoginManager;
|
||||
import com.zhidao.tcloginsdk.model.TokenData;
|
||||
import com.zhidao.tcloginsdk.network.LoginCallback;
|
||||
|
||||
public
|
||||
/*
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Keep
|
||||
class PassportManager implements IMogoPassportManager {
|
||||
|
||||
private static final String TAG = "PassportManager-sdk";
|
||||
private Context mContext;
|
||||
|
||||
private static volatile PassportManager sInstance;
|
||||
|
||||
private PassportManager() {
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static PassportManager getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( PassportManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new PassportManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTicket( final IMogoTicketCallback callback ) {
|
||||
LoginManager.getInstance( mContext ).login( DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE, DebugConfig.getProductFlavor(), new LoginCallback() {
|
||||
@Override
|
||||
public void onSuccess( TokenData.TokenResult result ) {
|
||||
if ( callback != null ) {
|
||||
callback.onLoginSuccess( result.token, result.sn );
|
||||
}
|
||||
getTicket( new TicketInfoCallback() {
|
||||
@Override
|
||||
public void onSuccess( String ticket ) {
|
||||
Logger.d( TAG, "success" );
|
||||
SpStorage.setTicket( ticket );
|
||||
if ( callback != null ) {
|
||||
callback.onTicketGot( ticket );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure( int code ) {
|
||||
Logger.d( TAG, "fail: code = %s", code );
|
||||
if ( callback != null ) {
|
||||
callback.onError( code, "getTicket error." );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure( int code, String msg ) {
|
||||
Logger.d( TAG, "onFailure: code = %s, msg = %s", code, msg );
|
||||
if ( callback != null ) {
|
||||
callback.onError( code, "login: " + msg );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
private void getTicket( TicketInfoCallback callback ) {
|
||||
CarPadClientManagerImpl.getInstance( mContext ).getTicket( "os2.0-launcher", new TicketInfoCallback() {
|
||||
@Override
|
||||
public void onSuccess( String ticket ) {
|
||||
if ( callback != null ) {
|
||||
callback.onSuccess( ticket );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure( int code ) {
|
||||
if ( callback != null ) {
|
||||
callback.onFailure( code );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
mContext = context;
|
||||
int mode = DebugConfig.getNetMode();
|
||||
if ( mode == DebugConfig.NET_MODE_DEMO ) {
|
||||
// 演示环境用 qa 的
|
||||
mode = DebugConfig.NET_MODE_QA;
|
||||
}
|
||||
LoginManager.getInstance( context ).setNetEnviron( mode );
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
package com.mogo.base.services.socket;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.mogo.base.services.BaseServicesConstants;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.network.Utils;
|
||||
import com.mogo.service.connection.IMogoMsgAckListener;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.connection.MsgBody;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.locupload.Platform;
|
||||
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
|
||||
import com.zhidao.socket.Callback;
|
||||
import com.zhidao.socket.CallbackManager;
|
||||
import com.zhidao.socket.Environment;
|
||||
import com.zhidao.socket.SocketClient;
|
||||
import com.zhidao.socket.SocketConfig;
|
||||
import com.zhidao.socket.utils.RequestUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/7/16
|
||||
*
|
||||
* 长链
|
||||
*/
|
||||
@Keep
|
||||
class SocketManager implements IMogoSocketManager, Callback {
|
||||
|
||||
private static final String TAG = "SocketManager-sdk";
|
||||
|
||||
private static volatile SocketManager sInstance;
|
||||
private String mAppId;
|
||||
|
||||
public SocketManager( Context context ) {
|
||||
CallbackManager.getInstance().register( this );
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static SocketManager getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( SocketManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new SocketManager( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理消息分发
|
||||
* <p>
|
||||
* key - msgType
|
||||
*/
|
||||
private Map< Integer, List< IMogoOnMessageListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 管理消息回执
|
||||
* <p>
|
||||
* key - msgId
|
||||
*/
|
||||
private Map< Long, IMogoMsgAckListener > mAckListeners = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static final int MAX_CAP = 64; //保证充足的容量应对非常延时的推送
|
||||
private ArrayList< Long > mReceivedMsgId = new ArrayList<>( MAX_CAP );
|
||||
private int mCurrentIndex = 0;
|
||||
|
||||
@Override
|
||||
public void init( Context context, String appId ) {
|
||||
mAppId = appId;
|
||||
SocketConfig.instance()
|
||||
.setAppContext( context.getApplicationContext() )
|
||||
.setEnvironment( getEnvironment() )
|
||||
.setClient( Platform.getClient( Platform.car ) )
|
||||
.setChannelId( BaseServicesConstants.SOCKET_CHANNEL_ID )
|
||||
.setOpenAnalytics( true )
|
||||
.setSn( MoGoAiCloudClientConfig.getInstance().getSn() )
|
||||
.setDebug( DebugConfig.isDebug() );
|
||||
SocketClient.getInstance().start( context );
|
||||
}
|
||||
|
||||
private Environment getEnvironment() {
|
||||
switch ( DebugConfig.getNetMode() ) {
|
||||
case 1:
|
||||
return Environment.dev;
|
||||
case 2:
|
||||
case 4:
|
||||
return Environment.qa;
|
||||
case 3:
|
||||
default:
|
||||
return Environment.release;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( @NonNull CallbackManager manager, @NonNull byte[] content, String appId, long msgId ) {
|
||||
try {
|
||||
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom( content );
|
||||
int msgType = payload.getMsgType();
|
||||
Logger.d( TAG, "received msg type = %d", msgType );
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
Iterator< IMogoOnMessageListener > iterator = listeners.iterator();
|
||||
if ( msgId != 0 ) { //兼容老版本
|
||||
if ( mReceivedMsgId.contains( msgId ) ) { // 避免消息重发
|
||||
return;
|
||||
}
|
||||
cacheLastReceivedMsgId( msgId );
|
||||
}
|
||||
Object object = null;
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoOnMessageListener listener = iterator.next();
|
||||
if ( object == null ) {
|
||||
object = GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() );
|
||||
}
|
||||
if ( listener != null ) {
|
||||
Logger.d( TAG, "received msgId = %s, content = %s", msgId, payload.getPayload().toStringUtf8() );
|
||||
listener.onMsgReceived( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
Logger.e( TAG, e, "parse msg error." );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck( @NonNull CallbackManager manager, @NonNull byte[] headerBytes, byte[] content ) {
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom( headerBytes );
|
||||
int msgType = header.getMsgType();
|
||||
String appId = header.getAppId();
|
||||
int productLine = header.getProductLine();
|
||||
long msgId = header.getMsgId();
|
||||
IMogoMsgAckListener listener = mAckListeners.remove( msgId );
|
||||
if ( listener != null ) {
|
||||
listener.onAck( msgId );
|
||||
}
|
||||
Logger.d( TAG, "send message success: msgType = %d, appId = %s, productLine = %d", msgType, appId, productLine );
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void cacheLastReceivedMsgId( long msgId ) {
|
||||
if ( msgId == 0 ) {
|
||||
return;
|
||||
}
|
||||
synchronized ( this ) {
|
||||
mReceivedMsgId.add( mCurrentIndex % MAX_CAP, msgId );
|
||||
mCurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( mListeners.containsKey( msgType ) ) {
|
||||
Logger.w( TAG, "msgType %d is exist.", msgType );
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
mListeners.put( msgType, new ArrayList<>() );
|
||||
}
|
||||
mListeners.get( msgType ).add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType ) {
|
||||
mListeners.remove( msgType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( listener == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
return;
|
||||
}
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && listeners.contains( listener ) ) {
|
||||
listeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg( MsgBody body, IMogoMsgAckListener listener ) {
|
||||
Logger.d( TAG, "sendMsg." );
|
||||
final byte[] pb = convertToPBBytes( body.getMsgType(), objectToBytes( body.getContent() ) );
|
||||
RequestUtil.sendPayloadData( mAppId, 2, pb, 1, true, System.currentTimeMillis() );
|
||||
}
|
||||
|
||||
public byte[] objectToBytes( Object obj ) {
|
||||
String jsonStr = GsonUtil.jsonFromObject( obj );
|
||||
return jsonStr.getBytes();
|
||||
}
|
||||
|
||||
private byte[] convertToPBBytes( int msgType, byte[] payloadBytes ) {
|
||||
MogoConnsvr.Payload payloadData = MogoConnsvr.Payload.newBuilder()
|
||||
.setMsgType( msgType )
|
||||
.setPayload( ByteString.copyFrom( payloadBytes ) ).build();
|
||||
return payloadData.toByteArray();
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
mListeners.clear();
|
||||
mListeners = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user