Bypass statsd CTS on low_ram devices which have statsd disabled.

Bug: 79324611
Test: statsd cts passes on marlin_svelte
Change-Id: I30637f51b75fc6a663ded037ef4edc02deee656e
diff --git a/hostsidetests/statsd/src/android/cts/statsd/alarm/AlarmTests.java b/hostsidetests/statsd/src/android/cts/statsd/alarm/AlarmTests.java
index da6a0a4..4983d06 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/alarm/AlarmTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/alarm/AlarmTests.java
@@ -49,6 +49,9 @@
     }
 
     public void testAlarm() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getBaseConfig();
         turnScreenOn();
         uploadConfig(config);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/alert/AnomalyDetectionTests.java b/hostsidetests/statsd/src/android/cts/statsd/alert/AnomalyDetectionTests.java
index d1c363d..e78a9cd 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/alert/AnomalyDetectionTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/alert/AnomalyDetectionTests.java
@@ -72,6 +72,9 @@
     // Tests that anomaly detection for count works.
     // Also tests that anomaly detection works when spanning multiple buckets.
     public void testCountAnomalyDetection() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getBaseConfig(10, 20, 2 /* threshold: > 2 counts */)
                 .addCountMetric(CountMetric.newBuilder()
                         .setId(METRIC_ID)
@@ -119,6 +122,9 @@
     // Tests that anomaly detection for duration works.
     // Also tests that refractory periods in anomaly detection work.
     public void testDurationAnomalyDetection() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int APP_BREADCRUMB_REPORTED_IS_ON_PREDICATE = 1423;
         StatsdConfig.Builder config =
                 getBaseConfig(17, 17, 10_000_000_000L  /*threshold: > 10 seconds in nanoseconds*/)
@@ -180,6 +186,9 @@
 
     // Tests that anomaly detection for duration works even when the alarm fires too late.
     public void testDurationAnomalyDetectionForLateAlarms() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int APP_BREADCRUMB_REPORTED_IS_ON_PREDICATE = 1423;
         StatsdConfig.Builder config =
                 getBaseConfig(50, 0, 6_000_000_000L /* threshold: > 6 seconds in nanoseconds */)
@@ -226,6 +235,9 @@
 
     // Tests that anomaly detection for value works.
     public void testValueAnomalyDetection() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getBaseConfig(4, 0, 6 /* threshold: value > 6 */)
                 .addValueMetric(ValueMetric.newBuilder()
                         .setId(METRIC_ID)
@@ -259,6 +271,9 @@
 
     // Test that anomaly detection integrates with perfetto properly.
     public void testPerfetto() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         String chars = getDevice().getProperty("ro.build.characteristics");
         if (chars.contains("watch")) {
                 return;
@@ -305,6 +320,9 @@
 
     // Tests that anomaly detection for gauge works.
     public void testGaugeAnomalyDetection() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getBaseConfig(1, 20, 6 /* threshold: value > 6 */)
                 .addGaugeMetric(GaugeMetric.newBuilder()
                         .setId(METRIC_ID)
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/AtomTestCase.java b/hostsidetests/statsd/src/android/cts/statsd/atom/AtomTestCase.java
index 3853f7b..83641af 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/AtomTestCase.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/AtomTestCase.java
@@ -82,6 +82,10 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+
+        if (statsdDisabled()) {
+            return;
+        }
         // TODO: need to do these before running real test:
         // 1. compile statsd and push to device
         // 2. make sure StatsCompanionService and incidentd is running
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/BaseTestCase.java b/hostsidetests/statsd/src/android/cts/statsd/atom/BaseTestCase.java
index 654861f..13335aa 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/BaseTestCase.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/BaseTestCase.java
@@ -141,4 +141,13 @@
             throw new AssertionError(errorBuilder.toString());
         }
     }
+
+    protected boolean statsdDisabled() throws DeviceNotAvailableException {
+        if (getDevice().getProperty("ro.statsd.enable").equals("false")
+                && getDevice().getProperty("ro.config.low_ram").equals("true")) {
+            CLog.d("Statsd is not enabled on the device");
+            return true;
+        }
+        return false;
+    }
 }
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
index d3f3dbd..c4e47bb 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
@@ -72,6 +72,9 @@
     }
 
     public void testScreenStateChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, make sure the screen is off.
         turnScreenOff();
         Thread.sleep(WAIT_TIME_LONG);
