diff --git a/app/src/main/java/com/mogo/launcher/stageone/ConfigStartUp.kt b/app/src/main/java/com/mogo/launcher/stageone/ConfigStartUp.kt index 1647869ae4..0f178d13cf 100644 --- a/app/src/main/java/com/mogo/launcher/stageone/ConfigStartUp.kt +++ b/app/src/main/java/com/mogo/launcher/stageone/ConfigStartUp.kt @@ -8,12 +8,12 @@ import com.mogo.eagle.core.data.app.AppConfigInfo.workingBranchName import com.mogo.eagle.core.data.config.FunctionBuildConfig import com.mogo.eagle.core.data.config.HdMapBuildConfig import com.mogo.eagle.core.data.config.HmiBuildConfig -import com.mogo.eagle.core.data.constants.MoGoConfig import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr import com.mogo.launcher.BuildConfig import com.mogo.launcher.R import com.mogo.test.crashreport.CrashReportConstants import com.rousetime.android_startup.AndroidStartup +import com.zhjt.mogo_core_function_devatools.env.* class ConfigStartUp : AndroidStartup() { @@ -44,7 +44,12 @@ class ConfigStartUp : AndroidStartup() { } private fun initDebugConfig(context: Context) { - DebugConfig.setNetMode(BuildConfig.NET_ENV) + var mode = BuildConfig.NET_ENV + val envConfig = EnvChangeManager.getEnvConfig() + if (envConfig != null) { + mode = envConfig.netMode + } + DebugConfig.setNetMode(mode) DebugConfig.setDebug(BuildConfig.DEBUG) DebugConfig.setLaunchLocationService(BuildConfig.LAUNCH_LOCATION_SERVICE) DebugConfig.setLauncher(BuildConfig.IS_LAUNCHER) diff --git a/app/src/main/java/com/mogo/launcher/stageone/HttpDnsStartUp.kt b/app/src/main/java/com/mogo/launcher/stageone/HttpDnsStartUp.kt index 70d47eca03..33f081ca2d 100644 --- a/app/src/main/java/com/mogo/launcher/stageone/HttpDnsStartUp.kt +++ b/app/src/main/java/com/mogo/launcher/stageone/HttpDnsStartUp.kt @@ -38,6 +38,8 @@ import com.mogo.eagle.core.utilcode.util.ThreadPoolService import com.mogo.eagle.core.utilcode.util.TimeUtils import com.mogo.module.common.constants.HostConst import com.rousetime.android_startup.AndroidStartup +import com.zhjt.mogo_core_function_devatools.env.* +import com.zhjt.mogo_core_function_devatools.env.EnvChangeManager.EnvConfig import com.zhjt.service.chain.ChainLog import com.zhjt.service.chain.TracingConstants.Endpoint.Companion.PAD @@ -123,6 +125,10 @@ class HttpDnsStartUp : AndroidStartup() { // clientConfig.setUseOriginSocket(true); clientConfig.iHttpDnsCurrentLocation = object : IHttpDnsCurrentLocation { override fun getCurrentLocation(): HttpDnsSimpleLocation? { + val envConfig = EnvChangeManager.getEnvConfig() + if (envConfig != null) { + return HttpDnsSimpleLocation(envConfig.cityCode, envConfig.lat, envConfig.lon) + } var mogoLocation: MogoLocation? = null val locationClient = CallerMapUIServiceManager.getSingletonLocationClient(AbsMogoApplication.getApp()) diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/env/EnvChangeManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/env/EnvChangeManager.kt new file mode 100644 index 0000000000..ebbcc2ee06 --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/env/EnvChangeManager.kt @@ -0,0 +1,97 @@ +package com.zhjt.mogo_core_function_devatools.env + +import android.content.Context.MODE_PRIVATE +import android.os.Process +import com.mogo.commons.constants.* +import com.mogo.commons.debug.* +import com.mogo.eagle.core.function.call.map.* +import com.mogo.eagle.core.utilcode.mogo.storage.* +import com.mogo.eagle.core.utilcode.util.* + + +object EnvChangeManager { + + private val sp = Utils.getApp().getSharedPreferences("env_change", MODE_PRIVATE) + + private fun updateCityCode(cityCode: String?) { + sp.edit().putString("city_code", cityCode).commit() + } + + private fun updateNetMode(netMode: Int) { + sp.edit().putInt("net_mode", netMode).commit() + } + + private fun getConfig() : Pair? { + val cityCode = sp.getString("city_code", null) + val severType = sp.getInt("net_mode", -1) + if (cityCode == null || severType == -1) { + return null + } + return Pair(cityCode, severType) + } + + fun getCityName(): String { + val cache = getConfig() + return if (cache == null) { + val cityCode = CallerMapLocationListenerManager.getCurrentLocation()?.cityCode ?: SharedPrefsMgr.getInstance(Utils.getApp()).getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010" + updateCityCode(cityCode) + when(cityCode) { + "010" -> "北京" + "0734" -> "衡阳" + else -> "未知" + } + } else { + when(cache.first) { + "010" -> "北京" + "0734" -> "衡阳" + else -> "未知" + } + } + } + + fun getNetMode(): String { + val cache = getConfig() + if (cache == null) { + val mode = DebugConfig.getNetMode() + updateNetMode(mode) + return when(mode) { + DebugConfig.NET_MODE_RELEASE -> "生产" + DebugConfig.NET_MODE_QA -> "测试" + DebugConfig.NET_MODE_DEMO -> "演示" + else -> "未知" + } + } else { + return when(cache.second) { + DebugConfig.NET_MODE_RELEASE -> "生产" + DebugConfig.NET_MODE_QA -> "测试" + DebugConfig.NET_MODE_DEMO -> "演示" + else -> "未知" + } + } + } + + fun changeTo(cityCode: String, netMode: Int) { + updateCityCode(cityCode) + updateNetMode(netMode) + restartApp() + } + + fun reset() { + updateCityCode(null) + updateNetMode(-1) + restartApp() + } + + private fun restartApp() { + Utils.getApp().startActivity(Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName)) + Process.killProcess(Process.myPid()) + } + + fun getEnvConfig(): EnvConfig? = getConfig()?.let { + EnvConfig(it.first, it.second, + if (it.first == "010") 116.397446 else 112.582654, + if (it.first == "010") 39.909004 else 26.816478) + } + + data class EnvConfig(val cityCode: String, val netMode: Int, val lat: Double, val lon: Double) +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt index 82bfc34c72..e2290c14e2 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/DebugSettingView.kt @@ -11,9 +11,12 @@ import android.text.Html import android.util.AttributeSet import android.view.LayoutInflater import android.view.View +import android.widget.* import androidx.annotation.RequiresApi +import androidx.appcompat.widget.PopupMenu import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat +import androidx.core.view.* import androidx.recyclerview.widget.LinearLayoutManager import chassis.Chassis import com.mogo.cloud.passport.MoGoAiCloudClient @@ -52,6 +55,7 @@ import com.mogo.eagle.core.function.hmi.R import com.mogo.eagle.core.function.hmi.ui.logcatch.ILogViewListener import com.mogo.eagle.core.function.hmi.ui.logcatch.LogInfoView import com.mogo.eagle.core.function.hmi.ui.upgrade.UpgradeListAdapter +import com.mogo.eagle.core.network.* import com.mogo.eagle.core.utilcode.kotlin.onClick import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel @@ -66,6 +70,7 @@ import com.mogo.map.uicontroller.VisualAngleMode.* import com.mogo.module.service.routeoverlay.* import com.zhidao.easysocket.utils.L import com.zhidao.support.adas.high.other.permission.BackgrounderPermission +import com.zhjt.mogo_core_function_devatools.env.* import kotlinx.android.synthetic.main.view_debug_setting.view.* import mogo.telematics.pad.MessagePad import mogo_msg.MogoReportMsg @@ -765,7 +770,7 @@ class DebugSettingView @JvmOverloads constructor( /** * 设置鹰眼本地参数配置监听 */ - private fun setEagleEyeConfigListener() { + @SuppressLint("SetTextI18n") private fun setEagleEyeConfigListener() { //初始化刹车加速度阈值信息 val brakeThreshold = SharedPrefsMgr.getInstance(context) .getFloat(MoGoConfig.BRAKE_ACCELERATION_THRESHOLD, -2.5F) @@ -810,6 +815,41 @@ class DebugSettingView @JvmOverloads constructor( tbReportWarning.visibility = GONE } + //切换环境 + tvCurEnv.text = "当前环境:${EnvChangeManager.getCityName()}${EnvChangeManager.getNetMode()}" + btChangeEnv.onClick { + PopupMenu(context, btChangeEnv).also { p -> + p.menuInflater.inflate(R.menu.menu_env_pop, p.menu) + MenuCompat.setGroupDividerEnabled(p.menu, true) + p.setOnMenuItemClickListener { item -> + when(item.itemId) { + R.id.group_hy -> { + return@setOnMenuItemClickListener false + } + R.id.group_bj -> { + return@setOnMenuItemClickListener false + } + R.id.env_reset -> + EnvChangeManager.reset() + R.id.hy_product -> + EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_RELEASE) + R.id.hy_qa -> + EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_QA) + R.id.hy_demo -> + EnvChangeManager.changeTo("0734", DebugConfig.NET_MODE_DEMO) + R.id.bj_product -> + EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_RELEASE) + R.id.bj_qa -> + EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_QA) + R.id.bj_demo -> + EnvChangeManager.changeTo("010", DebugConfig.NET_MODE_DEMO) + else -> + throw AssertionError("invalid item: $item") + } + return@setOnMenuItemClickListener true + } + }.show() + } } /** diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_debug_setting.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_debug_setting.xml index 2e71aef998..e320246b31 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_debug_setting.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_debug_setting.xml @@ -1036,6 +1036,38 @@ android:visibility="gone" tools:visibility="visible"> + + + + +