If I understood your problem correctly, then as per me you need to unlock and lock device in middle right?
If yes, then do following thing -
- Start driver with the aforementioned capabilities
- Lock the device when you want to, by following code ((AndroidDriver) driver) .pressKeyCode(AndroidKeyCode.KEYCODE_POWER);
- Close the driver.
Now open the driver in same manner with aforementioned capabilities.
I haven’t tried above scenario… Let me know if you face any challenges, we can then dig down more.