summaryrefslogtreecommitdiff
path: root/go/current/include/packages/modules/StatsD/lib/libstatssocket
diff options
context:
space:
mode:
Diffstat (limited to 'go/current/include/packages/modules/StatsD/lib/libstatssocket')
-rw-r--r--go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_annotations.h195
-rw-r--r--go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_buffer_writer.h30
-rw-r--r--go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_event.h207
-rw-r--r--go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_socket.h33
4 files changed, 465 insertions, 0 deletions
diff --git a/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_annotations.h b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_annotations.h
new file mode 100644
index 0000000..2963db9
--- /dev/null
+++ b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_annotations.h
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+enum AnnotationIds : uint8_t {
+ /**
+ * Annotation ID constant for logging UID field.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_IS_UID = 1,
+
+ /**
+ * Annotation ID constant to indicate logged atom event's timestamp should be truncated.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2,
+
+ /**
+ * Annotation ID constant for a state atom's primary field.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_PRIMARY_FIELD = 3,
+
+ /**
+ * Annotation ID constant for state atom's state field.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_EXCLUSIVE_STATE = 4,
+
+ /**
+ * Annotation ID constant to indicate the first UID in the attribution chain
+ * is a primary field.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID = 5,
+
+ /**
+ * Annotation ID constant to indicate which state is default for the state atom.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_DEFAULT_STATE = 6,
+
+ /**
+ * Annotation ID constant to signal that all states should be reset to the default state.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_TRIGGER_STATE_RESET = 7,
+
+ /**
+ * Annotation ID constant to indicate state changes need to account for nesting.
+ * This should only be used with binary state atoms.
+ *
+ * Introduced in API 31.
+ */
+ ASTATSLOG_ANNOTATION_ID_STATE_NESTED = 8,
+
+ /**
+ * Annotation ID constant to indicate the restriction category of an atom.
+ * This annotation must only be attached to the atom id. This is an int annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_RESTRICTION_CATEGORY = 9,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains peripheral device info.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_PERIPHERAL_DEVICE_INFO = 10,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains app usage information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_APP_USAGE = 11,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains app activity information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_APP_ACTIVITY = 12,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains health connect information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_HEALTH_CONNECT = 13,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains accessibility information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_ACCESSIBILITY = 14,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains system search information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_SYSTEM_SEARCH = 15,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains user engagement information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_USER_ENGAGEMENT = 16,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains ambient sensing information.
+ * This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_AMBIENT_SENSING = 17,
+
+ /**
+ * Annotation ID to indicate that a field of an atom contains demographic classification
+ * information. This is a bool annotation.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_ANNOTATION_ID_FIELD_RESTRICTION_DEMOGRAPHIC_CLASSIFICATION = 18,
+};
+
+enum AStatsLogRestrictionCategory : uint32_t {
+ /**
+ * Restriction category for atoms about diagnostics.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_RESTRICTION_CATEGORY_DIAGNOSTIC = 1,
+
+ /**
+ * Restriction category for atoms about system intelligence.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_RESTRICTION_CATEGORY_SYSTEM_INTELLIGENCE = 2,
+
+ /**
+ * Restriction category for atoms about authentication.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_RESTRICTION_CATEGORY_AUTHENTICATION = 3,
+
+ /**
+ * Restriction category for atoms about fraud and abuse.
+ *
+ * Introduced in API 34.
+ */
+ ASTATSLOG_RESTRICTION_CATEGORY_FRAUD_AND_ABUSE = 4,
+
+};
+__END_DECLS
diff --git a/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_buffer_writer.h b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_buffer_writer.h
new file mode 100644
index 0000000..5b41f0e
--- /dev/null
+++ b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_buffer_writer.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __CPLUSPLUS
+void stats_log_close();
+int stats_log_is_closed();
+int write_buffer_to_statsd(void* buffer, size_t size, uint32_t atomId);
+#ifdef __cplusplus
+}
+#endif // __CPLUSPLUS
diff --git a/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_event.h b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_event.h
new file mode 100644
index 0000000..23e1419
--- /dev/null
+++ b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_event.h
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_STATS_LOG_STATS_EVENT_H
+#define ANDROID_STATS_LOG_STATS_EVENT_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/*
+ * Functionality to build and store the buffer sent over the statsd socket.
+ * This code defines and encapsulates the socket protocol.
+ *
+ * Usage:
+ * AStatsEvent* event = AStatsEvent_obtain();
+ *
+ * AStatsEvent_setAtomId(event, atomId);
+ * AStatsEvent_addBoolAnnotation(event, 5, false); // atom-level annotation
+ * AStatsEvent_writeInt32(event, 24);
+ * AStatsEvent_addBoolAnnotation(event, 1, true); // annotation for preceding atom field
+ * AStatsEvent_addInt32Annotation(event, 2, 128);
+ * AStatsEvent_writeFloat(event, 2.0);
+ *
+ * AStatsEvent_write(event);
+ * AStatsEvent_release(event);
+ *
+ * Note that calls to add atom fields and annotations should be made in the
+ * order that they are defined in the atom.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __CPLUSPLUS
+
+/**
+ * Opaque struct use to represent a StatsEvent. It builds and stores the data that is sent to
+ * statsd.
+ */
+struct AStatsEvent;
+typedef struct AStatsEvent AStatsEvent;
+
+/**
+ * Returns a new AStatsEvent. If you call this function, you must call AStatsEvent_release to free
+ * the allocated memory.
+ */
+AStatsEvent* AStatsEvent_obtain();
+
+/**
+ * Builds and finalizes the AStatsEvent for a pulled event.
+ * This should only be called for pulled AStatsEvents.
+ *
+ * After this function, the StatsEvent must not be modified in any way other than calling release or
+ * write.
+ *
+ * Build can be called multiple times without error.
+ * If the event has been built before, this function is a no-op.
+ */
+void AStatsEvent_build(AStatsEvent* event);
+
+/**
+ * Writes the StatsEvent to the stats log.
+ *
+ * After calling this, AStatsEvent_release must be called,
+ * and is the only function that can be safely called.
+ */
+int AStatsEvent_write(AStatsEvent* event);
+
+/**
+ * Frees the memory held by this StatsEvent.
+ *
+ * After calling this, the StatsEvent must not be used or modified in any way.
+ */
+void AStatsEvent_release(AStatsEvent* event);
+
+/**
+ * Sets the atom id for this StatsEvent.
+ *
+ * This function should be called immediately after AStatsEvent_obtain. It may
+ * be called additional times as well, but subsequent calls will have no effect.
+ **/
+void AStatsEvent_setAtomId(AStatsEvent* event, uint32_t atomId);
+
+/**
+ * Writes an int32_t field to this StatsEvent.
+ **/
+void AStatsEvent_writeInt32(AStatsEvent* event, int32_t value);
+
+/**
+ * Writes an int64_t field to this StatsEvent.
+ **/
+void AStatsEvent_writeInt64(AStatsEvent* event, int64_t value);
+
+/**
+ * Writes a float field to this StatsEvent.
+ **/
+void AStatsEvent_writeFloat(AStatsEvent* event, float value);
+
+/**
+ * Write a bool field to this StatsEvent.
+ **/
+void AStatsEvent_writeBool(AStatsEvent* event, bool value);
+
+/**
+ * Write a byte array field to this StatsEvent.
+ **/
+void AStatsEvent_writeByteArray(AStatsEvent* event, const uint8_t* buf, size_t numBytes);
+
+/**
+ * Write a string field to this StatsEvent.
+ *
+ * The string must be null-terminated.
+ **/
+void AStatsEvent_writeString(AStatsEvent* event, const char* value);
+
+/**
+ * Write an attribution chain field to this StatsEvent.
+ *
+ * The sizes of uids and tags must be equal. The AttributionNode at position i is
+ * made up of uids[i] and tags[i].
+ *
+ * \param uids array of uids in the attribution chain.
+ * \param tags array of tags in the attribution chain. Each tag must be null-terminated.
+ * \param numNodes the number of AttributionNodes in the attribution chain. This is the length of
+ * the uids and the tags.
+ **/
+void AStatsEvent_writeAttributionChain(AStatsEvent* event, const uint32_t* uids,
+ const char* const* tags, uint8_t numNodes);
+
+/**
+ * Write a int32 array field to this StatsEvent.
+ *
+ * Max size of array is 127. If exceeded, array is not written and ERROR_LIST_TOO_LONG is appended
+ * to StatsEvent.
+ **/
+void AStatsEvent_writeInt32Array(AStatsEvent* event, const int32_t* elements, size_t numElements);
+
+/**
+ * Write a int64 array field to this StatsEvent.
+ *
+ * Max size of array is 127. If exceeded, array is not written and ERROR_LIST_TOO_LONG is appended
+ * to StatsEvent.
+ **/
+void AStatsEvent_writeInt64Array(AStatsEvent* event, const int64_t* elements, size_t numElements);
+
+/**
+ * Write a float array field to this StatsEvent.
+ *
+ * Max size of array is 127. If exceeded, array is not written and ERROR_LIST_TOO_LONG is appended
+ * to StatsEvent.
+ **/
+void AStatsEvent_writeFloatArray(AStatsEvent* event, const float* elements, size_t numElements);
+
+/**
+ * Write a bool array field to this StatsEvent.
+ *
+ * Max size of array is 127. If exceeded, array is not written and ERROR_LIST_TOO_LONG is appended
+ * to StatsEvent.
+ **/
+void AStatsEvent_writeBoolArray(AStatsEvent* event, const bool* elements, size_t numElements);
+
+/**
+ * Write a string array field to this StatsEvent.
+ *
+ * String array encoding is UTF8.
+ *
+ * Strings must be null terminated. Max size of array is 127. If exceeded, array is not written and
+ * ERROR_LIST_TOO_LONG is appended to StatsEvent.
+ **/
+void AStatsEvent_writeStringArray(AStatsEvent* event, const char* const* elements,
+ size_t numElements);
+
+/**
+ * Write a bool annotation for the previous field written.
+ **/
+void AStatsEvent_addBoolAnnotation(AStatsEvent* event, uint8_t annotationId, bool value);
+
+/**
+ * Write an integer annotation for the previous field written.
+ **/
+void AStatsEvent_addInt32Annotation(AStatsEvent* event, uint8_t annotationId, int32_t value);
+
+// Internal/test APIs. Should not be exposed outside of the APEX.
+void AStatsEvent_overwriteTimestamp(AStatsEvent* event, uint64_t timestampNs);
+uint32_t AStatsEvent_getAtomId(AStatsEvent* event);
+// Size is an output parameter.
+uint8_t* AStatsEvent_getBuffer(AStatsEvent* event, size_t* size);
+uint32_t AStatsEvent_getErrors(AStatsEvent* event);
+
+#ifdef __cplusplus
+}
+#endif // __CPLUSPLUS
+
+#endif // ANDROID_STATS_LOG_STATS_EVENT_H
diff --git a/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_socket.h b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_socket.h
new file mode 100644
index 0000000..5a75fc0
--- /dev/null
+++ b/go/current/include/packages/modules/StatsD/lib/libstatssocket/include/stats_socket.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+/**
+ * Helpers to manage the statsd socket.
+ **/
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __CPLUSPLUS
+
+/**
+ * Closes the statsd socket file descriptor.
+ **/
+void AStatsSocket_close();
+#ifdef __cplusplus
+}
+#endif // __CPLUSPLUS