Java Code Examples for de.robv.android.xposed.XposedHelpers#getObjectField()

The following examples show how to use de.robv.android.xposed.XposedHelpers#getObjectField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModStatusBar.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private static void expandNotificationPanel(boolean withQs) {
    Object notifPanel = XposedHelpers.getObjectField(mPhoneStatusBar, "mNotificationPanel");
    try {
        XposedHelpers.callMethod(notifPanel, "instantExpand");
        if (withQs && XposedHelpers.getBooleanField(notifPanel, "mQsExpansionEnabled")) {
            XposedHelpers.callMethod(notifPanel, "setQsExpansion",
                    XposedHelpers.getIntField(notifPanel, "mQsMaxExpansionHeight"));
        }
    } catch (Throwable t) {
        // fallback to alt method
        if (withQs) {
            XposedHelpers.callMethod(notifPanel, "expandWithQs");
        } else if (Utils.isOxygenOs35Rom()) {
            XposedHelpers.callMethod(notifPanel, "expand", true);
        } else {
            XposedHelpers.callMethod(notifPanel, "expand");
        }
    }
}
 
Example 2
Source File: CellularTile.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateTileView(View tileView) throws Throwable {
    super.onCreateTileView(tileView);

    if (isPrimary() && hasField(tileView, "mIconFrame") && !Utils.isOxygenOs35Rom()) {
        mDataOffView = new ImageView(mContext);
        mDataOffView.setImageDrawable(mGbContext.getDrawable(R.drawable.ic_mobile_data_off));
        mDataOffView.setVisibility(View.GONE);
        FrameLayout iconFrame = (FrameLayout) XposedHelpers.getObjectField(tileView, "mIconFrame");
        iconFrame.addView(mDataOffView, FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        if (mScalingFactor != 1f) {
            mDataOffView.setScaleX(mScalingFactor);
            mDataOffView.setScaleY(mScalingFactor);
        }
        if (PhoneWrapper.hasMsimSupport()) {
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mDataOffView.getLayoutParams();
            int marginPx = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, -4,
                    mContext.getResources().getDisplayMetrics()));
            lp.leftMargin = marginPx;
            lp.topMargin = Math.round(marginPx/2f);
            mDataOffView.setLayoutParams(lp);
        }
    }
}
 
