1 /**
2  * Copyright (c) 2020, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * @file incident_report.h
19  */
20 
21 #pragma once
22 
23 #include <stdbool.h>
24 #include <stdint.h>
25 
26 #if __cplusplus
27 extern "C" {
28 #endif // __cplusplus
29 
30 struct AIncidentReportArgs;
31 /**
32  * Opaque class to represent the arguments to an incident report request.
33  * Incident reports contain debugging data about the device at runtime.
34  * For more information see the android.os.IncidentManager java class.
35  */
36 typedef struct AIncidentReportArgs AIncidentReportArgs;
37 
38 // Privacy policy enum value, sync with frameworks/base/core/proto/android/privacy.proto,
39 // IncidentReportArgs.h and IncidentReportArgs.java.
40 enum {
41     /**
42      * Flag marking fields and incident reports than can be taken
43      * off the device only via adb.
44      */
45     INCIDENT_REPORT_PRIVACY_POLICY_LOCAL = 0,
46 
47     /**
48      * Flag marking fields and incident reports than can be taken
49      * off the device with contemporary consent.
50      */
51     INCIDENT_REPORT_PRIVACY_POLICY_EXPLICIT = 100,
52 
53     /**
54      * Flag marking fields and incident reports than can be taken
55      * off the device with prior consent.
56      */
57     INCIDENT_REPORT_PRIVACY_POLICY_AUTOMATIC = 200,
58 
59     /**
60      * Flag to indicate that a given field has not been marked
61      * with a privacy policy.
62      */
63     INCIDENT_REPORT_PRIVACY_POLICY_UNSET = 255
64 };
65 
66 /**
67  * Allocate and initialize an AIncidentReportArgs object.
68  */
69 AIncidentReportArgs* AIncidentReportArgs_init();
70 
71 /**
72  * Duplicate an existing AIncidentReportArgs object.
73  */
74 AIncidentReportArgs* AIncidentReportArgs_clone(AIncidentReportArgs* that);
75 
76 /**
77  * Clean up and delete an AIncidentReportArgs object.
78  */
79 void AIncidentReportArgs_delete(AIncidentReportArgs* args);
80 
81 /**
82  * Set this incident report to include all sections.
83  */
84 void AIncidentReportArgs_setAll(AIncidentReportArgs* args, bool all);
85 
86 /**
87  * Set this incident report privacy policy spec.
88  */
89 void AIncidentReportArgs_setPrivacyPolicy(AIncidentReportArgs* args, int privacyPolicy);
90 
91 /**
92  * Add this section to the incident report. The section IDs are the field numbers
93  * from the android.os.IncidentProto protobuf message.
94  */
95 void AIncidentReportArgs_addSection(AIncidentReportArgs* args, int section);
96 
97 /**
98  * Set the apk package name that will be sent a broadcast when the incident
99  * report completes.  Must be called in conjunction with AIncidentReportArgs_setReceiverClass.
100  */
101 void AIncidentReportArgs_setReceiverPackage(AIncidentReportArgs* args, char const* pkg);
102 
103 /**
104  * Set the fully qualified class name of the java BroadcastReceiver class that will be
105  * sent a broadcast when the report completes.  Must be called in conjunction with
106  * AIncidentReportArgs_setReceiverPackage.
107  */
108 void AIncidentReportArgs_setReceiverClass(AIncidentReportArgs* args, char const* cls);
109 
110 /**
111  * Add protobuf data as a header to the incident report. The buffer should be a serialized
112  * android.os.IncidentHeaderProto object.
113  */
114 void AIncidentReportArgs_addHeader(AIncidentReportArgs* args, uint8_t const* buf, size_t size);
115 
116 /**
117  * Initiate taking the report described in the args object.  Returns 0 on success,
118  * and non-zero otherwise.
119  */
120 int AIncidentReportArgs_takeReport(AIncidentReportArgs* args);
121 
122 #if __cplusplus
123 } // extern "C"
124 #endif // __cplusplus
125 
126