1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2023, 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 <stdint.h>
#include <sys/cdefs.h>
#ifndef __STATSD_SUBS_MIN_API__
// TODO(b/274054228): Change this to __ANDROID_API_U__ once U is finalized.
#define __STATSD_SUBS_MIN_API__ __ANDROID_API_FUTURE__
#endif
__BEGIN_DECLS
/**
* Reason codes for why subscription callback was triggered.
*/
typedef enum AStatsManager_SubscriptionCallbackReason : uint32_t {
/**
* SubscriptionCallbackReason constant for subscription data transfer initiated by stats
* service.
*
* Introduced in API 34.
*/
ASTATSMANAGER_SUBSCRIPTION_CALLBACK_REASON_STATSD_INITIATED = 1,
/**
* SubscriptionCallbackReason constant for subscriber requesting flush of pending data.
*
* Introduced in API 34.
*/
ASTATSMANAGER_SUBSCRIPTION_CALLBACK_REASON_FLUSH_REQUESTED = 2,
/**
* SubscriptionCallbackReason constant for final stream of data for a subscription.
*
* Introduced in API 34.
*/
ASTATSMANAGER_SUBSCRIPTION_CALLBACK_REASON_SUBSCRIPTION_ENDED = 3,
} AStatsManager_SubscriptionCallbackReason;
/**
* Callback interface for receiving subscription data by the stats service.
*
* This will be called on an arbitrary binder thread. There is a pool of such threads and there is a
* no guarantee a single thread will be used even for the same subscription. Clients must ensure it
* is safe to call callback from arbitrary threads.
*
* \param subscription_id the subscription id for which the callback is triggered.
* \param reason code for why the callback is triggered.
* \param payload encoded SubscriptionResults proto containing subscription data.
* Cannot be null.
* \param num_bytes size in bytes of the payload.
* \param cookie the opaque pointer passed in AStatsManager_addSubscription. Can be null.
*
* Introduced in API 34.
*/
typedef void (*AStatsManager_SubscriptionCallback)(int32_t subscription_id,
AStatsManager_SubscriptionCallbackReason reason,
uint8_t* _Nonnull payload, size_t num_bytes,
void* _Nullable cookie);
/**
* Adds a new subscription.
*
* Requires the READ_LOGS permission and is only available to AID_NOBODY.
*
* \param subscription_config encoded ShellSubscription proto containing parameters for a new
* subscription. Cannot be null.
* \param num_bytes size in bytes of the subscription_config.
* \param callback function called to deliver subscription data back to the subscriber. Each
* callback can be used for more than one subscription. Cannot be null.
* \param cookie opaque pointer to associate with the subscription. The provided callback will be
* invoked with this cookie as an argument when delivering data for this subscription. Can be
* null.
* \return subscription ID for the new subscription. Subscription ID is a positive integer. A
* negative value indicates an error.
*
* Introduced in API 34.
*/
int32_t AStatsManager_addSubscription(const uint8_t* _Nonnull subscription_config, size_t num_bytes,
const AStatsManager_SubscriptionCallback _Nonnull callback,
void* _Nullable cookie)
__INTRODUCED_IN(__STATSD_SUBS_MIN_API__);
/**
* Removes an existing subscription.
* This will trigger a flush of the remaining subscription data through
* AStatsManager_SubscriptionCallback with the reason as
* ASTATSMANAGER_SUBSCRIPTION_CALLBACK_REASON_SUBSCRIPTION_ENDED.
*
* Requires the READ_LOGS permission and is only available to AID_NOBODY.
*
* \param subscription_id subscription id of the subscription to terminate.
*
* Introduced in API 34.
*/
void AStatsManager_removeSubscription(int32_t subscription_id)
__INTRODUCED_IN(__STATSD_SUBS_MIN_API__);
/**
* Request stats service to flush a subscription.
* This will trigger AStatsManager_SubscriptionCallback with the reason as
* ASTATSMANAGER_SUBSCRIPTION_CALLBACK_REASON_FLUSH_REQUESTED.
*
* Requires the READ_LOGS permission and is only available to AID_NOBODY.
*
* \param subscription_id ID of the subscription to be flushed.
*
* Introduced in API 34.
*/
void AStatsManager_flushSubscription(int32_t subscription_id)
__INTRODUCED_IN(__STATSD_SUBS_MIN_API__);
__END_DECLS
|