diff --git a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/BooleanMetricType.kt b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/BooleanMetricType.kt index cb7cdd508..f5b44fb81 100644 --- a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/BooleanMetricType.kt +++ b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/BooleanMetricType.kt @@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting import com.sun.jna.StringArray import mozilla.telemetry.glean.Glean import mozilla.telemetry.glean.rust.LibGleanFFI +import mozilla.telemetry.glean.rust.toByte class BooleanMetricType( disabled: Boolean, @@ -27,7 +28,8 @@ class BooleanMetricType( name = name, send_in_pings = ffiPingsList, send_in_pings_len = sendInPings.size, - lifetime = lifetime.ordinal) + lifetime = lifetime.ordinal, + disabled = disabled.toByte()) } /** @@ -36,7 +38,7 @@ class BooleanMetricType( * @param value This is a user defined boolean value. */ fun set(value: Boolean) { - LibGleanFFI.INSTANCE.glean_boolean_set(Glean.handle, this.handle, if (value) { 1 } else { 0 }) + LibGleanFFI.INSTANCE.glean_boolean_set(Glean.handle, this.handle, value.toByte()) } /** diff --git a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/CounterMetricType.kt b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/CounterMetricType.kt index 30fc49b08..758a65618 100644 --- a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/CounterMetricType.kt +++ b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/CounterMetricType.kt @@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting import com.sun.jna.StringArray import mozilla.telemetry.glean.Glean import mozilla.telemetry.glean.rust.LibGleanFFI +import mozilla.telemetry.glean.rust.toByte import mozilla.telemetry.glean.Dispatchers // import mozilla.components.service.glean.storages.CountersStorageEngine @@ -43,7 +44,8 @@ class CounterMetricType( name = name, send_in_pings = ffiPingsList, send_in_pings_len = sendInPings.size, - lifetime = lifetime.ordinal) + lifetime = lifetime.ordinal, + disabled = disabled.toByte()) } /** diff --git a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/StringMetricType.kt b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/StringMetricType.kt index 5bb8793cc..a592e95bd 100644 --- a/glean-core/android/src/main/java/mozilla/telemetry/glean/private/StringMetricType.kt +++ b/glean-core/android/src/main/java/mozilla/telemetry/glean/private/StringMetricType.kt @@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting import com.sun.jna.StringArray import mozilla.telemetry.glean.Glean import mozilla.telemetry.glean.rust.LibGleanFFI +import mozilla.telemetry.glean.rust.toByte import mozilla.telemetry.glean.Dispatchers // import mozilla.components.service.glean.storages.StringsStorageEngine @@ -42,7 +43,8 @@ class StringMetricType( name = name, send_in_pings = ffiPingsList, send_in_pings_len = sendInPings.size, - lifetime = lifetime.ordinal) + lifetime = lifetime.ordinal, + disabled = disabled.toByte()) } /** diff --git a/glean-core/android/src/main/java/mozilla/telemetry/glean/rust/LibGleanFFI.kt b/glean-core/android/src/main/java/mozilla/telemetry/glean/rust/LibGleanFFI.kt index 7f8a7e426..693953ba3 100644 --- a/glean-core/android/src/main/java/mozilla/telemetry/glean/rust/LibGleanFFI.kt +++ b/glean-core/android/src/main/java/mozilla/telemetry/glean/rust/LibGleanFFI.kt @@ -12,6 +12,9 @@ import com.sun.jna.Pointer import com.sun.jna.StringArray import java.lang.reflect.Proxy +// Turn a boolean into its Byte (u8) representation +internal fun Boolean.toByte(): Byte = if (this) 1 else 0 + @Suppress("TooManyFunctions") internal interface LibGleanFFI : Library { companion object { @@ -52,7 +55,8 @@ internal interface LibGleanFFI : Library { name: String, send_in_pings: StringArray, send_in_pings_len: Int, - lifetime: Int + lifetime: Int, + disabled: Byte ): Long fun glean_new_counter_metric( @@ -60,7 +64,8 @@ internal interface LibGleanFFI : Library { name: String, send_in_pings: StringArray, send_in_pings_len: Int, - lifetime: Int + lifetime: Int, + disabled: Byte ): Long fun glean_new_string_metric( @@ -68,7 +73,8 @@ internal interface LibGleanFFI : Library { name: String, send_in_pings: StringArray, send_in_pings_len: Int, - lifetime: Int + lifetime: Int, + disabled: Byte ): Long fun glean_ping_collect(glean_handle: Long, ping_name: String): Pointer? diff --git a/glean-core/android/src/test/java/mozilla/telemetry/glean/private/CounterMetricTypeTest.kt b/glean-core/android/src/test/java/mozilla/telemetry/glean/private/CounterMetricTypeTest.kt index 9758ca709..e69344403 100644 --- a/glean-core/android/src/test/java/mozilla/telemetry/glean/private/CounterMetricTypeTest.kt +++ b/glean-core/android/src/test/java/mozilla/telemetry/glean/private/CounterMetricTypeTest.kt @@ -17,7 +17,6 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before -import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -61,7 +60,6 @@ class CounterMetricTypeTest { assertEquals(11, counterMetric.testGetValue()) } - @Ignore("Ignoring the test as 'disabled' is not passed through FFI") @Test fun `counters with no lifetime must not record data`() { // Define a 'counterMetric' counter metric, which will be stored in "store1". @@ -81,7 +79,6 @@ class CounterMetricTypeTest { counterMetric.testHasValue()) } - @Ignore("Ignoring the test as 'disabled' is not passed through FFI") @Test fun `disabled counters must not record data`() { // Define a 'counterMetric' counter metric, which will be stored in "store1". It's disabled diff --git a/glean-core/ffi/examples/glean.h b/glean-core/ffi/examples/glean.h index 2fb22c6fd..fb7fc058f 100644 --- a/glean-core/ffi/examples/glean.h +++ b/glean-core/ffi/examples/glean.h @@ -78,19 +78,22 @@ uint64_t glean_new_boolean_metric(FfiStr category, FfiStr name, RawStringArray send_in_pings, int32_t send_in_pings_len, - int32_t lifetime); + int32_t lifetime, + uint8_t disabled); uint64_t glean_new_counter_metric(FfiStr category, FfiStr name, RawStringArray send_in_pings, int32_t send_in_pings_len, - int32_t lifetime); + int32_t lifetime, + uint8_t disabled); uint64_t glean_new_string_metric(FfiStr category, FfiStr name, RawStringArray send_in_pings, int32_t send_in_pings_len, - int32_t lifetime); + int32_t lifetime, + uint8_t disabled); char *glean_ping_collect(uint64_t glean_handle, FfiStr ping_name); diff --git a/glean-core/ffi/src/lib.rs b/glean-core/ffi/src/lib.rs index 82cdadc66..3648500b4 100755 --- a/glean-core/ffi/src/lib.rs +++ b/glean-core/ffi/src/lib.rs @@ -92,6 +92,7 @@ pub extern "C" fn glean_new_boolean_metric( send_in_pings: RawStringArray, send_in_pings_len: i32, lifetime: i32, + disabled: u8, ) -> u64 { BOOLEAN_METRICS.insert_with_log(|| { let send_in_pings = unsafe { from_raw_string_array(send_in_pings, send_in_pings_len) }; @@ -106,7 +107,7 @@ pub extern "C" fn glean_new_boolean_metric( category: category.into_string(), send_in_pings, lifetime, - ..Default::default() + disabled: disabled != 0, })) }) } @@ -118,6 +119,7 @@ pub extern "C" fn glean_new_string_metric( send_in_pings: RawStringArray, send_in_pings_len: i32, lifetime: i32, + disabled: u8, ) -> u64 { STRING_METRICS.insert_with_log(|| { let send_in_pings = unsafe { from_raw_string_array(send_in_pings, send_in_pings_len) }; @@ -135,7 +137,7 @@ pub extern "C" fn glean_new_string_metric( category: category.into_string(), send_in_pings, lifetime, - ..Default::default() + disabled: disabled != 0, })) }) } @@ -147,6 +149,7 @@ pub extern "C" fn glean_new_counter_metric( send_in_pings: RawStringArray, send_in_pings_len: i32, lifetime: i32, + disabled: u8, ) -> u64 { COUNTER_METRICS.insert_with_log(|| { let send_in_pings = unsafe { from_raw_string_array(send_in_pings, send_in_pings_len) }; @@ -164,7 +167,7 @@ pub extern "C" fn glean_new_counter_metric( category: category.into_string(), send_in_pings, lifetime, - ..Default::default() + disabled: disabled != 0, })) }) }