[Android Head-Units] homer.ali:
Hey guys need some help;

I believe I can fix a lot of bugs that are in this unit but I feel like i'm re-inventing the wheel here. Hoping I can benefit from your shared experience and expertise here.

I decompiled eventcenter.apk and added a few logging lines to a few methods so I can trace what happens when something in the car is triggered (steering wheel button, brake pressed, etc) all the way to the translated android action.

I thought I had it but something is not adding up.

My understanding is that hardware signals get picked up by the MCU which then communicates with android via EventCenter when eventservice opens the serial port. This is supported by the following code blocks;

public void openSerialPort() {
try {
if (this.msp == null) {
this.msp = new ZXWSerialPort();
this.msp.open(EventUtils.getMcuComDevicePath(), EventUtils.UART_DEV_SPEED);
startProcessCmdThread();
startReceiveThread();
startSendThread();
}
} catch (Exception e) {
e.printStackTrace();
}
}

where openSerialPort() is called on initSysEventState method and startProcessCmdThread calls a message handler on a loop and if it has data, calls processcmd()

if (bybuf != null && bybuf.length > 0) {
try {
processCmd(bybuf);
} catch (Exception e) {
DebugLog.i(EventService.TAG, "processCmd error: " + e.toString());
}
}

Finally, processCmd just has a switch statement which determines which method to call based on the first numbers in the buffer array.

private void processCmd(byte[] bydata) {
switch (bydata[0]) {
case Byte.MIN_VALUE:
onCmdFreqSelectEvt(bydata);
return;
case -127:
onCmdModePowerOnEvt(bydata);
return;
case -126:
onCmdDiscAutoInEvt(bydata);
return;

case -125:
onCmdSysRTCTimeEvt(bydata);
return;
case -122:
onCmd8825ValEvent(bydata);
return;
case -120:
OnCmdWheelState(bydata);
return;
case -115:
onCmdMcuIRRadarData(bydata);
return;
case -114:
onCmdMcu3DHData(bydata);
return;
case -108:
Intent intent = new Intent("com.szchoiceway.eventcenter.EventUtils.ACTION_MCU_8836_VALUE_EVENT");
intent.putExtra("EventUtils.MCU_8836_VALUE_DATA", bydata);
EventService.this.sendBroadcastAsUser(intent, UserHandle.ALL);
return;
case -107:
onCmdMcuHdmiResolutionData(bydata);
return;
case -95:
onCmdCarAirEvent(bydata);
return;
case -91:
onCmdCanEvent(bydata);
return;
case -90:
onCmdMcuATAData(bydata);
return;
case EventUtils.CARTYPE_U6_LO /*109*/:
onCmdMcuPlugInRadarData(bydata);
return;
case EventUtils.CARTYPE_SenyaR7_HI /*112*/:
onCmdModeAck(bydata);
return;
case EventUtils.CARTYPE_Kaluola_LO /*113*/:
onCmdSysEvent(bydata);
return;
case EventUtils.CARTYPE_Kaluola_HI /*114*/:
onCmdKeyEvent(bydata);
return;
case EventUtils.CARTYPE_Siyu2016_LO /*115*/:
onCmdRadioEvent(bydata);
return;
case 116:
onCmdWheelEvent(bydata);
return;
case 117:
onCmdTVEvent(bydata);
return;
case EventUtils.CARTYPE_SLS_HI /*118*/:
onCmdBMTVolEvent(bydata);
return;
case EventUtils.CARTYPE_2013EXPLORER_LO /*119*/:
onCmdEQEvent(bydata);
return;
case 120:
onCmdMuteEvent(bydata);
return;
case EventUtils.CARTYPE_CRIDER_LO /*121*/:
onCmdMainVolEvent(bydata);
return;
case EventUtils.CARTYPE_CRIDER_HI /*122*/:
onCmdBalanceEvent(bydata);
return;
case EventUtils.CARTYPE_BIAOZHI408_LO /*123*/:
onCmdLoudnessEvent(bydata);
return;
case EventUtils.CARTYPE_BIAOZHI408_HI /*124*/:
onCmdMcuInitEvent(bydata);
return;
case 126:
onCmdKeyADEvent(bydata);
return;
case Byte.MAX_VALUE:
onCmdUpgradeAck(bydata);
return;
default:
return;
}
}

Based on this logic above I assumed I should be able to capture the direct MCU data by simply hooking onto the data sent to processCMD method before it decides what to do with it. To test this, I added a Log to the smali right at the beginning of that method which gives me the string formatted form of the bybuf array. However, the data sent to processCMD doesn't seem to make any sense when trying to relate it to physical events in the car.

For example, here is a portion of my logcat; during this time, I started by doing nothing then I pressed a couple of unassigned steering wheel buttons.

