微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.app.AndroidAppHelper的实例源码

项目:Screenshot-HookBox    文件X.java   
private String getLollipopRecentTask() {
    /** @hide Process is hosting the current top activities.  Note that this covers
     * all activities that are visible to the user. */
    final int PROCESS_STATE_TOP = 2;
    try {
        Field processstateField = ActivityManager.RunningAppProcessInfo.class.getDeclaredField("processstate");
        List<ActivityManager.RunningAppProcessInfo> processes = ((ActivityManager) AndroidAppHelper.currentApplication().getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo process : processes) {
            if (process.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && process.importanceReasonCode == 0) {
                int state = processstateField.getInt(process);
                if (state == PROCESS_STATE_TOP) {
                    String[] packname = process.pkgList;
                    return packname[0];
                }
            }
        }
    } catch (Exception e) {
        XposedBridge.log(e);
    }
    return "";
}
项目:Sensor-disabler    文件MockSensorValuesModificationMethod.java   
@Override
public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) {
    XposedHelpers.findAndHookMethod(
            "android.hardware.SystemSensorManager$ListenerDelegate",lpparam.classLoader,"onSensorChangedLocked",Sensor.class,float[].class,long[].class,int.class,new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) {
                    Sensor sensor = (Sensor) param.args[0];
                    Context context = AndroidAppHelper.currentApplication();
                    //Use processName here always. Not packageName.
                    if (!isPackageAllowedToSeeTrueSensor(lpparam.processName,sensor,context) && getSensorStatus(sensor,context) == Constants.SENSOR_STATUS_MOCK_VALUES) {
                        // Get the mock values from the settings.
                        float[] values = getSensorValues(sensor,context);

                        //noinspection SuspicIoUsSystemArraycopy
                        System.arraycopy(values,param.args[1],values.length);
                    }
                }
            }
    );
}
项目:Sensor-disabler    文件RemoveSensorModificationMethod.java   
@Override
public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) {
    XposedHelpers.findAndHookMethod("android.hardware.SystemSensorManager","getFullSensorList",new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            //Without this,you'd never be able to edit the values for a removed sensor! Aaah!
            if (!lpparam.packageName.equals(BuildConfig.APPLICATION_ID)) {
                //Create a new list so we don't modify the original list.
                @SuppressWarnings("unchecked") List<Sensor> fullSensorList = new ArrayList<>((Collection<? extends Sensor>) param.getResult());
                Iterator<Sensor> iterator = fullSensorList.iterator();
                Context context = AndroidAppHelper.currentApplication();
                while (iterator.hasNext()) {
                    Sensor sensor = iterator.next();
                    if (!isPackageAllowedToSeeTrueSensor(lpparam.processName,context) == Constants.SENSOR_STATUS_REMOVE_SENSOR) {
                        iterator.remove();
                    }
                }
                param.setResult(fullSensorList);
            }
        }
    });
}
项目:GemXperiaXposed    文件ModuleResources.java   
public static ModuleResources createInstance(String modulePath,XResources origRes)
{
  if(modulePath == null)
    throw new IllegalArgumentException("modulePath must not be null");

  AssetManager assets = (AssetManager)newInstance(AssetManager.class);
  callMethod(assets,"addAssetPath",modulePath);

  ModuleResources res;
  if(origRes != null)
    res = new ModuleResources(assets,origRes.getdisplayMetrics(),origRes.getConfiguration());
  else
    res = new ModuleResources(assets,null,null);

  AndroidAppHelper.addActiveResource(modulePath,res.hashCode(),false,res);
  return res;
}
项目:xposed-art    文件XModuleResources.java   
/**
 * Usually called with the automatically injected {@code MODULE_PATH} constant of the first parameter
 * and the resources received in the callback for {@link XposedBridge#hookInitPackageResources} (or
 * {@code null} for system-wide replacements.
 */
