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

Commit

Permalink
Warning for disabled restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Aug 15, 2014
1 parent 82e71af commit a2a3028
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,11 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage
else if (hook.getFrom() != null) {
String version = getSetting(new PSetting(userId, "", PrivacyManager.cSettingVersion, "0.0")).value;
if (new Version(version).compareTo(hook.getFrom()) < 0)
if (hook.getReplacedRestriction() == null)
if (hook.getReplacedRestriction() == null) {
Util.log(null, Log.WARN, "Disabled version=" + version + " from=" + hook.getFrom()
+ " hook=" + hook);
return mresult;
else {
} else {
restriction.restrictionName = hook.getReplacedRestriction();
restriction.methodName = hook.getReplacedMethod();
Util.log(null, Log.WARN, "Checking " + restriction + " instead of " + hook);
Expand Down
134 changes: 134 additions & 0 deletions src/biz/bokhorst/xprivacy/XFusedLocationApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package biz.bokhorst.xprivacy;

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;
import java.util.WeakHashMap;

import android.app.PendingIntent;
import android.location.Location;
import android.os.Binder;
import android.util.Log;

public class XFusedLocationApi extends XHook {
private Methods mMethod;
private String mClassName;
private static final Map<Object, Object> mMapProxy = new WeakHashMap<Object, Object>();

private XFusedLocationApi(Methods method, String restrictionName, String className) {
super(restrictionName, method.name(), "GMS5." + method.name());
mMethod = method;
mClassName = className;
}

public String getClassName() {
return mClassName;
}

// @formatter:off

// Location getLastLocation(GoogleApiClient client)
// abstract PendingResult<Status> removeLocationUpdates(GoogleApiClient client, LocationListener listener)
// abstract PendingResult<Status> removeLocationUpdates(GoogleApiClient client, PendingIntent callbackIntent)
// abstract PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationListener listener, Looper looper)
// abstract PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationListener listener)
// abstract PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, PendingIntent callbackIntent)
// https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html

// @formatter:on

private enum Methods {
getLastLocation, removeLocationUpdates, requestLocationUpdates
};

public static List<XHook> getInstances(Object instance) {
String className = instance.getClass().getName();
Util.log(null, Log.INFO, "Hooking class=" + className + " uid=" + Binder.getCallingUid());

List<XHook> listHook = new ArrayList<XHook>();
if (PrivacyManager.getTransient(className, null) == null) {
PrivacyManager.setTransient(className, Boolean.toString(true));

listHook.add(new XFusedLocationApi(Methods.getLastLocation, PrivacyManager.cLocation, className));
listHook.add(new XFusedLocationApi(Methods.removeLocationUpdates, PrivacyManager.cLocation, className));
listHook.add(new XFusedLocationApi(Methods.requestLocationUpdates, PrivacyManager.cLocation, className));
}
return listHook;
}

@Override
protected void before(XParam param) throws Throwable {
switch (mMethod) {
case getLastLocation:
// Do nothing
break;

case removeLocationUpdates:
if (param.args.length > 1)
if (param.args[1] instanceof PendingIntent) {
if (isRestricted(param, PrivacyManager.cLocation, "GMS5.requestLocationUpdates"))
param.setResult(null);
} else
synchronized (mMapProxy) {
if (mMapProxy.containsKey(param.args[1]))
param.args[1] = mMapProxy.get(param.args[1]);
}
break;

case requestLocationUpdates:
if (param.args.length > 2)
if (isRestricted(param))
if (param.args[2] instanceof PendingIntent)
param.setResult(null);
else if (param.thisObject != null && param.args[2] != null) {
// Create proxy
ClassLoader cl = param.thisObject.getClass().getClassLoader();
Class<?> ll = Class.forName("com.google.android.gms.location.LocationListener", false, cl);
InvocationHandler ih = new OnLocationChangedHandler(Binder.getCallingUid(), param.args[2]);
Object proxy = Proxy.newProxyInstance(cl, new Class<?>[] { ll }, ih);

// Use proxy
synchronized (mMapProxy) {
mMapProxy.put(param.args[2], proxy);
}
param.args[2] = proxy;
}
break;
}
}

@Override
protected void after(XParam param) throws Throwable {
switch (mMethod) {
case getLastLocation:
Location location = (Location) param.getResult();
if (location != null && isRestricted(param))
param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
break;

case removeLocationUpdates:
case requestLocationUpdates:
// Do nothing
break;
}
}

private class OnLocationChangedHandler implements InvocationHandler {
private int mUid;
private Object mTarget;

public OnLocationChangedHandler(int uid, Object target) {
mUid = uid;
mTarget = target;
}

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);
}
}
}

0 comments on commit a2a3028

Please sign in to comment.