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

Commit

Permalink
Restriction of draw over / on top (experimental)
Browse files Browse the repository at this point in the history
Refs #830
  • Loading branch information
M66B committed Nov 27, 2013
1 parent c3306ce commit b12e0ad
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
**Next release**

* Caching of application information for better response times
* Restriction of draw over / on top ([issue](https://github.com/M66B/XPrivacy/issues/830))
* Updated Arabic translation
* Updated Dutch translation
* Updated Polish translation
Expand Down
6 changes: 5 additions & 1 deletion assets/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@
<Hook restriction="system" method="android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE" dangerous="true" permissions="" sdk="14" />
<Hook restriction="system" method="ApplicationsProvider" permissions="" sdk="14" />

<Hook restriction="view" method="getSettings" permissions="" sdk="1" />
<Hook restriction="view" method="setUserAgent" permissions="" sdk="1" />
<Hook restriction="view" method="setUserAgentString" permissions="" sdk="1" />
<Hook restriction="view" method="WebView.constructor" permissions="" sdk="1" />
<Hook restriction="view" method="addView" permissions="" sdk="1" />
<Hook restriction="view" method="removeView" permissions="" sdk="1" />
<Hook restriction="view" method="updateViewLayout" permissions="" sdk="1" />
<Hook restriction="view" method="android.intent.action.VIEW" permissions="" sdk="14" />
</Meta>
53 changes: 52 additions & 1 deletion src/biz/bokhorst/xprivacy/XContextWrapper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package biz.bokhorst.xprivacy;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Binder;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedBridge;

public class XContextWrapper extends XHook {
private Methods mMethod;
private static boolean mWindowManagerHooked = false;

private XContextWrapper(Methods method, String restrictionName) {
super(restrictionName, method.name(), null);
Expand All @@ -23,16 +29,18 @@ public String getClassName() {

// public Context getApplicationContext()
// public Context getBaseContext()
// public Object getSystemService(String name)
// frameworks/base/core/java/android/content/ContextWrapper.java

private enum Methods {
getApplicationContext, getBaseContext
getApplicationContext, getBaseContext, getSystemService
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XContextWrapper(Methods.getApplicationContext, null));
listHook.add(new XContextWrapper(Methods.getBaseContext, null));
listHook.add(new XContextWrapper(Methods.getSystemService, PrivacyManager.cView));
return listHook;
}

Expand All @@ -49,7 +57,50 @@ protected void after(MethodHookParam param) throws Throwable {
Context context = (Context) param.getResult();
if (context != null && PrivacyManager.isExtraUsageDataEnabled(uid))
PrivacyManager.sendUsageData(this, context);
} else if (mMethod == Methods.getSystemService) {
if (!mWindowManagerHooked) {
String name = (String) param.args[0];
if (name != null && name.equals(Context.WINDOW_SERVICE)) {

// @formatter:off

// public void addView(View view, ViewGroup.LayoutParams params)
// public void removeView(View view)
// public void updateViewLayout(View view, ViewGroup.LayoutParams params)
// http://developer.android.com/reference/android/view/ViewManager.html
// http://developer.android.com/reference/android/view/WindowManager.html

// @formatter:on

Object windowManager = param.getResultOrThrowable();
if (windowManager != null) {
{
Class<?> clazz = windowManager.getClass();
hook(clazz, "addView", View.class, ViewGroup.LayoutParams.class);
hook(clazz, "removeView", View.class);
hook(clazz, "updateViewLayout", View.class, ViewGroup.LayoutParams.class);
mWindowManagerHooked = true;
}
}
}
}
} else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}

private void hook(Class<?> clazz, final String methodName, Class<?>... types) {
try {
Util.log(this, Log.INFO, "Hooking " + clazz.getName() + "." + methodName);
Method addView = clazz.getDeclaredMethod(methodName, types);
XposedBridge.hookMethod(addView, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (isRestricted(param, methodName))
param.setResult(null);
}
});
} catch (NoSuchMethodException ex) {
Util.bug(this, ex);
}
}
}
8 changes: 2 additions & 6 deletions src/biz/bokhorst/xprivacy/XWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ protected void after(MethodHookParam param) throws Throwable {
XposedBridge.hookMethod(setUserAgent, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (isRestricted(param)) {
Util.log(XWebView.this, Log.INFO, "Restricting setUserAgent");
if (isRestricted(param, "setUserAgent"))
param.setResult(null);
}
}
});
} catch (NoSuchFieldError ex) {
Expand All @@ -91,10 +89,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.hookMethod(setUserAgentString, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (isRestricted(param)) {
Util.log(XWebView.this, Log.INFO, "Restricting setUserAgentString");
if (isRestricted(param, "setUserAgentString"))
param.args[0] = PrivacyManager.getDefacedProp(Binder.getCallingUid(), "UA");
}
}
});
} catch (NoSuchFieldError ex) {
Expand Down

0 comments on commit b12e0ad

Please sign in to comment.