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

Unverified Commit adf96aca authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Location: Add some missing details

parent 33279a13
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package com.google.android.gms.common.internal;

import androidx.annotation.NonNull;
import org.microg.safeparcel.AutoSafeParcelable;

import java.util.Objects;

public class ClientIdentity extends AutoSafeParcelable {
    @Field(1)
    public int uid;
    @Field(2)
    public String packageName;

    @Override
    public int hashCode() {
        return uid;
    }

    @NonNull
    @Override
    public String toString() {
        return uid + ":" + packageName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClientIdentity that = (ClientIdentity) o;
        return uid == that.uid && Objects.equals(packageName, that.packageName);
    }

    public static final Creator<ClientIdentity> CREATOR = new AutoCreator<ClientIdentity>(ClientIdentity.class);
}
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ package org.microg.gms.common.api;

import com.google.android.gms.tasks.TaskCompletionSource;

public interface InstantGoogleApiCall<R, A extends ApiClient> extends PendingGoogleApiCall<R, A> {
public interface ReturningGoogleApiCall<R, A extends ApiClient> extends PendingGoogleApiCall<R, A> {
    R execute(A client) throws Exception;

    @Override
+63 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.utils;

import android.os.Build;
import android.os.WorkSource;
import android.util.Log;

import java.lang.reflect.Method;

import static android.os.Build.VERSION.SDK_INT;

public class WorkSourceUtil {
    private static final String TAG = "WorkSourceUtil";

    private static Method getMethod(String name, Class<?>... parameterTypes) throws Exception {
        Method method = WorkSource.class.getMethod(name, parameterTypes);
        method.setAccessible(true);
        return method;
    }

    private static <T> T invokeMethod(WorkSource workSource, Method method, Object... args) throws Exception {
        return (T) method.invoke(workSource, args);
    }

    private static <T> T invokeMethod(WorkSource workSource, String name, Object... args) throws Exception {
        return invokeMethod(workSource, getMethod(name), args);
    }

    public static void add(WorkSource workSource, int uid, String packageName) {
        try {
            invokeMethod(workSource, getMethod("add", Integer.TYPE, String.class), uid, packageName);
        } catch (Exception e) {
            try {
                invokeMethod(workSource, getMethod("add", Integer.TYPE), uid);
            } catch (Exception ex) {
                // Ignore
            }
        }
    }

    public static int size(WorkSource workSource) {
        try {
            return invokeMethod(workSource, "size");
        } catch (Exception e) {
            return 0;
        }
    }

    public static boolean isEmpty(WorkSource workSource) {
        if (SDK_INT >= 28) {
            try {
                return invokeMethod(workSource, "isEmpty");
            } catch (Exception e) {
                // Ignore and fall-through to size()
            }
        }
        return size(workSource) == 0;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
 */

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
    compileSdkVersion androidCompileSdk
@@ -21,6 +23,10 @@ android {
    }
}

apply from: '../gradle/publish-android.gradle'

description = 'microG implementation of play-services-location'

dependencies {
    // Dependencies from play-services-location:21.0.1
    api project(':play-services-base')
+10 −4
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.location.LocationManager.GPS_PROVIDER;
import static com.google.android.gms.location.LocationRequest.PRIORITY_HIGH_ACCURACY;
import static com.google.android.gms.location.LocationRequest.PRIORITY_NO_POWER;
import static com.google.android.gms.location.Priority.PRIORITY_HIGH_ACCURACY;
import static com.google.android.gms.location.Priority.PRIORITY_PASSIVE;

import androidx.lifecycle.Lifecycle;

@@ -159,7 +159,7 @@ public class GoogleLocationManager implements LocationChangeListener {
        } else {
            Log.w(TAG, "Not providing high accuracy location: missing permission");
        }
        if (networkProvider != null && request.hasCoarsePermission() && request.locationRequest.getPriority() != PRIORITY_NO_POWER) {
        if (networkProvider != null && request.hasCoarsePermission() && request.locationRequest.getPriority() != PRIORITY_PASSIVE) {
            Log.d(TAG, "Registering request with low accuracy location provider");
            networkProvider.addRequest(request);
        } else if (networkProvider != null && old != null) {
@@ -168,7 +168,13 @@ public class GoogleLocationManager implements LocationChangeListener {
        } else {
            Log.w(TAG, "Not providing low accuracy location: missing permission");
        }
        handler.postDelayed(this::onLocationChanged, request.locationRequest.getFastestInterval());
        Location lastLocation = getLocation(request.hasFinePermission(), request.hasCoarsePermission());
        if (lastLocation != null && lastLocation.getTime() > System.currentTimeMillis() - request.locationRequest.getMaxUpdateAgeMillis()) {
            Log.d(TAG, "Reporting previous location as it's newer than " + request.locationRequest.getMaxUpdateAgeMillis() + "ms");
            request.report(lastLocation);
        } else {
            Log.d(TAG, "Not reporting previous location as it's older than " + request.locationRequest.getMaxUpdateAgeMillis() + "ms");
        }
    }

    public void requestLocationUpdates(LocationRequest request, ILocationListener listener, String packageName) {
Loading