package ru.abusalimov.xposed.lightsensorfilter;

import android.util.Log;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class LightSensorFilter implements IXposedHookLoadPackage {

	@Override
	public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
		XposedHelpers.findAndHookMethod(
				"android.hardware.SystemSensorManager$SensorEventQueue",
				lpparam.classLoader,
				"dispatchSensorEvent",
				int.class, float[].class, int.class, long.class,

				new XC_MethodHook() {

					@Override
					protected void beforeHookedMethod(MethodHookParam param)
							throws Throwable {
						int handle = (int) param.args[0];
						if (handle == 1) {
							float[] values = (float[]) param.args[1];
							float lux = values[0];
							Log.v("LightSensorFilter", "lux value: " + lux);
						}

						// invoke the original method
					}

				});
	}

}

@@ -886,16 +886,17 @@
 rgs%5B1%5D;%0A
+%0A
 %09%09%09%09%09%09%09f
@@ -928,57 +928,198 @@
 %09%09%09%09
-Log.v(%22LightSensorFilter%22, %22lux
+if (Float.compare(lux, 30000.0f) == 0) %7B%0A%09%09%09%09%09%09%09%09param.setResult(null);%0A%09%09%09%09%09%09%09%09Log.v(%22LightSensorFilter%22,%0A%09%09%09%09%09%09%09%09%09%09%22suppresed bogus light sensor
  value
-:
  %22 +
- 
+%0A%09%09%09%09%09%09%09%09%09%09lux + %22
 lux
+%22
 );%0A
+%09%09%09%09%09%09%09%7D%0A
 %09%09%09%09

Suppress a bogus 30k lux value