Example 3
Source File: MissedCallNotifier.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
    try {
        final Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
        final String pkgName = context.getPackageName();
        final boolean isMissedCallNotifOrAll = pkgName.equals(ModTelecom.PACKAGE_NAME) &&
                (param.args.length == 0 || (Integer) param.args[1] == MISSED_CALL_NOTIF_ID);
        if (isMissedCallNotifOrAll && mNotifOnNextScreenOff != null) {
            mNotifOnNextScreenOff = null;
            context.unregisterReceiver(mScreenOffReceiver);
            if (DEBUG) log("Pending missed call notification canceled");
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 4
Source File: ModStatusBar.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private static void setNotificationPanelState(Intent intent, boolean withQs) {
    try {
        if (!intent.hasExtra(AShortcut.EXTRA_ENABLE)) {
            Object notifPanel = XposedHelpers.getObjectField(mPhoneStatusBar, "mNotificationPanel");
            if ((boolean) XposedHelpers.callMethod(notifPanel, "isFullyCollapsed")) {
                expandNotificationPanel(withQs);
            } else {
                collapseNotificationPanel();
            }
        } else {
            if (intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false)) {
                expandNotificationPanel(withQs);
            } else {
                collapseNotificationPanel();
            }
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 5
Source File: FixWakeLock.java    From AppOpsXposed with GNU General Public License v3.0 5 votes vote down vote up
private static Context getContextFromThis(Object object)
{
	final Object location = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
			XposedHelpers.getSurroundingThis(object) : object;

	return (Context) XposedHelpers.getObjectField(location, "mContext");
}
 
Example 6
Source File: CallFeatures.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void onCallsManagerCreated(Object callsManager) {
    if (DEBUG) log("onCallsManagerCreated()");
    mContext = (Context) XposedHelpers.getObjectField(callsManager, "mContext");
    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    mHandler = new Handler();
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mWakeLock  = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
 
Example 7
Source File: QsQuickPulldownHandler.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private boolean hasNotifications(Object o) {
    try {
        if (mNotificationData == null) {
            mNotificationData = XposedHelpers.getObjectField(
                    XposedHelpers.getObjectField(o, "mStatusBar"), "mNotificationData");
        }
        List<?> list = (List<?>)XposedHelpers.callMethod(mNotificationData, "getActiveNotifications");
        return list.size() > 0;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return true;
    }
}
 
Example 8
Source File: NotificationDataMonitor.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private boolean hasNotificationField(Object o) {
    try {
        XposedHelpers.getObjectField(o, "notification");
        return true;
    } catch (Throwable t) {
        return false;
    }
}
 
Example 9
Source File: SmsHandlerHook.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void deleteFromRawTable19(Object inboundSmsHandler, Object smsReceiver) throws ReflectiveOperationException {
    XLog.d("Delete raw SMS data from database on Android 19+");
    Object deleteWhere = XposedHelpers.getObjectField(smsReceiver, "mDeleteWhere");
    Object deleteWhereArgs = XposedHelpers.getObjectField(smsReceiver, "mDeleteWhereArgs");

    callDeclaredMethod(SMS_HANDLER_CLASS, inboundSmsHandler, "deleteFromRawTable",
            /* String deleteWhere       */ deleteWhere,
            /* String[] deleteWhereArgs */ deleteWhereArgs);
}
 
Example 10
Source File: ModVolumePanel.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static boolean isRingerSliderEnabled() {
    try {
        List<?> rows = (List<?>) XposedHelpers.getObjectField(mVolumePanel, "mRows");
        for (Object row : rows) {
            if (XposedHelpers.getIntField(row, "stream") == AudioManager.STREAM_RING) {
                return ((View) XposedHelpers.getObjectField(row, "slider")).isEnabled();
            }
        }
        return true;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return true;
    }
}
 
Example 11
Source File: BaseTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void updateMotoXtSignalIconLayout(View tileView) {
    try {
        View icon = (View) XposedHelpers.getObjectField(tileView,
                "mSignalImageView");
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams)
                icon.getLayoutParams();
        lp.width = Math.round(lp.width * mScalingFactor);
        lp.height = Math.round(lp.height * mScalingFactor);
        icon.setLayoutParams(lp);
    } catch (Throwable t) { /* ignore */ }
}
 
Example 12
Source File: ModMms.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
    try {
        if (!prepareUnicodeFilter()) return;

        if (DEBUG) log("ComposeMessageActivity created. Hooking to TextEditorWatcher");

        final TextWatcher textEditorWatcher = (TextWatcher) XposedHelpers.getObjectField(
                param.thisObject, "mTextEditorWatcher");
        if (textEditorWatcher != null) {
            XposedHelpers.findAndHookMethod(textEditorWatcher.getClass(), "onTextChanged", 
                    CharSequence.class, int.class, int.class, int.class, new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param2) throws Throwable {
                    if (param2.thisObject != textEditorWatcher) return;

                    CharSequence s = (CharSequence) param2.args[0];
                    if (DEBUG) log("TextEditorWatcher.onTextChanged: original ='" + s + "'");
                    s = mUnicodeFilter.filter(s);
                    if (DEBUG) log("TextEditorWatcher.onTextChanged: stripped ='" + s + "'");
                    param2.args[0] = s;
                }
            });
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 13
Source File: LegacyPositionCallbackImpl.java    From android_app_cputempinstatusbar with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setup(MethodHookParam param, View v) {
	 cputemp = v;
	 mStatusIcons = (LinearLayout)XposedHelpers.getObjectField(param.thisObject, "mStatusIcons");
	 mIcons = (LinearLayout)XposedHelpers.getObjectField(param.thisObject, "mIcons");
	 mNotificationIconArea = (LinearLayout)mIcons.getChildAt(0);
}
 
Example 14
Source File: ModNavigationBar.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static void setKeyColor() {
    try {
        View v = (View) XposedHelpers.getObjectField(mNavigationBarView, "mCurrentView");
        ViewGroup navButtons = (ViewGroup) v.findViewById(
                mResources.getIdentifier("nav_buttons", "id", PACKAGE_NAME));
        setKeyColorRecursive(navButtons);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 15
Source File: XposedHelpersWraper.java    From MIUIAnesthetist with MIT License 5 votes vote down vote up
public static Object getObjectField(Object obj, String fieldName) {
    try {
        return XposedHelpers.getObjectField(obj, fieldName);
    } catch (Throwable t) {
        log(t);
    }
    return null;
}
 
Example 16
Source File: BaseTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void updateLabelLayout(View tileView) {
    TextView label = (TextView) XposedHelpers.getObjectField(tileView, "mLabel");
    if (label != null) {
        label.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                label.getTextSize()*mScalingFactor);
    }
    Object dualLabel = XposedHelpers.getObjectField(tileView, "mDualLabel");
    if (dualLabel != null) {
        TextView first = (TextView) XposedHelpers.getObjectField(dualLabel, "mFirstLine");
        first.setTextSize(TypedValue.COMPLEX_UNIT_PX, first.getTextSize()*mScalingFactor);
        TextView second = (TextView) XposedHelpers.getObjectField(dualLabel, "mSecondLine");
        second.setTextSize(TypedValue.COMPLEX_UNIT_PX, second.getTextSize()*mScalingFactor);
    }
}
 
Example 17
Source File: ModHwKeys.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
private static void killForegroundApp() {
    Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneWindowManager, "mHandler");
    if (handler == null) return;

    handler.post(
            new Runnable() {
                @Override
                public void run() {
                    try {
                        final Intent intent = new Intent(Intent.ACTION_MAIN);
                        final PackageManager pm = mContext.getPackageManager();
                        String defaultHomePackage = "com.android.launcher";
                        intent.addCategory(Intent.CATEGORY_HOME);

                        final ResolveInfo res = pm.resolveActivity(intent, 0);
                        if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
                            defaultHomePackage = res.activityInfo.packageName;
                        }

                        ActivityManager am = getActivityManager();
                        List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();

                        String targetKilled = null;
                        for (RunningAppProcessInfo appInfo : apps) {
                            int uid = appInfo.uid;
                            // Make sure it's a foreground user application (not system,
                            // root, phone, etc.)
                            if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID
                                    && appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND &&
                                    !mKillIgnoreList.contains(appInfo.processName) &&
                                    !appInfo.processName.startsWith(defaultHomePackage)) {
                                if (appInfo.pkgList != null && appInfo.pkgList.length > 0) {
                                    for (String pkg : appInfo.pkgList) {
                                        if (DEBUG) log("Force stopping: " + pkg);
                                        XposedHelpers.callMethod(am, "forceStopPackage", pkg);
                                    }
                                } else {
                                    if (DEBUG)
                                        log("Killing process ID " + appInfo.pid + ": " + appInfo.processName);
                                    Process.killProcess(appInfo.pid);
                                }
                                targetKilled = appInfo.processName;
                                break;
                            }
                        }

                        if (targetKilled != null) {
                            try {
                                targetKilled = (String) pm.getApplicationLabel(
                                        pm.getApplicationInfo(targetKilled, 0));
                            } catch (PackageManager.NameNotFoundException nfe) {
                                //
                            }
                            Class<?>[] paramArgs = new Class<?>[3];
                            paramArgs[0] = XposedHelpers.findClass(CLASS_WINDOW_STATE, null);
                            paramArgs[1] = int.class;
                            paramArgs[2] = boolean.class;
                            XposedHelpers.callMethod(mPhoneWindowManager, "performHapticFeedbackLw",
                                    paramArgs, null, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING, true);
                            Toast.makeText(mContext,
                                    String.format(mStrAppKilled, targetKilled), Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(mContext, mStrNothingToKill, Toast.LENGTH_SHORT).show();
                        }
                    } catch (Exception e) {
                        XposedBridge.log(e);
                    }
                }
            }
    );
}
 
Example 18
Source File: XposedMod.java    From ActivityForceNewTask with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals("android"))
        return;

    XC_MethodHook hook = new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            settingsHelper.reload();
            if (settingsHelper.isModDisabled())
                return;
            Intent intent = (Intent) XposedHelpers.getObjectField(param.thisObject, "intent");

            // The launching app does not expect data back. It's safe to run the activity in a
            // new task.
            int requestCode = getIntField(param.thisObject, "requestCode");
            if (requestCode != -1)
                return;

            // The intent already has FLAG_ACTIVITY_NEW_TASK set, no need to do anything.
            if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == Intent.FLAG_ACTIVITY_NEW_TASK)
                return;

            String intentAction = intent.getAction();
            // If the intent is not a known safe intent (as in, the launching app does not expect
            // data back, so it's safe to run in a new task,) ignore it straight away.
            if (intentAction == null)
                return;

            // If the app is launching one of its own activities, we shouldn't open it in a new task.
            int uid = ((ActivityInfo) getObjectField(param.thisObject, "info")).applicationInfo.uid;
            if (getIntField(param.thisObject, "launchedFromUid") == uid)
                return;

            ComponentName componentName = (ComponentName) getObjectField(param.thisObject, "realActivity");
            String componentNameString = componentName.flattenToString();
            // Log if necessary.
            if (settingsHelper.isLogEnabled()) {
                // Get context
                Context context = AndroidAppHelper.currentApplication();

                if (context != null)
                    context.sendBroadcast(new Intent(Common.INTENT_LOG).putExtra(Common.INTENT_COMPONENT_EXTRA, componentNameString));
                else
                    XposedBridge.log("activityforcenewtask: couldn't get context.");
                XposedBridge.log("activityforcenewtask: componentString: " + componentNameString);
            }

            // If the blacklist is used and the component is in the blacklist, or if the
            // whitelist is used and the component isn't whitelisted, we shouldn't modify
            // the intent's flags.
            boolean isListed = settingsHelper.isListed(componentNameString);
            String listType = settingsHelper.getListType();
            if ((listType.equals(Common.PREF_BLACKLIST) && isListed) ||
                    (listType.equals(Common.PREF_WHITELIST) && !isListed))
                return;

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    };

    Class ActivityRecord = findClass("com.android.server.am.ActivityRecord", lpparam.classLoader);
    XposedBridge.hookAllConstructors(ActivityRecord, hook);
}
 
