Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit d42d8a81 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Ensure unified client is set up when using gms location

parent 6794ab44
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,10 +15,10 @@ dependencies {
    implementation "org.microg.nlp:location-v2:$nlpVersion"
    implementation "org.microg.nlp:location-v3:$nlpVersion"
    implementation "org.microg.nlp:service:$nlpVersion"
    implementation "org.microg.nlp:client:$nlpVersion"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"
    api "org.microg.nlp:client:$nlpVersion"
    api "org.microg.nlp:ui:$nlpVersion"
}

+16 −6
Original line number Diff line number Diff line
@@ -64,16 +64,26 @@ public class GoogleLocationManager implements LocationChangeListener {
            this.gpsProvider = null;
        }
        if (Utils.hasSelfPermissionOrNotify(context, Manifest.permission.ACCESS_COARSE_LOCATION)) {
            if (locationManager.getAllProviders().contains(NETWORK_PROVIDER)) {
            this.networkProvider = new UnifiedLocationProvider(context, this);
        } else {
                // TODO: Add ability to directly contact UnifiedNlp without the system location provider
            this.networkProvider = null;
        }
        mockProvider = new MockLocationProvider(this);
    }

    public void invokeOnceReady(Runnable runnable) {
        Runnable networkRunnable = () -> {
            if (networkProvider != null) {
                networkProvider.invokeOnceReady(runnable);
            } else {
            this.networkProvider = null;
                runnable.run();
            }
        };
        if (gpsProvider != null) {
            gpsProvider.invokeOnceReady(networkRunnable);
        } else {
            networkRunnable.run();
        }
        mockProvider = new MockLocationProvider(this);
    }

    public Location getLastLocation(String packageName) {
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package org.microg.gms.location;

import android.os.RemoteException;
import android.util.Log;

import com.google.android.gms.common.internal.GetServiceRequest;
import com.google.android.gms.common.internal.IGmsCallbacks;
@@ -33,6 +34,12 @@ public class GoogleLocationManagerService extends BaseService {

    @Override
    public void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest request, GmsService service) throws RemoteException {
        impl.invokeOnceReady(() -> {
            try {
                callback.onPostInitComplete(0, impl.asBinder(), null);
            } catch (RemoteException e) {
                Log.w(TAG, e);
            }
        });
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ public class GoogleLocationManagerServiceImpl extends IGoogleLocationManagerServ
        this.context = context;
    }

    public void invokeOnceReady(Runnable runnable) {
        getLocationManager().invokeOnceReady(runnable);
    }

    private GoogleLocationManager getLocationManager() {
        if (locationManager == null)
            locationManager = new GoogleLocationManager(context);
+6 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings("MissingPermission")
public class RealLocationProvider {
    public static final String TAG = "GmsLocProviderReal";
    private static final int MIN_GPS_TIME = 30000;
    private static final int MIN_GPS_TIME = 10000;

    private final LocationManager locationManager;
    private final String name;
@@ -76,6 +76,11 @@ public class RealLocationProvider {
        if (newLocation != null) lastLocation = newLocation;
    }

    public void invokeOnceReady(Runnable runnable) {
        // Always ready
        runnable.run();
    }

    public Location getLastLocation() {
        if (!connected.get()) {
            updateLastLocation();
Loading