@@ -111,6 +114,9 @@
     }
 
     public void testChargingStateChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, set charging state to full.
         setChargingState(5);
         Thread.sleep(WAIT_TIME_SHORT);
@@ -160,6 +166,9 @@
     }
 
     public void testPluggedStateChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, unplug device.
         unplugDevice();
         Thread.sleep(WAIT_TIME_SHORT);
@@ -209,6 +218,9 @@
     }
 
     public void testBatteryLevelChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, set battery level to full.
         setBatteryLevel(100);
         Thread.sleep(WAIT_TIME_SHORT);
@@ -253,6 +265,9 @@
     }
 
     public void testDeviceIdleModeStateChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, leave doze mode.
         leaveDozeMode();
         Thread.sleep(WAIT_TIME_SHORT);
@@ -289,6 +304,9 @@
     }
 
     public void testBatterySaverModeStateChangedAtom() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Setup, turn off battery saver.
         turnBatterySaverOff();
         Thread.sleep(WAIT_TIME_SHORT);
@@ -322,6 +340,9 @@
 
     @RestrictedBuildTest
     public void testRemainingBatteryCapacity() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -348,6 +369,9 @@
 
     @RestrictedBuildTest
     public void testFullBatteryCapacity() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -374,6 +398,9 @@
 
     @RestrictedBuildTest
     public void testTemperature() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -410,6 +437,9 @@
     }
 
     public void testKernelWakelock() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
                 .setField(Atom.KERNEL_WAKELOCK_FIELD_NUMBER)
@@ -436,6 +466,9 @@
     }
 
     public void testCpuTimePerFreq() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -461,6 +494,9 @@
     }
 
     public void testSubsystemSleepState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
                 .setField(Atom.SUBSYSTEM_SLEEP_STATE_FIELD_NUMBER)
@@ -486,6 +522,9 @@
     }
 
     public void testModemActivityInfo() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_TELEPHONY, true)) return;
         StatsdConfig.Builder config = getPulledConfig();
         addGaugeAtom(config, Atom.MODEM_ACTIVITY_INFO_FIELD_NUMBER, null);
@@ -507,6 +546,9 @@
     }
 
     public void testWifiActivityInfo() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WIFI, true)) return;
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
@@ -533,6 +575,9 @@
     }
 
     public void testBluetoothActivityInfo() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_BLUETOOTH, true)) return;
         StatsdConfig.Builder config = getPulledConfig();
         addGaugeAtom(config, Atom.BLUETOOTH_ACTIVITY_INFO_FIELD_NUMBER, null);
@@ -559,6 +604,9 @@
 
     // Explicitly tests if the adb command to log a breadcrumb is working.
     public void testBreadcrumbAdb() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.APP_BREADCRUMB_REPORTED_FIELD_NUMBER;
         createAndUploadConfig(atomTag);
         Thread.sleep(WAIT_TIME_SHORT);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/ProcStateAtomTests.java b/hostsidetests/statsd/src/android/cts/statsd/atom/ProcStateAtomTests.java
index 4aca288..cb0f758 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/ProcStateAtomTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/ProcStateAtomTests.java
@@ -112,6 +112,9 @@
     }
 
     public void testForegroundService() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         Set<Integer> onStates = new HashSet<>(Arrays.asList(
                 ProcessStateEnum.PROCESS_STATE_FOREGROUND_SERVICE_VALUE));
         Set<Integer> offStates = complement(onStates);
