add socket apk version
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -13,7 +13,7 @@
|
||||
<option name="HEAP_SIZE" value="1024" />
|
||||
<option name="LOCALE" value="zh_CN" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="12" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="12" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="请输入要查看的车机SN"
|
||||
android:text="F803BB2037EZD00071"
|
||||
android:text="F803EB2046PZD00149"
|
||||
android:textColor="#FFFF"
|
||||
app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
@@ -87,6 +87,11 @@ public class MoGoAiCloudClientConfig {
|
||||
*/
|
||||
private boolean mIsAccuracyDevice;
|
||||
|
||||
/**
|
||||
* 应用长连接id
|
||||
*/
|
||||
private String mSocketAppId;
|
||||
|
||||
/**
|
||||
* 设置HttpDns的位置监听
|
||||
*/
|
||||
@@ -327,6 +332,24 @@ public class MoGoAiCloudClientConfig {
|
||||
mIsAccuracyDevice = isAccuracyDevice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用长连接id
|
||||
*
|
||||
* @return String 长连接id
|
||||
*/
|
||||
public String getSocketAppId() {
|
||||
return mSocketAppId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置应用长连接id,三方应用无需设置
|
||||
*
|
||||
* @param socketAppId 设置应用长连接id
|
||||
*/
|
||||
public void setIsAccuracyDevice(String socketAppId) {
|
||||
mSocketAppId = socketAppId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回HttpDns的位置信息,必须设置,否则将无法使用网络请求
|
||||
*
|
||||
@@ -359,6 +382,8 @@ public class MoGoAiCloudClientConfig {
|
||||
", sn='" + sn + '\'' +
|
||||
", mLoopCheckDelay=" + mLoopCheckDelay +
|
||||
", mIsUseExternalLocation=" + mIsUseExternalLocation +
|
||||
", mIsAccuracyDevice=" + mIsAccuracyDevice +
|
||||
", mSocketAppId='" + mSocketAppId + '\'' +
|
||||
", mIHttpDnsCurrentLocation=" + mIHttpDnsCurrentLocation +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -26,11 +26,15 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
// 长链 http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48956182
|
||||
// 长链 http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48956182 外部SDK版本
|
||||
api 'com.zhidao.socket:built-in-socket:1.0.22'
|
||||
// 上报位置 http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48956200
|
||||
implementation 'com.zhidao.locupload:loc-upload-sdk:1.1.9'
|
||||
|
||||
// 长链 内部SDK版本
|
||||
implementation 'com.zhidao.socketsdk:socketsdk:2.1.4'
|
||||
implementation 'com.google.protobuf:protobuf-java:3.5.1'
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation "com.mogo.cloud:passport:${MOGO_PASSPORT_VERSION}"
|
||||
} else {
|
||||
|
||||
@@ -9,15 +9,10 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.mogo.cloud.GsonUtil;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.internal.InternalSocketManager;
|
||||
import com.mogo.cloud.socket.third.ThirdSocketManager;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
import com.zhidao.locupload.Platform;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -25,23 +20,18 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEV;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_QA;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE;
|
||||
import static com.mogo.cloud.socket.SocketServicesConstants.TAG;
|
||||
|
||||
|
||||
/**
|
||||
* Socket 长链核心服务
|
||||
*/
|
||||
public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
public class SocketManager implements IMogoCloudSocketManager {
|
||||
|
||||
private static volatile SocketManager mInstance;
|
||||
private MoGoAiCloudClientConfig cloudClientConfig;
|
||||
|
||||
private SocketManager() {
|
||||
CallbackManager.getInstance().register(this);
|
||||
cloudClientConfig = MoGoAiCloudClient.getInstance().getAiCloudClientConfig();
|
||||
}
|
||||
|
||||
@@ -77,21 +67,18 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
SocketConfig.instance()
|
||||
.setAppContext(context.getApplicationContext())
|
||||
.setEnvironment(getEnvironment())
|
||||
.setClient(Platform.getClient(Platform.car))
|
||||
.setChannelId(SocketServicesConstants.SOCKET_CHANNEL_ID)
|
||||
.setOpenAnalytics(true)
|
||||
.setSn(cloudClientConfig.getThirdPartyDeviceId())
|
||||
.setToken(cloudClientConfig.getToken())
|
||||
.setAuthPubKey(cloudClientConfig.getAuthPubKey())
|
||||
.setDebug(cloudClientConfig.isShowDebugLog());
|
||||
SocketClient.getInstance().start(context);
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().init(context);
|
||||
} else {
|
||||
InternalSocketManager.getInstance().init(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOnMessageListener(int msgType, IMogoCloudSocketOnMessageListener listener) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
if (mListeners.containsKey(msgType)) {
|
||||
Logger.w(TAG, "msgType %d is exist.", msgType);
|
||||
return;
|
||||
@@ -120,12 +107,15 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
public void sendMsg(String appId, int headerType, MsgBody body, IMogoCloudSocketMsgAckListener listener) {
|
||||
Logger.d(TAG, "sendMsg msgId : " + body.getMsgId());
|
||||
final byte[] pb = convertToPBBytes(body.getMsgType(), body.getContent());
|
||||
SocketClient.getInstance().sendData(appId, MogoCommon.Product.mogoBussiness.getNumber(), pb, headerType, true, body.getMsgId());
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().sendMsg(appId, pb, headerType, true, body.getMsgId());
|
||||
} else {
|
||||
InternalSocketManager.getInstance().sendMsg(pb, headerType, true, body.getMsgId());
|
||||
}
|
||||
mAckListeners.put(body.getMsgId(), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NonNull CallbackManager manager, @NonNull byte[] message, String appId, long msgId) {
|
||||
public void update(@NonNull byte[] message, long msgId) {
|
||||
try {
|
||||
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom(message);
|
||||
int msgType = payload.getMsgType();
|
||||
@@ -166,8 +156,7 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(@NonNull CallbackManager manager, @NonNull byte[] headerBytes, byte[] content) {
|
||||
public void onAck(@NonNull byte[] headerBytes) {
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom(headerBytes);
|
||||
int msgType = header.getMsgType();
|
||||
@@ -184,24 +173,6 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private Environment getEnvironment() {
|
||||
switch (cloudClientConfig.getNetMode()) {
|
||||
case HTTP_DNS_ENV_DEV:
|
||||
return Environment.dev;
|
||||
case HTTP_DNS_ENV_QA:
|
||||
case HTTP_DNS_ENV_DEMO:
|
||||
return Environment.qa;
|
||||
case HTTP_DNS_ENV_RELEASE:
|
||||
default:
|
||||
return Environment.release;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -211,6 +182,11 @@ public class SocketManager implements IMogoCloudSocketManager, Callback {
|
||||
|
||||
public synchronized void release() {
|
||||
mListeners.clear();
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().release();
|
||||
} else {
|
||||
InternalSocketManager.getInstance().release();
|
||||
}
|
||||
cloudClientConfig = null;
|
||||
mInstance = null;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,15 @@ package com.mogo.cloud.socket;
|
||||
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.zhidao.socket.Environment;
|
||||
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_DEV;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_QA;
|
||||
import static com.mogo.cloud.httpdns.MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE;
|
||||
|
||||
public class SocketServicesConstants {
|
||||
|
||||
public static final String TAG = "MoGoAiCloud_Socket";
|
||||
@@ -12,4 +21,18 @@ public class SocketServicesConstants {
|
||||
*/
|
||||
@Keep
|
||||
public static final String SOCKET_CHANNEL_ID = "dataCrawler";
|
||||
|
||||
public static Environment getEnvironment() {
|
||||
MoGoAiCloudClientConfig cloudClientConfig = MoGoAiCloudClient.getInstance().getAiCloudClientConfig();
|
||||
switch (cloudClientConfig.getNetMode()) {
|
||||
case HTTP_DNS_ENV_DEV:
|
||||
return com.zhidao.socket.Environment.dev;
|
||||
case HTTP_DNS_ENV_QA:
|
||||
case HTTP_DNS_ENV_DEMO:
|
||||
return com.zhidao.socket.Environment.qa;
|
||||
case HTTP_DNS_ENV_RELEASE:
|
||||
default:
|
||||
return com.zhidao.socket.Environment.release;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.mogo.cloud.socket.internal;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
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 static com.mogo.cloud.socket.SocketServicesConstants.TAG;
|
||||
|
||||
public class InternalSocketManager implements OnSocketReceiveCallback, OnSocketAckCallback {
|
||||
|
||||
private static volatile InternalSocketManager mInstance;
|
||||
private static final int MSG_PRODUCT_LINE = MogoCommon.Product.mogoBussiness_VALUE;
|
||||
|
||||
private final MoGoAiCloudClientConfig cloudClientConfig;
|
||||
private SocketConnManager mSocketConnManager;
|
||||
|
||||
private InternalSocketManager() {
|
||||
cloudClientConfig = MoGoAiCloudClient.getInstance().getAiCloudClientConfig();
|
||||
}
|
||||
|
||||
public static InternalSocketManager getInstance() {
|
||||
if (mInstance == null) {
|
||||
synchronized (InternalSocketManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new InternalSocketManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
mSocketConnManager = SocketConnManagerImpl.getInstance(context);
|
||||
mSocketConnManager.addSocketMessageCallback(this);
|
||||
mSocketConnManager.addSocketAckCallback(this);
|
||||
if (TextUtils.isEmpty(cloudClientConfig.getSocketAppId())) {
|
||||
Logger.e(TAG, "需要初始化 Socket AppId");
|
||||
return;
|
||||
}
|
||||
mSocketConnManager.init(cloudClientConfig.getSocketAppId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(byte[] headerBytes, byte[] payload) {
|
||||
Logger.d(TAG, "InternalSocketManager update ack");
|
||||
SocketManager.getInstance().onAck(headerBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(byte[] message) {
|
||||
Logger.d(TAG, "InternalSocketManager update message");
|
||||
SocketManager.getInstance().update(message, 0);
|
||||
}
|
||||
|
||||
public void sendMsg(byte[] pb, int headerType, boolean isAck, long msgId) {
|
||||
if (mSocketConnManager.isConnected()) {
|
||||
Logger.d(TAG, "isConnected.");
|
||||
mSocketConnManager.sendPayload(MSG_PRODUCT_LINE, pb, headerType, isAck, msgId);
|
||||
} else {
|
||||
Logger.e(TAG, "sendMsg error, connect is lost.");
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mSocketConnManager.onRelease();
|
||||
mSocketConnManager = null;
|
||||
mInstance = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.mogo.cloud.socket.third;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.mogo.cloud.socket.SocketServicesConstants;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
import com.zhidao.locupload.Platform;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
import com.zhidao.socket.Callback;
|
||||
import com.zhidao.socket.CallbackManager;
|
||||
import com.zhidao.socket.SocketClient;
|
||||
import com.zhidao.socket.SocketConfig;
|
||||
|
||||
import static com.mogo.cloud.socket.SocketServicesConstants.TAG;
|
||||
import static com.mogo.cloud.socket.SocketServicesConstants.getEnvironment;
|
||||
|
||||
public class ThirdSocketManager implements Callback {
|
||||
|
||||
private static volatile ThirdSocketManager mInstance;
|
||||
private final MoGoAiCloudClientConfig cloudClientConfig;
|
||||
|
||||
private ThirdSocketManager() {
|
||||
CallbackManager.getInstance().register(this);
|
||||
cloudClientConfig = MoGoAiCloudClient.getInstance().getAiCloudClientConfig();
|
||||
}
|
||||
|
||||
public static ThirdSocketManager getInstance() {
|
||||
if (mInstance == null) {
|
||||
synchronized (ThirdSocketManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new ThirdSocketManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
SocketConfig.instance()
|
||||
.setAppContext(context.getApplicationContext())
|
||||
.setEnvironment(getEnvironment())
|
||||
.setClient(Platform.getClient(Platform.car))
|
||||
.setChannelId(SocketServicesConstants.SOCKET_CHANNEL_ID)
|
||||
.setOpenAnalytics(true)
|
||||
.setSn(cloudClientConfig.getThirdPartyDeviceId())
|
||||
.setToken(cloudClientConfig.getToken())
|
||||
.setAuthPubKey(cloudClientConfig.getAuthPubKey())
|
||||
.setDebug(cloudClientConfig.isShowDebugLog());
|
||||
SocketClient.getInstance().start(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NonNull CallbackManager manager, @NonNull byte[] message, String appId, long msgId) {
|
||||
Logger.d(TAG,"ThirdSocketManager update message");
|
||||
SocketManager.getInstance().update(message, msgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(@NonNull CallbackManager manager, @NonNull byte[] header, byte[] content) {
|
||||
Logger.d(TAG,"ThirdSocketManager update ack");
|
||||
SocketManager.getInstance().onAck(header);
|
||||
}
|
||||
|
||||
public void sendMsg(String appId,
|
||||
byte[] payload,
|
||||
int headerType,
|
||||
boolean ack,
|
||||
long msgId) {
|
||||
SocketClient.getInstance().sendData(appId, MogoCommon.Product.mogoBussiness.getNumber(), payload, headerType, ack, msgId);
|
||||
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
SocketClient.getInstance().stop();
|
||||
mInstance = null;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
|
||||
USERNAME=xintai
|
||||
PASSWORD=xintai2018
|
||||
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
|
||||
RELEASE=true
|
||||
RELEASE=false
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.0.41
|
||||
|
||||
Reference in New Issue
Block a user