mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-12-12 05:37:45 +01:00
Start Location APIs
This commit is contained in:
parent
21e603b1e7
commit
c57656d321
@ -18,7 +18,7 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.google.android.gms"
|
package="com.google.android.gms"
|
||||||
android:versionName="1.0"
|
android:versionName="1.0"
|
||||||
android:versionCode="6111030">
|
android:versionCode="6599436">
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="16" />
|
<uses-sdk android:minSdkVersion="16" />
|
||||||
|
|
||||||
|
@ -16,45 +16,36 @@
|
|||||||
|
|
||||||
package com.google.android.location.internal;
|
package com.google.android.location.internal;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.google.android.gms.location.Geofence;
|
|
||||||
import com.google.android.gms.location.internal.IGeofencerCallbacks;
|
|
||||||
import com.google.android.gms.location.internal.IGoogleLocationManagerService;
|
|
||||||
import com.google.android.gms.common.AbstractGmsServiceBroker;
|
import com.google.android.gms.common.AbstractGmsServiceBroker;
|
||||||
import com.google.android.gms.common.internal.IGmsCallbacks;
|
import com.google.android.gms.common.internal.IGmsCallbacks;
|
||||||
|
import org.microg.gms.location.GoogleLocationManagerServiceImpl;
|
||||||
|
|
||||||
import java.util.List;
|
import static org.microg.gms.maps.Constants.ACTION_GMS_LOCATION_MANAGER_SERVICE_START;
|
||||||
|
|
||||||
public class GoogleLocationManagerService extends Service {
|
public class GoogleLocationManagerService extends Service {
|
||||||
private static final String TAG = GoogleLocationManagerService.class.getName();
|
private static final String TAG = "GmsLMS";
|
||||||
|
private AbstractGmsServiceBroker broker = new AbstractGmsServiceBroker() {
|
||||||
|
@Override
|
||||||
|
public void getGoogleLocationManagerService(IGmsCallbacks callback, int versionCode,
|
||||||
|
String packageName, Bundle params) throws RemoteException {
|
||||||
|
Log.d(TAG, "bound by: " + packageName);
|
||||||
|
callback.onPostInitComplete(0, impl.asBinder(), null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private GoogleLocationManagerServiceImpl impl = new GoogleLocationManagerServiceImpl(this);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return new Broker(intent).asBinder();
|
if (ACTION_GMS_LOCATION_MANAGER_SERVICE_START.equals(intent.getAction())) {
|
||||||
}
|
return broker.asBinder();
|
||||||
|
} else {
|
||||||
private class Broker extends AbstractGmsServiceBroker {
|
return null;
|
||||||
public Broker(Intent intent) {
|
|
||||||
Log.d(TAG, "Incoming intent: " + intent.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getGoogleLocationManagerService(IGmsCallbacks callback, int versionCode, String packageName, Bundle params) throws RemoteException {
|
|
||||||
params.keySet();
|
|
||||||
Log.d(TAG, "getGoogleLocationManagerService: " + versionCode + ", " + packageName + ", " + params);
|
|
||||||
callback.onPostInitComplete(0, new IGoogleLocationManagerService.Stub() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addGeofences(List<Geofence> geofences, PendingIntent pendingIntent, IGeofencerCallbacks callback, String str) throws RemoteException {
|
|
||||||
|
|
||||||
}
|
|
||||||
}, params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
106
src/org/microg/gms/location/GoogleLocationManager.java
Normal file
106
src/org/microg/gms/location/GoogleLocationManager.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package org.microg.gms.location;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import com.google.android.gms.location.LocationRequest;
|
||||||
|
import com.google.android.gms.location.internal.ILocationListener;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static android.location.LocationManager.GPS_PROVIDER;
|
||||||
|
import static android.location.LocationManager.NETWORK_PROVIDER;
|
||||||
|
import static org.microg.gms.maps.Constants.KEY_MOCK_LOCATION;
|
||||||
|
|
||||||
|
public class GoogleLocationManager {
|
||||||
|
private static final String MOCK_PROVIDER = KEY_MOCK_LOCATION;
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private LocationManager locationManager;
|
||||||
|
private Map<String, Location> lastKnownLocaton = new HashMap<>();
|
||||||
|
|
||||||
|
public GoogleLocationManager(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
updateLastKnownLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLastKnownLocation() {
|
||||||
|
lastKnownLocaton.put(GPS_PROVIDER, locationManager.getLastKnownLocation(GPS_PROVIDER));
|
||||||
|
lastKnownLocaton.put(NETWORK_PROVIDER,
|
||||||
|
locationManager.getLastKnownLocation(NETWORK_PROVIDER));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLastLocation(String packageName) {
|
||||||
|
if (lastKnownLocaton.get(KEY_MOCK_LOCATION) != null)
|
||||||
|
return lastKnownLocaton.get(KEY_MOCK_LOCATION);
|
||||||
|
if (hasFineLocationPermission()) {
|
||||||
|
Location network = lastKnownLocaton.get(NETWORK_PROVIDER);
|
||||||
|
Location gps = lastKnownLocaton.get(GPS_PROVIDER);
|
||||||
|
if (network == null)
|
||||||
|
return gps;
|
||||||
|
if (gps == null)
|
||||||
|
return network;
|
||||||
|
if (gps.getTime() > network.getTime())
|
||||||
|
return gps;
|
||||||
|
return network;
|
||||||
|
} else if (hasCoarseLocationPermission()) {
|
||||||
|
return lastKnownLocaton.get(NETWORK_PROVIDER);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasCoarseLocationPermission() {
|
||||||
|
return context.checkCallingPermission(Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasFineLocationPermission() {
|
||||||
|
return context.checkCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasMockLocationPermission() {
|
||||||
|
return context.checkCallingPermission(Manifest.permission.ACCESS_MOCK_LOCATION) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestLocationUpdates(LocationRequest request, ILocationListener listener,
|
||||||
|
String packageName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestLocationUpdates(LocationRequest request, PendingIntent intent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLocationUpdates(ILocationListener listener) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLocationUpdates(PendingIntent intent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMockMode(boolean mockMode) {
|
||||||
|
if (!hasMockLocationPermission())
|
||||||
|
return;
|
||||||
|
if (!mockMode)
|
||||||
|
lastKnownLocaton.put(MOCK_PROVIDER, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMockLocation(Location mockLocation) {
|
||||||
|
if (!hasMockLocationPermission())
|
||||||
|
return;
|
||||||
|
if (mockLocation.getExtras() == null) {
|
||||||
|
mockLocation.setExtras(new Bundle());
|
||||||
|
}
|
||||||
|
mockLocation.getExtras().putBoolean(KEY_MOCK_LOCATION, false);
|
||||||
|
lastKnownLocaton.put(MOCK_PROVIDER, mockLocation);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,261 @@
|
|||||||
|
package org.microg.gms.location;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
|
import com.google.android.gms.location.Geofence;
|
||||||
|
import com.google.android.gms.location.GeofencingRequest;
|
||||||
|
import com.google.android.gms.location.LocationRequest;
|
||||||
|
import com.google.android.gms.location.LocationStatus;
|
||||||
|
import com.google.android.gms.location.internal.IGeofencerCallbacks;
|
||||||
|
import com.google.android.gms.location.internal.IGoogleLocationManagerService;
|
||||||
|
import com.google.android.gms.location.internal.ILocationListener;
|
||||||
|
import com.google.android.gms.location.internal.LocationRequestInternal;
|
||||||
|
import com.google.android.gms.location.places.*;
|
||||||
|
import com.google.android.gms.location.places.internal.IPlacesCallbacks;
|
||||||
|
import com.google.android.gms.location.places.internal.PlacesParams;
|
||||||
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
import com.google.android.gms.maps.model.LatLngBounds;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GoogleLocationManagerServiceImpl extends IGoogleLocationManagerService.Stub {
|
||||||
|
private static final String TAG = "GmsLMSImpl";
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private GoogleLocationManager locationManager;
|
||||||
|
|
||||||
|
public GoogleLocationManagerServiceImpl(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GoogleLocationManager getLocationManager() {
|
||||||
|
if (locationManager == null)
|
||||||
|
locationManager = new GoogleLocationManager(context);
|
||||||
|
return locationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addGeofencesList(List<Geofence> geofences, PendingIntent pendingIntent,
|
||||||
|
IGeofencerCallbacks callbacks, String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "addGeofencesList: " + geofences);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeGeofencesByIntent(PendingIntent pendingIntent, IGeofencerCallbacks callbacks,
|
||||||
|
String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "removeGeofencesByIntent: " + pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeGeofencesById(String[] geofenceRequestIds, IGeofencerCallbacks callbacks,
|
||||||
|
String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "removeGeofencesById: " + geofenceRequestIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms4(IGeofencerCallbacks callbacks, String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms4: " + packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestActivityUpdates(long detectionIntervalMillis, boolean alwaysTrue,
|
||||||
|
PendingIntent callbackIntent) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestActivityUpdates: " + callbackIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeActivityUpdates(PendingIntent callbackIntent) throws RemoteException {
|
||||||
|
Log.d(TAG, "removeActivityUpdates: " + callbackIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getLastLocation() throws RemoteException {
|
||||||
|
Log.d(TAG, "getLastLocation");
|
||||||
|
return getLocationManager().getLastLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestLocationUpdatesWithListener(LocationRequest request,
|
||||||
|
final ILocationListener listener) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestLocationUpdatesWithListener: " + request);
|
||||||
|
getLocationManager().requestLocationUpdates(request, listener, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestLocationUpdatesWithIntent(LocationRequest request,
|
||||||
|
PendingIntent callbackIntent) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestLocationUpdatesWithIntent: " + request);
|
||||||
|
getLocationManager().requestLocationUpdates(request, callbackIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeLocationUpdatesWithListener(ILocationListener listener)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "removeLocationUpdatesWithListener: " + listener);
|
||||||
|
getLocationManager().removeLocationUpdates(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeLocationUpdatesWithIntent(PendingIntent callbackIntent)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "removeLocationUpdatesWithIntent: " + callbackIntent);
|
||||||
|
getLocationManager().removeLocationUpdates(callbackIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMockMode(boolean mockMode) throws RemoteException {
|
||||||
|
Log.d(TAG, "setMockMode: " + mockMode);
|
||||||
|
getLocationManager().setMockMode(mockMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMockLocation(Location mockLocation) throws RemoteException {
|
||||||
|
Log.d(TAG, "setMockLocation: " + mockLocation);
|
||||||
|
getLocationManager().setMockLocation(mockLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms14(LatLngBounds var1, int var2, PlaceFilter var3, PlacesParams var4,
|
||||||
|
IPlacesCallbacks var5) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms14: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms15(String var1, PlacesParams var2, IPlacesCallbacks var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms15: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms16(LatLng var1, PlaceFilter var2, PlacesParams var3, IPlacesCallbacks var4)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms16: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms17(PlaceFilter var1, PlacesParams var2, IPlacesCallbacks var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms17: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms18(PlaceRequest var1, PlacesParams var2, PendingIntent var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms18: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms19(PlacesParams var1, PendingIntent var2) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms19: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestLocationUpdates(LocationRequest request, ILocationListener listener,
|
||||||
|
String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestLocationUpdates: " + request);
|
||||||
|
getLocationManager().requestLocationUpdates(request, listener, packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getLastLocationWithPackage(String packageName) throws RemoteException {
|
||||||
|
Log.d(TAG, "getLastLocationWithPackage: " + packageName);
|
||||||
|
return getLocationManager().getLastLocation(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms25(PlaceReport var1, PlacesParams var2) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms25: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms26(Location var1, int var2) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms26: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocationStatus iglms34(String var1) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms34: " + var1);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms42(String var1, PlacesParams var2, IPlacesCallbacks var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms42: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms46(UserAddedPlace var1, PlacesParams var2, IPlacesCallbacks var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms46: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms47(LatLngBounds var1, int var2, String var3, PlaceFilter var4,
|
||||||
|
PlacesParams var5, IPlacesCallbacks var6) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms47: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms48(NearbyAlertRequest var1, PlacesParams var2, PendingIntent var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms48: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms49(PlacesParams var1, PendingIntent var2) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms49: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms50(UserDataType var1, LatLngBounds var2, List var3, PlacesParams var4,
|
||||||
|
IPlacesCallbacks var5) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms50: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder iglms51() throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms51");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestLocationUpdatesInternalWithListener(LocationRequestInternal request,
|
||||||
|
ILocationListener listener) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestLocationUpdatesInternalWithListener: " + request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestLocationUpdatesInternalWithIntent(LocationRequestInternal request,
|
||||||
|
PendingIntent callbackIntent) throws RemoteException {
|
||||||
|
Log.d(TAG, "requestLocationUpdatesInternalWithIntent: " + request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder iglms54() throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms54");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms55(String var1, LatLngBounds var2, AutocompleteFilter var3, PlacesParams var4,
|
||||||
|
IPlacesCallbacks var5) throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms54: " + var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addGeofences(GeofencingRequest geofencingRequest, PendingIntent pendingIntent,
|
||||||
|
IGeofencerCallbacks callbacks) throws RemoteException {
|
||||||
|
Log.d(TAG, "addGeofences: " + geofencingRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void iglms58(List var1, PlacesParams var2, IPlacesCallbacks var3)
|
||||||
|
throws RemoteException {
|
||||||
|
Log.d(TAG, "iglms54: " + var1);
|
||||||
|
}
|
||||||
|
}
|
@ -44,8 +44,8 @@ public class GmsMapsTypeHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BoundingBox fromLatLngBounds(LatLngBounds bounds) {
|
public static BoundingBox fromLatLngBounds(LatLngBounds bounds) {
|
||||||
return new BoundingBox(bounds.southWest.latitude, bounds.southWest.longitude,
|
return new BoundingBox(bounds.southwest.latitude, bounds.southwest.longitude,
|
||||||
bounds.northEast.latitude, bounds.northEast.longitude);
|
bounds.northeast.latitude, bounds.northeast.longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float fromBearing(float bearing) {
|
public static float fromBearing(float bearing) {
|
||||||
|
Loading…
Reference in New Issue
Block a user