In all seriousness though, if you modified something that reduced the safety of the vehicle and someone is harmed, I can only assume that would be a factor in the legal finding. I am not a lawyer however.
People can put random android radios into their cars, and nobody cares. And code quality will probably be quite atrocious.
A lot of infotainment systems lock out some features when the car is moving. For example, watching a DVD on the dashboard screen of a moving car is not normally possible. People share workarounds for that kind of thing on car enthusiast forums.
If someone removed restrictions from their infotainment system, and they were involved in an accident while using that system, it might come up if the matter went to court.
It could be brought up in court as piece of a larger effort to show negligence or actual lawbreaking.
For instance, in my state it's entirely legal to have a video system that is capable of showing video that is visible to the driver, but it's entirely illegal to use that system in a way that makes the video visible to the driver. So while having the system installed is legal, it could also be a piece of a larger collection of evidence showing wrongdoing.
Using the modified device where the public vehicle code applies might be, even if making the modification, alone, is not strictly illegal. (For instance use of the device so modified would be illegal on a public road in California, where it would violate the screen use law, which only allows screen use if it has a lockout of all but specified allowed functions while the vehicle is moving. Note that under the text, even if only the functions permitted while a vehicle is in operation are actually used, it would still violate the law to use the device if the lockout was disabled so that it was possible to use other functions.) Cal. Vehicle Code § 27602.
IMO (not a lawyer) the result is what the legal question would be. If you modified your car and it started pumping out emissions that would be otherwise illegal I'd be a bit concerned about that.
And once we decide which firmware in what CPU is being modified, now we get into what exactly the changes are.
In short, usually it's fine. In some extreme cases it's not.
I don't think there are different legal requirements for electric vs gasoline cars. In both cases, you can modify them all you want without running afoul of the laws about motor vehicles.
However, in both cases, you can absolutely make modifications that render the vehicle no longer street legal. Removing the turn signals would do it, for instance.