[6.8.0][NativeCrash] 修正因SP使用问题导致的崩溃
This commit is contained in:
@@ -13,88 +13,88 @@ import com.mogo.eagle.core.utilcode.util.Utils
|
|||||||
|
|
||||||
object EnvChangeManager {
|
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?) {
|
private fun updateCityCode(cityCode: String?) {
|
||||||
sp.edit().putString("city_code", cityCode).apply()
|
// sp.edit().putString("city_code", cityCode).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNetMode(netMode: Int) {
|
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>? {
|
private fun getConfig() : Pair<String, Int>? {
|
||||||
val cityCode = sp.getString("city_code", null)
|
// val cityCode = sp.getString("city_code", null)
|
||||||
val severType = sp.getInt("net_mode", -1)
|
// val severType = sp.getInt("net_mode", -1)
|
||||||
if (cityCode == null || severType == -1) {
|
// if (cityCode == null || severType == -1) {
|
||||||
return null
|
// return null
|
||||||
}
|
// }
|
||||||
return Pair(cityCode, severType)
|
// return Pair(cityCode, severType)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCityName(): String {
|
fun getCityName(): String {
|
||||||
val cache = getConfig()
|
// val cache = getConfig()
|
||||||
return if (cache == null) {
|
// return if (cache == null) {
|
||||||
when(CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()?.cityCode ?: SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010") {
|
// when(CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()?.cityCode ?: SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010") {
|
||||||
"010" -> "北京"
|
// "010" -> "北京"
|
||||||
"0734" -> "衡阳"
|
// "0734" -> "衡阳"
|
||||||
else -> "未知"
|
// else -> "未知"
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
when(cache.first) {
|
// when(cache.first) {
|
||||||
"010" -> "北京"
|
// "010" -> "北京"
|
||||||
"0734" -> "衡阳"
|
// "0734" -> "衡阳"
|
||||||
else -> "未知"
|
// else -> "未知"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
return "未知"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConfigNetMode(): Int {
|
fun getConfigNetMode(): Int {
|
||||||
val cache = getConfig()
|
// val cache = getConfig()
|
||||||
return cache?.second ?: -1
|
// return cache?.second ?: -1
|
||||||
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getNetMode(): String {
|
fun getNetMode(): String {
|
||||||
val cache = getConfig()
|
// val cache = getConfig()
|
||||||
return if (cache == null) {
|
// return if (cache == null) {
|
||||||
when(DebugConfig.getNetMode()) {
|
// when(DebugConfig.getNetMode()) {
|
||||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
// DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||||
DebugConfig.NET_MODE_QA -> "测试"
|
// DebugConfig.NET_MODE_QA -> "测试"
|
||||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
// DebugConfig.NET_MODE_DEMO -> "演示"
|
||||||
else -> "未知"
|
// else -> "未知"
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
when(cache.second) {
|
// when(cache.second) {
|
||||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
// DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||||
DebugConfig.NET_MODE_QA -> "测试"
|
// DebugConfig.NET_MODE_QA -> "测试"
|
||||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
// DebugConfig.NET_MODE_DEMO -> "演示"
|
||||||
else -> "未知"
|
// else -> "未知"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
return "未知"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeTo(cityCode: String, netMode: Int) {
|
fun changeTo(cityCode: String, netMode: Int) {
|
||||||
updateCityCode(cityCode)
|
// updateCityCode(cityCode)
|
||||||
updateNetMode(netMode)
|
// updateNetMode(netMode)
|
||||||
restartApp()
|
// restartApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
updateCityCode(null)
|
// updateCityCode(null)
|
||||||
updateNetMode(-1)
|
// updateNetMode(-1)
|
||||||
restartApp()
|
// restartApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restartApp() {
|
private fun restartApp() {
|
||||||
Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName)?.also {
|
// Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName)?.also {
|
||||||
ActivityUtils.startActivity(it)
|
// ActivityUtils.startActivity(it)
|
||||||
}
|
// }
|
||||||
Process.killProcess(Process.myPid())
|
// Process.killProcess(Process.myPid())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEnvConfig(): EnvConfig? = getConfig()?.let {
|
fun getEnvConfig(): EnvConfig? = null
|
||||||
EnvConfig(it.first, it.second,
|
|
||||||
if (it.first == "010") 116.397446 else 112.582654,
|
|
||||||
if (it.first == "010") 39.909004 else 26.816478)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1272,6 +1272,7 @@
|
|||||||
android:background="@drawable/debug_setting_edit_bg"
|
android:background="@drawable/debug_setting_edit_bg"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
@@ -1307,7 +1308,7 @@
|
|||||||
android:text="设置刹车加速度阈值"
|
android:text="设置刹车加速度阈值"
|
||||||
android:textSize="@dimen/dp_24"
|
android:textSize="@dimen/dp_24"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/llChangeEnv" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user