@@ -130,6 +133,9 @@
     }
 
     public void testForeground() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         Set<Integer> onStates = new HashSet<>(Arrays.asList(
                 ProcessStateEnum.PROCESS_STATE_IMPORTANT_FOREGROUND_VALUE));
         // There are no offStates, since the app remains in foreground until killed.
@@ -149,6 +155,9 @@
     }
 
     public void testBackground() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         Set<Integer> onStates = BG_STATES;
         Set<Integer> offStates = complement(onStates);
 
@@ -166,6 +175,9 @@
     }
 
     public void testTop() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         Set<Integer> onStates = new HashSet<>(Arrays.asList(
                 ProcessStateEnum.PROCESS_STATE_TOP_VALUE));
         Set<Integer> offStates = complement(onStates);
@@ -185,6 +197,9 @@
     }
 
     public void testTopSleeping() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         Set<Integer> onStates = new HashSet<>(Arrays.asList(
                 ProcessStateEnum.PROCESS_STATE_TOP_SLEEPING_VALUE));
@@ -213,6 +228,9 @@
     }
 
     public void testCached() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         Set<Integer> onStates = CACHED_STATES;
         Set<Integer> offStates = complement(onStates);
 
@@ -245,6 +263,9 @@
     }
 
     public void testValidityOfStates() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         assertFalse("UNKNOWN_TO_PROTO should not be a valid state",
                 ALL_STATES.contains(ProcessStateEnum.PROCESS_STATE_UNKNOWN_TO_PROTO_VALUE));
     }
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/UidAtomTests.java b/hostsidetests/statsd/src/android/cts/statsd/atom/UidAtomTests.java
index 1bfe778..3bf8bd8 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/UidAtomTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/UidAtomTests.java
@@ -78,6 +78,9 @@
     }
 
     public void testAppStartOccurred() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.APP_START_OCCURRED_FIELD_NUMBER;
 
         createAndUploadConfig(atomTag, false);
@@ -98,6 +101,9 @@
     }
 
     public void testBleScan() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_BLUETOOTH_LE, true)) return;
 
         final int atom = Atom.BLE_SCAN_STATE_CHANGED_FIELD_NUMBER;
@@ -117,6 +123,9 @@
     }
 
     public void testBleUnoptimizedScan() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_BLUETOOTH_LE, true)) return;
 
         final int atom = Atom.BLE_SCAN_STATE_CHANGED_FIELD_NUMBER;
@@ -158,6 +167,9 @@
     }
 
     public void testBleScanResult() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_BLUETOOTH_LE, true)) return;
 
         final int atom = Atom.BLE_SCAN_RESULT_RECEIVED_FIELD_NUMBER;
@@ -173,6 +185,9 @@
     }
 
     public void testCameraState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_CAMERA, true) && !hasFeature(FEATURE_CAMERA_FRONT, true)) return;
 
         final int atomTag = Atom.CAMERA_STATE_CHANGED_FIELD_NUMBER;
@@ -194,6 +209,9 @@
     }
 
     public void testCpuTimePerUid() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -229,6 +247,9 @@
 
     @RestrictedBuildTest
     public void testCpuActiveTime() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         StatsdConfig.Builder config = getPulledConfig();
         FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
@@ -264,6 +285,9 @@
     }
 
     public void testFlashlightState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_CAMERA_FLASH, true)) return;
 
         final int atomTag = Atom.FLASHLIGHT_STATE_CHANGED_FIELD_NUMBER;
@@ -291,6 +315,9 @@
     }
 
     public void testForegroundServiceState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.FOREGROUND_SERVICE_STATE_CHANGED_FIELD_NUMBER;
         final String name = "testForegroundService";
 
