diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/ext/Extentions.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/ext/Extentions.kt index 25a3ccdd0b..64e6279d23 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/ext/Extentions.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/ext/Extentions.kt @@ -144,13 +144,13 @@ fun Context.enqueuePop(content: View, width: Int, height: Int, key: String = "", @SuppressLint("ClickableViewAccessibility") -fun Context.normalPop(content: View, width: Int, height: Int, key: String = "", startX: Int = 0, startY: Int = 0, gravity: Int = Gravity.START, onOuterViewClicked:((focus: View) -> Unit)? = null, isFocusable: Boolean = true): () -> Unit { +fun Context.normalPop(content: View, width: Int, height: Int, startX: Int = 0, startY: Int = 0, gravity: Int = Gravity.START, onOuterViewClicked:((focus: View) -> Unit)? = null, isFocusable: Boolean = true): () -> Unit { val activity = (this as? FragmentActivity) ?: throw IllegalStateException("please use Activity to trigger pop show.") val isImmersiveMode = BarUtils.isImmersiveMode(activity) var tempPop: PopupWindow? = null activity.lifecycleScope.launchWhenResumed { + val decorView = activity.window.decorView val pop = PopupWindow(width, height).also { - tempPop = it it.isOutsideTouchable = true it.isTouchable = true it.isFocusable = isFocusable @@ -166,7 +166,6 @@ fun Context.normalPop(content: View, width: Int, height: Int, key: String = "", if (out.contains(event.x.toInt(), event.y.toInt()) && isVisibleOnPoint(content, event.x.toInt(), event.y.toInt())) { return@setTouchInterceptor false } - when(event.actionMasked) { MotionEvent.ACTION_DOWN -> { x = event.x @@ -187,7 +186,7 @@ fun Context.normalPop(content: View, width: Int, height: Int, key: String = "", try { return@setTouchInterceptor true } finally { - activity.window.decorView.dispatchTouchEvent(event) + decorView.dispatchTouchEvent(event) } } it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) @@ -201,7 +200,14 @@ fun Context.normalPop(content: View, width: Int, height: Int, key: String = "", pop.exitTransition = transition } pop.contentView = content - pop.showAtLocation(activity.window.decorView, gravity, startX, if (isImmersiveMode) 0 else BarUtils.getStatusBarHeight() + startY) + decorView.doOnAttach { + try { + pop.showAtLocation(it, gravity, startX, if (isImmersiveMode) 0 else BarUtils.getStatusBarHeight() + startY) + tempPop = pop + } catch (t: Throwable) { + t.printStackTrace() + } + } } return { tempPop?.takeIf { it.isShowing }?.dismiss() diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt index 0939955dcb..24c41bca56 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/entity/Status.kt @@ -121,7 +121,7 @@ internal class CanStatus(var enabled: Boolean = false): Status() { /** * 寻迹/算路/未知 */ -internal class TracingStatus(var state: Tracing): Status() { +internal class TracingStatus(var state: Tracing = UNKNOWN): Status() { enum class Tracing(val code: String? = "") { /** diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/can/CanImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/can/CanImpl.kt index 7096af4e37..c5fc03d2a9 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/can/CanImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/can/CanImpl.kt @@ -62,7 +62,7 @@ internal class CanImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotVehic private fun timeOutCheck() { job?.safeCancel() launch(Dispatchers.Default) { - delay(1000) + delay(4000) send(CanStatus(false)) }.also { job = it } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/nets/NetsImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/nets/NetsImpl.kt index 8c96e77dab..a7e6c9ebdb 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/nets/NetsImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/nets/NetsImpl.kt @@ -1,12 +1,16 @@ package com.zhjt.mogo_core_function_devatools.status.flow.nets +import android.* import android.content.* +import android.location.* import android.net.* import android.net.wifi.* import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.util.* +import androidx.core.location.* import com.mogo.eagle.core.utilcode.kotlin.* +import com.mogo.eagle.core.utilcode.util.* import com.zhjt.mogo_core_function_devatools.status.flow.IFlow import com.zhjt.mogo_core_function_devatools.status.entity.NetStatus import com.zhjt.mogo_core_function_devatools.status.entity.NetStatus.Speed @@ -90,7 +94,7 @@ internal class NetsImpl(ctx: Context): IFlow(ctx) { private fun checkAndSend() { val connectionInfo = wifiMgr.connectionInfo val enabled = isNetConnected() - val name = connectionInfo.ssid?.replace(Regex("[\\W]"), "") + val name = if (isLocationEnabled()) connectionInfo.ssid?.replace(Regex("[\\W]"), "") else "Wi-Fi" loopCheckAndSendJob?.safeCancel() launch(Dispatchers.Default) { delay(1000); checkAndSend() }.also { loopCheckAndSendJob = it } var tr = 0 @@ -106,6 +110,9 @@ internal class NetsImpl(ctx: Context): IFlow(ctx) { send(enabled, name, speed) } + private fun isLocationEnabled() = + LocationManagerCompat.isLocationEnabled(ctx.getSystemService(Context.LOCATION_SERVICE) as LocationManager) && PermissionUtils.isGranted(Manifest.permission.ACCESS_FINE_LOCATION) + private fun isNetConnected(): Boolean = if (VERSION.SDK_INT >= VERSION_CODES.M) { @@ -127,6 +134,5 @@ internal class NetsImpl(ctx: Context): IFlow(ctx) { connectMgr.unregisterNetworkCallback(cb) } loopCheckAndSendJob?.safeCancel() - } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt index babb29092b..addd4053f4 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/rtk/RTKImpl.kt @@ -4,32 +4,58 @@ import android.content.* import android.util.* import com.mogo.eagle.core.function.api.autopilot.* import com.mogo.eagle.core.function.call.autopilot.* +import com.mogo.eagle.core.utilcode.kotlin.* import com.zhjt.mogo_core_function_devatools.status.entity.RTKStatus import com.zhjt.mogo_core_function_devatools.status.flow.IFlow +import kotlinx.coroutines.* import mogo.telematics.pad.MessagePad.GnssInfo -internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotCarStateListener { +internal class RTKImpl(ctx: Context): IFlow(ctx), IMoGoAutopilotCarStateListener, IMoGoAutopilotStatusListener { companion object { const val TAG = "RTKImpl" } + private var job: Job? = null + override fun onCreate() { send(RTKStatus(isRTKEnabled())) Log.d(TAG, "-- onCreate --") CallerAutopilotCarStatusListenerManager.addListener(TAG, this) - + CallerAutoPilotStatusListenerManager.addListener(TAG, this) } private fun isRTKEnabled() = CallerAutoPilotManager.isConnected() && CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode() != "EHW_RTK" && CallerAutopilotCarStatusListenerManager.getCurrentGnssInfo() != null override fun onAutopilotCarStateData(gnssInfo: GnssInfo?) { + Log.d(TAG, "-- onAutopilotCarStateData --") send(RTKStatus(isRTKEnabled())) + timeOutCheck() + } + + override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) { + super.onAutopilotIpcConnectStatusChanged(status, reason) + if (!CallerAutoPilotManager.isConnected()) { + send(RTKStatus(false)) + } + } + + private fun timeOutCheck() { + job?.safeCancel() + launch(Dispatchers.Default) { + delay(4000) + send(RTKStatus(false)) + }.also { job = it } } override fun onDestroy() { super.onDestroy() Log.d(TAG, "-- onDestroy --") - CallerAutopilotCarStatusListenerManager.removeListener(TAG) + try { + CallerAutopilotCarStatusListenerManager.removeListener(TAG) + CallerAutoPilotStatusListenerManager.removeListener(TAG) + } finally { + job?.safeCancel() + } } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/trace/TracingImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/trace/TracingImpl.kt index 33c95a00b5..ebd92f11ed 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/trace/TracingImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/trace/TracingImpl.kt @@ -18,9 +18,9 @@ internal class TracingImpl(ctx: Context): IFlow(ctx), IMoGoAutopi override fun onCreate() { Log.d(TAG, "-- onCreate --") - val autoPilotReportMessageCode = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode() - old = autoPilotReportMessageCode - send(TracingStatus(autoPilotReportMessageCode.toState())) + val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode() + old = code + send(TracingStatus(code.toState())) CallerAutoPilotStatusListenerManager.addListener(TAG, this) } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt index 291ee63f15..ac6a9fb9f0 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/model/StatusModel.kt @@ -42,7 +42,6 @@ internal class StatusModel : ViewModel() { synchronized(old) { val v = old.get()?.second ?: status.value?.second ?: throw IllegalStateException("live data can't be null.") val nv = ArrayList(v).also { it.updateOrInsert(s) } - fixData(nv) val data = Pair(getExceptionStatus(nv), nv) old.set(data) Log.d(TAG, "status: $s") @@ -51,40 +50,6 @@ internal class StatusModel : ViewModel() { } } - private fun fixData(data: ArrayList) { - var netStatus: NetStatus? = null - var gpsStatus: GpsStatus? = null - for (d in data) { - if (d is NetStatus) { - netStatus = d - } - if (d is GpsStatus) { - gpsStatus = d - } - } - - if (netStatus != null && !netStatus.enabled) { - for (i in data) { - when(i) { - is RTKStatus -> - i.enabled = false - is CanStatus -> - i.enabled = false - is TracingStatus -> - i.state = UNKNOWN - else -> continue - } - } - } - - if (netStatus != null && gpsStatus != null) { - val wifiName = netStatus.name - if (!gpsStatus.enabled || !gpsStatus.isGranted || wifiName != null && wifiName.startsWith("unknow")) { - netStatus.name = "Wi-Fi" - } - } - } - private fun getExceptionStatus(l: ArrayList): Status? { var ret: Status? = null for (s in l) { @@ -118,9 +83,7 @@ internal class StatusModel : ViewModel() { } } is TracingStatus -> { - if (CallerAutoPilotManager.isConnected() && - (CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().pilotmode == 1) && - s.state.isException()) { + if (CallerAutoPilotManager.isConnected() && (CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().pilotmode == 1) && s.state.isException()) { s } else { null diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt index 01f2f90208..3febd674c3 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt @@ -176,7 +176,9 @@ class MoGoHmiFragment : MvpFragment(), setProxyNotificationView(V2XNotificationView(view.context)) context?.also { - CallerDevaToolsManager.showStatusBar(it) + if (!AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode)) { + CallerDevaToolsManager.showStatusBar(it) + } } }