summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/incident/Android.bp2
-rw-r--r--libs/incident/AndroidTest.xml28
-rw-r--r--libs/incident/TEST_MAPPING10
-rw-r--r--libs/incident/include/incident/incident_report.h71
-rw-r--r--libs/incident/tests/IncidentReportRequest_test.cpp67
-rw-r--r--libs/incident/tests/c_api_compile_test.c11
-rw-r--r--libs/protoutil/include/android/util/ProtoOutputStream.h1
-rw-r--r--libs/protoutil/src/EncodedBuffer.cpp14
-rw-r--r--libs/protoutil/src/ProtoOutputStream.cpp8
9 files changed, 119 insertions, 93 deletions
diff --git a/libs/incident/Android.bp b/libs/incident/Android.bp
index 512b8c439dcf..af6411011411 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 000000000000..7c0b04471d13
--- /dev/null
+++ b/libs/incident/AndroidTest.xml
@@ -0,0 +1,28 @@
+<?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>
+
diff --git a/libs/incident/TEST_MAPPING b/libs/incident/TEST_MAPPING
new file mode 100644
index 000000000000..59ebe7664b5f
--- /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 49fe5b9b73b4..4fbac9681214 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 <stdbool.h>
+#include <stdint.h>
#if __cplusplus
-#include <set>
-#include <string>
-#include <vector>
-
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<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 // ANDROID_INCIDENT_INCIDENT_REPORT_H
diff --git a/libs/incident/tests/IncidentReportRequest_test.cpp b/libs/incident/tests/IncidentReportRequest_test.cpp
index 6d218b6682a3..5619bb6c2220 100644
--- a/libs/incident/tests/IncidentReportRequest_test.cpp
+++ b/libs/incident/tests/IncidentReportRequest_test.cpp
@@ -17,9 +17,67 @@
#include <gtest/gtest.h>
-namespace android {
-namespace os {
-namespace statsd {
+#include <vector>
+#include <string>
+
+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<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;
+};
+
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 e1620dfe3280..000000000000
--- a/libs/incident/tests/c_api_compile_test.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <stdio.h>
-#include <incident/incident_report.h>
-
-/*
- * 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;
-}
-
diff --git a/libs/protoutil/include/android/util/ProtoOutputStream.h b/libs/protoutil/include/android/util/ProtoOutputStream.h
index 42bf03e6de05..f4a358de1c41 100644
--- a/libs/protoutil/include/android/util/ProtoOutputStream.h
+++ b/libs/protoutil/include/android/util/ProtoOutputStream.h
@@ -90,6 +90,7 @@ class ProtoOutputStream
{
public:
ProtoOutputStream();
+ ProtoOutputStream(sp<EncodedBuffer> buffer);
~ProtoOutputStream();
/**
diff --git a/libs/protoutil/src/EncodedBuffer.cpp b/libs/protoutil/src/EncodedBuffer.cpp
index 7ffd8874a8fb..96b54c63a836 100644
--- a/libs/protoutil/src/EncodedBuffer.cpp
+++ b/libs/protoutil/src/EncodedBuffer.cpp
@@ -16,6 +16,7 @@
#define LOG_TAG "libprotoutil"
#include <stdlib.h>
+#include <sys/mman.h>
#include <android/util/EncodedBuffer.h>
#include <android/util/protobuf.h>
@@ -82,14 +83,16 @@ EncodedBuffer::Pointer::copy() const
}
// ===========================================================
-EncodedBuffer::EncodedBuffer() : EncodedBuffer(0)
+EncodedBuffer::EncodedBuffer() : EncodedBuffer(BUFFER_SIZE)
{
}
EncodedBuffer::EncodedBuffer(size_t chunkSize)
:mBuffers()
{
- mChunkSize = chunkSize == 0 ? BUFFER_SIZE : chunkSize;
+ // Align chunkSize to memory page size
+ chunkSize = chunkSize == 0 ? BUFFER_SIZE : chunkSize;
+ mChunkSize = (chunkSize / PAGE_SIZE + ((chunkSize % PAGE_SIZE == 0) ? 0 : 1)) * PAGE_SIZE;
mWp = Pointer(mChunkSize);
mEp = Pointer(mChunkSize);
}
@@ -98,7 +101,7 @@ EncodedBuffer::~EncodedBuffer()
{
for (size_t i=0; i<mBuffers.size(); i++) {
uint8_t* buf = mBuffers[i];
- free(buf);
+ munmap(buf, mChunkSize);
}
}
@@ -135,7 +138,10 @@ EncodedBuffer::writeBuffer()
if (mWp.index() > mBuffers.size()) return NULL;
uint8_t* buf = NULL;
if (mWp.index() == mBuffers.size()) {
- buf = (uint8_t*)malloc(mChunkSize);
+ // Use mmap instead of malloc to ensure memory alignment i.e. no fragmentation so that
+ // the mem region can be immediately reused by the allocator after calling munmap()
+ buf = (uint8_t*)mmap(NULL, mChunkSize, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (buf == NULL) return NULL; // This indicates NO_MEMORY
diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp
index ea9b79a0353f..fcf82eed4eb1 100644
--- a/libs/protoutil/src/ProtoOutputStream.cpp
+++ b/libs/protoutil/src/ProtoOutputStream.cpp
@@ -26,8 +26,12 @@
namespace android {
namespace util {
-ProtoOutputStream::ProtoOutputStream()
- :mBuffer(new EncodedBuffer()),
+ProtoOutputStream::ProtoOutputStream(): ProtoOutputStream(new EncodedBuffer())
+{
+}
+
+ProtoOutputStream::ProtoOutputStream(sp<EncodedBuffer> buffer)
+ :mBuffer(buffer),
mCopyBegin(0),
mCompact(false),
mDepth(0),