08-15 13:11:26.554 1167 1433 I EventService: onCmdMainVolEvent = 0x79 0x05 0x7e
08-15 13:11:26.570 1167 1433 I ProcessCMD: : 0x8e 0x20 0x03 0xc0 0xeb 0xc0 0x3d 0x9e
08-15 13:11:26.667 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0xf0 0xeb 0x70 0x3d 0x5f
08-15 13:11:26.766 1167 1433 I ProcessCMD: : 0x8e 0x50 0x02 0xb0 0xeb 0x20 0x3c 0x20
08-15 13:11:26.868 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x01 0xc0 0xeb 0x30 0x3d 0x80
08-15 13:11:26.967 1167 1433 I ProcessCMD: : 0x8e 0xc0 0x01 0xc0 0xeb 0xd0 0x3d 0xf0
08-15 13:11:27.067 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0xc0 0xeb 0x10 0x3e 0x6e
08-15 13:11:27.166 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0x10 0xec 0x40 0x3e 0x7d
08-15 13:11:27.267 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0x00 0xec 0x20 0x3e 0xad
08-15 13:11:27.368 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0xe0 0xeb 0xa0 0x3c 0x40
08-15 13:11:27.467 1167 1433 I ProcessCMD: : 0x8e 0x30 0x02 0x40 0xeb 0xe0 0x3c 0xf0
08-15 13:11:27.568 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0x80 0xeb 0x20 0x3d 0x3f
08-15 13:11:27.667 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0x70 0xeb 0xc0 0x3d 0x3f
08-15 13:11:27.767 1167 1433 I ProcessCMD: : 0x8e 0x10 0x03 0x90 0xeb 0xd0 0x3d 0xce
08-15 13:11:27.868 1167 1433 I ProcessCMD: : 0x8e 0xb0 0x02 0x00 0xec 0xe0 0x3d 0xae
08-15 13:11:27.966 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0xd0 0xeb 0x50 0x3c 0xa0
08-15 13:11:28.067 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0x70 0xeb 0xd0 0x3c 0x00
08-15 13:11:28.166 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0x90 0xeb 0x40 0x3c 0x60
08-15 13:11:28.267 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0x90 0xeb 0xf0 0x3c 0xb0
08-15 13:11:28.368 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0xc0 0xeb 0xc0 0x3c 0x50
08-15 13:11:28.466 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0xa0 0xeb 0xe0 0x3d 0x1f
08-15 13:11:28.567 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0x90 0xeb 0xf0 0x3a 0x52
08-15 13:11:28.667 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0x70 0xeb 0x70 0x3a 0x92
08-15 13:11:28.767 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x02 0x80 0xeb 0x20 0x39 0xb3
08-15 13:11:28.868 1167 1433 I ProcessCMD: : 0x8e 0xb0 0x02 0x60 0xeb 0x60 0x38 0xd4
08-15 13:11:28.967 1167 1433 I ProcessCMD: : 0x8e 0x70 0x03 0xb0 0xeb 0xe0 0x38 0x43
08-15 13:11:29.067 1167 1433 I ProcessCMD: : 0x8e 0x20 0x03 0xa0 0xeb 0xf0 0x39 0x92
08-15 13:11:29.167 1167 1433 I ProcessCMD: : 0x8e 0x50 0x03 0x00 0xec 0x10 0x39 0xe1
08-15 13:11:29.266 1167 1433 I ProcessCMD: : 0x8e 0x30 0x03 0x00 0xec 0xc0 0x38 0x52
08-15 13:11:29.369 1167 1433 I ProcessCMD: : 0x8e 0x00 0x03 0xd0 0xeb 0x00 0x38 0x73
08-15 13:11:29.369 1167 1433 I ProcessCMD: : 0x71 0x01 0x00 0x89
08-15 13:11:29.369 1167 1433 I EventService: onCmdSysEvent: 0x71 0x01 0x00 0x89
08-15 13:11:29.467 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x02 0xd0 0xeb 0xc0 0x37 0xc5
08-15 13:11:29.567 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0x20 0xec 0xd0 0x37 0x84
08-15 13:11:29.667 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0x00 0xec 0x60 0x39 0x02
08-15 13:11:29.766 1167 1433 I ProcessCMD: : 0x8e 0x20 0x03 0x50 0xec 0x80 0x3a 0x50
08-15 13:11:29.868 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0x50 0xec 0x20 0x3b 0xf0
08-15 13:11:29.968 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0x20 0xec 0x30 0x3b 0x10
08-15 13:11:30.066 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0xf0 0xeb 0x60 0x3b 0x21
08-15 13:11:30.166 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0x10 0xec 0x70 0x3b 0x60
08-15 13:11:30.266 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0xf0 0xeb 0x40 0x3b 0x91
08-15 13:11:30.368 1167 1433 I ProcessCMD: : 0x8e 0x40 0x02 0xe0 0xeb 0x00 0x3d 0x1f
08-15 13:11:30.467 1167 1433 I ProcessCMD: : 0x8e 0x20 0x02 0x20 0xec 0x50 0x3d 0xae
08-15 13:11:30.567 1167 1433 I ProcessCMD: : 0x8e 0x30 0x02 0x20 0xec 0xe0 0x3d 0x0e
08-15 13:11:30.666 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0x60 0xec 0xa0 0x3d 0xde
08-15 13:11:30.767 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0x20 0xec 0xb0 0x3d 0x5e
08-15 13:11:30.868 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0xe0 0xeb 0x50 0x3c 0x00
08-15 13:11:30.967 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x01 0x90 0xeb 0x50 0x3d 0x80
08-15 13:11:31.067 1167 1433 I ProcessCMD: : 0x8e 0x40 0x02 0x20 0xec 0x60 0x3d 0x7e
08-15 13:11:31.167 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0xe0 0xeb 0x20 0x3e 0x9e
08-15 13:11:31.267 1167 1433 I ProcessCMD: : 0x8e 0x00 0x03 0xd0 0xeb 0xf0 0x3d 0x7e
08-15 13:11:31.368 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0xe0 0xeb 0xe0 0x3d 0x9f
08-15 13:11:31.467 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0xc0 0xeb 0xa0 0x3c 0x70
08-15 13:11:31.567 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0x60 0xeb 0x30 0x3d 0x9f
08-15 13:11:31.574 1167 4828 W libEGL : EGLNativeWindowType 0x77d8ee1010 disconnect failed
08-15 13:11:31.667 1167 1433 I ProcessCMD: : 0x8e 0x30 0x02 0xa0 0xeb 0x00 0x3d 0x6f
08-15 13:11:31.767 1167 1433 I ProcessCMD: : 0x8e 0x20 0x02 0x80 0xeb 0x00 0x3e 0x9e
08-15 13:11:31.868 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0xb0 0xeb 0xf0 0x3d 0xff
08-15 13:11:31.967 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0xb0 0xeb 0x60 0x3e 0xce
08-15 13:11:32.067 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0x80 0xeb 0x90 0x3c 0xd0
08-15 13:11:32.167 1167 1433 I ProcessCMD: : 0x8e 0x30 0x02 0x10 0xeb 0x00 0x3d 0xff
08-15 13:11:32.267 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0x40 0xeb 0xe0 0x3c 0xb0
08-15 13:11:32.368 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0x90 0xeb 0x10 0x3d 0x1f
08-15 13:11:32.467 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0xb0 0xeb 0xb0 0x3d 0xff
08-15 13:11:32.567 1167 1433 I ProcessCMD: : 0x8e 0x90 0x02 0x90 0xeb 0xd0 0x3d 0x4f
08-15 13:11:32.667 1167 1433 I ProcessCMD: : 0x8e 0x40 0x02 0x70 0xeb 0x10 0x3c 0x80
08-15 13:11:32.767 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x01 0x70 0xeb 0xb0 0x3c 0x31
08-15 13:11:32.867 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0xa0 0xeb 0x50 0x3c 0x50
08-15 13:11:32.967 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0x80 0xeb 0xf0 0x3b 0xd1
08-15 13:11:33.067 1167 1433 I ProcessCMD: : 0x8e 0x60 0x02 0xe0 0xeb 0x40 0x3c 0xc0
08-15 13:11:33.167 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0xd0 0xeb 0x70 0x3c 0x90
08-15 13:11:33.266 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0xb0 0xeb 0x70 0x3b 0xa1
08-15 13:11:33.369 1167 1433 I ProcessCMD: : 0x8e 0x30 0x02 0x70 0xeb 0x10 0x3b 0x91
08-15 13:11:33.369 1167 1433 I ProcessCMD: : 0x71 0x01 0x00 0x89
08-15 13:11:33.369 1167 1433 I EventService: onCmdSysEvent: 0x71 0x01 0x00 0x89
08-15 13:11:33.467 1167 1433 I ProcessCMD: : 0x8e 0x70 0x02 0x60 0xeb 0xf0 0x3a 0x82
08-15 13:11:33.567 1167 1433 I ProcessCMD: : 0x8e 0xb0 0x02 0x20 0xeb 0x80 0x3a 0xf2
08-15 13:11:33.666 1167 1433 I ProcessCMD: : 0x8e 0x20 0x03 0x20 0xeb 0x20 0x3b 0xe0
08-15 13:11:33.766 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x02 0x80 0xeb 0x00 0x3c 0xd0
08-15 13:11:33.868 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0xa0 0xeb 0x40 0x3a 0x92
08-15 13:11:33.967 1167 1433 I ProcessCMD: : 0x8e 0x90 0x02 0x40 0xeb 0xd0 0x3a 0xa2
08-15 13:11:34.067 1167 1433 I ProcessCMD: : 0x8e 0x50 0x02 0x40 0xeb 0xd0 0x3a 0xe2
08-15 13:11:34.167 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0x70 0xeb 0xa0 0x3b 0x31
08-15 13:11:34.267 1167 1433 I ProcessCMD: : 0x8e 0x80 0x02 0x80 0xeb 0xe0 0x3b 0x61
08-15 13:11:34.368 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0x60 0xeb 0xa0 0x3c 0xa0
08-15 13:11:34.467 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0x50 0xeb 0xd0 0x3a 0x82
08-15 13:11:34.566 1167 1433 I ProcessCMD: : 0x8e 0xb0 0x02 0x30 0xeb 0x70 0x3b 0xf1
08-15 13:11:34.667 1167 1433 I ProcessCMD: : 0x8e 0xc0 0x02 0x30 0xeb 0xb0 0x3a 0xa2
08-15 13:11:34.766 1167 1433 I ProcessCMD: : 0x8e 0xc0 0x02 0x50 0xeb 0x90 0x3a 0xa2
08-15 13:11:34.868 1167 1433 I ProcessCMD: : 0x8e 0x10 0x03 0xb0 0xeb 0x70 0x3b 0x10
08-15 13:11:34.967 1167 1433 I ProcessCMD: : 0x8e 0xe0 0x02 0xa0 0xeb 0x80 0x3c 0x40
08-15 13:11:35.067 1167 1433 I ProcessCMD: : 0x8e 0xb0 0x02 0xc0 0xeb 0xf0 0x3a 0xe2
08-15 13:11:35.167 1167 1433 I ProcessCMD: : 0x8e 0x50 0x02 0xc0 0xeb 0x20 0x3b 0x11
08-15 13:11:35.267 1167 1433 I ProcessCMD: : 0x8e 0x00 0x02 0x70 0xeb 0xe0 0x3a 0xf2
08-15 13:11:35.368 1167 1433 I ProcessCMD: : 0x8e 0x50 0x02 0x90 0xeb 0xe0 0x3a 0x82
08-15 13:11:35.467 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x02 0x30 0xec 0x50 0x3c 0xcf
08-15 13:11:35.567 1167 1433 I ProcessCMD: : 0x8e 0xc0 0x02 0x00 0xec 0xe0 0x3c 0x9f
08-15 13:11:35.667 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0x10 0xec 0x00 0x3c 0x5f
08-15 13:11:35.766 1167 1433 I ProcessCMD: : 0x8e 0x90 0x02 0xa0 0xeb 0xf0 0x3b 0x21
08-15 13:11:35.868 1167 1433 I ProcessCMD: : 0x8e 0x90 0x02 0x90 0xeb 0xb0 0x3c 0x70
08-15 13:11:35.967 1167 1433 I ProcessCMD: : 0x8e 0xc0 0x02 0x50 0xeb 0xf0 0x3c 0x40
08-15 13:11:36.067 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0xc0 0xeb 0x90 0x3d 0x1f
08-15 13:11:36.166 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x02 0x00 0xec 0xd0 0x3d 0x9e
08-15 13:11:36.267 1167 1433 I ProcessCMD: : 0x8e 0x90 0x02 0x10 0xec 0x90 0x3c 0x0f
08-15 13:11:36.368 1167 1433 I ProcessCMD: : 0x8e 0xf0 0x01 0x70 0xeb 0xf0 0x3c 0xf1
08-15 13:11:36.466 1167 1433 I ProcessCMD: : 0x8e 0xd0 0x01 0xb0 0xeb 0xe0 0x3c 0xe1
08-15 13:11:36.567 1167 1433 I ProcessCMD: : 0x8e 0x10 0x02 0x90 0xeb 0xa0 0x3d 0xff
08-15 13:11:36.667 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0x80 0xeb 0xf0 0x3d 0x2f
08-15 13:11:36.766 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x02 0xe0 0xeb 0x30 0x3f 0x8d
08-15 13:11:36.868 1167 1433 I ProcessCMD: : 0x8e 0xa0 0x01 0xb0 0xeb 0x00 0x3e 0xef

I can't seem to make sense of this stream especially since if I then assign that same steering wheel button via the settings app and then press it, i immediately get this in my logcat:

08-15 13:11:26.239 1167 1433 I ProcessCMD: : 0x72 0x12 0x78
08-15 13:11:26.242 1167 1433 I ProcessCMD: : 0x79 0x04 0x7f
08-15 13:11:26.242 1167 1433 I EventService: onCmdMainVolEvent = 0x79 0x04 0x7f

What am I missing here?

Does assigning an action to the steering wheel button somehow change the serial stream being sent by the MCU to EventCenter? or is the MCU communicating with some other method I haven't been able to find?