Ensure adb runs as root in the host test

The adb shell command to enable the boot-completed receiver fails unless adb is running as root (a SecurityException is thrown). As a result, the boot-completed receiver remains disabled, and thus the test fails. Fixing it by enabling adb root.

Bug: 297726328
Test: atest CtsExtServicesHostTests-tplus
Change-Id: I03031614903cdad8e2aa4c004fc14ace707e437e
diff --git a/java/tests/hosttests/src/android/ext/services/hosttests/AdServicesFilesCleanupBootCompleteReceiverHostTest.java b/java/tests/hosttests/src/android/ext/services/hosttests/AdServicesFilesCleanupBootCompleteReceiverHostTest.java
index 333e456..32d377b 100644
--- a/java/tests/hosttests/src/android/ext/services/hosttests/AdServicesFilesCleanupBootCompleteReceiverHostTest.java
+++ b/java/tests/hosttests/src/android/ext/services/hosttests/AdServicesFilesCleanupBootCompleteReceiverHostTest.java
@@ -35,6 +35,7 @@
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 
 import org.junit.After;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -71,6 +72,9 @@
     public void setUp() throws Exception {
         ITestDevice device = getDevice();
 
+        // Enabling the boot-completed receiver throws a SecurityException unless adb runs as root
+        Assume.assumeTrue("Needs adb root to enable the receiver", device.enableAdbRoot());
+
         logDeviceMetadata();
 
         // Find the extservices package
@@ -95,9 +99,12 @@
 
     @After
     public void tearDown() throws Exception {
-        if (mDevice != null && mAdServicesFilePath != null
-                && mDevice.doesFileExist(mAdServicesFilePath)) {
-            mDevice.deleteFile(mAdServicesFilePath);
+        if (mDevice != null) {
+            if (mAdServicesFilePath != null && mDevice.doesFileExist(mAdServicesFilePath)) {
+                mDevice.deleteFile(mAdServicesFilePath);
+            }
+
+            mDevice.disableAdbRoot();
         }
     }