UIAutomator2 and getCapability() returning null

I’m currently working on Android automation.
My environment is appium java-client 5.0.4.

I have recently updated UIAutomator to UIAutomator2 and now facing problem of getCapability() returning null.
My code to get capability is as follow:


This same code worked fine and returned correct capabilities when I used UIAutomator; but now with UIAutomator2, it started to return null.
Returns null for any capabilityName I put in.

Anyone have solution to it? Or point me to right direction?


Found a work around using getSessionDetails().