From b12e0ad262b8697f25b22e6e3591ef19dfa62609 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 27 Nov 2013 11:55:12 +0100 Subject: [PATCH] Restriction of draw over / on top (experimental) Refs #830 --- CHANGELOG.md | 1 + assets/meta.xml | 6 ++- .../bokhorst/xprivacy/XContextWrapper.java | 53 ++++++++++++++++++- src/biz/bokhorst/xprivacy/XWebView.java | 8 +-- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2968018..a197634a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/assets/meta.xml b/assets/meta.xml index f43b702b1..9056637ac 100644 --- a/assets/meta.xml +++ b/assets/meta.xml @@ -196,7 +196,11 @@ - + + + + + diff --git a/src/biz/bokhorst/xprivacy/XContextWrapper.java b/src/biz/bokhorst/xprivacy/XContextWrapper.java index 6ac8fe563..64c704451 100644 --- a/src/biz/bokhorst/xprivacy/XContextWrapper.java +++ b/src/biz/bokhorst/xprivacy/XContextWrapper.java @@ -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); @@ -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 getInstances() { List listHook = new ArrayList(); listHook.add(new XContextWrapper(Methods.getApplicationContext, null)); listHook.add(new XContextWrapper(Methods.getBaseContext, null)); + listHook.add(new XContextWrapper(Methods.getSystemService, PrivacyManager.cView)); return listHook; } @@ -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); + } + } } diff --git a/src/biz/bokhorst/xprivacy/XWebView.java b/src/biz/bokhorst/xprivacy/XWebView.java index aaf2ce763..59b8ef693 100644 --- a/src/biz/bokhorst/xprivacy/XWebView.java +++ b/src/biz/bokhorst/xprivacy/XWebView.java @@ -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) { @@ -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) {