guard against use of UiDevice prior to its initialization

The source of UI automation permission use to come from the fact
that the test is running as shell or root user; in this case,
it's fine to statically initialize UiDevice.

When running as an Instrumentation, the source of UI automation
permission comes from the privileged token created by system and
passed down via Instrumentation context; in this case, UiDevice
is not properly initialized until it has received the
UiAutomation instance. The particular problem happens when
statically declared UiObject makes use of
UiDevice#getAutomatorBridge() too early: UiObject really
shouldn't be declared statically

Change-Id: If0ecab9960c588c096ed2fb8cc431ef79caa963e
2 files changed