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

Commit f7df4585 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

7530: fakelocation, add logs to trace calls down to LocationProviderManager.

parent 3d4687eb
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -823,6 +823,7 @@ public class LocationManager {
        Preconditions.checkArgument(lastLocationRequest != null,
                "invalid null last location request");

        Log.d("AP-FakeLocation", "LocationManager::getLastKnownLocation")
        try {
            return mService.getLastLocation(provider, lastLocationRequest,
                    mContext.getPackageName(), mContext.getAttributionTag());
@@ -932,6 +933,7 @@ public class LocationManager {
            @NonNull LocationRequest locationRequest,
            @Nullable CancellationSignal cancellationSignal,
            @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Location> consumer) {
        Log.d("AP-FakeLocation", "LocationManager::getCurrentLocation");
        Preconditions.checkArgument(provider != null, "invalid null provider");
        Preconditions.checkArgument(locationRequest != null, "invalid null location request");

@@ -1480,6 +1482,7 @@ public class LocationManager {
            @NonNull LocationRequest locationRequest,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull LocationListener listener) {
        Log.d("AP-FakeLocation", "LocationManager::requestLocationIpdates")
        Preconditions.checkArgument(provider != null, "invalid null provider");
        Preconditions.checkArgument(locationRequest != null, "invalid null location request");

@@ -1529,6 +1532,7 @@ public class LocationManager {
    public void requestLocationUpdates(@NonNull String provider,
            @NonNull LocationRequest locationRequest,
            @NonNull PendingIntent pendingIntent) {
        Log.d("AP-FakeLocation", "LocatonManager::requestLocationUpdates (pendingIntent)")
        Preconditions.checkArgument(provider != null, "invalid null provider");
        Preconditions.checkArgument(locationRequest != null, "invalid null location request");
        Preconditions.checkArgument(pendingIntent != null, "invalid null pending intent");
@@ -1601,6 +1605,7 @@ public class LocationManager {
    @SuppressLint("SamShouldBeLast")
    public void requestFlush(@NonNull String provider, @NonNull LocationListener listener,
            @SuppressLint("ListenerLast") int requestCode) {
        //TODO: should we chek this ?
        Preconditions.checkArgument(provider != null, "invalid null provider");
        Preconditions.checkArgument(listener != null, "invalid null listener");

@@ -2183,6 +2188,7 @@ public class LocationManager {
    @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
    public void addProximityAlert(double latitude, double longitude, float radius, long expiration,
            @NonNull PendingIntent pendingIntent) {
        Log.d("AP-FakeLocation", "LocationManger::addProximityAlert");
        Preconditions.checkArgument(pendingIntent != null, "invalid null pending intent");

        if (Compatibility.isChangeEnabled(BLOCK_UNTARGETED_PENDING_INTENTS)) {
@@ -2496,6 +2502,7 @@ public class LocationManager {
    @RequiresPermission(ACCESS_FINE_LOCATION)
    public boolean addNmeaListener(
            @NonNull OnNmeaMessageListener listener, @Nullable Handler handler) {
        // TODO: should we handle this ?
        if (handler == null) {
            handler = new Handler();
        }
@@ -2519,6 +2526,7 @@ public class LocationManager {
    public boolean addNmeaListener(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull OnNmeaMessageListener listener) {
        // TODO: should we handle this ?
        GnssLazyLoader.sGnssNmeaListeners.addListener(listener,
                new GnssNmeaTransport(executor, mContext, listener));
        return true;
@@ -2619,6 +2627,7 @@ public class LocationManager {
    public boolean registerGnssMeasurementsCallback(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull GnssMeasurementsEvent.Callback callback) {
        // TODO: should we handle this !!?
        return registerGnssMeasurementsCallback(new GnssMeasurementRequest.Builder().build(),
                executor, callback);
    }
@@ -2803,7 +2812,7 @@ public class LocationManager {
        if (handler == null) {
            handler = new Handler();
        }

        // TODO : should we handle this !!
        return registerGnssNavigationMessageCallback(new HandlerExecutor(handler), callback);
    }

+6 −0
Original line number Diff line number Diff line
@@ -678,6 +678,7 @@ public class LocationManagerService extends ILocationManager.Stub implements
    public ICancellationSignal getCurrentLocation(String provider, LocationRequest request,
            ILocationCallback consumer, String packageName, @Nullable String attributionTag,
            String listenerId) {
        Log.d("AP-FakeLocation", "LocationManagerService::getCurrentLocation " + packageName);
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag,
                listenerId);
        int permissionLevel = LocationPermissions.getPermissionLevel(mContext, identity.getUid(),
@@ -701,6 +702,7 @@ public class LocationManagerService extends ILocationManager.Stub implements
    public void registerLocationListener(String provider, LocationRequest request,
            ILocationListener listener, String packageName, @Nullable String attributionTag,
            String listenerId) {
        Log.d("AP-FakeLocation", "LocationManagerService::resgisterLocationListener " + packageName);
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag,
                listenerId);
        int permissionLevel = LocationPermissions.getPermissionLevel(mContext, identity.getUid(),
@@ -728,6 +730,8 @@ public class LocationManagerService extends ILocationManager.Stub implements
            PendingIntent pendingIntent, String packageName, @Nullable String attributionTag) {
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag,
                AppOpsManager.toReceiverId(pendingIntent));
        Log.d("AP-FakeLocation", "LocationManagerService::resgisterLocationPendingIntent " + packageName);

        int permissionLevel = LocationPermissions.getPermissionLevel(mContext, identity.getUid(),
                identity.getPid());
        LocationPermissions.enforceLocationPermission(identity.getUid(), permissionLevel,
@@ -892,6 +896,7 @@ public class LocationManagerService extends ILocationManager.Stub implements
    public Location getLastLocation(String provider, LastLocationRequest request,
            String packageName, @Nullable String attributionTag) {
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag);
        Log.d("AP-FakeLocation", "LocationManagerService::getLastLocation from " + packageName);
        int permissionLevel = LocationPermissions.getPermissionLevel(mContext, identity.getUid(),
                identity.getPid());
        LocationPermissions.enforceLocationPermission(identity.getUid(), permissionLevel,
@@ -989,6 +994,7 @@ public class LocationManagerService extends ILocationManager.Stub implements
    @Override
    public void requestGeofence(Geofence geofence, PendingIntent intent, String packageName,
            String attributionTag) {
        Log.d("AP-FakeLocation", "LocationManagerService::requestGeofence " + packageName);
        mGeofenceManager.addGeofence(geofence, intent, packageName, attributionTag);
    }

+2 −0
Original line number Diff line number Diff line
@@ -294,6 +294,8 @@ public class GeofenceManager extends
     */
    public void addGeofence(Geofence geofence, PendingIntent pendingIntent, String packageName,
            @Nullable String attributionTag) {
        Log.d("AP-FakeLocation", "GeofenceManager::addGeofence " + packageName);
        // TODO: should we block geofence for blacklisted app, or fake it ?
        LocationPermissions.enforceCallingOrSelfLocationPermission(mContext, PERMISSION_FINE);

        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName,
+41 −0
Original line number Diff line number Diff line
@@ -199,6 +199,10 @@ public class LocationProviderManager extends
        @Override
        public void deliverOnLocationChanged(LocationResult locationResult,
                @Nullable IRemoteCallback onCompleteCallback) throws RemoteException {

            Location trueLoc = locationResult.getLastLocation();
            String locStr = (trueLoc != null)  trueLoc.longitude + " ; " + trueLoc.latitude ? "loc NULL";
            Log.d("AP-FakeLocation", "LocationProviderManager::LocationListenerTransport::deliverOnLocationChanged : " + locStr);
            mListener.onLocationChanged(locationResult.asList(), onCompleteCallback);
        }

@@ -229,6 +233,11 @@ public class LocationProviderManager extends
        public void deliverOnLocationChanged(LocationResult locationResult,
                @Nullable IRemoteCallback onCompleteCallback)
                throws PendingIntent.CanceledException {

            Location trueLoc = locationResult.getLastLocation();
            String locStr = (trueLoc != null)  trueLoc.longitude + " ; " + trueLoc.latitude ? "loc NULL";
            Log.d("AP-FakeLocation", "LocationProviderManager::LocationLPendingIntentTransport::deliverOnLocationChanged : " + locStr);

            BroadcastOptions options = BroadcastOptions.makeBasic();
            options.setDontSendToRestrictedApps(true);
            // allows apps to start a fg service in response to a location PI
@@ -310,6 +319,10 @@ public class LocationProviderManager extends
        public void deliverOnLocationChanged(@Nullable LocationResult locationResult,
                @Nullable IRemoteCallback onCompleteCallback)
                throws RemoteException {
            Location trueLoc = locationResult.getLastLocation();
            String locStr = (trueLoc != null)  trueLoc.longitude + " ; " + trueLoc.latitude ? "loc NULL";
            Log.d("AP-FakeLocation", "LocationProviderManager::GetCurrentLocationTransport::deliverOnLocationChanged : " + locStr);

            // ILocationCallback doesn't currently support completion callbacks
            Preconditions.checkState(onCompleteCallback == null);
            if (locationResult != null) {
@@ -968,6 +981,14 @@ public class LocationProviderManager extends
                    // if delivering to the same process, make a copy of the location first (since
                    // location is mutable)
                    LocationResult deliverLocationResult;
                    Log.d("AP-FakeLocation", "LocationProviderManager::LocationRegistration::acceptLocationChange, ListenerOperation::operate, fakeLocation");
                    Location trueLoc = locationResult.getLastLocation();
                    if (trueLoc != null) {
                        Log.d("AP-FakeLocation", "LocationRegistration...operate, true location is " + trueLoc.longitude + " ; " + trueLoc.latitude);
                    }
                    CallerIdentity identity = getIdentity();
                    Log.d("AP-FakeLocation", "LocationRegistration...operate, fakeLocation for app" + identity.getPackageName());

                    if (getIdentity().getPid() == Process.myPid()) {
                        deliverLocationResult = locationResult.deepCopy();
                    } else {
@@ -1270,6 +1291,16 @@ public class LocationProviderManager extends
                public void operate(LocationTransport listener) throws Exception {
                    // if delivering to the same process, make a copy of the location first (since
                    // location is mutable)
                    LocationResult deliverLocationResult;
                    Log.d("AP-FakeLocation", "LocationProviderManager::GetCurrentLocationListenerRegistration::acceptLocationChange, ListenerOperation::operate, fakeLocation");
                    Location trueLoc = locationResult.getLastLocation();
                    if (trueLoc != null) {
                        Log.d("AP-FakeLocation", "GetCurrentLocationListenerRegistration...operate, true location is " + trueLoc.longitude + " ; " + trueLoc.latitude);
                    }
                    CallerIdentity identity = getIdentity();
                    Log.d("AP-FakeLocation", "GetCurrentLocationListenerRegistration...operate, fakeLocation for app" + identity.getPackageName());


                    LocationResult deliverLocationResult;
                    if (getIdentity().getPid() == Process.myPid() && locationResult != null) {
                        deliverLocationResult = locationResult.deepCopy();
@@ -1656,6 +1687,9 @@ public class LocationProviderManager extends
                        Long.MAX_VALUE),
                permissionLevel);

        String locStr = (location != null) location.longitude + " ; " + location.latitude else "NO LOC";
        Log.d("AP-FakeLocation", "LocatonProviderManager::getLastLocation " + identity.getPackageName() + " true location: " + locStr);

        if (location != null && identity.getPid() == Process.myPid()) {
            // if delivering to the same process, make a copy of the location first (since
            // location is mutable)
@@ -1761,6 +1795,7 @@ public class LocationProviderManager extends
                    .build();
        }

        Log.d("AP-FakeLocation", "LocationProviderManager::getCurrentLocation from " + identity.getPackageName());
        GetCurrentLocationListenerRegistration registration =
                new GetCurrentLocationListenerRegistration(
                        request,
@@ -1804,6 +1839,9 @@ public class LocationProviderManager extends

    public void registerLocationRequest(LocationRequest request, CallerIdentity identity,
            @PermissionLevel int permissionLevel, ILocationListener listener) {

        Log.d("AP-FakeLocation", "LocatonProviderManager::registerLocationRequest " + identity.getPackageName());

        LocationListenerRegistration registration = new LocationListenerRegistration(
                request,
                identity,
@@ -1823,6 +1861,8 @@ public class LocationProviderManager extends

    public void registerLocationRequest(LocationRequest request, CallerIdentity callerIdentity,
            @PermissionLevel int permissionLevel, PendingIntent pendingIntent) {
        Log.d("AP-FakeLocation", "LocatonProviderManager::registerLocationRequest (pendingIntent) " + identity.getPackageName());

        LocationPendingIntentRegistration registration = new LocationPendingIntentRegistration(
                request,
                callerIdentity,
@@ -2450,6 +2490,7 @@ public class LocationProviderManager extends

        // attempt listener delivery
        deliverToListeners(registration -> {
            Log.d("AP-FakeLocation", "LocationProviderManager::onReportLocation, deliverToListener " + filtered);
            return registration.acceptLocationChange(filtered);
        });