Skip to content

Commit 318aedb

Browse files
committed
Hotfix to avoid crash on API<=18
1 parent 522df62 commit 318aedb

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "fr.frazew.virtualgyroscope"
99
minSdkVersion 16
1010
targetSdkVersion 23
11-
versionCode 120
12-
versionName "1.2"
11+
versionCode 121
12+
versionName "1.21"
1313
}
1414
buildTypes {
1515
release {

app/src/main/java/fr/frazew/virtualgyroscope/SensorModel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ public class SensorModel {
77
public int minDelay;
88
public float maxRange;
99
public boolean alreadyThere = false;
10-
public String stringType;
1110
public String permission;
1211

13-
public SensorModel(int sensorType, String name, int handle, float resolution, int minDelay, float maxRange, String stringType, String permission) {
12+
public SensorModel(int sensorType, String name, int handle, float resolution, int minDelay, float maxRange, String permission) {
1413
this.name = name;
1514
this.handle = (handle == -1 ? sensorType : handle);
1615
this.resolution = resolution;
1716
this.minDelay = minDelay;
1817
this.maxRange = maxRange;
19-
this.stringType = stringType;
2018
this.permission = permission;
2119
}
2220
}

app/src/main/java/fr/frazew/virtualgyroscope/XposedMod.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class XposedMod implements IXposedHookLoadPackage {
2424
public static boolean FIRST_LAUNCH_SINCE_BOOT = true;
2525

2626
public static final SparseArray<SensorModel> sensorsToEmulate = new SparseArray<SensorModel>() {{
27-
put(Sensor.TYPE_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_ROTATION_VECTOR, "VirtualSensor RotationVector", -1, 0.01F, -1, -1, Sensor.STRING_TYPE_ROTATION_VECTOR, "none"));
28-
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"));
29-
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"));
30-
put(Sensor.TYPE_GRAVITY, new SensorModel(Sensor.TYPE_GRAVITY, "VirtualSensor Gravity", -1, 0.01F, -1, -1, Sensor.STRING_TYPE_GRAVITY, "none"));
31-
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 (?!)
27+
put(Sensor.TYPE_ROTATION_VECTOR, new SensorModel(Sensor.TYPE_ROTATION_VECTOR, "VirtualSensor RotationVector", -1, 0.01F, -1, -1, "none"));
28+
put(Sensor.TYPE_GYROSCOPE, new SensorModel(Sensor.TYPE_GYROSCOPE, "VirtualSensor Gyroscope", -1, 0.01F, -1, (float)Math.PI, "android.hardware.sensor.gyroscope"));
29+
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"));
30+
put(Sensor.TYPE_GRAVITY, new SensorModel(Sensor.TYPE_GRAVITY, "VirtualSensor Gravity", -1, 0.01F, -1, -1, "none"));
31+
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 (?!)
3232
}};
3333

3434
@Override

app/src/main/java/fr/frazew/virtualgyroscope/hooks/SensorChangeHook.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.hardware.Sensor;
44
import android.hardware.SensorManager;
5+
import android.os.Build;
56
import android.util.SparseArray;
67

78
import java.util.ArrayList;
@@ -53,7 +54,7 @@ public static List<Object> changeSensorValues(Sensor s, float[] accelerometerVal
5354
System.arraycopy(values, 0, returnValues, 0, values.length);
5455
virtualListener.sensorRef = sensors.get(Sensor.TYPE_GYROSCOPE);
5556
}
56-
} else if (virtualListener.getSensor().getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR || virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR) {
57+
} else if ((Build.VERSION.SDK_INT >= 19 && virtualListener.getSensor().getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) || virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR) {
5758
float[] values = new float[5];
5859
float[] rotationMatrix = new float[9];
5960
SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magneticValues);
@@ -71,7 +72,7 @@ public static List<Object> changeSensorValues(Sensor s, float[] accelerometerVal
7172
System.arraycopy(values, 0, returnValues, 0, values.length);
7273
if (virtualListener.getSensor().getType() == Sensor.TYPE_ROTATION_VECTOR)
7374
virtualListener.sensorRef = sensors.get(Sensor.TYPE_ROTATION_VECTOR);
74-
else
75+
else if (Build.VERSION.SDK_INT >= 19)
7576
virtualListener.sensorRef = sensors.get(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
7677
} else if (virtualListener.getSensor().getType() == Sensor.TYPE_GRAVITY) {
7778
float[] values = new float[3];

app/src/main/java/fr/frazew/virtualgyroscope/hooks/SystemSensorManagerHook.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public static List<Object> fillSensorLists(ArrayList<Sensor> fullSensorList, Spa
5454
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
5555
if (model.maxRange != -1)
5656
XposedHelpers.setObjectField(s, "mMaxRange", model.maxRange);
57-
XposedHelpers.setObjectField(s, "mStringType", model.stringType);
58-
if (!model.permission.equals("none")) {
57+
58+
if (!model.permission.equals("none"))
5959
XposedHelpers.setObjectField(s, "mRequiredPermission", model.permission);
60-
}
60+
6161
fullSensorList.add(s);
6262
handleToSensor.append(model.handle, s);
6363
}

0 commit comments

Comments
 (0)