public static XModuleResources createInstance(String modulePath,XResources origRes) {
    if (modulePath == null)
        throw new IllegalArgumentException("modulePath must not be null");

    AssetManager assets = new AssetManager();
    assets.addAssetPath(modulePath);

    XModuleResources res;
    if (origRes != null)
        res = new XModuleResources(assets,origRes.getConfiguration());
    else
        res = new XModuleResources(assets,null);

    AndroidAppHelper.addActiveResource(modulePath,res);
    return res;
}
项目:XHangouts    文件UiCallButtons.java   
private static void selectCallType(final XC_MethodHook.MethodHookParam param) {
    Resources res = AndroidAppHelper.currentApplication().getResources();
    String callWithHangouts = res.getString(
            res.getIdentifier(HANGOUTS_STR_CALL_WITH_HANGOUTS,"string",HANGOUTS_RES_PKG_NAME));
    String callWithCellular = res.getString(
            res.getIdentifier(HANGOUTS_STR_CALL_WITH_PSTN,HANGOUTS_RES_PKG_NAME));

    CharSequence options[] = new CharSequence[]{callWithHangouts,callWithCellular};
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("");
    builder.setItems(options,new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog,int which) {
            switch (which) {
                case 0:
                    hangoutsCall(param);
                    break;
                case 1:
                    cellularCall();
                    break;
            }
        }
    });
    builder.show();
}
项目:NeverCrash    文件x.java   
private static String getCrashTip() {

        Context context = null;
        try {
            context = AndroidAppHelper.currentApplication().createPackageContext(PACKAGE_NAME,Context.CONTEXT_IGnorE_Security);
            return context.getString(R.string.crash_tip) + ": ";
        } catch (PackageManager.NameNotFoundException e) {
            return "";
        }
    }