@@ -316,6 +343,9 @@
     }
 
     public void testGpsScan() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_LOCATION_GPS, true)) return;
         // Whitelist this app against background location request throttling
         getDevice().executeShellCommand(String.format(
@@ -339,6 +369,9 @@
     }
 
     public void testOverlayState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.OVERLAY_STATE_CHANGED_FIELD_NUMBER;
 
         Set<Integer> entered = new HashSet<>(
@@ -364,6 +397,9 @@
     }
 
     public void testDavey() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!DAVEY_ENABLED ) return;
         long MAX_DURATION = 2000;
         long MIN_DURATION = 750;
@@ -382,6 +418,9 @@
     }
 
     public void testScheduledJobState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         String expectedName = "com.android.server.cts.device.statsd/.StatsdJobService";
         final int atomTag = Atom.SCHEDULED_JOB_STATE_CHANGED_FIELD_NUMBER;
         Set<Integer> jobSchedule = new HashSet<>(
@@ -411,6 +450,9 @@
 
     //Note: this test does not have uid, but must run on the device
     public void testScreenBrightness() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         int initialBrightness = getScreenBrightness();
         boolean isInitialManual = isScreenBrightnessModeManual();
         setScreenBrightnessMode(true);
@@ -445,6 +487,9 @@
             atom -> atom.getScreenBrightnessChanged().getLevel());
     }
     public void testSyncState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.SYNC_STATE_CHANGED_FIELD_NUMBER;
         Set<Integer> syncOn = new HashSet<>(Arrays.asList(SyncStateChanged.State.ON_VALUE));
         Set<Integer> syncOff = new HashSet<>(Arrays.asList(SyncStateChanged.State.OFF_VALUE));
@@ -465,6 +510,9 @@
     }
 
     public void testWakelockState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.WAKELOCK_STATE_CHANGED_FIELD_NUMBER;
         Set<Integer> wakelockOn = new HashSet<>(Arrays.asList(
                 WakelockStateChanged.State.ACQUIRE_VALUE,
@@ -500,6 +548,9 @@
     }
 
     public void testWakeupAlarm() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.WAKEUP_ALARM_OCCURRED_FIELD_NUMBER;
 
         StatsdConfig.Builder config = createConfigBuilder();
@@ -514,6 +565,9 @@
     }
 
     public void testWifiLock() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WIFI, true)) return;
 
         final int atomTag = Atom.WIFI_LOCK_STATE_CHANGED_FIELD_NUMBER;
@@ -535,6 +589,9 @@
     }
 
     public void testWifiMulticastLock() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WIFI, true)) return;
 
         final int atomTag = Atom.WIFI_MULTICAST_LOCK_STATE_CHANGED_FIELD_NUMBER;
@@ -558,6 +615,9 @@
     }
 
     public void testWifiScan() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WIFI, true)) return;
 
         final int atom = Atom.WIFI_SCAN_STATE_CHANGED_FIELD_NUMBER;
@@ -580,6 +640,9 @@
     }
 
     public void testAudioState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_AUDIO_OUTPUT, true)) return;
 
         final int atomTag = Atom.AUDIO_STATE_CHANGED_FIELD_NUMBER;
@@ -608,6 +671,9 @@
     }
 
     public void testMediaCodecActivity() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false)) return;
         final int atomTag = Atom.MEDIA_CODEC_STATE_CHANGED_FIELD_NUMBER;
 
@@ -633,6 +699,9 @@
     }
 
     public void testPictureInPictureState() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!hasFeature(FEATURE_WATCH, false) ||
             !hasFeature(FEATURE_PICTURE_IN_PICTURE, true)) return;
         final int atomTag = Atom.PICTURE_IN_PICTURE_STATE_CHANGED_FIELD_NUMBER;
@@ -656,6 +725,9 @@
     }
 
     public void testAppCrashOccurred() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int atomTag = Atom.APP_CRASH_OCCURRED_FIELD_NUMBER;
         createAndUploadConfig(atomTag, false);
         Thread.sleep(WAIT_TIME_SHORT);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/metadata/MetadataTests.java b/hostsidetests/statsd/src/android/cts/statsd/metadata/MetadataTests.java
