Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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");
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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."
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading