Change getUid before turning screen off

getUid is based on ADB shell command execution and device should be connected
to host. However, there're turnScreenOff during test and it causes device
getting suspend state. In that case, the test cannot complete properly due to
ADB disconnection. Therefore, getUid should be uppper turnScreenOff.

Bug: b/143046081
Test: run cts -m CtsStatsdHostTestCases -t android.cts.statsd.validation.ValidationTests#testPartialWakelockDuration
Change-Id: Id71f08d067d463e78a9dccb6b55dfab6c768888b
Merged-In: Id71f08d067d463e78a9dccb6b55dfab6c768888b
diff --git a/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java b/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
index 5eb19c3..c0c8340 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
@@ -148,6 +148,10 @@
         if (statsdDisabled()) {
             return;
         }
+        // getUid() needs shell command via ADB. turnScreenOff() sometimes let system go to suspend.
+        // ADB disconnection causes failure of getUid(). Move up here before turnScreenOff().
+        final int EXPECTED_UID = getUid();
+
         if (!hasFeature(FEATURE_AUTOMOTIVE, false)) return;
         turnScreenOn(); // To ensure that the ScreenOff later gets logged.
         // AoD needs to be turned off because the screen should go into an off state. But, if AoD is
@@ -168,7 +172,6 @@
 
         final String EXPECTED_TAG = "StatsdPartialWakelock";
         final long EXPECTED_TAG_HASH = Long.parseUnsignedLong("15814523794762874414");
-        final int EXPECTED_UID = getUid();
         final int MIN_DURATION = 350;
         final int MAX_DURATION = 700;