1. 增加延时检测空接口访问

2. opt TopViewAnimHelper
This commit is contained in:
tongchenfei
2020-12-24 15:45:24 +08:00
parent bf05411d3d
commit ceaa1cd33a
12 changed files with 483 additions and 170 deletions

View File

@@ -34,6 +34,7 @@ dependencies {
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
implementation rootProject.ext.dependencies.callchatprovider
implementation "com.mogo.httpdns:httpdns-helper:1.0.1"
if (Boolean.valueOf(RELEASE)) {
api rootProject.ext.dependencies.mogomap
api rootProject.ext.dependencies.mogomapapi

View File

@@ -0,0 +1,64 @@
package com.mogo.module.common.utils;
import android.content.Context;
import com.mogo.commons.network.Utils;
import com.mogo.httpdnshelper.sdk.HttpDnsHelper;
import com.mogo.httpdnshelper.sdk.IHttpDnsConfig;
import com.mogo.httpdnshelper.sdk.bean.HttpDnsSimpleLocation;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import org.jetbrains.annotations.NotNull;
/**
* MogoHttpDnsHelper包装类
*
* @author tongchenfei
*/
public class MogoHttpDnsUtil {
private MogoHttpDnsUtil(){
}
private final static MogoHttpDnsUtil INSTANCE = new MogoHttpDnsUtil();
public static MogoHttpDnsUtil getInstance(){
return INSTANCE;
}
public void init(Context context){
HttpDnsHelper.INSTANCE.init(context, new IHttpDnsConfig() {
@NotNull
@Override
public HttpDnsSimpleLocation getCurrentLocation() {
MogoLocation last = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation();
if(last!=null){
return new HttpDnsSimpleLocation(last.getCityCode(), last.getLatitude(), last.getLongitude());
}
return null;
}
@Override
public boolean showDebugLog() {
return true;
}
@NotNull
@Override
public String getSn() {
return Utils.getSn();
}
});
}
public String getHttpAddress(){
return HttpDnsHelper.INSTANCE.getHttpDnsAddress(HttpDnsHelper.HTTP_DNS_TYPE_HTTP);
}
public String getWsAddress(){
return HttpDnsHelper.INSTANCE.getHttpDnsAddress(HttpDnsHelper.HTTP_DNS_TYPE_WS);
}
public void release(){
HttpDnsHelper.INSTANCE.release();
}
}

View File

@@ -1,26 +0,0 @@
package com.mogo.module.extensions.net;
import com.mogo.commons.data.BaseData;
import java.util.Map;
import io.reactivex.Observable;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
/**
* 时延验证相关接口
*
* @author tongchenfei
*/
public interface DelayCheckApiServices {
@GET("/yycp-test-service/net/delay/heartbeat")
Observable<BaseData> emptyInterface();
@POST("/yycp-test-service/net/delay/log")
@FormUrlEncoded
Observable<BaseData> uploadDelayCheckData(@FieldMap Map<String, Object> params);
}

View File

@@ -1,142 +0,0 @@
package com.mogo.module.extensions.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.extensions.net.DelayCheckApiServices;
import com.mogo.module.extensions.net.DztHttpConstant;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.network.RequestOptions;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.schedulers.Schedulers;
/**
* 延时验证工具类
*
* @author tongchenfei
*/
public class DelayCheckUtil implements Handler.Callback {
private final Handler handler = new Handler(this);
private static final int MSG_CHECK_NET_CONNECT_STATUS = 1001;
private static final long FIRST_CHECK_NET_CONNECT_STATUS_DELAY = 10 * 60 * 1000;
private static final long CHECK_NET_CONNECT_STATUS_DELAY = 5000L;
private static final int MSG_START_DELAY_CHECK = 1002;
private static final long DELAY_CHECK_DELAY = 10 * 60 * 1000;
private final Context context;
public DelayCheckUtil(Context context) {
this.context = context;
}
/**
* 每5s检查一下网络状态网络状态为连接状态时开始空接口请求以及后续的参数上报
*/
public void waitingForCheck() {
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, FIRST_CHECK_NET_CONNECT_STATUS_DELAY);
}
private long requestTime, netDelay, requestSystemTime;
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_CHECK_NET_CONNECT_STATUS:
if (NetworkUtils.isConnected(context)) {
handler.sendEmptyMessage(MSG_START_DELAY_CHECK);
} else {
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
return true;
case MSG_START_DELAY_CHECK:
// 请求空接口
startEmptyRequest();
return true;
default:
return false;
}
}
private void startEmptyRequest() {
requestTime = SystemClock.elapsedRealtime();
requestSystemTime = System.currentTimeMillis();
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl())
.emptyInterface().subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(context)) {
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
netDelay = SystemClock.elapsedRealtime() - requestTime;
startUpload();
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
private void startUpload() {
MogoLocation lastLocation = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation();
if (lastLocation == null) {
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY);
return;
}
Map<String, Object> params = new HashMap<>(8);
params.put("sn", Utils.getSn());
params.put("startTime", requestSystemTime);
params.put("endTime", System.currentTimeMillis());
params.put("netState", NetworkUtils.netStrengthLevel);
params.put("place", lastLocation.getAddress());
params.put("cityCode", lastLocation.getCityCode());
params.put("lat", lastLocation.getLatitude());
params.put("lon", lastLocation.getLongitude());
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl())
.uploadDelayCheckData(params).observeOn(Schedulers.io()).subscribeOn(Schedulers.io())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(context)) {
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY);
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
}

