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

Commit

Permalink
Added restrictions for Google Maps API v1
Browse files Browse the repository at this point in the history
Refs #1807
  • Loading branch information
M66B committed Jul 12, 2014
1 parent 5ad0dfb commit 33c5ad1
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Changelog

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

* Added restrictions for [Google Maps API v1](https://developers.google.com/maps/documentation/android/v1/reference/index) ([issue](/../../issues/1807))

**Version 2.1.24-2 TEST**

* Added IPC restriction *ICameraService*
Expand Down
5 changes: 5 additions & 0 deletions src/biz/bokhorst/xprivacy/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,16 @@ public static List<Hook> get() {
mListHook.add(new Hook("location", "getAllCellInfo", "ACCESS_COARSE_UPDATES", 17, null, null));
mListHook.add(new Hook("location", "getScanResults", "ACCESS_WIFI_STATE", 1, null, null).dangerous());
mListHook.add(new Hook("location", "listen", "ACCESS_COARSE_LOCATION", 1, null, null));

mListHook.add(new Hook("location", "GMS.addGeofences", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, null, null));
mListHook.add(new Hook("location", "GMS.getLastLocation", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, null, null));
mListHook.add(new Hook("location", "GMS.requestLocationUpdates", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, null, null));
mListHook.add(new Hook("location", "GMS.requestActivityUpdates", "com.google.android.gms.permission.ACTIVITY_RECOGNITION", 1, null, null));

mListHook.add(new Hook("location", "MapV1.getLatitudeE6", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));
mListHook.add(new Hook("location", "MapV1.getLongitudeE6", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));
mListHook.add(new Hook("location", "MapV1.enableMyLocation", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));

mListHook.add(new Hook("location", "MapV2.getMyLocation", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));
mListHook.add(new Hook("location", "MapV2.getPosition", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));
mListHook.add(new Hook("location", "MapV2.setLocationSource", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null));
Expand Down
88 changes: 88 additions & 0 deletions src/biz/bokhorst/xprivacy/XGoogleMapV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package biz.bokhorst.xprivacy;

import java.util.ArrayList;
import java.util.List;

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

public class XGoogleMapV1 extends XHook {
private Methods mMethod;

private XGoogleMapV1(Methods method, String restrictionName) {
super(restrictionName, method.name(), String.format("MapV1.%s", method.name()));
mMethod = method;
}

private XGoogleMapV1(Methods method, String restrictionName, int sdk) {
super(restrictionName, method.name(), String.format("MapV1.%s", method.name()), sdk);
mMethod = method;
}

public String getClassName() {
if (mMethod == Methods.getLatitudeE6 || mMethod == Methods.getLongitudeE6)
return "com.google.android.maps.GeoPoint";
else
return "com.google.android.maps.MyLocationOverlay";
}

// @formatter:off

// int getLatitudeE6()
// int getLongitudeE6()
// boolean enableMyLocation()
// GeoPoint getMyLocation()
// https://developers.google.com/maps/documentation/android/v1/reference/index

// @formatter:on

private enum Methods {
getLatitudeE6, getLongitudeE6, enableMyLocation
};

public static List<XHook> getInstances() {
Util.log(null, Log.WARN, "Google Maps V1 uid=" + Binder.getCallingUid());
List<XHook> listHook = new ArrayList<XHook>();
for (Methods method : Methods.values())
listHook.add(new XGoogleMapV1(method, PrivacyManager.cLocation).optional());
return listHook;
}

@Override
protected void before(XParam param) throws Throwable {
if (mMethod == Methods.getLatitudeE6) {
// Do nothing

} else if (mMethod == Methods.getLongitudeE6) {
// Do nothing

} else if (mMethod == Methods.enableMyLocation) {
if (isRestricted(param))
param.setResult(false);

} else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}

@Override
protected void after(XParam param) throws Throwable {
if (mMethod == Methods.getLatitudeE6) {
if (isRestricted(param)) {
Location fakeLocation = PrivacyManager.getDefacedLocation(Binder.getCallingUid(), null);
param.setResult((int) Math.round(fakeLocation.getLatitude() * 1e6));
}

} else if (mMethod == Methods.getLongitudeE6) {
if (isRestricted(param)) {
Location fakeLocation = PrivacyManager.getDefacedLocation(Binder.getCallingUid(), null);
param.setResult((int) Math.round(fakeLocation.getLongitude() * 1e6));
}

} else if (mMethod == Methods.enableMyLocation) {
// Do nothing

} else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import android.os.Binder;
import android.util.Log;

public class XGoogleMap extends XHook {
public class XGoogleMapV2 extends XHook {
private Methods mMethod;

private XGoogleMap(Methods method, String restrictionName) {
private XGoogleMapV2(Methods method, String restrictionName) {
super(restrictionName, method.name(), String.format("MapV2.%s", method.name()));
mMethod = method;
}

private XGoogleMap(Methods method, String restrictionName, int sdk) {
private XGoogleMapV2(Methods method, String restrictionName, int sdk) {
super(restrictionName, method.name(), String.format("MapV2.%s", method.name()), sdk);
mMethod = method;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ private enum Methods {
public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
for (Methods method : Methods.values())
listHook.add(new XGoogleMap(method, PrivacyManager.cLocation).optional());
listHook.add(new XGoogleMapV2(method, PrivacyManager.cLocation).optional());
return listHook;
}

Expand Down
13 changes: 10 additions & 3 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void classLoaded(Class<?> clazz) {
MS.hookClassLoad("com.google.android.gms.maps.GoogleMap", new MS.ClassLoadHook() {
@Override
public void classLoaded(Class<?> clazz) {
hookAll(XGoogleMap.getInstances(), clazz.getClassLoader(), mSecret);
hookAll(XGoogleMapV2.getInstances(), clazz.getClassLoader(), mSecret);
}
});
}
Expand Down Expand Up @@ -352,10 +352,17 @@ private static void handleLoadPackage(String packageName, ClassLoader classLoade
} catch (Throwable ignored) {
}

// Google Map
// Google Map V1
try {
Class.forName("com.google.android.maps.GeoPoint", false, classLoader);
hookAll(XGoogleMapV1.getInstances(), classLoader, secret);
} catch (Throwable ignored) {
}

// Google Map V2
try {
Class.forName("com.google.android.gms.maps.GoogleMap", false, classLoader);
hookAll(XGoogleMap.getInstances(), classLoader, secret);
hookAll(XGoogleMapV2.getInstances(), classLoader, secret);
} catch (Throwable ignored) {
}
}
Expand Down

0 comments on commit 33c5ad1

Please sign in to comment.