项目:Zebpay-Unblock    文件ZebpayUnblocker.java   
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals("zebpay.Application"))
        return;
    findAndHookMethod("zebpay.Application.activity.SplashActivity","b",new XC_MethodReplacement() {
        @Override
        protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
            String warning = "App has been hooked by third party app,but ignored by Zebpay Unblock. HODL!";
            Context context = AndroidAppHelper.currentApplication();
            Toast toast = Toast.makeText(context,warning,Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER,0);
            toast.show();
            return true;
        }
    });
}
项目:Screenshot-HookBox    文件X.java   
private String getShotObject() {
    String ret = getLollipopRecentTask();
    if (ret.isEmpty())
        if (BoolConfigIO.get(REC))
            return "RecentTasksList";
        else
            return "unkNown";
    else if (((KeyguardManager) AndroidAppHelper.currentApplication().getSystemService(Context.KEyguard_SERVICE)).inKeyguardRestrictedInputMode())
        return "LockScreen";
    else {
        Log.d(TAG,"getShotObject:" + ret);
        return ret;
    }
}
项目:ThreeStepsAhead    文件IPC.java   
public boolean connect(Context context) {
    if (isConnected()) {
        return true;
    }
    ComponentName cn;
    if (context == null) {
        // only valid from Xposed context in hooked app
        context = AndroidAppHelper.currentApplication();
        cn = new ComponentName(THIS_APP,THIS_APP + ".JoystickService");
    } else {
        cn = new ComponentName(context,JoystickService.class);
    }

    if (context != null) {
        if (messenger == null) {
            messenger = new Messenger(incomingHandler);
        }

        Intent intent = new Intent();
        intent.setComponent(cn);
        if (!context.bindService(intent,this,Context.BIND_AUTO_CREATE)) {
            Toast.makeText(AndroidAppHelper.currentApplication(),"Unable to start service! Did you reboot after updating?",Toast.LENGTH_SHORT).show();
        }
        return true;
    }
    return false;
}
项目:NFCLockScreenOffEnablerMM    文件NFCLockScreenOffEnabler.java   
@SuppressWarnings("deprecation")
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
    prefs = AndroidAppHelper.getSharedPreferencesForPackage(MY_PACKAGE_NAME,Common.PREFS,Context.MODE_PRIVATE);
    //prefs = new XSharedPreferences(MY_PACKAGE_NAME,Common.PREFS).makeWorldReadable();
    MODULE_PATH = startupParam.modulePath;
    mDebugMode = prefs.getBoolean(Common.PREF_DEBUG_MODE,false);
}
项目:Sensor-disabler    文件MockSensorValuesModificationMethodApi18.java   
@Override
public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) {
    XC_MethodHook mockSensorHook = new XC_MethodHook() {
        @SuppressWarnings("unchecked")
        @Override
        protected void beforeHookedMethod(MethodHookParam param)
                throws Throwable {

            Object systemSensorManager = XposedHelpers.getobjectField(param.thisObject,"mManager");
            SparseArray<Sensor> sensors = getSensors(systemSensorManager);

            // params.args[] is an array that holds the arguments that dispatchSensorEvent received,which are a handle pointing to a sensor
            // in sHandletoSensor and a float[] of values that should be applied to that sensor.
            int handle = (Integer) (param.args[0]); // This tells us which sensor was currently called.
            Sensor sensor = sensors.get(handle);
            Context context = AndroidAppHelper.currentApplication();
            if (!isPackageAllowedToSeeTrueSensor(lpparam.processName,context) == Constants.SENSOR_STATUS_MOCK_VALUES) {
                float[] values = getSensorValues(sensor,context);
                    /*The SystemSensorManager compares the array it gets with the array from the a SensorEvent,and some sensors (looking at you,Proximity) only use one index in the array
                    but still send along a length 3 array,so we copy here instead of replacing it
                    outright. */

                //noinspection SuspicIoUsSystemArraycopy
                System.arraycopy(values,values.length);
            }
        }
    };
    XposedHelpers.findAndHookMethod("android.hardware.SystemSensorManager$SensorEventQueue","dispatchSensorEvent",long.class,mockSensorHook);
}
项目:XposedAppLocale    文件XposedMod.java   
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
    loadPrefs();

    try {
        XposedHelpers.findAndHookMethod(
                Resources.class,"updateConfiguration",Configuration.class,displayMetrics.class,"android.content.res.CompatibilityInfo",new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        if (param.args[0] == null) {
                            return;
                        }

                        String packageName;
                        Resources res = ((Resources) param.thisObject);
                        if (res instanceof XResources) {
                            packageName = ((XResources) res).getPackageName();
                        } else if (res instanceof XModuleResources) {
                            return;
                        } else {
                            try {
                                packageName = XResources.getPackageNameDuringConstruction();
                            } catch (IllegalStateException e) {
                                return;
                            }
                        }

                        String hostPackageName = AndroidAppHelper.currentPackageName();
                        boolean isActiveApp = hostPackageName.equals(packageName);

                        Configuration newConfig = null;

                        if (packageName != null) {
                            Locale loc = getPackageSpecificLocale(packageName);
                            if (loc != null) {
                                newConfig = new Configuration((Configuration) param.args[0]);

                                setConfigurationLocale(newConfig,loc);

                                if (isActiveApp) {
                                    Locale.setDefault(loc);
                                }
                            }
                        }

                        if (newConfig != null) {
                            param.args[0] = newConfig;
                        }
                    }
                }
        );
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
项目:PreventADBInstall    文件HookMain.java   
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {

    installPackageHook = new XC_MethodHook() {
        @Override
        public void beforeHookedMethod(MethodHookParam param) throws Throwable {
            mContext = AndroidAppHelper.currentApplication();
            mContext = (Context) XposedHelpers.getobjectField(param.thisObject,"mContext");
            boolean isInstallStage = "installStage".equals(param.method.getName());
            int flags = 0;
            int id = 0;

            if (isInstallStage) {
                try {
                    id = 4;
                    flags = (Integer) XposedHelpers.getobjectField(param.args[id],"installFlags");
                    XposedBridge.log("PreventADBInstall: Hook Flags Success!");
                } catch (Exception e) {
                    XposedBridge.log(e);
                }
            } else {
                try {
                    id = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? 2 : 1;
                    flags = (Integer) param.args[id];
                    XposedBridge.log("PreventADBInstall: Hook Flags Success!");
                } catch (Exception e) {
                    XposedBridge.log(e);
                }
            }

            if (isInstallStage) {
                Object sessions = param.args[id];
                XposedHelpers.setIntField(sessions,"installFlags",flags);
                param.args[id] = sessions;
            } else {
                param.args[id] = flags;
            }

            if ((getCallingUid() == 2000) || (getCallingUid() == 0)) {
                param.setResult(null);
                XposedBridge.log("PreventADBInstall: Block Success!");
                Looper.prepare();
                Toast.makeText(mContext,"拦截 ADB 安装成功!",Toast.LENGTH_LONG).show();
                Looper.loop();
                return;
            }
        }
    };
}
项目:Xposed-ShowSimOperator    文件ShowSimOperator.java   
private static Context getContext() {
  return (Context) AndroidAppHelper.currentApplication();
}
项目:ActivityForceNewTask    文件XposedMod.java   
@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);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。