From dddcfb02f08a15778531c59c7dac5021c26a4e73 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 21 Oct 2017 13:14:41 +0200 Subject: [PATCH] ruffy: unbound existing pump on pairing reset. --- .../org/monkey/d/ruffy/ruffy/driver/Ruffy.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java b/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java index 7a191a2b53..7350fadca6 100644 --- a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java +++ b/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java @@ -2,6 +2,7 @@ package org.monkey.d.ruffy.ruffy.driver; import android.app.Activity; import android.app.Service; +import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.content.SharedPreferences; @@ -12,6 +13,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.DisplayParser; import org.monkey.d.ruffy.ruffy.driver.display.DisplayParserHandler; import org.monkey.d.ruffy.ruffy.driver.display.Menu; +import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -100,6 +102,19 @@ public class Ruffy extends Service { { SharedPreferences prefs = Ruffy.this.getSharedPreferences("pumpdata", Activity.MODE_PRIVATE); prefs.edit().putBoolean("paired",false).apply(); + + String bondedDeviceId = prefs.getString("device", null); + if (bondedDeviceId != null) { + BluetoothDevice boundedPump = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(bondedDeviceId); + // TODO I know! + try { + Method removeBound = boundedPump.getClass().getMethod("removeBond", (Class[]) null); + removeBound.invoke(boundedPump, (Object[]) null); + } catch (ReflectiveOperationException e) { + // it's not going better here either + } + } + synRun=false; rtModeRunning =false; }