[MTCD Software Development] doitright:
This is mostly for the new Joying INTEL units.

*********************************************

OLD STUFF: aka "BlueBalls.apk"

The bluetooth stack on these units appears to be ENTIRELY functional, but for whatever reason (don't ask me to guess at the thought processes that go into developing a head unit in China....) they HIDE the button in the Settings application that links to BLUETOOTH settings.

This is the simplest/dumbest application anyone has ever written.

The code inside it is literally JUST the following THREE LINES;

Intent intentOpenBluetoothSettings = new Intent();
intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intentOpenBluetoothSettings);

It launches the bluetooth settings activity that Joying has hidden.

**************************************************

NEW STUFF!!!!

Ok, so the thing is, even with blueballs installed, the process of tethering is somewhat... MANUAL. On both sides of the connection -- data source, typically your phone, and head unit. Wouldn't it be nice to AUTOMATE things a little bit?

While there are some guides and hackish programs that suggest that they can get this done, for instance http://xdaforums.com/showthread.php?t=2574310 -- the reality is that NONE of these solutions will actually WORK, nor are they simple to configure, nor are they reliable. They are a BIG UGLY MESS.

So I decided to do it myself, in a nice, clean, self-contained Android application.

The result is the BluetoothTethering.apk attached below.

Here is description of this program;

Start up the program, and you are presented with a screen with some buttons, switches, and spinners.

FOR THE CAR RADIO SIDE:

At the top of the screen is a spinner containing a list of all paired bluetooth devices. If you select one of those devices, and hit the "CONNECT PAN" button, it will try to connect to that device as a bluetooth tethering client. If you enable the switch "Auto Connect PAN", then whenever it connects to that device (the one currently showing in the spinner), it will AUTOMATICALLY try to connect PAN. The application does NOT need to be running for this to occur, since there is a receiver registered in the application's manifest.

The next button down, "Launch Bluetooth Settings", just launches the standard Android Settings --> Bluetooth activity. This is the same as what BlueBalls does, so you don't need to install both.

FOR THE PHONE SIDE:

At the bottom, there is a button "START SERVICE", hit that button on your phone, and it should start up bluetooth tethering service.

And the switch "Auto Bluetooth Tethering", means that every time the bluetooth device turns ON, it will automatically enable bluetooth tethering. Again, it receives an intent and does the work in the background, so the application need not be open.

CAVEATS!!!

Ok, this is where the fun begins! Starting with Android version 3.1, newly installed applications are given a default state of "stopped", in which they are unable to receive any broadcast intents. In order to get the application out of the stopped state such that it can receive broadcast intents, it needs to be manually run first. A second part of this feature, is that if an application is force stopped, it is RETURNED to the "stopped" state. This becomes a problem on at least some Chinese Android car radios. In particular, it is a problem on at LEAST Joying units (possibly also others). In these units, when the car ignition is turned off, after a few minutes they go to SLEEP mode so that they don't drain the car's battery. The problem is that just before going to sleep, everything running is FORCE STOPPED, sending everything, INCLUDING BluetoothTethering.apk, into a "stopped" state, thus disabling the application's ability to receive the broadcast intent necessary in order to activate PAN!

Workaround:

NOW TESTED AND VERIFIED FUNCTIONAL

... provisioning the application with enhanced privileges, by installing it into /system/priv-app/, will allow it to avoid the "stopped" state, or at least allow it to receive broadcast intents regardless of that state. After all, there are many system receivers that fire as expected, even if you don't manually open the applicable application manually!

If you are going to do this (which you MUST on Joying Intel car radios, and possibly other MTCD Intel car radios), the steps are as follows;

Connect it and a laptop (with adb installed) to a common wifi network. This CAN be a hotspot running on the head unit or laptop, or even your PHONE. Just as long as they are all on the same network! Find the IP address of the head unit. If the head unit is connected to a different AP rather than hosting a hotspot, you can look in wifi --> 3dots menu --> advanced. If the head unit IS the hotspot, then look at your laptop (terminal --> ifconfig) and find ITS IP address (for example, 192.168.30.123) and change the last byte to a "1" to find the head unit's IP address, in this case, it would be 192.168.30.1.

In a terminal on the computer, run following;

adb connect <ip address of head unit>
adb push BluetoothTethering.apk /sdcard/
adb shell
$ su
# mount -o remount,rw /system
# mkdir /system/priv-app/BluetoothTethering
# cp /sdcard/BluetoothTethering.apk /system/priv-app/BluetoothTethering/
# chmod 755 /system/priv-app/BluetoothTethering
# chmod 644 /system/priv-app/BluetoothTethering/BluetoothTethering.apk
# sync
# reboot

Now the application is installed with extra privileges, so it will respond properly to the broadcasts when the unit powers back on after sleeping.

Note: This application will not currently work with a typical Android TABLET. The reason is that despite being "paired" to your phone for tethering, the two devices do not automatically establish a connection when they are in proximity. A car radio and phone DO automatically establish a connection when in proximity in order that your phone calls will be directed over bluetooth. I will be looking into whether or not there is some battery efficient mechanism for accomplishing this, but I am not hopeful.

I am also aware that the auto-tethering setting is currently limited to a selection of ONE bluetooth device. If two people share a car, this may be inadequate. My intention is to create a LIST of devices that it can try connecting to. CANNOT just try ALL devices, since obviously it would be silly to try to establish a PAN connection with your OBD dongle.

There is also a potential weakness where if the bluetooth connection is established BEFORE the PHONE has bluetooth tethering enabled, the head unit will just try once to connect PAN, fail, and give up. I intend to have it periodically retry if the connection is established to an enabled device, but PAN failed.