Example 19
Source File: RetalDriverApplication.java    From ratel with Apache License 2.0 4 votes vote down vote up
@Override
protected void attachBaseContext(Context base) {
    //第一步需要call supper,否则Application并不完整,还无法作为context使用,当然此时base context是可用状态
    super.attachBaseContext(base);
    //exposed框架,在driver下面定义,所以需要在替换classloader之前,完成exposed框架的so库加载
    ExposedBridge.initOnce(this, getApplicationInfo(), getClassLoader());

    if (!checkSupport()) {
        throw new IllegalStateException("epic 不支持的版本");
    }
    //释放两个apk,一个是xposed模块,一个是原生的apk,原生apk替换为当前的Application作为真正的宿主,xposed模块apk在Application被替换之前作为补丁代码注入到当前进程
    releaseApkFiles();

    //替换classloader
    Class<?> contextImplClazz = XposedHelpers.findClassIfExists("android.app.ContextImpl", base.getClassLoader());
    Object contextImpl = XposedHelpers.callStaticMethod(contextImplClazz, "getImpl", base);
    Object loadApk = XposedHelpers.getObjectField(contextImpl, "mPackageInfo");
    ClassLoader parentClassLoader = RetalDriverApplication.class.getClassLoader();
    try {
        //  Class<?> aClass = XposedHelpers.findClass("android.app.LoadedApk", RetalDriverApplication.class.getClassLoader());
        parentClassLoader = (ClassLoader) XposedHelpers.getObjectField(loadApk, "mClassLoader");
    } catch (Exception e) {
        //ignore
    }
    String originApkSourceDir = new File(ratelWorkDir(this), originAPKFileName).getAbsolutePath();
    PathClassLoader originClassLoader = new PathClassLoader(originApkSourceDir, parentClassLoader);
    XposedHelpers.setObjectField(loadApk, "mClassLoader", originClassLoader);

    //context中的resource,仍然绑定在老的apk环境下,现在把他们迁移
    ApplicationInfo appinfoInLoadedApk = (ApplicationInfo) XposedHelpers.getObjectField(loadApk, "mApplicationInfo");
    appinfoInLoadedApk.sourceDir = originApkSourceDir;
    XposedHelpers.setObjectField(loadApk, "mAppDir", originApkSourceDir);
    XposedHelpers.setObjectField(loadApk, "mResDir", originApkSourceDir);
    XposedHelpers.setObjectField(loadApk, "mResources", null);
    Resources resources = (Resources) XposedHelpers.callMethod(loadApk, "getResources", currentActivityThread());
    if (resources != null) {
        XposedHelpers.setObjectField(contextImpl, "mResources", resources);
    }
    //替换之后,再也无法访问容器apk里面的资源了,容器中的所有资源全部被替换为原始apk的资源
    loadResources(originApkSourceDir);
}
 
Example 20
Source File: CommonHandler.java    From xposed-aweme with Apache License 2.0 2 votes vote down vote up
public Object getAwemeObject(View view) {

        if (view == null) return null;

        return XposedHelpers.getObjectField(view.getTag(), mVersionConfig.fieldViewTagAweme);
    }