Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SensorMod/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SensorMod

This Module allows you to selectively disable sensors on your android device.
Every sensor is listed and can be selectively disabled at choice.
Supports all sensors reported by Android through the SensorManager API.
Select all apps to disable the sensors for as scope for the module.
21 changes: 21 additions & 0 deletions SensorMod/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
alias(libs.plugins.buildlogic.android.application)
}

android {
namespace = "com.programminghoch10.SensorMod"

defaultConfig {
minSdk = 16
targetSdk = 35
multiDexEnabled = true
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}

dependencies {
implementation(libs.androidx.preference)
coreLibraryDesugaring(libs.android.desugarJdkLibs)
}
33 changes: 33 additions & 0 deletions SensorMod/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">

<application android:label="@string/app_name">
<activity
android:name=".SettingsActivity"
android:exported="true"
android:label="@string/title_activity_settings"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN" />
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
</intent-filter>
</activity>

<meta-data
android:name="xposedmodule"
android:value="true"
/>
<meta-data
android:name="xposeddescription"
android:value="@string/description"
/>
<meta-data
android:name="xposedminversion"
android:value="93"
/>
</application>
</manifest>
1 change: 1 addition & 0 deletions SensorMod/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.programminghoch10.SensorMod.Hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.programminghoch10.SensorMod;

import android.hardware.Sensor;

import java.util.Objects;

public class Common {

public static boolean DEFAULT_SENSOR_STATE = true;

public static String getKey(Sensor sensor) {
return "sensor_" + Objects.hash(sensor.getName(), sensor.getId(), sensor.getVendor(), sensor.getVersion(), sensor.getType());
}
}
38 changes: 38 additions & 0 deletions SensorMod/src/main/java/com/programminghoch10/SensorMod/Hook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.programminghoch10.SensorMod;

import static com.programminghoch10.SensorMod.Common.DEFAULT_SENSOR_STATE;
import static com.programminghoch10.SensorMod.Common.getKey;

import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.util.Log;

import java.util.List;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class Hook implements IXposedHookLoadPackage {

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals(BuildConfig.APPLICATION_ID)) return;
SharedPreferences sharedPreferences = new XSharedPreferences(BuildConfig.APPLICATION_ID, "sensors");
Class<SensorManager> systemSensorManager = (Class<SensorManager>) XposedHelpers.findClass("android.hardware.SystemSensorManager", lpparam.classLoader);
XposedHelpers.findAndHookMethod(systemSensorManager, "getFullSensorList", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (param.hasThrowable()) return;
Log.d("Logger", "afterHookedMethod: filter getFullSensorList");
List<Sensor> result = (List<Sensor>) param.getResult();
result = result.stream().filter(sensor -> sharedPreferences.getBoolean(getKey(sensor), DEFAULT_SENSOR_STATE)).toList();
param.setResult(result);
}
});
Log.d("Logger", "handleLoadPackage: Hooked SystemSensorManager");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.programminghoch10.SensorMod;

import static com.programminghoch10.SensorMod.Common.DEFAULT_SENSOR_STATE;
import static com.programminghoch10.SensorMod.Common.getKey;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;

import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;

import java.util.List;

public class SettingsActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
}
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(
getSupportFragmentManager().getBackStackEntryCount() > 0
);
}
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@SuppressLint("WorldReadableFiles")
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager preferenceManager = getPreferenceManager();
setPreferenceScreen(preferenceManager.createPreferenceScreen(requireContext()));
preferenceManager.setSharedPreferencesName("sensors");
preferenceManager.setSharedPreferencesMode(MODE_WORLD_READABLE);
PreferenceScreen preferenceScreen = getPreferenceScreen();
SensorManager sensorManager = (SensorManager) requireContext().getSystemService(SENSOR_SERVICE);
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor sensor : sensors) {
SwitchPreference preference = new SwitchPreference(requireContext());
preference.setDefaultValue(DEFAULT_SENSOR_STATE);
preference.setKey(getKey(sensor));
preference.setTitle(sensor.getName());
preference.setSummary(getKey(sensor) + " - " + sensor);
preferenceScreen.addPreference(preference);
}
}
}
}
14 changes: 14 additions & 0 deletions SensorMod/src/main/res/layout/settings_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/AppTheme.Edge2EdgeFix"
>

<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
4 changes: 4 additions & 0 deletions SensorMod/src/main/res/values-v21/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Settings" />
</resources>
5 changes: 5 additions & 0 deletions SensorMod/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<string name="app_name">SensorMod</string>
<string name="description">Selectively disable sensors.</string>
<string name="title_activity_settings">SensorMod Settings</string>
</resources>
8 changes: 8 additions & 0 deletions SensorMod/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault" />

<style name="AppTheme.Edge2EdgeFix">
<item name="android:fitsSystemWindows">true</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This Module allows you to selectively disable sensors on your android device.
Every sensor is listed and can be selectively disabled at choice.
Supports all sensors reported by Android through the SensorManager API.
Select all apps to disable the sensors for as scope for the module.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Selectively disable sensors.
1 change: 1 addition & 0 deletions metadata/com.programminghoch10.SensorMod/en-US/title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SensorMod
1 change: 1 addition & 0 deletions modules.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ include(":PersistentForegroundServiceNotifications")
include(":PreventAudioFocus")
include(":ResetAllNotificationChannels")
include(":RotationControl")
include(":SensorMod")
include(":UpsideWifi")