MuntashirAkon/AppManager · error · IOException

Could not ${enable ? "enable" : "disable"} sensor.

Error message

Could not ${enable ? "enable" : "disable"} sensor.

What it means

Thrown by SensorServiceCompat.enableSensor when the binder shell command ('set-uid-state') sent to the system 'sensorservice' service returns a non-zero exit code, meaning Android's sensor privacy manager refused to enable or disable sensor access for the package. This reflects a failure of the privileged remote operation, not a local API misuse.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/compat/SensorServiceCompat.java:44

        try {
            BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);
            return "active".equals(result.getStdout().trim());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }

    @RequiresPermission(ManifestCompat.permission.MANAGE_SENSORS)
    public static void enableSensor(@NonNull String packageName, @UserIdInt int userId, boolean enable) throws IOException {
        String state = enable ? "active" : "idle";
        String[] command;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
            command = new String[]{"set-uid-state", packageName, state, "--user", String.valueOf(userId)};
        } else command = new String[]{"set-uid-state", packageName, state};
        BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);
        if (result.getResultCode() != 0) {
            throw new IOException("Could not " + (enable ? "enable" : "disable") + " sensor.");
        }
    }

    @RequiresPermission(ManifestCompat.permission.MANAGE_SENSORS)
    public static void resetSensor(@NonNull String packageName, @UserIdInt int userId) throws IOException {
        String[] command;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
            command = new String[]{"reset-uid-state", packageName, "--user", String.valueOf(userId)};
        } else command = new String[]{"reset-uid-state", packageName};
        BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);
        if (result.getResultCode() != 0) {
            throw new IOException("Could not reset sensor.");
        }
    }

    @NonNull
    private static IBinder getSensorService() {
        return ProxyBinder.getService("sensorservice");

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify the app is running with root, ADB shell, or a privileged (system) identity that holds MANAGE_SENSORS permission
  2. Check the target userId exists (adb shell am get-current-user / list users) before calling
  3. Log BinderShellExecutor.ShellResult output to read the underlying error from sensorservice
  4. Test on the same Android version in a shell: cmd sensorservice or service call sensorservice equivalents to confirm support

Example fix

// before
BinderShellExecutor.execute(getSensorService(), command); // ignore result details
// after
BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);
if (result.getResultCode() != 0) {
    Log.e(TAG, "set-uid-state failed: " + result.getResultCode() + " " + result.getOutput());
    throw new IOException("Could not " + (enable ? "enable" : "disable") + " sensor.");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// requires privileged identity
boolean privileged = appIsRootOrShellOrSystem();
if (!privileged) throw new SecurityException("MANAGE_SENSORS requires root/shell");

Try / catch

try {
    SensorServiceCompat.enableSensor(pkg, userId, enable);
} catch (IOException e) {
    Log.w(TAG, "Sensor toggle failed for " + pkg, e);
    showSensorToggleFailedNotice();
}

Prevention

When it happens

Trigger: Calling SensorServiceCompat.enableSensor(packageName, userId, enable) on Android > Q without sufficient privileges (MANAGE_SENSORS / shell or root identity), on a ROM where the sensorservice set-uid-state command is unavailable or rejects the target user, or when the binder call itself fails.

Common situations: Non-rooted devices where the app's shell identity lacks sensor-management permission; restricted users/work profiles where the target userId is invalid; vendor ROMs that removed or altered the set-uid-state interface.

Understand the failure class

Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/2ca2f55978f2e746. Report an issue: GitHub.