Java Code Examples for android.app.AndroidAppHelper#currentApplication()

The following examples show how to use android.app.AndroidAppHelper#currentApplication() . 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: MockSensorValuesModificationMethodApi18.java    From Sensor-Disabler with MIT License 5 votes vote down vote up
@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, sensor, context) && getSensorStatus(sensor, 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, 0, param.args[1], 0, values.length);
            }
        }
    };
    XposedHelpers.findAndHookMethod("android.hardware.SystemSensorManager$SensorEventQueue", lpparam.classLoader, "dispatchSensorEvent", int.class, float[].class, int.class, long.class, mockSensorHook);
}
 
Example 2
Source File: Util.java    From MinMinGuard with GNU General Public License v3.0 5 votes vote down vote up
public static Application getCurrentApplication()
{
    try
    {
        return AndroidAppHelper.currentApplication();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    return null;
}
 
Example 3
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);
}