Enable --relaxed-security programmatically in Java

Hi there,

How can I enable --relaxed-security programatically?
I need that in order to run driver.executeScript(), to run shell commands. Is there a workaround for that?

My code:

public void setUpServer() {
serviceBuilder = new AppiumServiceBuilder()
.withAppiumJS(new File(establishServerPath()))
.withArgument(GeneralServerFlag.LOG_LEVEL, “info”)
.usingAnyFreePort();
service = serviceBuilder.build();
}

public void startServer() {
service.start();
}

public void setCapabilities(Device device, Command command) throws DeviceException {
caps = new DesiredCapabilities();

    caps.setCapability(MobileCapabilityType.DEVICE_NAME, device.getModel());
    caps.setCapability(MobileCapabilityType.UDID, device.getSerialNo());
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, device.getOS());
    caps.setCapability("autoGrantPermissions", "true");
    caps.setCapability("automationName", "UiAutomator2");
    caps.setCapability("automationName", "--relaxed-security");

    caps.setCapability("appPackage", command.getAppPackage());
    caps.setCapability("appActivity", command.getAppActivity());
}

public void initDriver() {
try {
driver = new AndroidDriver(service.getUrl(), caps);
} catch (WebDriverException ex) {
logger.error(ex.getMessage());
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

Also, I found a solution to do that with Runtime:
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(“cmd.exe /c start cmd.exe /k \“appium -a 127.0.0.1 -p 4723 --session-override -dc \”{\”\“noReset\”\": \"\“false\”\"}\"\"");
Thread.sleep(10000);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}

But if I do that, I’m not able to set the capabilities like I did before.

Thank you!