Home | History | Annotate | Download | only in android_internal
      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 <android/os/IIncidentManager.h>
     20 #include <android/os/IncidentReportArgs.h>
     21 #include <binder/IBinder.h>
     22 #include <binder/IServiceManager.h>
     23 #include <binder/Status.h>
     24 #include <stddef.h>
     25 #include <stdint.h>
     26 
     27 #include <string>
     28 
     29 namespace perfetto {
     30 namespace android_internal {
     31 
     32 bool StartIncidentReport(const char* dest_pkg,
     33                          const char* dest_class,
     34                          int privacy_level) {
     35   android::os::IncidentReportArgs incidentReport;
     36   incidentReport.addSection(3026);  // system_trace only
     37 
     38   if (privacy_level != android::os::PRIVACY_POLICY_AUTOMATIC &&
     39       privacy_level != android::os::PRIVACY_POLICY_EXPLICIT) {
     40     return false;
     41   }
     42   incidentReport.setPrivacyPolicy(privacy_level);
     43 
     44   std::string pkg(dest_pkg);
     45   std::string cls(dest_class);
     46   if (pkg.size() == 0 || cls.size() == 0) {
     47     return false;
     48   }
     49   incidentReport.setReceiverPkg(pkg);
     50   incidentReport.setReceiverCls(cls);
     51 
     52   android::sp<android::os::IIncidentManager> service =
     53       android::interface_cast<android::os::IIncidentManager>(
     54           android::defaultServiceManager()->getService(
     55               android::String16("incident")));
     56 
     57   if (!service) {
     58     return false;
     59   }
     60   android::binder::Status s = service->reportIncident(incidentReport);
     61   return s.isOk();
     62 }
     63 
     64 }  // namespace android_internal
     65 }  // namespace perfetto
     66