diff --git a/cmds/statsd/src/subscriber/IncidentdReporter.cpp b/cmds/statsd/src/subscriber/IncidentdReporter.cpp index 30c90b1e1f71b..1d77513d9d33e 100644 --- a/cmds/statsd/src/subscriber/IncidentdReporter.cpp +++ b/cmds/statsd/src/subscriber/IncidentdReporter.cpp @@ -130,15 +130,15 @@ bool GenerateIncidentReport(const IncidentdDetails& config, int64_t rule_id, int return false; } - android::os::IncidentReportRequest incidentReport; + AIncidentReportArgs* args = AIncidentReportArgs_init(); vector protoData; getProtoData(rule_id, metricId, dimensionKey, metricValue, configKey, config.alert_description(), &protoData); - incidentReport.addHeader(protoData); + AIncidentReportArgs_addHeader(args, protoData.data(), protoData.size()); for (int i = 0; i < config.section_size(); i++) { - incidentReport.addSection(config.section(i)); + AIncidentReportArgs_addSection(args, config.section(i)); } uint8_t dest; @@ -152,13 +152,16 @@ bool GenerateIncidentReport(const IncidentdDetails& config, int64_t rule_id, int default: dest = INCIDENT_REPORT_PRIVACY_POLICY_AUTOMATIC; } - incidentReport.setPrivacyPolicy(dest); + AIncidentReportArgs_setPrivacyPolicy(args, dest); - incidentReport.setReceiverPackage(config.receiver_pkg()); + AIncidentReportArgs_setReceiverPackage(args, config.receiver_pkg().c_str()); - incidentReport.setReceiverClass(config.receiver_cls()); + AIncidentReportArgs_setReceiverClass(args, config.receiver_cls().c_str()); - return incidentReport.takeReport() == NO_ERROR; + int err = AIncidentReportArgs_takeReport(args); + AIncidentReportArgs_delete(args); + + return err == NO_ERROR; } } // namespace statsd diff --git a/libs/incident/Android.bp b/libs/incident/Android.bp index 512b8c439dcf1..af64110114111 100644 --- a/libs/incident/Android.bp +++ b/libs/incident/Android.bp @@ -93,6 +93,7 @@ cc_library_shared { cc_test { name: "libincident_test", + test_config: "AndroidTest.xml", defaults: ["libincidentpriv_defaults"], test_suites: ["device-tests"], @@ -104,7 +105,6 @@ cc_test { srcs: [ "tests/IncidentReportArgs_test.cpp", "tests/IncidentReportRequest_test.cpp", - "tests/c_api_compile_test.c", ], shared_libs: [ diff --git a/libs/incident/AndroidTest.xml b/libs/incident/AndroidTest.xml new file mode 100644 index 0000000000000..7c0b04471d139 --- /dev/null +++ b/libs/incident/AndroidTest.xml @@ -0,0 +1,28 @@ + + + + + diff --git a/libs/incident/TEST_MAPPING b/libs/incident/TEST_MAPPING new file mode 100644 index 0000000000000..59ebe7664b5f3 --- /dev/null +++ b/libs/incident/TEST_MAPPING @@ -0,0 +1,10 @@ +{ + "presubmit": [ + { + "name": "libincident_test" + }, + { + "name": "GtsLibIncidentTests" + } + ] +} diff --git a/libs/incident/include/incident/incident_report.h b/libs/incident/include/incident/incident_report.h index 49fe5b9b73b40..4fbac9681214c 100644 --- a/libs/incident/include/incident/incident_report.h +++ b/libs/incident/include/incident/incident_report.h @@ -18,16 +18,12 @@ * @file incident_report.h */ -#ifndef ANDROID_INCIDENT_INCIDENT_REPORT_H -#define ANDROID_INCIDENT_INCIDENT_REPORT_H +#pragma once #include +#include #if __cplusplus -#include -#include -#include - extern "C" { #endif // __cplusplus @@ -125,68 +121,5 @@ int AIncidentReportArgs_takeReport(AIncidentReportArgs* args); #if __cplusplus } // extern "C" - -namespace android { -namespace os { - -class IncidentReportRequest { -public: - inline IncidentReportRequest() { - mImpl = AIncidentReportArgs_init(); - } - - inline IncidentReportRequest(const IncidentReportRequest& that) { - mImpl = AIncidentReportArgs_clone(that.mImpl); - } - - inline ~IncidentReportRequest() { - AIncidentReportArgs_delete(mImpl); - } - - inline AIncidentReportArgs* getImpl() { - return mImpl; - } - - inline void setAll(bool all) { - AIncidentReportArgs_setAll(mImpl, all); - } - - inline void setPrivacyPolicy(int privacyPolicy) { - AIncidentReportArgs_setPrivacyPolicy(mImpl, privacyPolicy); - } - - inline void addSection(int section) { - AIncidentReportArgs_addSection(mImpl, section); - } - - inline void setReceiverPackage(const std::string& pkg) { - AIncidentReportArgs_setReceiverPackage(mImpl, pkg.c_str()); - }; - - inline void setReceiverClass(const std::string& cls) { - AIncidentReportArgs_setReceiverClass(mImpl, cls.c_str()); - }; - - inline void addHeader(const std::vector& headerProto) { - AIncidentReportArgs_addHeader(mImpl, headerProto.data(), headerProto.size()); - }; - - inline void addHeader(const uint8_t* buf, size_t size) { - AIncidentReportArgs_addHeader(mImpl, buf, size); - }; - - // returns a status_t - inline int takeReport() { - return AIncidentReportArgs_takeReport(mImpl); - } - -private: - AIncidentReportArgs* mImpl; -}; - -} // namespace os -} // namespace android - #endif // __cplusplus -#endif // ANDROID_INCIDENT_INCIDENT_REPORT_H diff --git a/libs/incident/tests/IncidentReportRequest_test.cpp b/libs/incident/tests/IncidentReportRequest_test.cpp index 6d218b6682a38..5619bb6c2220c 100644 --- a/libs/incident/tests/IncidentReportRequest_test.cpp +++ b/libs/incident/tests/IncidentReportRequest_test.cpp @@ -17,9 +17,67 @@ #include -namespace android { -namespace os { -namespace statsd { +#include +#include + +using namespace std; +using namespace android::os; + +class IncidentReportRequest { +public: + inline IncidentReportRequest() { + mImpl = AIncidentReportArgs_init(); + } + + inline IncidentReportRequest(const IncidentReportRequest& that) { + mImpl = AIncidentReportArgs_clone(that.mImpl); + } + + inline ~IncidentReportRequest() { + AIncidentReportArgs_delete(mImpl); + } + + inline AIncidentReportArgs* getImpl() { + return mImpl; + } + + inline void setAll(bool all) { + AIncidentReportArgs_setAll(mImpl, all); + } + + inline void setPrivacyPolicy(int privacyPolicy) { + AIncidentReportArgs_setPrivacyPolicy(mImpl, privacyPolicy); + } + + inline void addSection(int section) { + AIncidentReportArgs_addSection(mImpl, section); + } + + inline void setReceiverPackage(const string& pkg) { + AIncidentReportArgs_setReceiverPackage(mImpl, pkg.c_str()); + }; + + inline void setReceiverClass(const string& cls) { + AIncidentReportArgs_setReceiverClass(mImpl, cls.c_str()); + }; + + inline void addHeader(const vector& headerProto) { + AIncidentReportArgs_addHeader(mImpl, headerProto.data(), headerProto.size()); + }; + + inline void addHeader(const uint8_t* buf, size_t size) { + AIncidentReportArgs_addHeader(mImpl, buf, size); + }; + + // returns a status_t + inline int takeReport() { + return AIncidentReportArgs_takeReport(mImpl); + } + +private: + AIncidentReportArgs* mImpl; +}; + TEST(IncidentReportRequestTest, testWrite) { IncidentReportRequest request; @@ -60,6 +118,3 @@ TEST(IncidentReportRequestTest, testWrite) { EXPECT_EQ(headers, args->headers()); } -} // namespace statsd -} // namespace os -} // namespace android diff --git a/libs/incident/tests/c_api_compile_test.c b/libs/incident/tests/c_api_compile_test.c deleted file mode 100644 index e1620dfe3280c..0000000000000 --- a/libs/incident/tests/c_api_compile_test.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -/* - * This file ensures that incident/incident_report.h actually compiles with C, - * since there is no other place in the tree that actually uses it from C. - */ -int not_called() { - return 0; -} -