-
-
Save Frazew/eeb91f49b03165fad19c1b04bc8e1486 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.frazew.virtualgyroscope.hooks.sensorchange; | |
import android.hardware.Sensor; | |
import android.util.SparseArray; | |
import de.robv.android.xposed.XC_MethodHook; | |
import de.robv.android.xposed.XposedHelpers; | |
import de.robv.android.xposed.callbacks.XC_LoadPackage; | |
import fr.frazew.virtualgyroscope.VirtualSensorListener; | |
import fr.frazew.virtualgyroscope.XposedMod; | |
import fr.frazew.virtualgyroscope.hooks.SensorChange; | |
public class API18 extends XC_MethodHook { | |
private SensorChange mSensorChange; | |
private Class SYSTEM_SENSOR_MANAGER; | |
public API18(XC_LoadPackage.LoadPackageParam lpparam) { | |
super(XC_MethodHook.PRIORITY_HIGHEST); | |
this.mSensorChange = new SensorChange(); | |
SYSTEM_SENSOR_MANAGER = XposedHelpers.findClassIfExists("android.hardware.SystemSensorManager", lpparam.classLoader); | |
} | |
@Override | |
@SuppressWarnings("unchecked") | |
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { | |
Object listener = XposedHelpers.getObjectField(param.thisObject, "mListener"); | |
int handle = (int) param.args[0]; | |
SparseArray<Sensor> sensors = (SparseArray<Sensor>) XposedHelpers.getStaticObjectField(SYSTEM_SENSOR_MANAGER, "sHandleToSensor"); | |
Sensor s = sensors.get(handle); | |
if (listener instanceof VirtualSensorListener) { | |
float[] values = this.mSensorChange.handleListener(s, (VirtualSensorListener) listener, ((float[]) param.args[1]).clone(), (int) param.args[2], (long) param.args[3], XposedMod.ACCELEROMETER_RESOLUTION, XposedMod.MAGNETIC_RESOLUTION); | |
if (values != null) { | |
System.arraycopy(values, 0, param.args[1], 0, values.length); | |
param.args[0] = XposedMod.sensorTypetoHandle.get(((VirtualSensorListener) listener).getSensor().getType()); | |
} else param.setResult(null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment