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

Commit

Permalink
Restrict FusedLocationApi
Browse files Browse the repository at this point in the history
Refs #1774
  • Loading branch information
M66B committed Aug 15, 2014
1 parent a2a3028 commit a8f5eb7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Version 2.99.x and version 3.x will be available with a [pro license](http://www

**Next release**

* Added restriction *GMS5.getLastLocation* and *GMS5.requestLocationUpdates* ([issue](/../../issues/1774))

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

**Version 2.99.25 BETA**
Expand Down
10 changes: 8 additions & 2 deletions src/biz/bokhorst/xprivacy/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ public static List<Hook> get() {
mListHook.add(new Hook("location", "GMS.requestLocationUpdates", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, null, null).unsafe().optional());
mListHook.add(new Hook("location", "GMS.requestActivityUpdates", "com.google.android.gms.permission.ACTIVITY_RECOGNITION", 1, null, null).unsafe());

mListHook.add(new Hook("location", "GMS5.getLastLocation", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.99.26", null).unsafe().optional());
mListHook.add(new Hook("location", "GMS5.requestLocationUpdates", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.99.26", null).unsafe().optional());

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

mListHook.add(new Hook("location", "MapV2.getMyLocation", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null).unsafe().optional());
Expand Down Expand Up @@ -529,8 +532,8 @@ public static List<Hook> get() {
mListHook.add(new Hook(null, "getSystemService", "", 1, null, null).notAOSP(19));

// GoogleApiClient.Builder
mListHook.add(new Hook(null, "GAC.addConnectionCallbacks", "", 1, null, null).optional());
mListHook.add(new Hook(null, "GAC.onConnected", "", 1, null, null));
mListHook.add(new Hook(null, "GMS5.addConnectionCallbacks", "", 1, null, null).optional());
mListHook.add(new Hook(null, "GMS5.onConnected", "", 1, null, null));

// IntentFirewall
mListHook.add(new Hook(null, "checkIntent", "", 19, null, null));
Expand All @@ -540,6 +543,9 @@ public static List<Hook> get() {
mListHook.add(new Hook(null, "GMS.removeGeofences", "", 1, null, null).optional());
mListHook.add(new Hook(null, "GMS.removeLocationUpdates", "", 1, null, null).optional());

// FusedLocationProviderApi
mListHook.add(new Hook(null, "GMS5.removeLocationUpdates", "", 1, "2.99.26", null).optional());

// LocationManager/Service
mListHook.add(new Hook(null, "removeUpdates", "", 3, null, null).notAOSP(19));
mListHook.add(new Hook(null, "Srv_removeUpdates", "", 19, null, null));
Expand Down
25 changes: 21 additions & 4 deletions src/biz/bokhorst/xprivacy/XConnectionCallbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class XConnectionCallbacks extends XHook {
private String mClassName;

private XConnectionCallbacks(Methods method, String restrictionName, String className) {
super(restrictionName, method.name(), "GAC." + method.name());
super(restrictionName, method.name(), "GMS5." + method.name());
mMethod = method;
mClassName = className;
}
Expand All @@ -33,7 +33,7 @@ private enum Methods {

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

List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XConnectionCallbacks(Methods.onConnected, null, className));
Expand All @@ -44,14 +44,31 @@ public static List<XHook> getInstances(Object instance) {
protected void before(XParam param) throws Throwable {
switch (mMethod) {
case onConnected:
Util.log(this, Log.INFO, "onConnected uid=" + Binder.getCallingUid());
ClassLoader loader = param.thisObject.getClass().getClassLoader();

// FusedLocationApi
Class<?> cLoc = Class.forName("com.google.android.gms.location.LocationServices", false, loader);
Object fusedLocationApi = cLoc.getDeclaredField("FusedLocationApi").get(null);
Util.log(this, Log.WARN, "FusedLocationApi class=" + fusedLocationApi.getClass());
if (PrivacyManager.getTransient(fusedLocationApi.getClass().getName(), null) == null) {
PrivacyManager.setTransient(fusedLocationApi.getClass().getName(), Boolean.toString(true));

XPrivacy.hookAll(XFusedLocationApi.getInstances(fusedLocationApi), loader, getSecret());
}

// ActivityRecognitionApi
Class<?> cRec = Class.forName("com.google.android.gms.location.ActivityRecognition", false, loader);
Object activityRecognitionApi = cRec.getDeclaredField("ActivityRecognitionApi").get(null);
Util.log(this, Log.WARN, "ActivityRecognitionApi class=" + activityRecognitionApi.getClass());
if (PrivacyManager.getTransient(activityRecognitionApi.getClass().getName(), null) == null) {
PrivacyManager.setTransient(activityRecognitionApi.getClass().getName(), Boolean.toString(true));
}

// AppIndexApi
Class<?> cApp = Class.forName("com.google.android.gms.appindexing.AppIndex", false, loader);
Object appIndexApi = cApp.getDeclaredField("AppIndexApi").get(null);
if (PrivacyManager.getTransient(appIndexApi.getClass().getName(), null) == null) {
PrivacyManager.setTransient(appIndexApi.getClass().getName(), Boolean.toString(true));
}

break;
}
Expand Down
10 changes: 3 additions & 7 deletions src/biz/bokhorst/xprivacy/XFusedLocationApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ public static List<XHook> getInstances(Object instance) {
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));
}
listHook.add(new XFusedLocationApi(Methods.getLastLocation, PrivacyManager.cLocation, className));
listHook.add(new XFusedLocationApi(Methods.removeLocationUpdates, null, className));
listHook.add(new XFusedLocationApi(Methods.requestLocationUpdates, PrivacyManager.cLocation, className));
return listHook;
}

Expand Down
8 changes: 6 additions & 2 deletions src/biz/bokhorst/xprivacy/XGoogleApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import java.util.ArrayList;
import java.util.List;

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

public class XGoogleApiClient extends XHook {
private Methods mMethod;

private XGoogleApiClient(Methods method, String restrictionName) {
super(restrictionName, method.name(), "GAC." + method.name());
super(restrictionName, method.name(), "GMS5." + method.name());
mMethod = method;
}

Expand All @@ -27,7 +30,7 @@ private enum Methods {
};

public static List<XHook> getInstances() {
Util.log(null, android.util.Log.WARN, "Loaded GAC");
Util.log(null, Log.INFO, "Loaded GoogleApiClient$Builder uid=" + Binder.getCallingUid());
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XGoogleApiClient(Methods.addConnectionCallbacks, null));
return listHook;
Expand All @@ -41,6 +44,7 @@ protected void before(XParam param) throws Throwable {
Class<?> clazz = param.args[0].getClass();
if (PrivacyManager.getTransient(clazz.getName(), null) == null) {
PrivacyManager.setTransient(clazz.getName(), Boolean.toString(true));

XPrivacy.hookAll(XConnectionCallbacks.getInstances(param.args[0]), clazz.getClassLoader(),
getSecret());
}
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XLocationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void before(XParam param) throws Throwable {
if (isRestricted(param))
if (param.args[1] instanceof PendingIntent)
param.setResult(null);
else if (param.thisObject != null) {
else if (param.thisObject != null && param.args[1] != null) {
// Create proxy
ClassLoader cl = param.thisObject.getClass().getClassLoader();
Class<?> ll = Class.forName("com.google.android.gms.location.LocationListener", false, cl);
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private static void handleLoadPackage(String packageName, ClassLoader classLoade

// GoogleApiClient.Builder
try {
Class.forName("com.google.android.gms.common.api.GoogleApiClient", false, classLoader);
Class.forName("com.google.android.gms.common.api.GoogleApiClient$Builder", false, classLoader);
hookAll(XGoogleApiClient.getInstances(), classLoader, secret);
} catch (Throwable ignored) {
}
Expand Down

0 comments on commit a8f5eb7

Please sign in to comment.