index 18db006..bc5c972 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/metadata/MetadataTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/metadata/MetadataTests.java
@@ -42,6 +42,9 @@
 
     // Tests that anomaly detection for value works.
     public void testConfigTtl() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         final int TTL_TIME_SEC = 8;
         StatsdConfig.Builder config = getBaseConfig();
         config.setTtlInSeconds(TTL_TIME_SEC); // should reset in 3 seconds.
diff --git a/hostsidetests/statsd/src/android/cts/statsd/metric/CountMetricsTests.java b/hostsidetests/statsd/src/android/cts/statsd/metric/CountMetricsTests.java
index a5c31d0..50211c6 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/metric/CountMetricsTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/metric/CountMetricsTests.java
@@ -35,6 +35,9 @@
 public class CountMetricsTests extends DeviceAtomTestCase {
 
     public void testSimpleEventCountMetric() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         int matcherId = 1;
         StatsdConfigProto.StatsdConfig.Builder builder = createConfigBuilder();
         builder.addCountMetric(StatsdConfigProto.CountMetric.newBuilder()
@@ -59,6 +62,9 @@
         assertEquals(2, countData.getData(0).getBucketInfo(0).getCount());
     }
     public void testEventCountWithCondition() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         int startMatcherId = 1;
         int endMatcherId = 2;
         int whatMatcherId = 3;
@@ -116,6 +122,9 @@
     }
 
     public void testPartialBucketCountMetric() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         int matcherId = 1;
         StatsdConfigProto.StatsdConfig.Builder builder = createConfigBuilder();
         builder.addCountMetric(StatsdConfigProto.CountMetric.newBuilder()
diff --git a/hostsidetests/statsd/src/android/cts/statsd/metric/DurationMetricsTests.java b/hostsidetests/statsd/src/android/cts/statsd/metric/DurationMetricsTests.java
index 127cec7..8e74386 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/metric/DurationMetricsTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/metric/DurationMetricsTests.java
@@ -43,6 +43,9 @@
     private static final int APP_BREADCRUMB_REPORTED_B_MATCH_STOP_ID = 3;
 
     public void testDurationMetric() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Add AtomMatcher's.
         AtomMatcher startAtomMatcher =
             MetricsUtils.startAtomMatcher(APP_BREADCRUMB_REPORTED_A_MATCH_START_ID);
@@ -94,6 +97,9 @@
     }
 
     public void testDurationMetricWithDimension() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // Add AtomMatcher's.
         AtomMatcher startAtomMatcherA =
             MetricsUtils.startAtomMatcher(APP_BREADCRUMB_REPORTED_A_MATCH_START_ID);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/metric/GaugeMetricsTests.java b/hostsidetests/statsd/src/android/cts/statsd/metric/GaugeMetricsTests.java
