package org.owntracks.android.support;

import org.owntracks.android.injection.scopes.PerApplication;
import org.owntracks.android.services.BackgroundService;

import java.lang.ref.WeakReference;

import javax.inject.Inject;

import androidx.annotation.NonNull;

@PerApplication
public class ServiceBridge {
    private WeakReference<ServiceBridgeInterface> serviceWeakReference;

    public interface ServiceBridgeInterface {
        void requestOnDemandLocationUpdate();
    }

    @Inject
    ServiceBridge() {
    }

    public void bind(@NonNull ServiceBridgeInterface service) {
        this.serviceWeakReference = new WeakReference<ServiceBridgeInterface>(service);
    }

    public void requestOnDemandLocationFix() {
        ServiceBridgeInterface service = serviceWeakReference.get();
        if(service != null) {
            service.requestOnDemandLocationUpdate();
        }
    }


}

@@ -98,65 +98,8 @@
 ion;
-%0Aimport org.owntracks.android.services.BackgroundService;
 %0A%0Aim
@@ -199,16 +199,17 @@
 nNull;%0A%0A
+%0A
 @PerAppl
@@ -241,24 +241,24 @@
 iceBridge %7B%0A
-
     private 
@@ -315,16 +315,66 @@
 eference
+ = new WeakReference%3CServiceBridgeInterface%3E(null)
 ;%0A%0A    p
@@ -886,8 +886,9 @@
   %7D%0A%0A%0A%7D%0A
+%0A

Fix crash when receiving reportLocation command before service is bound