Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 084aa3cb authored by Joe Onorato's avatar Joe Onorato
Browse files

Native API Council asked that we remove the C++ class from the public header.

The API is simple enough, so just reimplement everything using the
C API directly.

Bug: 148940365
Test: treehugger
Change-Id: I0a75744e975e8d3c2a557e533eacd03200388ddc
parent 18122752
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -130,15 +130,15 @@ bool GenerateIncidentReport(const IncidentdDetails& config, int64_t rule_id, int
        return false;
        return false;
    }
    }


    android::os::IncidentReportRequest incidentReport;
    AIncidentReportArgs* args = AIncidentReportArgs_init();


    vector<uint8_t> protoData;
    vector<uint8_t> protoData;
    getProtoData(rule_id, metricId, dimensionKey, metricValue, configKey,
    getProtoData(rule_id, metricId, dimensionKey, metricValue, configKey,
                 config.alert_description(), &protoData);
                 config.alert_description(), &protoData);
    incidentReport.addHeader(protoData);
    AIncidentReportArgs_addHeader(args, protoData.data(), protoData.size());


    for (int i = 0; i < config.section_size(); i++) {
    for (int i = 0; i < config.section_size(); i++) {
        incidentReport.addSection(config.section(i));
        AIncidentReportArgs_addSection(args, config.section(i));
    }
    }


    uint8_t dest;
    uint8_t dest;
@@ -152,13 +152,16 @@ bool GenerateIncidentReport(const IncidentdDetails& config, int64_t rule_id, int
        default:
        default:
            dest = INCIDENT_REPORT_PRIVACY_POLICY_AUTOMATIC;
            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
}  // namespace statsd
+1 −1
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ cc_library_shared {


cc_test {
cc_test {
    name: "libincident_test",
    name: "libincident_test",
    test_config: "AndroidTest.xml",
    defaults: ["libincidentpriv_defaults"],
    defaults: ["libincidentpriv_defaults"],
    test_suites: ["device-tests"],
    test_suites: ["device-tests"],


@@ -104,7 +105,6 @@ cc_test {
    srcs: [
    srcs: [
        "tests/IncidentReportArgs_test.cpp",
        "tests/IncidentReportArgs_test.cpp",
        "tests/IncidentReportRequest_test.cpp",
        "tests/IncidentReportRequest_test.cpp",
        "tests/c_api_compile_test.c",
    ],
    ],


    shared_libs: [
    shared_libs: [
+28 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Config for libincident_test">
    <option name="test-suite-tag" value="device-tests" />
    <option name="config-descriptor:metadata" key="component" value="misc" />
    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
        <option name="cleanup" value="true" />
        <option name="push" value="libincident_test->/data/local/tmp/libincident_test" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.GTest" >
        <option name="native-test-device-path" value="/data/local/tmp" />
        <option name="module-name" value="libincident_test" />
    </test>
</configuration>
+10 −0
Original line number Original line Diff line number Diff line
{
  "presubmit": [
    {
      "name": "libincident_test"
    },
    {
      "name": "GtsLibIncidentTests"
    }
  ]
}
+2 −69
Original line number Original line Diff line number Diff line
@@ -18,16 +18,12 @@
 * @file incident_report.h
 * @file incident_report.h
 */
 */


#ifndef ANDROID_INCIDENT_INCIDENT_REPORT_H
#pragma once
#define ANDROID_INCIDENT_INCIDENT_REPORT_H


#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>


#if __cplusplus
#if __cplusplus
#include <set>
#include <string>
#include <vector>

extern "C" {
extern "C" {
#endif // __cplusplus
#endif // __cplusplus


@@ -125,68 +121,5 @@ int AIncidentReportArgs_takeReport(AIncidentReportArgs* args);


#if __cplusplus
#if __cplusplus
} // extern "C"
} // 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<uint8_t>& 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 // __cplusplus
#endif // ANDROID_INCIDENT_INCIDENT_REPORT_H
Loading