diff --git a/src/java/com/google/devtools/mobileharness/api/model/error/AndroidErrorId.java b/src/java/com/google/devtools/mobileharness/api/model/error/AndroidErrorId.java index e19aa02fe7..f7390e2931 100644 --- a/src/java/com/google/devtools/mobileharness/api/model/error/AndroidErrorId.java +++ b/src/java/com/google/devtools/mobileharness/api/model/error/AndroidErrorId.java @@ -410,6 +410,7 @@ public enum AndroidErrorId implements ErrorId { // Android LabTestSupport: 103_201 ~ 103_250 LAB_TEST_SUPPORT_DISABLE_SMART_LOCK_FOR_PASSWORDS_AND_FAST_PAIR_ERROR( 103_201, ErrorType.INFRA_ISSUE), + LAB_TEST_SUPPORT_ENABLE_ADS_DEBUG_LOGGING_ERROR(103_202, ErrorType.INFRA_ISSUE), /** Android Devices: 110_001 ~ 115_000 */ // Android Detector: 110_001 ~ 110_200 @@ -663,6 +664,8 @@ public enum AndroidErrorId implements ErrorId { // AndroidLabTestSupportSettingsDecorator: 129_951 ~ 130_000 ANDROID_LAB_TEST_SUPPORT_SETTINGS_DECORATOR_DISABLE_SMART_LOCK_FOR_PASSWORDS_AND_FAST_PAIR_ERROR( 129_951, ErrorType.INFRA_ISSUE), + ANDROID_LAB_TEST_SUPPORT_SETTINGS_DECORATOR_ENABLE_ADS_DEBUG_LOGGING_ERROR( + 129_952, ErrorType.INFRA_ISSUE), // AndroidShippingApiLevelCheckDecorator: 130_001 ~ 130_050 ANDROID_SHIPPING_API_LEVEL_CHECK_DECORATOR_API_LEVEL_TOO_LOW(130_001, ErrorType.CUSTOMER_ISSUE), diff --git a/src/java/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelper.java b/src/java/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelper.java index 3811d2a195..acc738fdfe 100644 --- a/src/java/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelper.java +++ b/src/java/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelper.java @@ -41,6 +41,10 @@ public class LabTestSupportHelper { static final String LTS_CONFIG_PHENOTYPE_FLAGS_INSTRUMENTATION_RUNNER_NAME = LAB_TEST_SUPPORT_PACKAGE + ".ConfigurePhenotypeFlagsInstrumentation"; + @VisibleForTesting + static final String LTS_ENABLE_ADS_DEBUG_LOGGING_INSTRUMENTATION_RUNNER_NAME = + LAB_TEST_SUPPORT_PACKAGE + ".EnableAdsDebugLoggingInstrumentation"; + private final AndroidAdbUtil androidAdbUtil; private final AndroidInstrumentationUtil androidInstrumentationUtil; @@ -65,7 +69,8 @@ public LabTestSupportHelper() { public boolean disableSmartLockForPasswordsAndFastPair(String serial, int deviceSdkVersion) throws MobileHarnessException, InterruptedException { try { - return configurePhenotypeFlags(serial, deviceSdkVersion); + return runLtsInstrumentation( + serial, deviceSdkVersion, LTS_CONFIG_PHENOTYPE_FLAGS_INSTRUMENTATION_RUNNER_NAME); } catch (MobileHarnessException e) { throw new MobileHarnessException( AndroidErrorId.LAB_TEST_SUPPORT_DISABLE_SMART_LOCK_FOR_PASSWORDS_AND_FAST_PAIR_ERROR, @@ -77,7 +82,20 @@ public boolean disableSmartLockForPasswordsAndFastPair(String serial, int device } } - private boolean configurePhenotypeFlags(String serial, int deviceSdkVersion) + public boolean enableAdsDebuggingLogging(String serial, int deviceSdkVersion) + throws MobileHarnessException, InterruptedException { + try { + return runLtsInstrumentation( + serial, deviceSdkVersion, LTS_ENABLE_ADS_DEBUG_LOGGING_INSTRUMENTATION_RUNNER_NAME); + } catch (MobileHarnessException e) { + throw new MobileHarnessException( + AndroidErrorId.LAB_TEST_SUPPORT_ENABLE_ADS_DEBUG_LOGGING_ERROR, + String.format("Failed to enable ads debugging logging on device %s", serial), + e); + } + } + + private boolean runLtsInstrumentation(String serial, int deviceSdkVersion, String runnerName) throws MobileHarnessException, InterruptedException { // This property is checked by the gms phenotype service. androidAdbUtil.setProperty(serial, ALLOW_LTS_PROP_NAME, "true"); @@ -87,7 +105,7 @@ private boolean configurePhenotypeFlags(String serial, int deviceSdkVersion) deviceSdkVersion, AndroidInstrumentationSetting.create( LAB_TEST_SUPPORT_PACKAGE, - LTS_CONFIG_PHENOTYPE_FLAGS_INSTRUMENTATION_RUNNER_NAME, + runnerName, /* className= */ null, /* otherOptions= */ null, /* async= */ false, diff --git a/src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/AndroidLabTestSupportSettingsDecorator.java b/src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/AndroidLabTestSupportSettingsDecorator.java index 6107e827e2..78ed09d85c 100644 --- a/src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/AndroidLabTestSupportSettingsDecorator.java +++ b/src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/AndroidLabTestSupportSettingsDecorator.java @@ -65,6 +65,7 @@ public void run(TestInfo testInfo) throws MobileHarnessException, InterruptedExc AndroidLabTestSupportSettingsDecoratorSpec spec = testInfo.jobInfo().combinedSpec(this, deviceId); String labTestSupportApkPath = testInfo.jobInfo().files().getSingle(TAG_LAB_TEST_SUPPORT_APK); + int deviceSdkVersion = androidSystemSettingUtil.getDeviceSdkVersion(deviceId); apkInstaller.installApkIfNotExist( getDevice(), @@ -74,7 +75,6 @@ public void run(TestInfo testInfo) throws MobileHarnessException, InterruptedExc .build(), testInfo.log()); - int deviceSdkVersion = androidSystemSettingUtil.getDeviceSdkVersion(deviceId); if (spec.getDisableSmartLockForPasswordsAndFastPair() && !labTestSupportHelper.disableSmartLockForPasswordsAndFastPair( deviceId, deviceSdkVersion)) { @@ -87,6 +87,13 @@ public void run(TestInfo testInfo) throws MobileHarnessException, InterruptedExc deviceId)); } + if (spec.getEnableAdsDebugLogging() + && !labTestSupportHelper.enableAdsDebuggingLogging(deviceId, deviceSdkVersion)) { + throw new MobileHarnessException( + AndroidErrorId.ANDROID_LAB_TEST_SUPPORT_SETTINGS_DECORATOR_ENABLE_ADS_DEBUG_LOGGING_ERROR, + String.format("Failed to enable ads debugging logging on device %s", deviceId)); + } + getDecorated().run(testInfo); } } diff --git a/src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/decorator/android_lab_test_support_settings_decorator_spec.proto b/src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/decorator/android_lab_test_support_settings_decorator_spec.proto index 92454bc498..6e39a83be7 100644 --- a/src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/decorator/android_lab_test_support_settings_decorator_spec.proto +++ b/src/java/com/google/wireless/qa/mobileharness/shared/proto/spec/decorator/android_lab_test_support_settings_decorator_spec.proto @@ -24,7 +24,7 @@ option java_package = "com.google.wireless.qa.mobileharness.shared.proto.spec.de option java_multiple_files = true; // Specs for AndroidLabTestSupportSettingsDecorator. -// Next tag: 2 +// Next tag: 3 message AndroidLabTestSupportSettingsDecoratorSpec { extend DecoratorSpec { optional AndroidLabTestSupportSettingsDecoratorSpec ext = 1011; @@ -38,4 +38,11 @@ message AndroidLabTestSupportSettingsDecoratorSpec { "device." } ]; + + optional bool enable_ads_debug_logging = 2 [ + default = false, + (field_detail) = { + help: "If set to 'true', enables ads debug logging on the device." + } + ]; } diff --git a/src/javatests/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelperTest.java b/src/javatests/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelperTest.java index 92c0268a9a..37fc0ffb08 100644 --- a/src/javatests/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelperTest.java +++ b/src/javatests/com/google/devtools/mobileharness/platform/android/labtestsupport/util/LabTestSupportHelperTest.java @@ -103,4 +103,50 @@ public void disableSmartLockForPasswordsAndFastPair_instrumentationFailed_throws .isEqualTo( AndroidErrorId.LAB_TEST_SUPPORT_DISABLE_SMART_LOCK_FOR_PASSWORDS_AND_FAST_PAIR_ERROR); } + + @Test + public void enableAdsDebuggingLogging_success() throws Exception { + when(androidInstrumentationUtil.instrument(any(), anyInt(), any(), any())) + .thenReturn("success=true"); + + assertThat( + labTestSupportHelper.enableAdsDebuggingLogging(DEVICE_ID, /* deviceSdkVersion= */ 34)) + .isTrue(); + + verify(androidAdbUtil).setProperty(DEVICE_ID, LabTestSupportHelper.ALLOW_LTS_PROP_NAME, "true"); + verify(androidInstrumentationUtil) + .instrument( + DEVICE_ID, + /* deviceSdkVersion= */ 34, + AndroidInstrumentationSetting.create( + LabTestSupportHelper.LAB_TEST_SUPPORT_PACKAGE, + LabTestSupportHelper.LTS_ENABLE_ADS_DEBUG_LOGGING_INSTRUMENTATION_RUNNER_NAME, + /* className= */ null, + /* otherOptions= */ null, + /* async= */ false, + /* showRawResults= */ false, + /* prefixAndroidTest= */ false, + /* noIsolatedStorage= */ false, + /* useTestStorageService= */ false, + /* enableCoverage= */ false), + /* timeout= */ Duration.ofMinutes(1)); + } + + @Test + public void enableAdsDebuggingLogging_instrumentationFailed_throwsException() throws Exception { + when(androidInstrumentationUtil.instrument(any(), anyInt(), any(), any())) + .thenThrow( + new MobileHarnessException( + AndroidErrorId.ANDROID_INSTRUMENTATION_COMMAND_EXEC_FAILED, + "instrumentation failed")); + + assertThat( + assertThrows( + MobileHarnessException.class, + () -> + labTestSupportHelper.enableAdsDebuggingLogging( + DEVICE_ID, /* deviceSdkVersion= */ 34)) + .getErrorId()) + .isEqualTo(AndroidErrorId.LAB_TEST_SUPPORT_ENABLE_ADS_DEBUG_LOGGING_ERROR); + } }