Skip to content

Commit

Permalink
Hotfix: ZLink hanging up instead of starting call
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaggly committed Apr 7, 2023
1 parent 7309950 commit 98ed007
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 28
targetSdkVersion 33
versionCode 1
versionName "1.2.0"
versionName "1.2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.snaggly.ksw_toolkit.core.service
import android.app.AlertDialog
import android.app.Service
import android.content.Intent
import android.content.IntentFilter
import android.os.IBinder
import android.view.WindowManager
import android.widget.Toast
Expand All @@ -13,6 +14,8 @@ import com.snaggly.ksw_toolkit.core.service.mcu.McuReaderHandler
import com.snaggly.ksw_toolkit.core.service.mcu.PreCheckLogcat
import com.snaggly.ksw_toolkit.core.service.remote.KSWToolKitService
import com.snaggly.ksw_toolkit.core.service.remote.ServiceValidation
import com.snaggly.ksw_toolkit.receiver.ZLinkReceiver
import com.wits.pms.bean.ZlinkMessage
import kotlin.random.Random

class CoreService : Service() {
Expand Down Expand Up @@ -48,8 +51,12 @@ class CoreService : Service() {

override fun onCreate() {
PreCheckLogcat().getLightsStatus()

val zLinkReceiver = ZLinkReceiver()
registerReceiver(zLinkReceiver, IntentFilter(ZlinkMessage.ZLINK_NORMAL_ACTION))

try {
val lMcuReaderHandler = McuReaderHandler(applicationContext)
val lMcuReaderHandler = McuReaderHandler(applicationContext, zLinkReceiver)
lMcuReaderHandler.startMcuReader()
mcuReaderHandler = lMcuReaderHandler
kswToolKitService = KSWToolKitService(lMcuReaderHandler)
Expand All @@ -72,7 +79,7 @@ class CoreService : Service() {
}

private fun startTest() {
val lMcuReaderHandler = McuReaderHandler(applicationContext)
val lMcuReaderHandler = McuReaderHandler(applicationContext, ZLinkReceiver())
mcuReaderHandler = lMcuReaderHandler
kswToolKitService = KSWToolKitService(lMcuReaderHandler)
McuLogic.mcuCommunicator = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.snaggly.ksw_toolkit.core.service.mcu.action.screen_switch.*
import com.snaggly.ksw_toolkit.core.service.mcu.parser.*
import com.snaggly.ksw_toolkit.core.service.sys_observers.BrightnessObserver
import com.snaggly.ksw_toolkit.core.service.view.BackTapper
import com.snaggly.ksw_toolkit.receiver.ZLinkReceiver
import com.snaggly.ksw_toolkit.util.brightnesstools.AdvancedBrightnessHandler
import com.snaggly.ksw_toolkit.util.manager.AutoThemeManager
import com.snaggly.ksw_toolkit.util.brightnesstools.DaytimeObserver
Expand All @@ -24,7 +25,7 @@ import projekt.auto.mcu.ksw.serial.reader.SerialReader
import projekt.auto.mcu.ksw.serial.writer.SerialWriter
import kotlin.collections.ArrayList

class McuReaderHandler(val context: Context) {
class McuReaderHandler(val context: Context, zLinkReceiver: ZLinkReceiver) {
val config = ConfigManager.getConfig(context)

private val backTapper = BackTapper(context)
Expand All @@ -34,7 +35,7 @@ class McuReaderHandler(val context: Context) {
private var eventAction : EventAction? = null
private var parseMcuEvent = McuEvent(context, backTapper)
private val daytimeObserver = DaytimeObserver(context)
private val autoThemeManager = AutoThemeManager(context)
private val autoThemeManager = AutoThemeManager(context, zLinkReceiver)

init {
when {
Expand Down
93 changes: 62 additions & 31 deletions app/src/main/java/com/snaggly/ksw_toolkit/receiver/ZLinkReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.snaggly.ksw_toolkit.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.wits.pms.bean.ZlinkMessage
import com.wits.pms.handler.ZLinkHandler
import com.wits.pms.statuscontrol.PowerManagerApp
Expand All @@ -22,12 +23,28 @@ class ZLinkReceiver : BroadcastReceiver(), ICustomReceiver<ZLinkReceiver.ZLinkDa
Unknown
}

data class ZLinkData(var currentConnection: Connection, var isShowing: Boolean, var isCalling: Boolean)
data class ZLinkData(
var currentConnection: Connection,
var isShowing: Boolean,
var isCalling: Boolean,
var isRinging: Boolean,
var mainAudio: Boolean,
var siriOn: Boolean //Interesting quirk: During a phone call this turns on
)
/*
Calling flows as:
PHONE_RING_ON
PHONE_CALL_ON
MAIN_AUDIO_START (<- up to here ringer still going- not actually calling)
PHONE_RING_OFF (<- clicked on accept)
SIRI_ON
SIRI_OFF (<- clicked on hang up)
PHONE_CALL_OFF
MAIN_AUDIO_STOP
*/

companion object {
val CurrentDataSet : ZLinkData
get() {
return ZLinkData(
val CurrentDataSet = ZLinkData(
currentConnection = if (SystemProperties.get(ZlinkMessage.ZLINK_CONNECT) == "1") Connection.CarPlayWireless
else if (SystemProperties.get(ZlinkMessage.ZLINK_CARPLAY_WRIED_CONNECT) == "1") Connection.CarPlayWired
else if (SystemProperties.get(ZlinkMessage.ZLINK_ANDROID_AUTO_CONNECT) == "1") Connection.AndroidAutoWired
Expand All @@ -37,49 +54,63 @@ class ZLinkReceiver : BroadcastReceiver(), ICustomReceiver<ZLinkReceiver.ZLinkDa
else if (SystemProperties.get(ZlinkMessage.ZLINK_ANDROID_MIRROR_CONNECT) == "1") Connection.AndroidMirrorWired
else Connection.Disconnected,
isShowing = ZLinkHandler.isUsing(),
isCalling = ZLinkHandler.isCalling()
isCalling = ZLinkHandler.isCalling(),
isRinging = ZLinkHandler.isRinging(),
mainAudio = false,
siriOn = false
)
}
}

private var callBackHandler : ((ZLinkData) -> Unit)? = null
var dataSet = CurrentDataSet
private set

override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action != ZlinkMessage.ZLINK_NORMAL_ACTION)
return

val message = ZlinkMessage(intent)

when (message.status) {
"DISCONNECT" -> {
dataSet.currentConnection = Connection.Disconnected
}
"CONNECTED" -> {
dataSet.currentConnection = when (message.bundle.getString("phoneMode")) {
"carplay_wired" -> Connection.CarPlayWired
"carplay_wireless" -> Connection.CarPlayWireless
"airplay_wired" -> Connection.AirPlayWired
"airplay_wireless" -> Connection.AirPlayWireless
"auto_wired" -> Connection.AndroidAutoWired
"auto_wireless" -> Connection.AndroidAutoWireless
"android_mirror_wired" -> Connection.AndroidMirrorWired
"android_mirror_wireless" -> Connection.AndroidMirrorWireless
else -> Connection.Unknown
if (message.status != null) {
when (message.status) {
"DISCONNECT" -> {
CurrentDataSet.currentConnection = Connection.Disconnected
}
"CONNECTED" -> {
CurrentDataSet.currentConnection =
when (message.bundle.getString("phoneMode")) {
"carplay_wired" -> Connection.CarPlayWired
"carplay_wireless" -> Connection.CarPlayWireless
"airplay_wired" -> Connection.AirPlayWired
"airplay_wireless" -> Connection.AirPlayWireless
"auto_wired" -> Connection.AndroidAutoWired
"auto_wireless" -> Connection.AndroidAutoWireless
"android_mirror_wired" -> Connection.AndroidMirrorWired
"android_mirror_wireless" -> Connection.AndroidMirrorWireless
else -> Connection.Unknown
}
}
"MAIN_PAGE_SHOW" -> {
CurrentDataSet.isShowing = true
}
"MAIN_PAGE_HIDDEN" -> {
CurrentDataSet.isShowing = false
}
// Following don't seem to work for Android Auto!
"PHONE_CALL_ON" -> CurrentDataSet.isCalling = true
"PHONE_CALL_OFF" -> CurrentDataSet.isCalling = false
"PHONE_RING_ON" -> CurrentDataSet.isRinging = true
"PHONE_RING_OFF" -> CurrentDataSet.isRinging = false
"MAIN_AUDIO_START" -> CurrentDataSet.mainAudio = true
"MAIN_AUDIO_STOP" -> CurrentDataSet.mainAudio = false
}
"MAIN_PAGE_SHOW" -> {
dataSet.isShowing = true
}
"MAIN_PAGE_HIDDEN" -> {
dataSet.isShowing = false
}
else if (message.command != null) {
when (message.command) {
"SIRI_ON" -> CurrentDataSet.siriOn = true
"SIRI_OFF" -> CurrentDataSet.siriOn = false
}
"PHONE_CALL_ON" -> dataSet.isCalling = true //Doesn't seem to work for Android Auto!
"PHONE_CALL_OFF" -> dataSet.isCalling = false
}

callBackHandler?.let { it(dataSet) }
callBackHandler?.let { it(CurrentDataSet) }
}

override fun setReceiverHandler(handler: (ZLinkData) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ import com.wits.pms.bean.ZlinkMessage
import com.wits.pms.handler.ZLinkHandler
import com.snaggly.ksw_toolkit.receiver.ZLinkReceiver.Connection

class AutoThemeManager(val context: Context) {
class AutoThemeManager(val context: Context, private val zLinkReceiver: ZLinkReceiver) {
private val uiModeManager = context.getSystemService(UiModeManager::class.java)
private val zLinkHandler = ZLinkHandler(context)
private val zLinkReceiver = ZLinkReceiver()

private var isAnyLightOn = false
private var isNightTime = false

init {
context.applicationContext.registerReceiver(zLinkReceiver, IntentFilter(ZlinkMessage.ZLINK_NORMAL_ACTION))
}

private fun handleThemeChange() {
if (isAnyLightOn || isNightTime) {
if (zLinkReceiver.dataSet.isShowing && zLinkReceiver.dataSet.currentConnection != Connection.Disconnected) {
if (ZLinkReceiver.CurrentDataSet.isShowing && ZLinkReceiver.CurrentDataSet.currentConnection != Connection.Disconnected) {
zLinkHandler.setDarkTheme()
zLinkReceiver.setReceiverHandler {
if (!it.isShowing) {
Expand All @@ -43,7 +38,7 @@ class AutoThemeManager(val context: Context) {
}
}
else {
if (zLinkReceiver.dataSet.isShowing && zLinkReceiver.dataSet.currentConnection != Connection.Disconnected) {
if (ZLinkReceiver.CurrentDataSet.isShowing && ZLinkReceiver.CurrentDataSet.currentConnection != Connection.Disconnected) {
zLinkHandler.setLightTheme()
zLinkReceiver.setReceiverHandler {
if (!it.isShowing) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/wits/pms/handler/CallHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ private static void zlinkHandleAutoCall(Context context) {
private static void zlinkHandleCall(Context context) {
String callStatus = SystemProperties.get(ZlinkMessage.ZLINK_CALL);
Log.d("CenterControl", "zlinkHandleCall callStatus = " + callStatus);
if (callStatus.equals(ZlinkMessage.ZLINK_CALL_OFF)) {
zlinkCallOn(context);
} else if (callStatus.equals(ZlinkMessage.ZLINK_CALL_ON)) {
if (callStatus.equals("2")) {
zlinkCallOff(context);
} else {
zlinkCallOn(context);
}
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/wits/pms/handler/ZLinkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public static boolean isConnected() {
|| (Objects.equals(SystemProperties.get(ZlinkMessage.ZLINK_ANDROID_MIRROR_CONNECT), "1"));
}

public static boolean isRinging() {
return Objects.equals(SystemProperties.get(ZlinkMessage.ZLINK_CALL), "1")
|| PowerManagerApp.getStatusInt("callStatus") == 6;
}

public static boolean isCalling() {
return Objects.equals(SystemProperties.get(ZlinkMessage.ZLINK_CALL), "1") || PowerManagerApp.getStatusInt("callStatus") == 6;
return Objects.equals(SystemProperties.get(ZlinkMessage.ZLINK_CALL), "2")
|| PowerManagerApp.getStatusInt("callStatus") == 6;
}

private final Context mContext;
Expand Down

0 comments on commit 98ed007

Please sign in to comment.