{"record":{"id":"f2cccfb0b908b29d","repo":"MuntashirAkon/AppManager","slug":"could-not-reset-sensor","errorCode":null,"errorMessage":"Could not reset sensor.","messagePattern":"Could not reset sensor\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/SensorServiceCompat.java","lineNumber":56,"sourceCode":"        String[] command;\n        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n            command = new String[]{\"set-uid-state\", packageName, state, \"--user\", String.valueOf(userId)};\n        } else command = new String[]{\"set-uid-state\", packageName, state};\n        BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);\n        if (result.getResultCode() != 0) {\n            throw new IOException(\"Could not \" + (enable ? \"enable\" : \"disable\") + \" sensor.\");\n        }\n    }\n\n    @RequiresPermission(ManifestCompat.permission.MANAGE_SENSORS)\n    public static void resetSensor(@NonNull String packageName, @UserIdInt int userId) throws IOException {\n        String[] command;\n        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n            command = new String[]{\"reset-uid-state\", packageName, \"--user\", String.valueOf(userId)};\n        } else command = new String[]{\"reset-uid-state\", packageName};\n        BinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);\n        if (result.getResultCode() != 0) {\n            throw new IOException(\"Could not reset sensor.\");\n        }\n    }\n\n    @NonNull\n    private static IBinder getSensorService() {\n        return ProxyBinder.getService(\"sensorservice\");\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":65,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/SensorServiceCompat.java#L38-L65","documentation":"Thrown by SensorServiceCompat.resetSensor when the 'reset-uid-state' binder shell command to the 'sensorservice' service exits non-zero, i.e. the sensor privacy state for the package could not be reset to default.","triggerScenarios":"Calling SensorServiceCompat.resetSensor(packageName, userId) on a device/ROM where sensorservice rejects reset-uid-state, with an invalid userId, or without the privileged identity required to manage sensors.","commonSituations":"Same privilege gaps as enable/disable: non-rooted device, unsupported vendor ROM, stale userId after user removal, or the package never having had its UID state modified.","solutions":["Ensure the process runs as root/shell or a privileged system app with MANAGE_SENSORS","Validate the userId exists before resetting; iterate only over returned user handles","Capture shell stderr from the ShellResult for the true failure reason","Fall back to per-user handling: retry without the --user argument on Android <= Q paths if applicable"],"exampleFix":"// before\nBinderShellExecutor.execute(getSensorService(), command);\n// after\nBinderShellExecutor.ShellResult result = BinderShellExecutor.execute(getSensorService(), command);\nif (result.getResultCode() != 0) {\n    Log.e(TAG, \"reset-uid-state failed: \" + result.getOutput());\n    throw new IOException(\"Could not reset sensor.\");\n}","handlingStrategy":"try-catch","validationCode":"// ensure the uid state was actually modified before reset\nif (!userExists(userId)) return; // nothing to reset","typeGuard":null,"tryCatchPattern":"try {\n    SensorServiceCompat.resetSensor(pkg, userId);\n} catch (IOException e) {\n    Log.w(TAG, \"Sensor reset failed for \" + pkg, e);\n}","preventionTips":["Check privileges first","Validate userId exists","Capture shell stderr","Skip reset when no state was changed"],"tags":["android","binder","shell","sensor-privacy"],"backgroundTag":"insufficient-permissions","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}