Search in sources :

Example 1 with XC_MethodHook

use of de.robv.android.xposed.XC_MethodHook in project XPrivacy by M66B.

the class XPrivacy method initZygote.

public void initZygote(StartupParam startupParam) throws Throwable {
    Util.log(null, Log.WARN, "Init path=" + startupParam.modulePath);
    // Check for LBE security master
    if (Util.hasLBE()) {
        Util.log(null, Log.ERROR, "LBE installed");
        return;
    }
    // Generate secret
    mSecret = Long.toHexString(new Random().nextLong());
    // Reading files with SELinux enabled can result in bootloops
    boolean selinux = Util.isSELinuxEnforced();
    if ("true".equals(Util.getXOption("ignoreselinux"))) {
        selinux = false;
        Log.w("Xprivacy", "Ignoring SELinux");
    }
    // Read list of disabled hooks
    if (mListDisabled.size() == 0 && !selinux) {
        File disabled = new File("/data/system/xprivacy/disabled");
        if (disabled.exists() && disabled.canRead())
            try {
                Log.w("XPrivacy", "Reading " + disabled.getAbsolutePath());
                FileInputStream fis = new FileInputStream(disabled);
                InputStreamReader ir = new InputStreamReader(fis);
                BufferedReader br = new BufferedReader(ir);
                String line;
                while ((line = br.readLine()) != null) if (line.length() > 0 && !line.startsWith("#")) {
                    String[] name = line.split("/");
                    if (name.length > 0) {
                        String methodName = (name.length > 1 ? name[1] : null);
                        CRestriction restriction = new CRestriction(0, name[0], methodName, null);
                        Log.w("XPrivacy", "Disabling " + restriction);
                        mListDisabled.add(restriction);
                    }
                }
                br.close();
                ir.close();
                fis.close();
            } catch (Throwable ex) {
                Log.w("XPrivacy", ex.toString());
            }
    }
    // AOSP mode override
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !selinux)
        try {
            Class<?> libcore = Class.forName("libcore.io.Libcore");
            Field fOs = libcore.getDeclaredField("os");
            fOs.setAccessible(true);
            Object os = fOs.get(null);
            Method setenv = os.getClass().getMethod("setenv", String.class, String.class, boolean.class);
            setenv.setAccessible(true);
            boolean aosp = new File("/data/system/xprivacy/aosp").exists();
            setenv.invoke(os, "XPrivacy.AOSP", Boolean.toString(aosp), false);
            Util.log(null, Log.WARN, "AOSP mode forced=" + aosp);
        } catch (Throwable ex) {
            Util.bug(null, ex);
        }
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Class<?> at = Class.forName("android.app.ActivityThread");
            XposedBridge.hookAllMethods(at, "systemMain", new XC_MethodHook() {

                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    try {
                        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
                        Class<?> am = Class.forName("com.android.server.am.ActivityManagerService", false, loader);
                        XposedBridge.hookAllConstructors(am, new XC_MethodHook() {

                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                try {
                                    PrivacyService.register(mListHookError, loader, mSecret, param.thisObject);
                                    hookSystem(loader);
                                } catch (Throwable ex) {
                                    Util.bug(null, ex);
                                }
                            }
                        });
                    } catch (Throwable ex) {
                        Util.bug(null, ex);
                    }
                }
            });
        } else {
            Class<?> cSystemServer = Class.forName("com.android.server.SystemServer");
            Method mMain = cSystemServer.getDeclaredMethod("main", String[].class);
            XposedBridge.hookMethod(mMain, new XC_MethodHook() {

                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    try {
                        PrivacyService.register(mListHookError, null, mSecret, null);
                    } catch (Throwable ex) {
                        Util.bug(null, ex);
                    }
                }
            });
        }
        hookZygote();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            hookSystem(null);
    } catch (Throwable ex) {
        Util.bug(null, ex);
    }
}
Also used : XC_MethodHook(de.robv.android.xposed.XC_MethodHook) InputStreamReader(java.io.InputStreamReader) Method(java.lang.reflect.Method) FileInputStream(java.io.FileInputStream) Field(java.lang.reflect.Field) Random(java.util.Random) BufferedReader(java.io.BufferedReader) XposedHelpers.findClass(de.robv.android.xposed.XposedHelpers.findClass) File(java.io.File)

Example 2 with XC_MethodHook

use of de.robv.android.xposed.XC_MethodHook in project Xposed-Tinted-Status-Bar by MohammadAG.

the class ColourChangerMod method doClockHooks.

private void doClockHooks(ClassLoader loader) {
    Class<?> Clock = XposedHelpers.findClass("com.android.systemui.statusbar.policy.Clock", loader);
    XposedBridge.hookAllConstructors(Clock, new XC_MethodHook() {

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            addTextLabel((TextView) param.thisObject);
            mFoundClock = true;
        }
    });
    findAndHookMethod(Clock, "updateClock", new XC_MethodHook() {

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            TextView textView = (TextView) param.thisObject;
            textView.setTextColor(mColorForStatusIcons);
        }
    });
}
Also used : XC_MethodHook(de.robv.android.xposed.XC_MethodHook) TextView(android.widget.TextView)

