From c0bfe2f715459e23c08300e218a18590af65d8fa Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 31 Jan 2015 11:49:46 +0100 Subject: [PATCH] make quit button work by letting BtSocketIoThread actually leave its main loop, do not display "Unknown" for unknown numbers but the number itself. --- .../gadgetbridge/BluetoothCommunicationService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index 1599e7fb..481e4047 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -150,6 +150,7 @@ public class BluetoothCommunicationService extends Service { super.onDestroy(); if (mBtSocketIoThread != null) { try { + mBtSocketIoThread.quit(); mBtSocketIoThread.join(); } catch (InterruptedException e) { e.printStackTrace(); @@ -172,7 +173,7 @@ public class BluetoothCommunicationService extends Service { private String getContactDisplayNameByNumber(String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); - String name = "Unknown"; + String name = number; if (number == null || number.equals("")) { return name; @@ -233,6 +234,7 @@ public class BluetoothCommunicationService extends Service { private class BtSocketIoThread extends Thread { private final InputStream mmInStream; private final OutputStream mmOutStream; + private boolean mQuit = false; public BtSocketIoThread(InputStream instream, OutputStream outstream) { mmInStream = instream; @@ -243,7 +245,7 @@ public class BluetoothCommunicationService extends Service { byte[] buffer = new byte[8192]; int bytes; - while (true) { + while (!mQuit) { try { bytes = mmInStream.read(buffer, 0, 4); if (bytes < 4) @@ -296,5 +298,9 @@ public class BluetoothCommunicationService extends Service { } catch (IOException e) { } } + + public void quit() { + mQuit = true; + } } }