| 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 | #define LOG_TAG "libincident" |
| 18 | |
| 19 | #include <incident/incident_report.h> |
| 20 | |
| 21 | #include <android/os/IIncidentManager.h> |
| 22 | #include <android/os/IncidentReportArgs.h> |
| 23 | #include <binder/IServiceManager.h> |
| 24 | #include <binder/Status.h> |
| 25 | #include <log/log.h> |
| 26 | |
| 27 | using android::sp; |
| 28 | using android::binder::Status; |
| 29 | using android::os::IncidentReportArgs; |
| 30 | using android::os::IIncidentManager; |
| 31 | using std::string; |
| 32 | using std::vector; |
| 33 | |
| 34 | AIncidentReportArgs* AIncidentReportArgs_init() { |
| 35 | return reinterpret_cast<AIncidentReportArgs*>(new IncidentReportArgs()); |
| 36 | } |
| 37 | |
| 38 | AIncidentReportArgs* AIncidentReportArgs_clone(AIncidentReportArgs* that) { |
| 39 | return reinterpret_cast<AIncidentReportArgs*>( |
| 40 | new IncidentReportArgs(*reinterpret_cast<IncidentReportArgs*>(that))); |
| 41 | } |
| 42 | |
| 43 | void AIncidentReportArgs_delete(AIncidentReportArgs* args) { |
| 44 | delete reinterpret_cast<IncidentReportArgs*>(args); |
| 45 | } |
| 46 | |
| 47 | void AIncidentReportArgs_setAll(AIncidentReportArgs* args, bool all) { |
| 48 | reinterpret_cast<IncidentReportArgs*>(args)->setAll(all); |
| 49 | } |
| 50 | |
| 51 | void AIncidentReportArgs_setPrivacyPolicy(AIncidentReportArgs* args, int privacyPolicy) { |
| 52 | reinterpret_cast<IncidentReportArgs*>(args)->setPrivacyPolicy(privacyPolicy); |
| 53 | } |
| 54 | |
| 55 | void AIncidentReportArgs_addSection(AIncidentReportArgs* args, int section) { |
| 56 | reinterpret_cast<IncidentReportArgs*>(args)->addSection(section); |
| 57 | } |
| 58 | |
| 59 | void AIncidentReportArgs_setReceiverPackage(AIncidentReportArgs* args, char const* pkg) { |
| 60 | reinterpret_cast<IncidentReportArgs*>(args)->setReceiverPkg(string(pkg)); |
| 61 | } |
| 62 | |
| 63 | void AIncidentReportArgs_setReceiverClass(AIncidentReportArgs* args, char const* cls) { |
| 64 | reinterpret_cast<IncidentReportArgs*>(args)->setReceiverCls(string(cls)); |
| 65 | } |
| 66 | |
| 67 | void AIncidentReportArgs_addHeader(AIncidentReportArgs* args, uint8_t const* buf, size_t size) { |
| 68 | vector<uint8_t> vec(buf, buf+size); |
| 69 | reinterpret_cast<IncidentReportArgs*>(args)->addHeader(vec); |
| 70 | } |
| 71 | |
| 72 | int AIncidentReportArgs_takeReport(AIncidentReportArgs* argp) { |
| 73 | IncidentReportArgs* args = reinterpret_cast<IncidentReportArgs*>(argp); |
| 74 | |
| 75 | sp<IIncidentManager> service = android::interface_cast<IIncidentManager>( |
| 76 | android::defaultServiceManager()->getService(android::String16("incident"))); |
| 77 | if (service == nullptr) { |
| 78 | ALOGW("Failed to fetch incident service."); |
| 79 | return false; |
| 80 | } |
| 81 | Status s = service->reportIncident(*args); |
| 82 | return s.transactionError(); |
| 83 | } |