Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Alternate location proxy implementation
Browse files Browse the repository at this point in the history
Refs #2105
  • Loading branch information
M66B committed Jan 6, 2015
1 parent 348de98 commit 038bddc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Changelog

**Next release**

* Fixed disabling location updates in compatibility mode ([issue](/../../issues/2105))
* Removed Cydia Substrate library
* Updated Hindi translation
* Updated Slovak translation
Expand Down
63 changes: 38 additions & 25 deletions src/biz/bokhorst/xprivacy/XLocationManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package biz.bokhorst.xprivacy;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -12,8 +9,7 @@
import android.app.PendingIntent;
import android.location.Location;
import android.os.Binder;
import android.os.IInterface;
import android.util.Log;
import android.os.Bundle;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.LocationListener;
Expand Down Expand Up @@ -326,19 +322,25 @@ private void proxyLocationListener(XParam param, int arg, Class<?> interfaze) th
param.setResult(null);

else if (param.args[arg] != null && param.thisObject != null) {
// Create proxy
ClassLoader cl = param.thisObject.getClass().getClassLoader();
InvocationHandler ih = new OnLocationChangedHandler(Binder.getCallingUid(), param.args[arg]);
Object proxy = Proxy.newProxyInstance(cl, new Class<?>[] { interfaze }, ih);

Object key = param.args[arg];
if (key instanceof IInterface)
key = ((IInterface) key).asBinder();
synchronized (mMapProxy) {
// Reuse existing proxy
if (mMapProxy.containsKey(key)) {
param.args[arg] = mMapProxy.get(key);
return;
}

// Already proxied
if (mMapProxy.containsValue(key))
return;
}

// Create proxy
Object proxy = new ProxyLocationListener(Binder.getCallingUid(), (LocationListener) param.args[arg]);

// Use proxy
synchronized (mMapProxy) {
mMapProxy.put(key, proxy);
Util.log(this, Log.INFO, "proxyLocationListener uid=" + Binder.getCallingUid());
}
param.args[arg] = proxy;
}
Expand All @@ -351,31 +353,42 @@ private void unproxyLocationListener(XParam param, int arg) {

else if (param.args[arg] != null) {
Object key = param.args[arg];
if (key instanceof IInterface)
key = ((IInterface) key).asBinder();

synchronized (mMapProxy) {
if (mMapProxy.containsKey(key)) {
param.args[arg] = mMapProxy.get(key);
Util.log(this, Log.INFO, "unproxyLocationListener uid=" + Binder.getCallingUid());
}
}
}
}

private class OnLocationChangedHandler implements InvocationHandler {
private static class ProxyLocationListener implements LocationListener {
private int mUid;
private Object mTarget;
private LocationListener mListener;

public OnLocationChangedHandler(int uid, Object target) {
public ProxyLocationListener(int uid, LocationListener listener) {
mUid = uid;
mTarget = target;
mListener = listener;
}

@Override
public void onLocationChanged(Location location) {
Location fakeLocation = PrivacyManager.getDefacedLocation(mUid, location);
mListener.onLocationChanged(fakeLocation);
}

@Override
public void onProviderDisabled(String provider) {
mListener.onProviderDisabled(provider);
}

@Override
public void onProviderEnabled(String provider) {
mListener.onProviderEnabled(provider);
}

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("onLocationChanged".equals(method.getName()))
args[0] = PrivacyManager.getDefacedLocation(mUid, (Location) args[0]);
return method.invoke(mTarget, args);
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
mListener.onStatusChanged(provider, status, extras);
}
}
}

0 comments on commit 038bddc

Please sign in to comment.