Skip to content

Commit

Permalink
Updates for Marshmallow support.
Browse files Browse the repository at this point in the history
  • Loading branch information
wardellbagby committed Nov 16, 2015
1 parent 4dea4b8 commit 57cd5c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/Disable Proximitiy Sensor.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mrchandler.disableprox"
android:versionCode="2"
android:versionName="1.0.1" >
android:versionCode="3"
android:versionName="1.0.2" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Proximity Sensor Disabler
========================

This disables the proximity sensor in 4.1 - 5.0.1 devices. It has not been tested on anything less than 4.1, and does not currently work on 5.1.
This disables the proximity sensor in 4.1 - 6.0 devices. It has not been tested on anything less than 4.1, and does currently have Marshmallow support.

Installation
------------
Expand Down
12 changes: 8 additions & 4 deletions src/com/mrchandler/disableprox/XposedMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,28 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
);
} else {

XposedHelpers.findAndHookMethod(
"android.hardware.SystemSensorManager$SensorEventQueue", lpparam.classLoader, "dispatchSensorEvent", int.class, float[].class, int.class, long.class, new XC_MethodHook() {
@SuppressWarnings("unchecked")
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
// This pulls the 'Handle to Sensor' array straight from the SystemSensorManager class, so it should always pull the appropriate sensor.
SparseArray<Sensor> sensors = (SparseArray<Sensor>) XposedHelpers.getStaticObjectField(systemSensorManager, "sHandleToSensor");
SparseArray<Sensor> sensors;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
sensors = (SparseArray<Sensor>) XposedHelpers.getStaticObjectField(systemSensorManager, "sHandleToSensor");
} else {
Object systemSensorManager = XposedHelpers.getObjectField(param.thisObject, "mManager");
sensors = (SparseArray<Sensor>) XposedHelpers.getObjectField(systemSensorManager, "mHandleToSensor");
}

// 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 s = sensors.get(handle);
if (s.getType() == Sensor.TYPE_PROXIMITY) {// This could be expanded to disable ANY sensor.

float[] values = (float[]) param.args[1];
values[0] = 100f;
values[0] = s.getMaximumRange();
param.args[1] = values;
}
}
Expand Down

0 comments on commit 57cd5c1

Please sign in to comment.