mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-02 14:07:32 +01:00
Ensure to clean up location requests on update
This commit is contained in:
parent
5146559f89
commit
ac5f7457bd
@ -56,10 +56,10 @@ public class LocationRequestUpdateData extends AutoSafeParcelable {
|
||||
return "LocationRequestUpdateData{" +
|
||||
"opCode=" + opCode +
|
||||
", request=" + request +
|
||||
", listener=" + listener +
|
||||
", listener=" + (listener != null ? listener.asBinder() : null) +
|
||||
", pendingIntent=" + pendingIntent +
|
||||
", callback=" + callback +
|
||||
", fusedLocationProviderCallback=" + fusedLocationProviderCallback +
|
||||
", callback=" + (callback != null ? callback.asBinder() : null) +
|
||||
", fusedLocationProviderCallback=" + (fusedLocationProviderCallback != null ? fusedLocationProviderCallback.asBinder() : null) +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -116,12 +116,27 @@ public class GoogleLocationManager implements LocationChangeListener {
|
||||
}
|
||||
|
||||
private void requestLocationUpdates(LocationRequestHelper request) {
|
||||
LocationRequestHelper old = null;
|
||||
for (LocationRequestHelper req : currentRequests) {
|
||||
if (req.respondsTo(request.pendingIntent) || req.respondsTo(request.listener) || req.respondsTo(request.callback)) {
|
||||
old = req;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (old != null) {
|
||||
currentRequests.remove(old);
|
||||
}
|
||||
currentRequests.add(request);
|
||||
if (gpsProvider != null && request.hasFinePermission() && request.locationRequest.getPriority() == PRIORITY_HIGH_ACCURACY) {
|
||||
gpsProvider.addRequest(request);
|
||||
} else if (gpsProvider != null && old != null) {
|
||||
gpsProvider.removeRequest(old);
|
||||
}
|
||||
if (networkProvider != null && request.hasCoarsePermission() && request.locationRequest.getPriority() != PRIORITY_NO_POWER)
|
||||
if (networkProvider != null && request.hasCoarsePermission() && request.locationRequest.getPriority() != PRIORITY_NO_POWER) {
|
||||
networkProvider.addRequest(request);
|
||||
} else if (networkProvider != null && old != null) {
|
||||
networkProvider.removeRequest(old);
|
||||
}
|
||||
}
|
||||
|
||||
public void requestLocationUpdates(LocationRequest request, ILocationListener listener, String packageName) {
|
||||
@ -162,12 +177,6 @@ public class GoogleLocationManager implements LocationChangeListener {
|
||||
packageName = PackageUtils.packageFromPendingIntent(data.pendingIntent);
|
||||
if (data.opCode == LocationRequestUpdateData.REQUEST_UPDATES) {
|
||||
requestLocationUpdates(new LocationRequestHelper(context, packageName, Binder.getCallingUid(), data));
|
||||
if (data.fusedLocationProviderCallback != null) {
|
||||
try {
|
||||
data.fusedLocationProviderCallback.onFusedLocationProviderResult(FusedLocationProviderResult.SUCCESS);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
} else if (data.opCode == LocationRequestUpdateData.REMOVE_UPDATES) {
|
||||
for (int i = 0; i < currentRequests.size(); i++) {
|
||||
if (currentRequests.get(i).respondsTo(data.listener)
|
||||
@ -178,6 +187,12 @@ public class GoogleLocationManager implements LocationChangeListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data.fusedLocationProviderCallback != null) {
|
||||
try {
|
||||
data.fusedLocationProviderCallback.onFusedLocationProviderResult(FusedLocationProviderResult.SUCCESS);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setMockMode(boolean mockMode) {
|
||||
|
@ -53,9 +53,9 @@ public class LocationRequestHelper {
|
||||
public final String packageName;
|
||||
public final int uid;
|
||||
private final boolean selfHasAppOpsRights;
|
||||
private ILocationListener listener;
|
||||
private PendingIntent pendingIntent;
|
||||
private ILocationCallback callback;
|
||||
public ILocationListener listener;
|
||||
public PendingIntent pendingIntent;
|
||||
public ILocationCallback callback;
|
||||
|
||||
private Location lastReport;
|
||||
private int numReports = 0;
|
||||
@ -105,7 +105,7 @@ public class LocationRequestHelper {
|
||||
}
|
||||
lastReport = new Location(location);
|
||||
lastReport.setProvider("fused");
|
||||
Log.d(TAG, "sending Location: " + location);
|
||||
Log.d(TAG, "sending Location: " + location + " to " + packageName);
|
||||
if (listener != null) {
|
||||
try {
|
||||
listener.onLocationChanged(lastReport);
|
||||
|
@ -87,6 +87,13 @@ public class RealLocationProvider {
|
||||
|
||||
public void addRequest(LocationRequestHelper request) {
|
||||
Log.d(TAG, name + ": addRequest " + request);
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
LocationRequestHelper req = requests.get(i);
|
||||
if (req.respondsTo(request.pendingIntent) || req.respondsTo(request.listener) || req.respondsTo(request.callback)) {
|
||||
requests.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
requests.add(request);
|
||||
updateConnection();
|
||||
}
|
||||
@ -109,7 +116,7 @@ public class RealLocationProvider {
|
||||
for (LocationRequestHelper request : requests) {
|
||||
minTime = Math.min(request.locationRequest.getInterval(), minTime);
|
||||
minDistance = Math.min(request.locationRequest.getSmallestDesplacement(), minDistance);
|
||||
if (sb.length() == 0) sb.append(", ");
|
||||
if (sb.length() != 0) sb.append(", ");
|
||||
sb.append(request.packageName).append(":").append(request.locationRequest.getInterval()).append("ms");
|
||||
}
|
||||
Log.d(TAG, name + ": requesting location updates with interval " + minTime + "ms (" + sb + "), minDistance=" + minDistance);
|
||||
|
@ -31,6 +31,13 @@ class UnifiedLocationProvider(context: Context?, changeListener: LocationChangeL
|
||||
|
||||
fun addRequest(request: LocationRequestHelper) {
|
||||
Log.d(TAG, "unified network: addRequest $request")
|
||||
for (i in 0..requests.size) {
|
||||
if (i >= requests.size) break
|
||||
val req = requests[i]
|
||||
if (req.respondsTo(request.pendingIntent) || req.respondsTo(request.listener) || req.respondsTo(request.callback)) {
|
||||
requests.removeAt(i)
|
||||
}
|
||||
}
|
||||
requests.add(request)
|
||||
updateConnection()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user