Example 3 with XC_MethodHook

use of de.robv.android.xposed.XC_MethodHook in project Xposed-Tinted-Status-Bar by MohammadAG.

the class WindowDimHooks method doHook.

public static void doHook() {
    findAndHookMethod("com.android.internal.policy.impl.PhoneWindow$DecorView", null, "onWindowFocusChanged", boolean.class, new XC_MethodHook() {

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            Window window = (Window) XposedHelpers.getObjectField(param.thisObject, "this$0");
            if ((window.getAttributes().flags & LayoutParams.FLAG_DIM_BEHIND) == LayoutParams.FLAG_DIM_BEHIND) {
                boolean focused = (Boolean) param.args[0];
                Intent intent = new Intent(INTENT_DIM_CHANGED);
                intent.putExtra(KEY_DIM_AMOUNT, focused ? window.getAttributes().dimAmount : 0F);
                window.getContext().sendBroadcast(intent);
            }
        }
    });
    findAndHookMethod("com.android.internal.policy.impl.PhoneWindow$DecorView", null, "onDetachedFromWindow", new XC_MethodHook() {

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            Window window = (Window) XposedHelpers.getObjectField(param.thisObject, "this$0");
            if ((window.getAttributes().flags & LayoutParams.FLAG_DIM_BEHIND) == LayoutParams.FLAG_DIM_BEHIND) {
                Intent intent = new Intent(INTENT_DIM_CHANGED);
                intent.putExtra(KEY_DIM_AMOUNT, 0F);
                window.getContext().sendBroadcast(intent);
            }
        }
    });
}
Also used : Window(android.view.Window) XC_MethodHook(de.robv.android.xposed.XC_MethodHook) Intent(android.content.Intent)

Example 4 with XC_MethodHook

use of de.robv.android.xposed.XC_MethodHook in project Xposed-Tinted-Status-Bar by MohammadAG.

the class LGHooks method doImeHook.

public static void doImeHook() {
    if (!isLGKitKatDevice())
        return;
    try {
        Class<?> inputMethodMgrClss = findClass("com.android.server.InputMethodManagerService", null);
        findAndHookMethod(inputMethodMgrClss, "setImeWindowStatus", IBinder.class, int.class, int.class, new XC_MethodHook() {

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                int vis = (Integer) param.args[1];
                Context mContext = (Context) getObjectField(param.thisObject, "mContext");
                boolean isKeyboardUp = (vis & IME_ACTIVE) != 0;
                if (isKeyboardUp != mWasKeyboardUp && mContext != null) {
                    Intent intent = new Intent(Common.INTENT_KEYBOARD_VISIBLITY_CHANGED);
                    intent.putExtra(Common.EXTRA_KEY_KEYBOARD_UP, isKeyboardUp);
                    mContext.sendBroadcast(intent);
                    mWasKeyboardUp = isKeyboardUp;
                }
            }
        });
    } catch (ClassNotFoundError e) {
    //DO NOTHING
    }
}
Also used : Context(android.content.Context) ClassNotFoundError(de.robv.android.xposed.XposedHelpers.ClassNotFoundError) XC_MethodHook(de.robv.android.xposed.XC_MethodHook) Intent(android.content.Intent)

Example 5 with XC_MethodHook

use of de.robv.android.xposed.XC_MethodHook in project Xposed-Tinted-Status-Bar by MohammadAG.

the class LGHooks method hookStatusBar.

private static void hookStatusBar(ClassLoader classLoader) {
    // REMOVE THE BACKGROUND ONLY
    try {
        Class<?> StatusBarBackGroundClss = findClass("com.lge.systemui.StatusBarBackground", classLoader);
        findAndHookMethod(StatusBarBackGroundClss, "applyMode", int.class, boolean.class, new XC_MethodHook() {

            @SuppressLint("NewApi")
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                int i = (Integer) param.args[0];
                if (i != 1 && i != 2) {
                    XposedHelpers.setIntField(param.thisObject, "mMode", i);
                    ImageView imageView = (ImageView) param.thisObject;
                    imageView.setBackground(null);
                    imageView.setVisibility(View.VISIBLE);
                    param.setResult(null);
                }
            }
        });
    } catch (ClassNotFoundError e) {
        XposedBridge.log("TintedStatusBar: LG StatusBarBackground has not been found...skipping");
    }
}
Also used : ClassNotFoundError(de.robv.android.xposed.XposedHelpers.ClassNotFoundError) XC_MethodHook(de.robv.android.xposed.XC_MethodHook) SuppressLint(android.annotation.SuppressLint) ImageView(android.widget.ImageView)

Aggregations

XC_MethodHook (de.robv.android.xposed.XC_MethodHook)6 Context (android.content.Context)2 Intent (android.content.Intent)2 ClassNotFoundError (de.robv.android.xposed.XposedHelpers.ClassNotFoundError)2 XposedHelpers.findClass (de.robv.android.xposed.XposedHelpers.findClass)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 Window (android.view.Window)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Mam.findMamClass (bin.xposed.Unblock163MusicClient.CloudMusicPackage.Mam.findMamClass)1 SettingsActivity (bin.xposed.Unblock163MusicClient.ui.SettingsActivity)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1