ApiQueryGadgets: fix undefined variable and other cleanup

Change-Id: I13f9a091776c4b833e7f29d767e4698e95f03b5e
Merge "ApiQueryGadgets: fix undefined variable and other cleanup" into RL2