Fetch activity everytime we need it

Calling Activity#recreate() causes the activity to be re-created with a *new* instance.
And the recreate() method is called in some tests in android.preference.cts.* (e.g. PreferenceActivityLegacyFlowTest#legacyActivityRecreateTest).

Currently, hasVerticalNavBar() refers to the activity at the time of ctor of this TestUtils class, but since the instance of the activity after calling the recreate() is “re-created”, there is no guarantee that the target activity at the time of calling hasVerticalNavBar() is the same as one at the time of ctor of this TestUtils class.
So we should get an activity reference everytime we need it instead of holding a reference to the activity at ctor.

Note that this hasVerticalNavBar() is called by takeScreenshot() to calc the crop region.

Test: atest android.preference.cts.*
Bug: 160180368
Change-Id: I6ca9af0a73d28987dac6adc12000a7f94120bd5e
1 file changed