Skip to content

Commit

Permalink
Hotfix to avoid crash on API<=18
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazew committed Jul 26, 2016
1 parent 522df62 commit 318aedb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "fr.frazew.virtualgyroscope"
minSdkVersion 16
targetSdkVersion 23
versionCode 120
versionName "1.2"
versionCode 121
versionName "1.21"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ public class SensorModel {
public int minDelay;
public float maxRange;
public boolean alreadyThere = false;
public String stringType;
public String permission;

public SensorModel(int sensorType, String name, int handle, float resolution, int minDelay, float maxRange, String stringType, String permission) {
public SensorModel(int sensorType, String name, int handle, float resolution, int minDelay, float maxRange, String permission) {
this.name = name;
this.handle = (handle == -1 ? sensorType : handle);
this.resolution = resolution;
this.minDelay = minDelay;
this.maxRange = maxRange;
this.stringType = stringType;
this.permission = permission;
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/fr/frazew/virtualgyroscope/XposedMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class XposedMod implements IXposedHookLoadPackage {
public static boolean FIRST_LAUNCH_SINCE_BOOT = true;

public static final SparseArray<SensorModel> sensorsToEmulate = new SparseArray<SensorModel>() {{
put(Sensor.TYPE_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_ROTATION_VECTOR, "VirtualSensor RotationVector", -1, 0.01F, -1, -1, Sensor.STRING_TYPE_ROTATION_VECTOR, "none"));
put(Sensor.TYPE_GYROSCOPE, new SensorModel(Sensor.TYPE_GYROSCOPE, "VirtualSensor Gyroscope", -1, 0.01F, -1, (float)Math.PI, Sensor.STRING_TYPE_GYROSCOPE, "android.hardware.sensor.gyroscope"));
put(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, "VirtualSensor GeomagneticRotationVector", -1, 0.01F, -1, -1, Sensor.STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR, "none"));
put(Sensor.TYPE_GRAVITY, new SensorModel(Sensor.TYPE_GRAVITY, "VirtualSensor Gravity", -1, 0.01F, -1, -1, Sensor.STRING_TYPE_GRAVITY, "none"));
put(Sensor.TYPE_LINEAR_ACCELERATION, new SensorModel(Sensor.TYPE_LINEAR_ACCELERATION, "VirtualSensor LinearAcceleration", 4242, 0.01F, -1, -1, Sensor.STRING_TYPE_LINEAR_ACCELERATION, "none")); // Had to use another handle as it broke the magnetic sensor's readings (?!)
put(Sensor.TYPE_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_ROTATION_VECTOR, "VirtualSensor RotationVector", -1, 0.01F, -1, -1, "none"));
put(Sensor.TYPE_GYROSCOPE, new SensorModel(Sensor.TYPE_GYROSCOPE, "VirtualSensor Gyroscope", -1, 0.01F, -1, (float)Math.PI, "android.hardware.sensor.gyroscope"));
if (Build.VERSION.SDK_INT >= 19) put(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR, "VirtualSensor GeomagneticRotationVector", -1, 0.01F, -1, -1, "none"));
put(Sensor.TYPE_GRAVITY, new SensorModel(Sensor.TYPE_GRAVITY, "VirtualSensor Gravity", -1, 0.01F, -1, -1, "none"));
put(Sensor.TYPE_LINEAR_ACCELERATION, new SensorModel(Sensor.TYPE_LINEAR_ACCELERATION, "VirtualSensor LinearAcceleration", 4242, 0.01F, -1, -1, "none")); // Had to use another handle as it broke the magnetic sensor's readings (?!)
}};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;
import android.util.SparseArray;

import java.util.ArrayList;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static List<Object> changeSensorValues(Sensor s, float[] accelerometerVal
System.arraycopy(values, 0, returnValues, 0, values.length);
virtualListener.sensorRef = sensors.get(Sensor.TYPE_GYROSCOPE);
}
} else if (virtualListener.getSensor().getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR || virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR) {
} else if ((Build.VERSION.SDK_INT >= 19 && virtualListener.getSensor().getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) || virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR) {
float[] values = new float[5];
float[] rotationMatrix = new float[9];
SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magneticValues);
Expand All @@ -71,7 +72,7 @@ public static List<Object> changeSensorValues(Sensor s, float[] accelerometerVal
System.arraycopy(values, 0, returnValues, 0, values.length);
if (virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR)
virtualListener.sensorRef = sensors.get(Sensor.TYPE_ROTATION_VECTOR);
else
else if (Build.VERSION.SDK_INT >= 19)
virtualListener.sensorRef = sensors.get(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
} else if (virtualListener.getSensor().getType() == Sensor.TYPE_GRAVITY) {
float[] values = new float[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public static List<Object> fillSensorLists(ArrayList<Sensor> fullSensorList, Spa
XposedHelpers.setObjectField(s, "mResolution", model.resolution == -1 ? 0.01F : model.resolution); // This 0.01F is a placeholder, it doesn't seem to change anything but I keep it
if (model.maxRange != -1)
XposedHelpers.setObjectField(s, "mMaxRange", model.maxRange);
XposedHelpers.setObjectField(s, "mStringType", model.stringType);
if (!model.permission.equals("none")) {

if (!model.permission.equals("none"))
XposedHelpers.setObjectField(s, "mRequiredPermission", model.permission);
}

fullSensorList.add(s);
handleToSensor.append(model.handle, s);
}
Expand Down

0 comments on commit 318aedb

Please sign in to comment.