I tried to perform a factory reset in Android using the RecoverySystem class, but I get permission errors, which I can not overwrite because they are system permissions. I w
After Android 8.0, you can send am broadcast to trigger the factory reset process if you can get root permission:
am broadcast -p "android" --receiver-foreground -a android.intent.action.FACTORY_RESET