[Change] 增加了对定位上报及Socket的日志输出控制
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.mogo.cloud.location;
|
||||
|
||||
/**
|
||||
* 位置服务配置
|
||||
*/
|
||||
public class LocationConfig {
|
||||
// 是否打印 Log信息
|
||||
public static boolean isPrintLog = true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.mogo.cloud.location.third;
|
||||
import android.content.Context;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.location.LocationConfig;
|
||||
import com.mogo.cloud.location.third.core.LocUploadConfig;
|
||||
import com.mogo.cloud.location.third.core.LocUploadManager;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
@@ -34,16 +35,22 @@ public class ThirdLocationManager {
|
||||
setAppId(cloudClientConfig.getServiceAppId()).
|
||||
setContext(context.getApplicationContext()).
|
||||
setLocInterval(1000L);
|
||||
Logger.d(TAG, "location sdk - init");
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "location sdk - init");
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
LocUploadManager.getInstance().startUpload();
|
||||
Logger.d( TAG, "sdk - start" );
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "sdk - start");
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
LocUploadManager.getInstance().stopUpload();
|
||||
Logger.d( TAG, "sdk - stop" );
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "sdk - stop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.cloud.location.third.core;
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.elegant.spi.AbstractDelegateManager;
|
||||
import com.elegant.spi.core.visitor.ServiceClassValue;
|
||||
import com.mogo.cloud.location.LocationConfig;
|
||||
|
||||
public class LocationDelegateManager extends AbstractDelegateManager<LocationServiceProvider>
|
||||
implements AbstractDelegateManager.DelegateListener<Class<? extends LocationServiceProvider>> {
|
||||
@@ -35,8 +36,10 @@ public class LocationDelegateManager extends AbstractDelegateManager<LocationSer
|
||||
public void unloadDelegates() {
|
||||
if (loaded) {
|
||||
if(locationServiceProvider != null){
|
||||
Logger.d(TAG, String.format("注销 LocationServiceProvider -> %s",
|
||||
locationServiceProvider.getClass().getName()));
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, String.format("注销 LocationServiceProvider -> %s",
|
||||
locationServiceProvider.getClass().getName()));
|
||||
}
|
||||
locationServiceProvider = null;
|
||||
}
|
||||
loaded = false;
|
||||
@@ -48,8 +51,10 @@ public class LocationDelegateManager extends AbstractDelegateManager<LocationSer
|
||||
try {
|
||||
locationServiceProvider = ServiceClassValue.of(p, unit)
|
||||
.accept(SERVICE_CLASS_VISITOR, unit);
|
||||
Logger.d(TAG, String.format("Biz id is [%s], 注册 LocationServiceProvider -> %s ",
|
||||
unit, p.getName()));
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, String.format("Biz id is [%s], 注册 LocationServiceProvider -> %s ",
|
||||
unit, p.getName()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@ import com.elegant.log.simplelog.Logger;
|
||||
import com.elegant.utils.ThreadPoolService;
|
||||
import com.elegant.utils.UiThreadHandler;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.mogo.cloud.location.LocationConfig;
|
||||
import com.mogo.cloud.location.third.core.LocUploadConfig;
|
||||
import com.mogo.cloud.location.third.core.Location;
|
||||
import com.mogo.cloud.location.third.core.LocationDelegateManager;
|
||||
import com.mogo.cloud.location.third.core.LocationServiceProvider;
|
||||
import com.mogo.cloud.location.third.core.LocUploadConfig;
|
||||
import com.mogo.cloud.socket.third.core.Callback;
|
||||
import com.mogo.cloud.socket.third.core.CallbackManager;
|
||||
import com.mogo.cloud.socket.third.core.SocketClient;
|
||||
@@ -34,17 +35,21 @@ public class UploadDataService extends Service {
|
||||
private final Callback callback = new Callback() {
|
||||
@Override
|
||||
public void update(@NonNull CallbackManager manager, @NonNull byte[] message, String appId, long msgId) {
|
||||
Logger.d(TAG, " socket收到的消息 " + new String(message)
|
||||
+ ", app id is " + appId
|
||||
+ ", msg id is " + msgId);
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, " socket收到的消息 " + new String(message)
|
||||
+ ", app id is " + appId
|
||||
+ ", msg id is " + msgId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(@NonNull CallbackManager manager, @NonNull byte[] headerBytes, byte[] content) {
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom(headerBytes);
|
||||
if(header != null){
|
||||
Logger.d(TAG, "socket 收到的 onAck " + header.toString());
|
||||
if (header != null) {
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "socket 收到的 onAck " + header.toString());
|
||||
}
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
@@ -64,7 +69,7 @@ public class UploadDataService extends Service {
|
||||
@Override
|
||||
public void run() {
|
||||
final LocationServiceProvider provider = LocationDelegateManager.getInstance().getLocationServiceProvider();
|
||||
if(provider != null){
|
||||
if (provider != null) {
|
||||
final Location location = new Location();
|
||||
location.setAccuracy(provider.getAccuracy());
|
||||
location.setAdCode(provider.getAdCode());
|
||||
@@ -83,7 +88,7 @@ public class UploadDataService extends Service {
|
||||
location.setTime(provider.getTime());
|
||||
buildCoordinates(location);
|
||||
}
|
||||
UiThreadHandler.postDelayed(this,LocUploadConfig.instance().getLocInterval());
|
||||
UiThreadHandler.postDelayed(this, LocUploadConfig.instance().getLocInterval());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,20 +125,26 @@ public class UploadDataService extends Service {
|
||||
private void buildCoordinates(Location location) {
|
||||
MogoPayload.Coordinate coordinate = SocketRequestUtil.buildBCoordinate(location);
|
||||
if (coordinate.getLat() != 0 && coordinate.getLon() != 0) {
|
||||
Logger.d(TAG, "socket-location is " + location.toString());
|
||||
Logger.d(TAG, "socket-coordinates.size()" + coordinates.size());
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "socket-location is " + location.toString());
|
||||
Logger.d(TAG, "socket-coordinates.size()" + coordinates.size());
|
||||
}
|
||||
coordinates.offer(coordinate);
|
||||
} else {
|
||||
Logger.d(TAG, "coordinates size is 0, give up uploading for Socket");
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "coordinates size is 0, give up uploading for Socket");
|
||||
}
|
||||
}
|
||||
|
||||
while (coordinates.size() > MAX_LOCATION_CACHE_SIZE) {
|
||||
Logger.d(TAG, "socket-coordinates number is " + coordinates.size());
|
||||
if (LocationConfig.isPrintLog) {
|
||||
Logger.d(TAG, "socket-coordinates number is " + coordinates.size());
|
||||
}
|
||||
coordinates.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private void clearLocationCache(){
|
||||
private void clearLocationCache() {
|
||||
coordinates.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mogo.cloud.socket;
|
||||
|
||||
/**
|
||||
* 长链接配置
|
||||
*/
|
||||
public class SocketBuildConfig {
|
||||
// 是否打印 Log信息
|
||||
public static boolean isPrintLog = true;
|
||||
}
|
||||
@@ -84,7 +84,9 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
return;
|
||||
}
|
||||
if (mListeners.containsKey(msgType)) {
|
||||
Logger.w(getTag(), "msgType %d is exist.", msgType);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.w(getTag(), "msgType %d is exist.", msgType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!mListeners.containsKey(msgType)) {
|
||||
@@ -123,7 +125,10 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
|
||||
@Override
|
||||
public void sendMsg(String appId, int headerType, MsgBody body, IMogoCloudSocketMsgAckListener listener) {
|
||||
Logger.d(getTag(), "sendMsg msgId : " + body.getMsgId());
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "sendMsg msgId : " + body.getMsgId());
|
||||
}
|
||||
|
||||
final byte[] pb = convertToPBBytes(body.getMsgType(), body.getContent());
|
||||
if (cloudClientConfig.isThirdLogin()) {
|
||||
ThirdSocketManager.getInstance().sendMsg(appId, pb, headerType, true, body.getMsgId());
|
||||
@@ -137,7 +142,10 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
try {
|
||||
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom(message);
|
||||
int msgType = payload.getMsgType();
|
||||
Logger.d(getTag(), "received msg type = %d", msgType);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "received msg type = %d", msgType);
|
||||
}
|
||||
|
||||
List<IMogoCloudSocketOnMessageListener> listeners = mListeners.get(msgType);
|
||||
if (listeners != null && !listeners.isEmpty()) {
|
||||
Iterator<IMogoCloudSocketOnMessageListener> iterator = listeners.iterator();
|
||||
@@ -159,12 +167,15 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
}
|
||||
}
|
||||
if (listener != null) {
|
||||
Logger.d(getTag(), "received msgId = %s, content = %s", msgId, payload.getPayload().toStringUtf8());
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "received msgId = %s, content = %s", msgId, payload.getPayload().toStringUtf8());
|
||||
}
|
||||
listener.onMsgReceived(msgType, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(getTag(), e, "parse msg error.");
|
||||
}
|
||||
}
|
||||
@@ -190,7 +201,9 @@ public class SocketManager implements IMogoCloudSocketManager {
|
||||
if (listener != null) {
|
||||
listener.onAck(msgId);
|
||||
}
|
||||
Logger.d(getTag(), "send message success: msgId = %d msgType = %d, appId = %s, productLine = %d", msgId, msgType, appId, productLine);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "send message success: msgId = %d msgType = %d, appId = %s, productLine = %d", msgId, msgType, appId, productLine);
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.text.TextUtils;
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
import com.zhidao.socketsdk.manager.OnSocketAckCallback;
|
||||
@@ -45,7 +46,10 @@ public class InternalSocketManager implements OnSocketReceiveCallback, OnSocketA
|
||||
mSocketConnManager.addSocketAckCallback(this);
|
||||
String appId = cloudClientConfig.getServiceAppId();
|
||||
if (TextUtils.isEmpty(appId)) {
|
||||
Logger.e(TAG, "需要初始化 Socket AppId");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.e(TAG, "需要初始化 Socket AppId");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
mSocketConnManager.init(appId);
|
||||
@@ -53,19 +57,27 @@ public class InternalSocketManager implements OnSocketReceiveCallback, OnSocketA
|
||||
|
||||
@Override
|
||||
public void onAck(byte[] headerBytes, byte[] payload) {
|
||||
Logger.d(TAG, "InternalSocketManager update ack");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG, "InternalSocketManager update ack");
|
||||
}
|
||||
SocketManager.getInstance().onAck(headerBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(byte[] message) {
|
||||
Logger.d(TAG, "InternalSocketManager update message");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
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.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG, "isConnected.");
|
||||
}
|
||||
|
||||
mSocketConnManager.sendPayload(MSG_PRODUCT_LINE, pb, headerType, isAck, msgId);
|
||||
} else {
|
||||
Logger.e(TAG, "sendMsg error, connect is lost.");
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.SocketManager;
|
||||
import com.mogo.cloud.socket.SocketServicesConstants;
|
||||
import com.mogo.cloud.socket.third.core.Callback;
|
||||
@@ -59,13 +60,18 @@ public class ThirdSocketManager implements Callback {
|
||||
|
||||
@Override
|
||||
public void update(@NonNull CallbackManager manager, @NonNull byte[] message, String appId, long msgId) {
|
||||
Logger.d(getTag(), "ThirdSocketManager update message");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "ThirdSocketManager update message");
|
||||
}
|
||||
SocketManager.getInstance().update(message, msgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck(@NonNull CallbackManager manager, @NonNull byte[] header, byte[] content) {
|
||||
Logger.d(getTag(), "ThirdSocketManager update ack");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "ThirdSocketManager update ack");
|
||||
}
|
||||
|
||||
SocketManager.getInstance().onAck(header);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.text.TextUtils;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.elegant.utils.CheckUtils;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.core.SocketConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -24,7 +25,9 @@ public class EventRequest {
|
||||
*/
|
||||
public static void trackSocketStatus(String status, String desc) {
|
||||
if(!SocketConfig.instance().isAnalyticsOpen()){
|
||||
Logger.d(TAG,"analytics is closed");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG,"analytics is closed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
EventManager.trackEvent(SOCKET_STATUS, buildAuthStatus(status, desc));
|
||||
@@ -37,7 +40,9 @@ public class EventRequest {
|
||||
*/
|
||||
public static void trackException(String reason) {
|
||||
if(!SocketConfig.instance().isAnalyticsOpen()){
|
||||
Logger.d(TAG,"analytics is closed");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG,"analytics is closed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(reason)) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.collection.ArraySet;
|
||||
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -24,7 +25,9 @@ public final class CallbackManager {
|
||||
|
||||
public synchronized void register(Callback callback) {
|
||||
if (callback == null) {
|
||||
Logger.i(SocketConstants.TAG, "Can not register a callback that is null.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Can not register a callback that is null.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
observers.add(callback);
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.collection.ArraySet;
|
||||
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -24,7 +25,9 @@ public class ConnCallbackManager {
|
||||
|
||||
public synchronized void register(ConnectionLifecycleListener callback) {
|
||||
if (callback == null) {
|
||||
Logger.i(SocketConstants.TAG, "Can not register a callback that is null.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Can not register a callback that is null.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
observers.add(callback);
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.text.TextUtils;
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.elegant.network.NetConfig;
|
||||
import com.elegant.utils.UiThreadHandler;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.core.client.ClientSocketManager;
|
||||
import com.mogo.cloud.socket.third.core.network.RequestManager;
|
||||
import com.mogo.cloud.socket.third.core.network.model.SocketAddressData;
|
||||
@@ -139,7 +140,9 @@ public class SocketClient {
|
||||
public void onGetSocketAddressSuccess(SocketAddressData addressData) {
|
||||
if (addressData.result != null && checkHost(addressData.result.ip) && checkPort(addressData.result.port)) {
|
||||
internalStart(addressData.result.ip, addressData.result.port);
|
||||
Logger.d(getTag(), "network--->ip:" + addressData.result.ip + " & port: " + addressData.result.port);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "network--->ip:" + addressData.result.ip + " & port: " + addressData.result.port);
|
||||
}
|
||||
} else {
|
||||
retryGetAddress(1000L); //todo 时间调整为1秒,后续在重连时增加网络状态验证,以及增加链路日志
|
||||
}
|
||||
@@ -147,19 +150,25 @@ public class SocketClient {
|
||||
|
||||
@Override
|
||||
public void onGetSocketAddressFailed(int code, String msg) {
|
||||
Logger.d(getTag(), "onFailed-->" + code + ":" + msg);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "onFailed-->" + code + ":" + msg);
|
||||
}
|
||||
retryGetAddress(1000L); //todo 时间调整为1秒,后续在重连时增加网络状态验证,以及增加链路日志
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final Runnable mRequestSocketAddressTask = () -> {
|
||||
Logger.d(getTag(), "get socket address");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "get socket address");
|
||||
}
|
||||
requestSocketAddress();
|
||||
};
|
||||
|
||||
private void internalStart(String host, int port) {
|
||||
Logger.d(getTag(), "internalStart-->host: " + host + " & port: " + port);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "internalStart-->host: " + host + " & port: " + port);
|
||||
}
|
||||
ClientSocketManager.getInstance().setConnectionLifecycleListener(connectionLifecycleListener);
|
||||
ClientSocketManager.getInstance().start(host, port);
|
||||
}
|
||||
@@ -168,10 +177,14 @@ public class SocketClient {
|
||||
@Override
|
||||
public void onConnectLost(boolean reconnect) {
|
||||
super.onConnectLost(reconnect);
|
||||
Logger.d(getTag(), "---onConnectLost");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "---onConnectLost");
|
||||
}
|
||||
ConnCallbackManager.getInstance().onConnectLost(reconnect);
|
||||
if (reconnect) {
|
||||
Logger.d(getTag(), "---onConnectLost reconnect");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "---onConnectLost reconnect");
|
||||
}
|
||||
retryGetAddress(1000L);//1-7s //todo 时间调整为1秒,后续在重连时增加网络状态验证,以及增加链路日志
|
||||
}
|
||||
}
|
||||
@@ -179,7 +192,9 @@ public class SocketClient {
|
||||
@Override
|
||||
public void onConnectFailure() {
|
||||
super.onConnectFailure();
|
||||
Logger.d(getTag(), "---onConnectFailure");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "---onConnectFailure");
|
||||
}
|
||||
ConnCallbackManager.getInstance().onConnectFailure();
|
||||
retryGetAddress(1000L);//3-6s //todo 时间调整为1秒,后续在重连时增加网络状态验证,以及增加链路日志
|
||||
}
|
||||
@@ -187,7 +202,9 @@ public class SocketClient {
|
||||
@Override
|
||||
public void onConnectSuccess() {
|
||||
super.onConnectSuccess();
|
||||
Logger.d(getTag(), "---onConnectSuccess");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(getTag(), "---onConnectSuccess");
|
||||
}
|
||||
ConnCallbackManager.getInstance().onConnectSuccess();
|
||||
}
|
||||
};
|
||||
@@ -199,7 +216,9 @@ public class SocketClient {
|
||||
|
||||
private boolean checkPort(int port) {
|
||||
if (port < 0 || port > 0xFFFF) {
|
||||
Logger.e(getTag(), "port out of range:" + port);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.e(getTag(), "port out of range:" + port);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -207,7 +226,9 @@ public class SocketClient {
|
||||
|
||||
private boolean checkHost(String hostname) {
|
||||
if (TextUtils.isEmpty(hostname)) {
|
||||
Logger.e(getTag(), "hostname can't be null");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.e(getTag(), "hostname can't be null");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.cloud.socket.third.core.client;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.analytics.EventRequest;
|
||||
import com.mogo.cloud.socket.third.analytics.SocketStatus;
|
||||
import com.mogo.cloud.socket.third.core.CallbackManager;
|
||||
@@ -39,11 +40,15 @@ import io.netty.util.ReferenceCountUtil;
|
||||
switch (e.state()) {
|
||||
case WRITER_IDLE:
|
||||
RequestUtil.sendHeartbeat(ctx.channel());
|
||||
Logger.i(SocketConstants.TAG, "client send heartbeat write-idle");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "client send heartbeat write-idle");
|
||||
}
|
||||
break;
|
||||
case READER_IDLE:
|
||||
RequestUtil.sendHeartbeat(ctx.channel());
|
||||
Logger.i(SocketConstants.TAG, "client send heartbeat reader-idle");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "client send heartbeat reader-idle");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -56,24 +61,31 @@ import io.netty.util.ReferenceCountUtil;
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext channelHandlerContext, Object msg) throws Exception {
|
||||
if (!(msg instanceof MogoConnsvrPacket)) {
|
||||
Logger.i(SocketConstants.TAG, "msg is null or msg is not MogoConnsvrPacket type---" + (msg == null ? "" : msg.toString()));
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "msg is null or msg is not MogoConnsvrPacket type---" + (msg == null ? "" : msg.toString()));
|
||||
}
|
||||
EventRequest.trackException("msg is not instanceof MogoConnsvrPacket");
|
||||
//重新请求ip port
|
||||
onRetryLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.i(SocketConstants.TAG, "Client---client receive server---" + msg.toString());
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client---client receive server---" + msg.toString());
|
||||
}
|
||||
|
||||
final MogoConnsvrPacket mogoConnsvrPacket = (MogoConnsvrPacket) msg;
|
||||
final MogoConnsvr.MsgType msgType = mogoConnsvrPacket.getMsgType(((MogoConnsvrPacket) msg).getHeaderPb());
|
||||
|
||||
Logger.i(SocketConstants.TAG, "receive server---msgType" + msgType.name());
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "receive server---msgType" + msgType.name());
|
||||
}
|
||||
if (msgType == MogoConnsvr.MsgType.mogoMsgTypeConnSvrAuthMidRsp) {
|
||||
//返回256位随机字符串, 加密后再次发给服务端验证
|
||||
LoginStatusUtil.setStatus(false);
|
||||
if (mogoConnsvrPacket.getPayload() == null) {
|
||||
Logger.i(SocketConstants.TAG, "AuthMidRsp==>Packet.getPayload is null");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "AuthMidRsp==>Packet.getPayload is null");
|
||||
}
|
||||
EventRequest.trackException("AuthMidRsp==>Packet.getPayload is null");
|
||||
//重新请求ip port
|
||||
onRetryLogin();
|
||||
@@ -92,7 +104,9 @@ import io.netty.util.ReferenceCountUtil;
|
||||
LoginStatusUtil.setStatus(false);
|
||||
if (mogoConnsvrPacket.getPayload() == null) {
|
||||
EventRequest.trackException("AuthRsp==> Packet.getPayload is null");
|
||||
Logger.i(SocketConstants.TAG, "login response ---> response is null");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "login response ---> response is null");
|
||||
}
|
||||
//重新请求ip port
|
||||
onRetryLogin();
|
||||
return;
|
||||
@@ -114,7 +128,9 @@ import io.netty.util.ReferenceCountUtil;
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeConnSvrAgentInfoRsp) {//用户信息
|
||||
final MogoConnsvr.ConnSvrUserInfoRsp userInfoResponse = MogoConnsvr.ConnSvrUserInfoRsp.parseFrom(mogoConnsvrPacket.getPayloadBytes());
|
||||
if (userInfoResponse.getResult()) {
|
||||
Logger.i(SocketConstants.TAG, "Client receives server's user info response, result is true.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client receives server's user info response, result is true.");
|
||||
}
|
||||
LoginStatusUtil.setStatus(true);
|
||||
} else {
|
||||
EventRequest.trackSocketStatus(SocketStatus.send_userInfo_rsp_failed, "send_userInfo_rsp_failed");
|
||||
@@ -123,22 +139,30 @@ import io.netty.util.ReferenceCountUtil;
|
||||
}
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeConnSvrDisconnectRsp) {//链接断开
|
||||
LoginStatusUtil.setStatus(false);
|
||||
Logger.i(SocketConstants.TAG, "mogoMsgTypeConnSvrDisconnectRsp retry login");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "mogoMsgTypeConnSvrDisconnectRsp retry login");
|
||||
}
|
||||
EventRequest.trackSocketStatus(SocketStatus.socket_disconnect, "disconnect");
|
||||
//重新请求ip port
|
||||
onRetryLogin();
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeAppPushKickMessageReq) {
|
||||
LoginStatusUtil.setStatus(false);
|
||||
Logger.i(SocketConstants.TAG, "close channel response ---> 被踢下线");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "close channel response ---> 被踢下线");
|
||||
}
|
||||
EventRequest.trackSocketStatus(SocketStatus.socket_disconnect, "kick out, socket is close");
|
||||
ClientSocketManager.getInstance().close();
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeAppPushMessageReq) {//推送消息
|
||||
if (mogoConnsvrPacket.getPayload() == null) {
|
||||
Logger.i(SocketConstants.TAG, "push message response is null");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "push message response is null");
|
||||
}
|
||||
EventRequest.trackException("push payload message response is null");
|
||||
return;
|
||||
}
|
||||
Logger.i(SocketConstants.TAG, "push message response received");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "push message response received");
|
||||
}
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom(mogoConnsvrPacket.getHeaderBytes());
|
||||
if (header != null) {
|
||||
@@ -158,7 +182,9 @@ import io.netty.util.ReferenceCountUtil;
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeAppUpstreamAck) {
|
||||
Logger.i(SocketConstants.TAG, "receive message ack");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "receive message ack");
|
||||
}
|
||||
|
||||
byte[] bytes = mogoConnsvrPacket.getHeaderBytes();
|
||||
try {
|
||||
@@ -170,14 +196,18 @@ import io.netty.util.ReferenceCountUtil;
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (msgType == MogoConnsvr.MsgType.mogoMsgTypeConnSvrHeartbeatReq) {
|
||||
Logger.i(SocketConstants.TAG, "Client receives server's heartbeat.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client receives server's heartbeat.");
|
||||
}
|
||||
}
|
||||
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
|
||||
private void onAuthSuccess(Channel channel) {
|
||||
Logger.i(SocketConstants.TAG, "Client authority check succeeded");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client authority check succeeded");
|
||||
}
|
||||
//send heartbeat.
|
||||
HeartbeatAlarmManager.getInstance().send();
|
||||
//send user info
|
||||
@@ -186,7 +216,9 @@ import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
private synchronized void onRetryLogin() {
|
||||
onConnectFailure();
|
||||
Logger.i(SocketConstants.TAG, "Client login fails, retry ing");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client login fails, retry ing");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +229,9 @@ import io.netty.util.ReferenceCountUtil;
|
||||
if (connectionLifecycleListener != null) {
|
||||
//关闭原有通道,重新请求通道
|
||||
ClientSocketManager.getInstance().close();
|
||||
Logger.i(SocketConstants.TAG, "Client onConnectFailure, retry in 5s");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client onConnectFailure, retry in 5s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.cloud.socket.third.core.client;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.core.ConnectionLifecycleListener;
|
||||
import com.mogo.cloud.socket.third.core.SocketConstants;
|
||||
import com.mogo.cloud.socket.third.utils.LoginStatusUtil;
|
||||
@@ -96,12 +97,16 @@ public class ClientSocketManager {
|
||||
|
||||
private synchronized void writeAndFlush(Object msg) {
|
||||
if (channel == null) {
|
||||
Logger.i(SocketConstants.TAG, "socket channel is null when write and flush");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "socket channel is null when write and flush");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(msg instanceof MogoConnsvrPacket)) {
|
||||
Logger.i(SocketConstants.TAG, "msg is not MogoConnsvrPacket type when write and flush.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "msg is not MogoConnsvrPacket type when write and flush.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,7 +123,9 @@ public class ClientSocketManager {
|
||||
|
||||
public synchronized void start(String host, int port) {
|
||||
if (isConnected) {
|
||||
Logger.i(SocketConstants.TAG, "do not need to start, channel is connected");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "do not need to start, channel is connected");
|
||||
}
|
||||
return;
|
||||
}
|
||||
canReconnect = true;
|
||||
@@ -141,7 +148,9 @@ public class ClientSocketManager {
|
||||
|
||||
private synchronized void doConnection(long delayInMs) {
|
||||
if (channel != null && channel.isOpen() && channel.isActive()) {
|
||||
Logger.i(SocketConstants.TAG, "channel is active, no need to call doConnection(long delayInMs)");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "channel is active, no need to call doConnection(long delayInMs)");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -152,7 +161,9 @@ public class ClientSocketManager {
|
||||
final ChannelFuture future = bootstrap.connect();
|
||||
future.addListener((ChannelFutureListener) future1 -> {
|
||||
if (future1.isSuccess()) {
|
||||
Logger.i(SocketConstants.TAG, "Client---connecting server succeeds");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "Client---connecting server succeeds");
|
||||
}
|
||||
onConnectSuccess(future1.channel());
|
||||
} else {
|
||||
Logger.i(SocketConstants.TAG, "Client---connecting server fails,失败重试");
|
||||
@@ -193,7 +204,9 @@ public class ClientSocketManager {
|
||||
if (channel != null) {
|
||||
channel.close();
|
||||
channel = null;
|
||||
Logger.i(SocketConstants.TAG, "channel is null");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "channel is null");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.cloud.socket.third.core.client;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.analytics.EventRequest;
|
||||
import com.mogo.cloud.socket.third.analytics.SocketStatus;
|
||||
import com.mogo.cloud.socket.third.core.SocketConstants;
|
||||
@@ -18,13 +19,17 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
Logger.i(SocketConstants.TAG, "channel is active");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "channel is active");
|
||||
}
|
||||
ctx.fireChannelActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Logger.i(SocketConstants.TAG, "channel is inactive, it depends on client's choice whether to reconnect or not.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "channel is inactive, it depends on client's choice whether to reconnect or not.");
|
||||
}
|
||||
EventRequest.trackSocketStatus(SocketStatus.socket_disconnect, "channel is inactive");
|
||||
ClientSocketManager.getInstance().onConnectionLost();
|
||||
ctx.fireChannelInactive();
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.net.ConnectivityManager;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.cloud.passport.utils.DevicesUtils;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.analytics.EventRequest;
|
||||
import com.mogo.cloud.socket.third.analytics.SocketStatus;
|
||||
import com.mogo.cloud.socket.third.core.SocketConfig;
|
||||
@@ -43,8 +44,9 @@ import com.mogo.cloud.socket.third.utils.RequestUtil;
|
||||
alarmManager.cancel(pendingIntent);
|
||||
alarmManager = null;
|
||||
pendingIntent = null;
|
||||
|
||||
Logger.i(SocketConstants.TAG, "heartbeat alarm is cancelled");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "heartbeat alarm is cancelled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +67,9 @@ import com.mogo.cloud.socket.third.utils.RequestUtil;
|
||||
private void sendHeartbeatRepeatedly(long interval) {
|
||||
final Context appContext = SocketConfig.instance().getAppContext();
|
||||
if (appContext == null) {
|
||||
Logger.i(SocketConstants.TAG, "sendHeartbeatRepeatedly---> app context is null.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "sendHeartbeatRepeatedly---> app context is null.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
final int requestCode = 1001;
|
||||
@@ -82,16 +86,18 @@ import com.mogo.cloud.socket.third.utils.RequestUtil;
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
System.currentTimeMillis() + interval,
|
||||
pendingIntent);
|
||||
|
||||
Logger.i(SocketConstants.TAG, "setExact(...)");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "setExact(...)");
|
||||
}
|
||||
} else {
|
||||
alarmManager.setRepeating(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
System.currentTimeMillis() + interval,
|
||||
interval,
|
||||
pendingIntent);
|
||||
|
||||
Logger.i(SocketConstants.TAG, "setRepeating(...)");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "setRepeating(...)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,22 +106,27 @@ import com.mogo.cloud.socket.third.utils.RequestUtil;
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!ClientSocketManager.getInstance().isConnected()) {
|
||||
Logger.i(SocketConstants.TAG, "onReceive--->channel is not connected");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "onReceive--->channel is not connected");
|
||||
}
|
||||
EventRequest.trackSocketStatus(SocketStatus.socket_disconnect, "heartbeat netty socket disconnect");
|
||||
onRetryConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean result = LoginStatusUtil.isLogin();
|
||||
Logger.i(SocketConstants.TAG, "socket connected is : " + result);
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "socket connected is : " + result);
|
||||
}
|
||||
//重试逻辑
|
||||
if (!LoginStatusUtil.isLogin()) {
|
||||
EventRequest.trackSocketStatus(SocketStatus.socket_disconnect, "heartbeat product socket disconnect");
|
||||
onRetryConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.i(SocketConstants.TAG, "onReceive--->send heartbeat");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.i(SocketConstants.TAG, "onReceive--->send heartbeat");
|
||||
}
|
||||
RequestUtil.sendHeartbeat(ClientSocketManager.getInstance().getChannel());
|
||||
|
||||
if (DevicesUtils.isSdkHigherThan18() || lastNetworkType != DevicesUtils.getNetworkType(SocketConfig.instance().getAppContext())) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.elegant.network.utils.NetworkSdkUtils;
|
||||
import com.elegant.utils.CommonUtils;
|
||||
import com.mogo.cloud.httpdns.bean.HttpDnsSimpleLocation;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.socket.SocketBuildConfig;
|
||||
import com.mogo.cloud.socket.third.core.SocketConfig;
|
||||
import com.mogo.cloud.socket.third.core.network.model.MessageCallbackData;
|
||||
import com.mogo.cloud.socket.third.core.network.model.SocketAddressData;
|
||||
@@ -45,19 +46,25 @@ public class RequestManager {
|
||||
@Override
|
||||
protected void onFailure(int code, String message) {
|
||||
super.onFailure(code, message);
|
||||
Logger.d(TAG, "socket message callback failed");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG, "socket message callback failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSuccess(BaseResp o) {
|
||||
super.onSuccess(o);
|
||||
Logger.d(TAG, "socket message callback succeeded");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG, "socket message callback succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNetworkLost() {
|
||||
super.onNetworkLost();
|
||||
Logger.d(TAG, "request socket message callback, network is not available.");
|
||||
if (SocketBuildConfig.isPrintLog) {
|
||||
Logger.d(TAG, "request socket message callback, network is not available.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
|
||||
USERNAME=xintai
|
||||
PASSWORD=xintai2018
|
||||
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
|
||||
RELEASE=false
|
||||
RELEASE=true
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.3.14
|
||||
|
||||
Reference in New Issue
Block a user