From a4843cac76d1ca6bf305e7db3a1a4f0cb9259e4e Mon Sep 17 00:00:00 2001 From: dakhnod Date: Tue, 24 Jul 2018 00:22:17 +0200 Subject: [PATCH 1/2] added ability to connect to the current DeviceSupport --- .../gadgetbridge/service/DeviceCommunicationService.java | 9 ++++++++- .../gadgetbridge/service/ServiceDeviceSupport.java | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 3003a93949..fd40270ac8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -31,6 +31,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.support.annotation.Nullable; @@ -751,9 +752,15 @@ public void onDestroy() { } } + public class CommunicationServiceBinder extends Binder{ + public DeviceSupport getDeviceSupport(){ + return ((ServiceDeviceSupport)DeviceCommunicationService.this.mDeviceSupport).getDelegate(); + } + } + @Override public IBinder onBind(Intent intent) { - return null; + return new CommunicationServiceBinder(); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 4c77c5a01f..e3373ebfe3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -62,6 +62,10 @@ public ServiceDeviceSupport(DeviceSupport delegate, EnumSet flags) { this.flags = flags; } + public DeviceSupport getDelegate() { + return delegate; + } + @Override public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) { delegate.setContext(gbDevice, btAdapter, context); From 020baf52487d107391cbe0dee53e794d4777ba13 Mon Sep 17 00:00:00 2001 From: dakhnod Date: Tue, 24 Jul 2018 03:11:42 +0200 Subject: [PATCH 2/2] Fixed possible case of missing device --- .../gadgetbridge/service/DeviceCommunicationService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index fd40270ac8..f29bb66ef8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -754,6 +754,7 @@ public void onDestroy() { public class CommunicationServiceBinder extends Binder{ public DeviceSupport getDeviceSupport(){ + if(mDeviceSupport == null) return null; return ((ServiceDeviceSupport)DeviceCommunicationService.this.mDeviceSupport).getDelegate(); } }