1 /*
2  * Copyright (C) 2019 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 #include "src/android_internal/incident_service.h"
18 
19 #include <binder/IBinder.h>
20 #include <binder/IServiceManager.h>
21 #include <binder/Status.h>
22 #include <incident/incident_report.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include <string>
27 
28 namespace perfetto {
29 namespace android_internal {
30 
StartIncidentReport(const char * dest_pkg,const char * dest_class,int privacy_policy)31 bool StartIncidentReport(const char* dest_pkg,
32                          const char* dest_class,
33                          int privacy_policy) {
34   if (privacy_policy != INCIDENT_REPORT_PRIVACY_POLICY_AUTOMATIC &&
35       privacy_policy != INCIDENT_REPORT_PRIVACY_POLICY_EXPLICIT) {
36     return false;
37   }
38 
39   if (strlen(dest_pkg) == 0 || strlen(dest_class) == 0) {
40     return false;
41   }
42 
43   AIncidentReportArgs* args = AIncidentReportArgs_init();
44 
45   AIncidentReportArgs_addSection(args, 3026);  // system_trace only
46   AIncidentReportArgs_setPrivacyPolicy(args, privacy_policy);
47   AIncidentReportArgs_setReceiverPackage(args, dest_pkg);
48   AIncidentReportArgs_setReceiverClass(args, dest_class);
49 
50   int err = AIncidentReportArgs_takeReport(args);
51   AIncidentReportArgs_delete(args);
52 
53   return err == 0;
54 }
55 
56 }  // namespace android_internal
57 }  // namespace perfetto
58