[6.8.0][NativeCrash] 修正因SP使用问题导致的崩溃

This commit is contained in:
renwj
2024-11-29 19:37:00 +08:00
parent 63fd42bc51
commit e2fc87494b
2 changed files with 58 additions and 57 deletions

View File

@@ -13,88 +13,88 @@ import com.mogo.eagle.core.utilcode.util.Utils
object EnvChangeManager {
private val sp = Utils.getApp().getSharedPreferences("env_change", MODE_PRIVATE)
// private val sp = Utils.getApp().getSharedPreferences("env_change", MODE_PRIVATE)
private fun updateCityCode(cityCode: String?) {
sp.edit().putString("city_code", cityCode).apply()
// sp.edit().putString("city_code", cityCode).apply()
}
private fun updateNetMode(netMode: Int) {
sp.edit().putInt("net_mode", netMode).apply()
// sp.edit().putInt("net_mode", netMode).apply()
}
private fun getConfig() : Pair<String, Int>? {
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)
// 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)
return null
}
fun getCityName(): String {
val cache = getConfig()
return if (cache == null) {
when(CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()?.cityCode ?: SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010") {
"010" -> "北京"
"0734" -> "衡阳"
else -> "未知"
}
} else {
when(cache.first) {
"010" -> "北京"
"0734" -> "衡阳"
else -> "未知"
}
}
// val cache = getConfig()
// return if (cache == null) {
// when(CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()?.cityCode ?: SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010") {
// "010" -> "北京"
// "0734" -> "衡阳"
// else -> "未知"
// }
// } else {
// when(cache.first) {
// "010" -> "北京"
// "0734" -> "衡阳"
// else -> "未知"
// }
// }
return "未知"
}
fun getConfigNetMode(): Int {
val cache = getConfig()
return cache?.second ?: -1
// val cache = getConfig()
// return cache?.second ?: -1
return -1
}
fun getNetMode(): String {
val cache = getConfig()
return if (cache == null) {
when(DebugConfig.getNetMode()) {
DebugConfig.NET_MODE_RELEASE -> "生产"
DebugConfig.NET_MODE_QA -> "测试"
DebugConfig.NET_MODE_DEMO -> "演示"
else -> "未知"
}
} else {
when(cache.second) {
DebugConfig.NET_MODE_RELEASE -> "生产"
DebugConfig.NET_MODE_QA -> "测试"
DebugConfig.NET_MODE_DEMO -> "演示"
else -> "未知"
}
}
// val cache = getConfig()
// return if (cache == null) {
// when(DebugConfig.getNetMode()) {
// DebugConfig.NET_MODE_RELEASE -> "生产"
// DebugConfig.NET_MODE_QA -> "测试"
// DebugConfig.NET_MODE_DEMO -> "演示"
// else -> "未知"
// }
// } else {
// when(cache.second) {
// DebugConfig.NET_MODE_RELEASE -> "生产"
// DebugConfig.NET_MODE_QA -> "测试"
// DebugConfig.NET_MODE_DEMO -> "演示"
// else -> "未知"
// }
// }
return "未知"
}
fun changeTo(cityCode: String, netMode: Int) {
updateCityCode(cityCode)
updateNetMode(netMode)
restartApp()
// updateCityCode(cityCode)
// updateNetMode(netMode)
// restartApp()
}
fun reset() {
updateCityCode(null)
updateNetMode(-1)
restartApp()
// updateCityCode(null)
// updateNetMode(-1)
// restartApp()
}
private fun restartApp() {
Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName)?.also {
ActivityUtils.startActivity(it)
}
Process.killProcess(Process.myPid())
// Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName)?.also {
// ActivityUtils.startActivity(it)
// }
// 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)
}
fun getEnvConfig(): EnvConfig? = null
}

View File

@@ -1272,6 +1272,7 @@
android:background="@drawable/debug_setting_edit_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -1307,7 +1308,7 @@
android:text="设置刹车加速度阈值"
android:textSize="@dimen/dp_24"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/llChangeEnv" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"