View File

@@ -292,12 +292,12 @@ public class TopViewAnimHelper {
int scene = 0;
if (animNavInfoView.isVisible()) {
scene = Scene.NAVI_WITH_ROAD_EVENT;
animNavInfoView.animate().translationY(computeNaviMarginTop(child.getHeight())).start();
animNavInfoView.animate().translationY(computeNaviMarginTop(params.height)).start();
animNavInfoView.exchangeToSmall(true);
} else {
scene = Scene.AIMLESS_WITH_ROAD_EVENT;
}
topContainer.animate().translationY(child.getHeight()).setListener(mainAnimListener).start();
topContainer.animate().translationY(params.height).setListener(mainAnimListener).start();
Logger.d(TAG, "show top setMapCenterPointByScene: " + scene);
MapCenterPointStrategy.setMapCenterPointByScene(mogoMapUIController, scene);
} catch (Exception e) {

View File

@@ -0,0 +1,39 @@
package com.mogo.module.main.delaycheck;
import com.mogo.commons.data.BaseData;
import java.util.Map;
import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
/**
* 时延验证相关接口
*
* @author tongchenfei
*/
public interface DelayCheckApiServices {
/**
* 空接口
* @return 什么都不返回
*/
@GET("/yycp-test-service/net/delay/heartbeat")
Observable<BaseData> emptyInterface();
/**
* 时延上报接口 接口文档如下
* http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48967034
* @param params 相关参数,详见文档
* @return 相关返回值,详见文档
*/
@POST("/yycp-test-service/net/delay/log")
@Headers({"Content-type:application/json;charset=UTF-8"})
Observable<DelayCheckResponse> uploadDelayCheckData(@Body RequestBody params);
}

View File

@@ -0,0 +1,28 @@
package com.mogo.module.main.delaycheck;
import com.mogo.commons.debug.DebugConfig;
/**
* dzt base url
*
* @author tongchenfei
*/
public class DelayCheckHttpConstant {
public static final String HOST_DEV = "http://dzt-test.zhidaozhixing.com";
public static final String HOST_TEST = "http://dzt-test.zhidaozhixing.com";
public static final String HOST_DEMO = "http://dzt-show.zhidaozhixing.com";
public static final String HOST_PRODUCT = "http://dzt.zhidaozhixing.com";
public static String getBaseUrl(){
switch ( DebugConfig.getNetMode() ) {
case DebugConfig.NET_MODE_DEV:
return HOST_DEV;
case DebugConfig.NET_MODE_QA:
return HOST_TEST;
case DebugConfig.NET_MODE_DEMO:
return HOST_DEMO;
default:
return HOST_PRODUCT;
}
}
}

View File

@@ -0,0 +1,29 @@
package com.mogo.module.main.delaycheck;
import com.mogo.commons.data.BaseData;
/**
* 延迟检测response
*
* @author tongchenfei
*/
public class DelayCheckResponse extends BaseData {
private DelayCheckResult result;
public DelayCheckResult getResult() {
return result;
}
public void setResult(DelayCheckResult result) {
this.result = result;
}
@Override
public String toString() {
return "DelayCheckResponse{" +
"result=" + result +
", code=" + code +
", msg='" + msg + '\'' +
'}';
}
}

View File

@@ -0,0 +1,41 @@
package com.mogo.module.main.delaycheck;
/**
* 延迟检查返回结果
*
* @author tongchenfei
*/
public class DelayCheckResult {
/**
* 是否保持心跳
*/
private boolean necessary;
/**
* 心跳间隔,单位 s
*/
private int beatSeconds;
public boolean isNecessary() {
return necessary;
}
public void setNecessary(boolean necessary) {
this.necessary = necessary;
}
public int getBeatSeconds() {
return beatSeconds;
}
public void setBeatSeconds(int beatSeconds) {
this.beatSeconds = beatSeconds;
}
@Override
public String toString() {
return "DelayCheckResult{" +
"necessary=" + necessary +
", beatSeconds=" + beatSeconds +
'}';
}
}

View File

@@ -0,0 +1,111 @@
package com.mogo.module.main.delaycheck;
/**
* 时延检测上报请求参数
*
* @author tongchenfei
*/
public class DelayCheckUploadRequest {
private String sn;
private long startTime;
private long endTime;
/**
* 请求时长
*/
private long burning;
/**
* 信号强度
*/
private int netState;
private String place;
private String cityCode;
private double lat;
private double lon;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
public long getBurning() {
return burning;
}
public void setBurning(long burning) {
this.burning = burning;
}
public int getNetState() {
return netState;
}
public void setNetState(int netState) {
this.netState = netState;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public String getCityCode() {
return cityCode;
}
public void setCityCode(String cityCode) {
this.cityCode = cityCode;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
@Override
public String toString() {
return "DelayCheckUploadRequest{" +
"sn='" + sn + '\'' +
", startTime=" + startTime +
", endTime=" + endTime +
", burning=" + burning +
", netState=" + netState +
", place='" + place + '\'' +
", cityCode='" + cityCode + '\'' +
", lat=" + lat +
", lon=" + lon +
'}';
}
}

View File

@@ -0,0 +1,160 @@
package com.mogo.module.main.delaycheck;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
/**
* 延时验证工具类
*
* @author tongchenfei
*/
public class DelayCheckUtil implements Handler.Callback {
private static final String TAG = "DelayCheckUtil";
private final Handler handler = new Handler(this);
private static final int MSG_CHECK_NET_CONNECT_STATUS = 1001;
/**
* 首次延时检测时间间隔暂定10分钟等待机器稳定后再做打算
*/
private static final long FIRST_CHECK_NET_CONNECT_STATUS_DELAY = 10 * 60 * 1000;
private static final long CHECK_NET_CONNECT_STATUS_DELAY = 5000L;
private static final int MSG_START_DELAY_CHECK = 1002;
/**
* 默认检测时间间隔,若服务端正确返回,以服务端返回为主
*/
private static final long DELAY_CHECK_DELAY = 10 * 60 * 1000;
private final Context context;
public DelayCheckUtil(Context context) {
this.context = context;
}
/**
* 每5s检查一下网络状态网络状态为连接状态时开始空接口请求以及后续的参数上报
*/
public void waitingForCheck() {
Logger.d(TAG, "waitingForCheck===");
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, FIRST_CHECK_NET_CONNECT_STATUS_DELAY);
}
private long requestTime, netDelay, requestStartSystemTime,requestEndSystem;
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_CHECK_NET_CONNECT_STATUS:
if (NetworkUtils.isConnected(context)) {
handler.sendEmptyMessage(MSG_START_DELAY_CHECK);
} else {
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
return true;
case MSG_START_DELAY_CHECK:
// 请求空接口
startEmptyRequest();
return true;
default:
return false;
}
}
private void startEmptyRequest() {
Logger.d(TAG, "start empty request");
requestTime = SystemClock.elapsedRealtime();
requestStartSystemTime = System.currentTimeMillis();
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DelayCheckHttpConstant.getBaseUrl())
.emptyInterface().subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(context)) {
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
requestEndSystem = System.currentTimeMillis();
netDelay = SystemClock.elapsedRealtime() - requestTime;
startUpload();
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
private void startUpload() {
Logger.d(TAG, "start upload");
MogoLocation lastLocation = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation();
if (lastLocation == null) {
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY);
return;
}
Logger.d(TAG, "lastLocation: " + lastLocation);
DelayCheckUploadRequest request = new DelayCheckUploadRequest();
request.setSn(Utils.getSn());
request.setStartTime(requestStartSystemTime);
request.setEndTime(requestEndSystem);
request.setNetState(NetworkUtils.netStrengthLevel);
request.setPlace(lastLocation.getAddress());
request.setCityCode(lastLocation.getCityCode());
request.setLat(lastLocation.getLatitude());
request.setLon(lastLocation.getLongitude());
request.setBurning(netDelay);
RequestBody params = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(request));
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DelayCheckHttpConstant.getBaseUrl())
.uploadDelayCheckData(params).observeOn(Schedulers.io()).subscribeOn(Schedulers.io())
.subscribe(new SubscribeImpl<DelayCheckResponse>(RequestOptions.create(context)) {
@Override
public void onSuccess(DelayCheckResponse o) {
super.onSuccess(o);
Logger.d(TAG, "上报时延成功 " + o);
DelayCheckResult result = o.getResult();
if(result.isNecessary()) {
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, result.getBeatSeconds() * 1000);
}
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
}

View File

@@ -12,8 +12,10 @@ import com.mogo.map.location.IMogoLocationClient;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.utils.MogoHttpDnsUtil;
import com.mogo.module.main.EventDispatchCenter;
import com.mogo.module.main.cards.MogoModulesManager;
import com.mogo.module.main.delaycheck.DelayCheckUtil;
import com.mogo.service.IMogoServiceApis;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
@@ -48,6 +50,11 @@ class MogoMainService extends Service implements IMogoLocationListener {
initGpsSimulatorListener();
}, 2_000L
);
// 开启延时检测
DelayCheckUtil delayCheckUtil = new DelayCheckUtil(this);
delayCheckUtil.waitingForCheck();
MogoHttpDnsUtil.getInstance().init(this);
}
@Nullable
@@ -104,5 +111,6 @@ class MogoMainService extends Service implements IMogoLocationListener {
mLocationClient = null;
}
mServiceApis = null;
MogoHttpDnsUtil.getInstance().release();
}
}