add new func of httpdns switch city to fit socketserver
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.mogo.launcher;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Process;
|
||||
@@ -25,6 +24,7 @@ import com.mogo.module.carchatting.card.CallChatConstant;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.common.constants.HostConst;
|
||||
import com.mogo.module.main.service.MogoMainService;
|
||||
import com.mogo.module.push.base.PushUIConstants;
|
||||
import com.mogo.module.service.ServiceConst;
|
||||
@@ -57,6 +57,7 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
|
||||
private long start;
|
||||
private volatile static RefWatcher refWatcher;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
initDebugConfig();
|
||||
@@ -69,7 +70,7 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
CrashSystem crashSystem = CrashSystem.getInstance(this);
|
||||
crashSystem.init();
|
||||
//设置debug模式,日志不上传
|
||||
crashSystem.setDebug(BuildConfig.DEBUG);
|
||||
// crashSystem.setDebug(BuildConfig.DEBUG);
|
||||
Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF);
|
||||
initTipToast();
|
||||
initModules();
|
||||
@@ -120,16 +121,6 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
prepareBaseService();
|
||||
}
|
||||
|
||||
//todo
|
||||
protected HttpSimpleLocation getCurrentLocation() {
|
||||
MogoLocation location = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(this).getLastKnowLocation();
|
||||
if (location == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new HttpSimpleLocation(location.getCityCode(), location.getLatitude(), location.getLongitude());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础服务:passport、location、socket
|
||||
*/
|
||||
@@ -177,9 +168,9 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
break;
|
||||
}
|
||||
// 设置应用服务AppId 长链、鉴权
|
||||
if(DebugConfig.getNetMode() == DebugConfig.NET_MODE_RELEASE){
|
||||
if (DebugConfig.getNetMode() == DebugConfig.NET_MODE_RELEASE) {
|
||||
clientConfig.setServiceAppId("com_mogo_launcher");
|
||||
}else{
|
||||
} else {
|
||||
clientConfig.setServiceAppId("com.mogo.launcher");
|
||||
}
|
||||
// 设置AI云平台分配给三方应用的签名密钥,需要从AI云平台申请
|
||||
@@ -189,69 +180,75 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
clientConfig.setLoopCheckDelay(15 * 1000);
|
||||
|
||||
// 设置DNS经纬度位置
|
||||
clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() {
|
||||
@Override
|
||||
public HttpDnsSimpleLocation getCurrentLocation() {
|
||||
MogoLocation mogoLocation =
|
||||
MogoApisHandler.getInstance()
|
||||
.getApis().getMapServiceApi()
|
||||
.getSingletonLocationClient(getApp())
|
||||
.getLastKnowLocation();
|
||||
HttpDnsSimpleLocation httpDnsSimpleLocation;
|
||||
if (mogoLocation != null
|
||||
&& mogoLocation.getLatitude() != 0
|
||||
&& mogoLocation.getLongitude() != 0) {
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
mogoLocation.getCityCode(),
|
||||
mogoLocation.getLatitude(),
|
||||
mogoLocation.getLongitude());
|
||||
Logger.i(TAG, "使用实时GPS信息:" + httpDnsSimpleLocation);
|
||||
} else {
|
||||
String ciyCode = SharedPrefsMgr.getInstance(getApp())
|
||||
.getString(SharedPrefsConstants.LOCATION_CITY_CODE);
|
||||
String latitude = SharedPrefsMgr.getInstance(getApp())
|
||||
.getString(SharedPrefsConstants.LOCATION_LATITUDE);
|
||||
String longitude = SharedPrefsMgr.getInstance(getApp())
|
||||
.getString(SharedPrefsConstants.LOCATION_LONGITUDE);
|
||||
try {
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
ciyCode,
|
||||
Double.parseDouble(latitude),
|
||||
Double.parseDouble(longitude));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation("010", 1, 1);
|
||||
}
|
||||
Logger.i(TAG, "使用缓存GPS信息:" + httpDnsSimpleLocation);
|
||||
}
|
||||
return httpDnsSimpleLocation;
|
||||
}
|
||||
clientConfig.setIHttpDnsCurrentLocation(() -> {
|
||||
SocketTestBroadCastReceiver.SocketTestData socketTestData = SocketTestBroadCastReceiver.SocketTestData.getInstance();
|
||||
Log.d("TEST-SOCKET","socketTestData cityCode: " + socketTestData.getCityCode());
|
||||
return new HttpDnsSimpleLocation(socketTestData.getCityCode(),socketTestData.getLat(),socketTestData.getLon()); //todo 对象唯一实例优化
|
||||
});
|
||||
// clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() {
|
||||
// @Override
|
||||
// public HttpDnsSimpleLocation getCurrentLocation() {
|
||||
// MogoLocation mogoLocation =
|
||||
// MogoApisHandler.getInstance()
|
||||
// .getApis().getMapServiceApi()
|
||||
// .getSingletonLocationClient(getApp())
|
||||
// .getLastKnowLocation();
|
||||
// HttpDnsSimpleLocation httpDnsSimpleLocation;
|
||||
// if (mogoLocation != null
|
||||
// && mogoLocation.getLatitude() != 0
|
||||
// && mogoLocation.getLongitude() != 0) {
|
||||
// httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
// mogoLocation.getCityCode(),
|
||||
// mogoLocation.getLatitude(),
|
||||
// mogoLocation.getLongitude());
|
||||
// Logger.i(TAG, "使用实时GPS信息:" + httpDnsSimpleLocation);
|
||||
// } else {
|
||||
// String ciyCode = SharedPrefsMgr.getInstance(getApp())
|
||||
// .getString(SharedPrefsConstants.LOCATION_CITY_CODE);
|
||||
// String latitude = SharedPrefsMgr.getInstance(getApp())
|
||||
// .getString(SharedPrefsConstants.LOCATION_LATITUDE);
|
||||
// String longitude = SharedPrefsMgr.getInstance(getApp())
|
||||
// .getString(SharedPrefsConstants.LOCATION_LONGITUDE);
|
||||
// try {
|
||||
// httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
// ciyCode,
|
||||
// Double.parseDouble(latitude),
|
||||
// Double.parseDouble(longitude));
|
||||
// } catch (NumberFormatException e) {
|
||||
// e.printStackTrace();
|
||||
// httpDnsSimpleLocation = new HttpDnsSimpleLocation("010", 1, 1);
|
||||
// }
|
||||
// Logger.i(TAG, "使用缓存GPS信息:" + httpDnsSimpleLocation);
|
||||
// }
|
||||
// return httpDnsSimpleLocation;
|
||||
// }
|
||||
// });
|
||||
|
||||
// 初始化SDK,可以设置状态回调来监听
|
||||
MoGoAiCloudClient.getInstance().init(this, clientConfig).addTokenCallbacks(
|
||||
new IMoGoTokenCallback() {
|
||||
@Override
|
||||
public void onTokenGot(String token, String sn) {
|
||||
//todo
|
||||
Logger.d("TEST-SOCKET", "onTokenGot ");
|
||||
// 异步初始化NetConfig
|
||||
asyncInit();
|
||||
// 鉴权成功后开启socket长链服务
|
||||
prepareSocketAndLocationServices();
|
||||
// HttpDns ttl回调 --- socketTTL
|
||||
registerSocketHttpDnsTTL(HostConst.SOCKET_CENTER_DOMAIN);
|
||||
// 开启每5s/次定位上报
|
||||
uploadLocPerFiveSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String msg) {
|
||||
Log.d(TAG,"初始化MogoAiCloudSdk failed ,reason : " + msg + " , 未能开启长链服务和初始化Modules服务");
|
||||
Log.d(TAG, "初始化MogoAiCloudSdk failed ,reason : " + msg + " , 未能开启长链服务和初始化Modules服务");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void prepareSocketAndLocationServices() {
|
||||
//开启Socket长链服务
|
||||
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
|
||||
apis.getSocketManagerApi(getApplicationContext()).init(getApplicationContext(), DebugConfig.getSocketAppId());
|
||||
private void uploadLocPerFiveSecond(){
|
||||
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE) {
|
||||
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
|
||||
apis.getLocationInfoApi().start();
|
||||
apis.getMapServiceApi().getSingletonLocationClient(getApplicationContext()).addLocationListener(location -> {
|
||||
apis.getLocationInfoApi().provideLocation(location);
|
||||
@@ -259,8 +256,22 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
}
|
||||
}
|
||||
|
||||
private void initModules(){
|
||||
Logger.d(TAG,"initModules");
|
||||
private void prepareSocketAndLocationServices() {
|
||||
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
|
||||
// 关闭长链服务
|
||||
apis.getSocketManagerApi(getApplicationContext()).destroy();
|
||||
// 开启Socket长链服务
|
||||
apis.getSocketManagerApi(getApplicationContext()).init(getApplicationContext(), DebugConfig.getSocketAppId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void socketTTL() {
|
||||
// 鉴权成功后开启socket长链服务
|
||||
prepareSocketAndLocationServices();
|
||||
}
|
||||
|
||||
private void initModules() {
|
||||
Logger.d(TAG, "initModules");
|
||||
if (DebugConfig.isNeedLoadGuideModule()) {
|
||||
MogoModulePaths.addModule(new MogoModule(MogoModulePaths.PATH_GUIDE, MogoModulePaths.PATH_GUIDE));
|
||||
}
|
||||
@@ -309,8 +320,8 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
if (refWatcher == null){
|
||||
refWatcher = LeakCanary.install(this);
|
||||
if (refWatcher == null) {
|
||||
refWatcher = LeakCanary.install(this);
|
||||
}
|
||||
|
||||
// 初始化 bugly 升级
|
||||
@@ -320,18 +331,18 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
// }
|
||||
ARouter.getInstance().navigation(ITestCrashReportProvider.class);
|
||||
Log.i("timer", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
|
||||
try {
|
||||
if (DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_LENOVO) {
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(new ComponentName("com.zhidao.speech.voice.pad",
|
||||
"com.zhidao.speech.MainActivity"));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// if (DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_LENOVO) {
|
||||
// Intent intent = new Intent();
|
||||
// intent.setComponent(new ComponentName("com.zhidao.speech",
|
||||
// "com.zhidao.speech.MainActivity"));
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.mogo.launcher;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public class SocketTestBroadCastReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "SocketTestBroadCastReceiver";
|
||||
|
||||
/**
|
||||
* Adas测试控制面板广播Action
|
||||
*/
|
||||
public static final String BROADCAST_TEST_PANEL_CONTROL_TYPE_EXTRA_KEY = "sceneType";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
try {
|
||||
this.mContext = context;
|
||||
int sceneType = intent.getIntExtra(BROADCAST_TEST_PANEL_CONTROL_TYPE_EXTRA_KEY, 0);
|
||||
Logger.d(TAG, "textPanelOpenType:" + sceneType);
|
||||
// 分发场景
|
||||
dispatchSceneTest(sceneType);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchSceneTest(int sceneType) {
|
||||
if (sceneType == 0) {
|
||||
// 更改地址为衡阳
|
||||
SocketTestData socketTestData = SocketTestData.getInstance();
|
||||
socketTestData.setCityCode("0734");
|
||||
socketTestData.setLat(26.81624);
|
||||
socketTestData.setLon(112.580089);
|
||||
}
|
||||
if (sceneType == 1) {
|
||||
// 更改地址为北京
|
||||
SocketTestData socketTestData = SocketTestData.getInstance();
|
||||
socketTestData.setCityCode("010");
|
||||
socketTestData.setLat(40.1993457314);
|
||||
socketTestData.setLon(116.7355931215);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SocketTestData {
|
||||
|
||||
private SocketTestData(){}
|
||||
|
||||
private static final byte[] bytes = new byte[0];
|
||||
|
||||
private volatile static SocketTestData instance;
|
||||
|
||||
public static SocketTestData getInstance(){
|
||||
if(instance == null){
|
||||
synchronized (bytes){
|
||||
if(instance == null){
|
||||
instance = new SocketTestData();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private String cityCode = "010";
|
||||
private Double lat = 0.0;
|
||||
private Double lon = 0.0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user