From f5a466e110ddfb9cdb8b964fa484d1f74e9ac589 Mon Sep 17 00:00:00 2001 From: fr3ts0n Date: Sat, 7 Nov 2015 20:16:09 +0100 Subject: [PATCH] allow plain bluetooth connection (configurable) --- res/values-de/strings.xml | 19 +++++ res/values/strings.xml | 42 +++++++++- res/xml/settings.xml | 84 +++++++++++-------- .../ecu/gui/androbd/BtCommService.java | 2 +- .../fr3ts0n/ecu/gui/androbd/MainActivity.java | 15 +++- 5 files changed, 123 insertions(+), 39 deletions(-) diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 7515194c..c824ded5 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -121,4 +121,23 @@ Dadurch kann eine Lernphase nötig werden, während welcher der Motor ungleichm letzter OBD service letzter Datenanzeige-Modus Allgemeine Einstellungen zur Programmsteuerung + BUS Fehler + Verbunden + Verbinde… + Datenfehler + Keine Verbindung + ECU Suche… + ECU gefunden + Fehler + Initialisiert + Initialisiere… + Keine Daten + RX Fehler + Gestoppt + Undefiniert + Sichere Verbindung + Benutze verschlüsselte Bluetooth-Verbindung + ELM Einstellungen + ELM Initialisierung + eigene ELM Befehle zur Initialisierung diff --git a/res/values/strings.xml b/res/values/strings.xml index a9e95cbd..1545b204 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -180,7 +180,47 @@ period of time while the ECU recalibrates itself. Select ECU address … Disconnect Reset last pre-selections - Use last settings at startup (BT address, ECU address, Display items ...) + Use last settings at startup (BT address, ECU address, Display items …) Use last settings Common settings for app control + Secure connection + Use encrypted Bluetooth connection + ELM options + NONE + ELM custom init + ELM custom initialisation commands + + + Undefined + Initializing… + Initialized + ECU detect… + ECU detected + Connecting… + Connected + No data + Stopped + Disconnected + BUS error + DATA error + RX error + Error + + + @string/UNDEFINED + @string/INITIALIZING + @string/INITIALIZED + @string/ECU_DETECT + @string/ECU_DETECTED + @string/CONNECTING + @string/CONNECTED + @string/NODATA + @string/STOPPED + @string/DISCONNECTED + @string/BUSERROR + @string/DATAERROR + @string/RXERROR + @string/ERROR + + diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 27c44611..70cde2ed 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -8,8 +8,8 @@ > + android:summary="@string/common_settings_description" + android:title="@string/common_settings"> - - @@ -66,6 +56,9 @@ android:summary="@string/obd_opt_description" android:title="@string/obd_options"> + + + + + - - + - + + + + + + + + diff --git a/src/com/fr3ts0n/ecu/gui/androbd/BtCommService.java b/src/com/fr3ts0n/ecu/gui/androbd/BtCommService.java index 4c175565..65f184b3 100644 --- a/src/com/fr3ts0n/ecu/gui/androbd/BtCommService.java +++ b/src/com/fr3ts0n/ecu/gui/androbd/BtCommService.java @@ -240,7 +240,7 @@ public BtConnectThread(BluetoothDevice device, boolean secure) tmp = device.createRfcommSocketToServiceRecord(SPP_UUID); } else { - tmp = device.createRfcommSocketToServiceRecord(SPP_UUID); + tmp = device.createInsecureRfcommSocketToServiceRecord(SPP_UUID); } } catch (IOException e) { diff --git a/src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java b/src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java index d25cf4e3..0dad96bc 100644 --- a/src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java +++ b/src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java @@ -387,7 +387,7 @@ public void handleMessage(Message msg) /* Show ELM status only in ONLINE mode */ if (getMode() != MODE.DEMO) { - setStatus(String.valueOf(state)); + setStatus(getResources().getStringArray(R.array.elmcomm_states)[state.ordinal()]); } // if last selection shall be restored ... if(istRestoreWanted(PRESELECT.LAST_SERVICE)) @@ -784,13 +784,16 @@ public void setMode(MODE mode) && address != null) { // ... connect with previously connected device - connectBtDevice(address, true); + connectBtDevice(address, prefs.getBoolean("bt_secure_connection", false)); } else { // ... otherwise launch the BtDeviceListActivity to see devices and do scan Intent serverIntent = new Intent(this, BtDeviceListActivity.class); - startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); + startActivityForResult(serverIntent, + prefs.getBoolean("bt_secure_connection", false) + ? REQUEST_CONNECT_DEVICE_SECURE + : REQUEST_CONNECT_DEVICE_INSECURE ); } break; @@ -1167,10 +1170,14 @@ private void clearPreselections() @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + boolean secureConnection = false; + switch (requestCode) { // device is connected case REQUEST_CONNECT_DEVICE_SECURE: + secureConnection = true; + // no break here ... case REQUEST_CONNECT_DEVICE_INSECURE: // When BtDeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) @@ -1180,7 +1187,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) BtDeviceListActivity.EXTRA_DEVICE_ADDRESS); // save reported address as last setting prefs.edit().putString(PRESELECT.LAST_DEV_ADDRESS.toString(), address).apply(); - connectBtDevice(address, false); + connectBtDevice(address, secureConnection); } else { setMode(MODE.OFFLINE);