index be2558e..e2c5a9b 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/metric/GaugeMetricsTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/metric/GaugeMetricsTests.java
@@ -38,6 +38,9 @@
   private static final int APP_BREADCRUMB_REPORTED_B_MATCH_START_ID = 2;
 
   public void testGaugeMetric() throws Exception {
+    if (statsdDisabled()) {
+      return;
+    }
     // Add AtomMatcher's.
     AtomMatcher startAtomMatcher =
         MetricsUtils.startAtomMatcher(APP_BREADCRUMB_REPORTED_A_MATCH_START_ID);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/metric/ValueMetricsTests.java b/hostsidetests/statsd/src/android/cts/statsd/metric/ValueMetricsTests.java
index 3867e04..9340fd2 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/metric/ValueMetricsTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/metric/ValueMetricsTests.java
@@ -56,6 +56,9 @@
   private static final int APP_BREADCRUMB_REPORTED_B_MATCH_START_ID = 2;
 
   public void testValueMetric() throws Exception {
+    if (statsdDisabled()) {
+      return;
+    }
     // Add AtomMatcher's.
     AtomMatcher startAtomMatcher =
         MetricsUtils.startAtomMatcher(APP_BREADCRUMB_REPORTED_A_MATCH_START_ID);
@@ -117,6 +120,9 @@
 
   // Test value metric with pulled atoms and across multiple buckets
   public void testPullerAcrossBuckets() throws Exception {
+    if (statsdDisabled()) {
+      return;
+    }
     // Add AtomMatcher's.
     final String predicateTrueName = "APP_BREADCRUMB_REPORTED_START";
     final String predicateFalseName = "APP_BREADCRUMB_REPORTED_STOP";
@@ -192,6 +198,9 @@
 
   // Test value metric with pulled atoms and across multiple buckets
   public void testMultipleEventsPerBucket() throws Exception {
+    if (statsdDisabled()) {
+      return;
+    }
     // Add AtomMatcher's.
     final String predicateTrueName = "APP_BREADCRUMB_REPORTED_START";
     final String predicateFalseName = "APP_BREADCRUMB_REPORTED_STOP";
diff --git a/hostsidetests/statsd/src/android/cts/statsd/uidmap/UidMapTests.java b/hostsidetests/statsd/src/android/cts/statsd/uidmap/UidMapTests.java
index f7c9df6..bf599d3 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/uidmap/UidMapTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/uidmap/UidMapTests.java
@@ -33,6 +33,9 @@
 
     // Tests that every report has at least one snapshot.
     public void testUidSnapshotIncluded() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         // There should be at least the test app installed during the test setup.
         createAndUploadConfig(AtomsProto.Atom.UID_PROCESS_STATE_CHANGED_FIELD_NUMBER);
 
@@ -64,6 +67,9 @@
 
     // Tests that delta event included during app installation.
     public void testChangeFromInstallation() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         getDevice().uninstallPackage(DEVICE_SIDE_TEST_PACKAGE);
         createAndUploadConfig(AtomsProto.Atom.UID_PROCESS_STATE_CHANGED_FIELD_NUMBER);
         // Install the package after the config is sent to statsd. The uid map is not guaranteed to
@@ -90,6 +96,9 @@
 
     // We check that a re-installation gives a change event (similar to an app upgrade).
     public void testChangeFromReinstall() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(mCtsBuild);
         getDevice().installPackage(buildHelper.getTestFile(DEVICE_SIDE_TEST_APK), false, true);
         createAndUploadConfig(AtomsProto.Atom.UID_PROCESS_STATE_CHANGED_FIELD_NUMBER);
@@ -113,6 +122,9 @@
     }
 
     public void testChangeFromUninstall() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(mCtsBuild);
         getDevice().installPackage(buildHelper.getTestFile(DEVICE_SIDE_TEST_APK), true, true);
         createAndUploadConfig(AtomsProto.Atom.UID_PROCESS_STATE_CHANGED_FIELD_NUMBER);
diff --git a/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java b/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
index 362d4cc..4dac5c1 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/validation/ValidationTests.java
@@ -78,6 +78,9 @@
     }
 
     public void testPartialWakelock() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         resetBatteryStats();
         unplugDevice();
         turnScreenOff();
@@ -134,6 +137,9 @@
 
     @RestrictedBuildTest
     public void testPartialWakelockDuration() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         turnScreenOn(); // To ensure that the ScreenOff later gets logged.
         uploadWakelockDurationBatteryStatsConfig(TimeUnit.CTS);
         Thread.sleep(WAIT_TIME_SHORT);
@@ -189,6 +195,9 @@
     }
 
     public void testPartialWakelockLoad() throws Exception {
+        if (statsdDisabled()) {
+            return;
+        }
         if (!ENABLE_LOAD_TEST) return;
         turnScreenOn(); // To ensure that the ScreenOff later gets logged.
         uploadWakelockDurationBatteryStatsConfig(TimeUnit.CTS);