Use modern c++ code style for incidentd.
This cl does not contain code logic changes.
Bug: 77333635
Test: manual and incidentd_test
Change-Id: Iea0a402b1051defd45159ca267e6dd705f9ffa49
diff --git a/cmds/incident_helper/src/TextParserBase.cpp b/cmds/incident_helper/src/TextParserBase.cpp
index a8f9968..e9bc70f 100644
--- a/cmds/incident_helper/src/TextParserBase.cpp
+++ b/cmds/incident_helper/src/TextParserBase.cpp
@@ -21,7 +21,6 @@
#include <android-base/file.h>
using namespace android::base;
-using namespace std;
// ================================================================================
status_t NoopParser::Parse(const int in, const int out) const
diff --git a/cmds/incident_helper/src/TextParserBase.h b/cmds/incident_helper/src/TextParserBase.h
index 1667966..784c181 100644
--- a/cmds/incident_helper/src/TextParserBase.h
+++ b/cmds/incident_helper/src/TextParserBase.h
@@ -21,6 +21,7 @@
#include <utils/String8.h>
using namespace android;
+using namespace std;
/**
* Base class for text parser
diff --git a/cmds/incident_helper/src/ih_util.cpp b/cmds/incident_helper/src/ih_util.cpp
index 5b413e9..4c4d1b9 100644
--- a/cmds/incident_helper/src/ih_util.cpp
+++ b/cmds/incident_helper/src/ih_util.cpp
@@ -98,9 +98,9 @@
size_t lastIndex = 0;
int i = 0;
while (headerNames[i] != NULL) {
- string s = headerNames[i];
+ std::string s = headerNames[i];
lastIndex = line.find(s, lastIndex);
- if (lastIndex == string::npos) {
+ if (lastIndex == std::string::npos) {
fprintf(stderr, "Bad Task Header: %s\n", line.c_str());
return false;
}
@@ -271,7 +271,7 @@
:mEnums(),
mEnumValuesByName()
{
- map<std::string, uint64_t> fields;
+ std::map<std::string, uint64_t> fields;
for (int i = 0; i < count; i++) {
fields[names[i]] = ids[i];
}
@@ -286,11 +286,11 @@
Table::addEnumTypeMap(const char* field, const char* enumNames[], const int enumValues[], const int enumSize)
{
if (mFields.find(field) == mFields.end()) {
- fprintf(stderr, "Field '%s' not found", string(field).c_str());
+ fprintf(stderr, "Field '%s' not found", field);
return;
}
- map<std::string, int> enu;
+ std::map<std::string, int> enu;
for (int i = 0; i < enumSize; i++) {
enu[enumNames[i]] = enumValues[i];
}
@@ -420,10 +420,10 @@
// Try to find the message field which is the prefix of name, so the value would be inserted
// recursively into the submessage.
- string mutableName = name;
+ std::string mutableName = name;
for (auto iter = mSubMessages.begin(); iter != mSubMessages.end(); iter++) {
- string fieldName = iter->first;
- string prefix = fieldName + "_"; // underscore is the delimiter in the name
+ std::string fieldName = iter->first;
+ std::string prefix = fieldName + "_"; // underscore is the delimiter in the name
if (stripPrefix(&mutableName, prefix.c_str())) {
if (mPreviousField != fieldName) {
endSession(proto);
@@ -437,7 +437,7 @@
}
void
-Message::startSession(ProtoOutputStream* proto, const string& name)
+Message::startSession(ProtoOutputStream* proto, const std::string& name)
{
uint64_t fieldId = mTable->mFields[name];
uint64_t token = proto->start(fieldId);
diff --git a/cmds/incident_helper/src/ih_util.h b/cmds/incident_helper/src/ih_util.h
index c4eda4a..c02a349 100644
--- a/cmds/incident_helper/src/ih_util.h
+++ b/cmds/incident_helper/src/ih_util.h
@@ -150,9 +150,9 @@
// Return false if the given name can't be found.
bool insertField(ProtoOutputStream* proto, const std::string& name, const std::string& value);
private:
- map<std::string, uint64_t> mFields;
- map<std::string, map<std::string, int>> mEnums;
- map<std::string, int> mEnumValuesByName;
+ std::map<std::string, uint64_t> mFields;
+ std::map<std::string, std::map<std::string, int>> mEnums;
+ std::map<std::string, int> mEnumValuesByName;
};
/**
@@ -187,15 +187,15 @@
bool insertField(ProtoOutputStream* proto, const std::string& name, const std::string& value);
// Starts a new message field proto session.
- void startSession(ProtoOutputStream* proto, const string& name);
+ void startSession(ProtoOutputStream* proto, const std::string& name);
// Ends the previous message field proto session.
void endSession(ProtoOutputStream* proto);
private:
Table* mTable;
std::string mPreviousField;
- stack<uint64_t> mTokens;
- map<std::string, Message*> mSubMessages;
+ std::stack<uint64_t> mTokens;
+ std::map<std::string, Message*> mSubMessages;
};
#endif // INCIDENT_HELPER_UTIL_H
diff --git a/cmds/incidentd/src/FdBuffer.cpp b/cmds/incidentd/src/FdBuffer.cpp
index c6e561f..86c2e20 100644
--- a/cmds/incidentd/src/FdBuffer.cpp
+++ b/cmds/incidentd/src/FdBuffer.cpp
@@ -26,6 +26,10 @@
#include <unistd.h>
#include <wait.h>
+namespace android {
+namespace os {
+namespace incidentd {
+
const ssize_t BUFFER_SIZE = 16 * 1024; // 16 KB
const ssize_t MAX_BUFFER_COUNT = 256; // 4 MB max
@@ -206,7 +210,7 @@
}
if (amt < 0) {
if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
- VLOG("Fail to write toFd.get() %d: %s", toFd.get(), strerror(errno));
+ VLOG("Fail to write toFd %d: %s", toFd.get(), strerror(errno));
return -errno;
} // otherwise just continue
} else {
@@ -252,3 +256,7 @@
size_t FdBuffer::size() const { return mBuffer.size(); }
EncodedBuffer::iterator FdBuffer::data() const { return mBuffer.begin(); }
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
diff --git a/cmds/incidentd/src/FdBuffer.h b/cmds/incidentd/src/FdBuffer.h
index f467da8..20deefd 100644
--- a/cmds/incidentd/src/FdBuffer.h
+++ b/cmds/incidentd/src/FdBuffer.h
@@ -22,10 +22,12 @@
#include <android/util/EncodedBuffer.h>
#include <utils/Errors.h>
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
+
using namespace android::base;
using namespace android::util;
-using namespace std;
/**
* Reads data from fd into a buffer, fd must be closed explicitly.
@@ -104,4 +106,8 @@
bool mTruncated;
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // FD_BUFFER_H
diff --git a/cmds/incidentd/src/IncidentService.cpp b/cmds/incidentd/src/IncidentService.cpp
index d02b4dd..e305b54 100644
--- a/cmds/incidentd/src/IncidentService.cpp
+++ b/cmds/incidentd/src/IncidentService.cpp
@@ -34,9 +34,6 @@
#include <unistd.h>
-using namespace android;
-using namespace android::base;
-
enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 };
#define DEFAULT_BACKLOG_DELAY_NS (1000000000LL)
@@ -44,7 +41,10 @@
#define DEFAULT_BYTES_SIZE_LIMIT (20 * 1024 * 1024) // 20MB
#define DEFAULT_REFACTORY_PERIOD_MS (24 * 60 * 60 * 1000) // 1 Day
-// ================================================================================
+namespace android {
+namespace os {
+namespace incidentd {
+
String16 const DUMP_PERMISSION("android.permission.DUMP");
String16 const USAGE_STATS_PERMISSION("android.permission.PACKAGE_USAGE_STATS");
@@ -94,6 +94,7 @@
}
return Status::ok();
}
+
// ================================================================================
ReportRequestQueue::ReportRequestQueue() {}
@@ -373,3 +374,7 @@
}
return NO_ERROR;
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
diff --git a/cmds/incidentd/src/IncidentService.h b/cmds/incidentd/src/IncidentService.h
index 0ab34ed..e176bfd 100644
--- a/cmds/incidentd/src/IncidentService.h
+++ b/cmds/incidentd/src/IncidentService.h
@@ -28,11 +28,14 @@
#include "Throttler.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
using namespace android;
using namespace android::base;
using namespace android::binder;
using namespace android::os;
-using namespace std;
// ================================================================================
class ReportRequestQueue : public virtual RefBase {
@@ -126,4 +129,8 @@
status_t cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // INCIDENT_SERVICE_H
diff --git a/cmds/incidentd/src/Privacy.cpp b/cmds/incidentd/src/Privacy.cpp
index c42a87b..6e55f90 100644
--- a/cmds/incidentd/src/Privacy.cpp
+++ b/cmds/incidentd/src/Privacy.cpp
@@ -19,6 +19,10 @@
#include <android/os/IncidentReportArgs.h>
#include <stdlib.h>
+namespace android {
+namespace os {
+namespace incidentd {
+
uint64_t encode_field_id(const Privacy* p) { return (uint64_t)p->type << 32 | p->field_id; }
const Privacy* lookup(const Privacy* p, uint32_t fieldId) {
@@ -65,3 +69,7 @@
return PrivacySpec(android::os::DEST_AUTOMATIC);
}
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
diff --git a/cmds/incidentd/src/Privacy.h b/cmds/incidentd/src/Privacy.h
index 6b6de9c..a3df490 100644
--- a/cmds/incidentd/src/Privacy.h
+++ b/cmds/incidentd/src/Privacy.h
@@ -20,6 +20,10 @@
#include <stdint.h>
+namespace android {
+namespace os {
+namespace incidentd {
+
// This is the default value of DEST enum, sync with privacy.proto
const uint8_t DEST_UNSET = 255; // DEST_UNSET is not exposed to libincident
const uint8_t DEST_DEFAULT_VALUE = DEST_UNSET;
@@ -82,4 +86,8 @@
PrivacySpec(uint8_t dest) : dest(dest) {}
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // PRIVACY_H
diff --git a/cmds/incidentd/src/PrivacyBuffer.cpp b/cmds/incidentd/src/PrivacyBuffer.cpp
index f1f7c589..6cd2fe1 100644
--- a/cmds/incidentd/src/PrivacyBuffer.cpp
+++ b/cmds/incidentd/src/PrivacyBuffer.cpp
@@ -23,7 +23,9 @@
#include <android/util/protobuf.h>
#include <cutils/log.h>
-using namespace android::util;
+namespace android {
+namespace os {
+namespace incidentd {
/**
* Write the field to buf based on the wire type, iterator will point to next field.
@@ -140,3 +142,7 @@
}
return NO_ERROR;
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
diff --git a/cmds/incidentd/src/PrivacyBuffer.h b/cmds/incidentd/src/PrivacyBuffer.h
index cd29d8b..eac3862 100644
--- a/cmds/incidentd/src/PrivacyBuffer.h
+++ b/cmds/incidentd/src/PrivacyBuffer.h
@@ -25,7 +25,10 @@
#include <stdint.h>
#include <utils/Errors.h>
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
+
using namespace android::util;
/**
@@ -69,4 +72,8 @@
void writeFieldOrSkip(uint32_t fieldTag, bool skip);
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // PRIVACY_BUFFER_H
\ No newline at end of file
diff --git a/cmds/incidentd/src/Reporter.cpp b/cmds/incidentd/src/Reporter.cpp
index fc8a6db..103004d 100644
--- a/cmds/incidentd/src/Reporter.cpp
+++ b/cmds/incidentd/src/Reporter.cpp
@@ -37,6 +37,10 @@
*/
static const char* INCIDENT_DIRECTORY = "/data/misc/incidents/";
+namespace android {
+namespace os {
+namespace incidentd {
+
// ================================================================================
ReportRequest::ReportRequest(const IncidentReportArgs& a,
const sp<IIncidentReportStatusListener>& l, int f)
@@ -320,3 +324,7 @@
return REPORT_FINISHED;
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
diff --git a/cmds/incidentd/src/Reporter.h b/cmds/incidentd/src/Reporter.h
index f9a092a..45fd944 100644
--- a/cmds/incidentd/src/Reporter.h
+++ b/cmds/incidentd/src/Reporter.h
@@ -30,9 +30,9 @@
#include "Throttler.h"
#include "frameworks/base/libs/incident/proto/android/os/metadata.pb.h"
-using namespace android;
-using namespace android::os;
-using namespace std;
+namespace android {
+namespace os {
+namespace incidentd {
// ================================================================================
struct ReportRequest : public virtual RefBase {
@@ -110,4 +110,8 @@
bool isTest = true; // default to true for testing
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // REPORTER_H
diff --git a/cmds/incidentd/src/Section.cpp b/cmds/incidentd/src/Section.cpp
index 3f693fa..45d6281 100644
--- a/cmds/incidentd/src/Section.cpp
+++ b/cmds/incidentd/src/Section.cpp
@@ -43,9 +43,12 @@
#include "frameworks/base/core/proto/android/util/log.proto.h"
#include "incidentd_util.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
using namespace android::base;
using namespace android::util;
-using namespace std;
// special section ids
const int FIELD_ID_INCIDENT_HEADER = 1;
@@ -321,8 +324,8 @@
}
VLOG("GZipSection is using file %s, fd=%d", mFilenames[index], fd.get());
if (fd.get() == -1) {
- ALOGW("GZipSection %s can't open all the files", this->name.string());
- return NO_ERROR; // e.g. LAST_KMSG will reach here in user build.
+ ALOGW("GZipSection %s can't open all the files", this->name.string());
+ return NO_ERROR; // e.g. LAST_KMSG will reach here in user build.
}
FdBuffer buffer;
Fpipe p2cPipe;
@@ -909,7 +912,7 @@
dump[i] = iterator.next();
i++;
}
- long long token = proto.start(android::os::BackTraceProto::TRACES);
+ uint64_t token = proto.start(android::os::BackTraceProto::TRACES);
proto.write(android::os::BackTraceProto::Stack::PID, pid);
proto.write(android::os::BackTraceProto::Stack::DUMP, dump.get(), i);
proto.write(android::os::BackTraceProto::Stack::DUMP_DURATION_NS,
@@ -921,3 +924,7 @@
proto.flush(pipeWriteFd);
return err;
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file
diff --git a/cmds/incidentd/src/Section.h b/cmds/incidentd/src/Section.h
index 19ef7ee..34a3613 100644
--- a/cmds/incidentd/src/Section.h
+++ b/cmds/incidentd/src/Section.h
@@ -27,7 +27,9 @@
#include <utils/String8.h>
#include <utils/Vector.h>
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
const int64_t REMOTE_CALL_TIMEOUT_MS = 10 * 1000; // 10 seconds
@@ -175,4 +177,8 @@
std::string mType;
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // SECTIONS_H
diff --git a/cmds/incidentd/src/Throttler.cpp b/cmds/incidentd/src/Throttler.cpp
index 1abf267..2b790ca 100644
--- a/cmds/incidentd/src/Throttler.cpp
+++ b/cmds/incidentd/src/Throttler.cpp
@@ -20,6 +20,10 @@
#include <utils/SystemClock.h>
+namespace android {
+namespace os {
+namespace incidentd {
+
Throttler::Throttler(size_t limit, int64_t refractoryPeriodMs)
: mSizeLimit(limit),
mRefractoryPeriodMs(refractoryPeriodMs),
@@ -48,3 +52,7 @@
fprintf(out, "mRefractoryPeriodMs=%d\n", (int)mRefractoryPeriodMs);
fprintf(out, "mLastRefractoryMs=%d\n", (int)mLastRefractoryMs);
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file
diff --git a/cmds/incidentd/src/Throttler.h b/cmds/incidentd/src/Throttler.h
index c56f753..e8f317d7 100644
--- a/cmds/incidentd/src/Throttler.h
+++ b/cmds/incidentd/src/Throttler.h
@@ -20,6 +20,10 @@
#include <utils/RefBase.h>
#include <unistd.h>
+
+namespace android {
+namespace os {
+namespace incidentd {
/**
* This is a size-based throttler which prevents incidentd to take more data.
*/
@@ -45,4 +49,8 @@
int64_t mLastRefractoryMs;
};
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // THROTTLER_H
diff --git a/cmds/incidentd/src/incidentd_util.cpp b/cmds/incidentd/src/incidentd_util.cpp
index 7db1fa7..af685d8 100644
--- a/cmds/incidentd/src/incidentd_util.cpp
+++ b/cmds/incidentd/src/incidentd_util.cpp
@@ -23,6 +23,12 @@
#include "section_list.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
+using namespace android::base;
+
const Privacy* get_privacy_of_section(int id) {
int l = 0;
int r = PRIVACY_POLICY_COUNT - 1;
@@ -149,3 +155,7 @@
if (!died) return kill_child(pid);
return statusCode(status);
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file
diff --git a/cmds/incidentd/src/incidentd_util.h b/cmds/incidentd/src/incidentd_util.h
index b5f6e21..3dac2c4 100644
--- a/cmds/incidentd/src/incidentd_util.h
+++ b/cmds/incidentd/src/incidentd_util.h
@@ -26,7 +26,10 @@
#include "Privacy.h"
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
+
using namespace android::base;
/**
@@ -75,4 +78,8 @@
status_t kill_child(pid_t pid);
status_t wait_child(pid_t pid);
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // INCIDENTD_UTIL_H
diff --git a/cmds/incidentd/src/main.cpp b/cmds/incidentd/src/main.cpp
index 38b7449..4948823 100644
--- a/cmds/incidentd/src/main.cpp
+++ b/cmds/incidentd/src/main.cpp
@@ -29,6 +29,7 @@
#include <sys/types.h>
using namespace android;
+using namespace android::os::incidentd;
// ================================================================================
int main(int /*argc*/, char** /*argv*/) {
@@ -43,7 +44,7 @@
IPCThreadState::self()->disableBackgroundScheduling(true);
// Create the service
- android::sp<IncidentService> service = new IncidentService(looper);
+ sp<IncidentService> service = new IncidentService(looper);
if (defaultServiceManager()->addService(String16("incident"), service) != 0) {
ALOGE("Failed to add service");
return -1;
diff --git a/cmds/incidentd/src/report_directory.cpp b/cmds/incidentd/src/report_directory.cpp
index f023ee1..e2883ba 100644
--- a/cmds/incidentd/src/report_directory.cpp
+++ b/cmds/incidentd/src/report_directory.cpp
@@ -29,8 +29,9 @@
#include <vector>
-using namespace android;
-using namespace std;
+namespace android {
+namespace os {
+namespace incidentd {
status_t create_directory(const char* directory) {
struct stat st;
@@ -89,8 +90,8 @@
return err;
}
-static bool stat_mtime_cmp(const pair<String8, struct stat>& a,
- const pair<String8, struct stat>& b) {
+static bool stat_mtime_cmp(const std::pair<String8, struct stat>& a,
+ const std::pair<String8, struct stat>& b) {
return a.second.st_mtime < b.second.st_mtime;
}
@@ -99,7 +100,7 @@
struct dirent* entry;
struct stat st;
- vector<pair<String8, struct stat>> files;
+ std::vector<std::pair<String8, struct stat>> files;
if ((dir = opendir(directory)) == NULL) {
ALOGE("Couldn't open incident directory: %s", directory);
@@ -125,7 +126,7 @@
if (!S_ISREG(st.st_mode)) {
continue;
}
- files.push_back(pair<String8, struct stat>(filename, st));
+ files.push_back(std::pair<String8, struct stat>(filename, st));
totalSize += st.st_size;
totalCount++;
@@ -142,10 +143,14 @@
sort(files.begin(), files.end(), stat_mtime_cmp);
// Remove files until we're under our limits.
- for (vector<pair<String8, struct stat>>::iterator it = files.begin();
+ for (std::vector<std::pair<String8, struct stat>>::iterator it = files.begin();
it != files.end() && totalSize >= maxSize && totalCount >= maxCount; it++) {
remove(it->first.string());
totalSize -= it->second.st_size;
totalCount--;
}
}
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file
diff --git a/cmds/incidentd/src/report_directory.h b/cmds/incidentd/src/report_directory.h
index 2a3cf4c..a63f8df 100644
--- a/cmds/incidentd/src/report_directory.h
+++ b/cmds/incidentd/src/report_directory.h
@@ -21,7 +21,15 @@
#include <sys/types.h>
#include <utils/Errors.h>
+namespace android {
+namespace os {
+namespace incidentd {
+
android::status_t create_directory(const char* directory);
void clean_directory(const char* directory, off_t maxSize, size_t maxCount);
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // DIRECTORY_CLEANER_H
diff --git a/cmds/incidentd/src/section_list.h b/cmds/incidentd/src/section_list.h
index 697e66f..1498127 100644
--- a/cmds/incidentd/src/section_list.h
+++ b/cmds/incidentd/src/section_list.h
@@ -23,6 +23,10 @@
#include "Privacy.h"
#include "Section.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
/**
* This is the mapping of section IDs to the commands that are run to get those commands.
* The section IDs are guaranteed in ascending order, NULL-terminated.
@@ -37,4 +41,8 @@
extern const int PRIVACY_POLICY_COUNT;
+} // namespace incidentd
+} // namespace os
+} // namespace android
+
#endif // SECTION_LIST_H
diff --git a/cmds/incidentd/tests/FdBuffer_test.cpp b/cmds/incidentd/tests/FdBuffer_test.cpp
index 7a05d7e..9d208df 100644
--- a/cmds/incidentd/tests/FdBuffer_test.cpp
+++ b/cmds/incidentd/tests/FdBuffer_test.cpp
@@ -24,15 +24,16 @@
#include <signal.h>
#include <string.h>
+using namespace android;
+using namespace android::base;
+using namespace android::os::incidentd;
+using ::testing::Test;
+
const int READ_TIMEOUT = 5 * 1000;
const int BUFFER_SIZE = 16 * 1024;
const int QUICK_TIMEOUT_MS = 100;
const std::string HEAD = "[OK]";
-using namespace android;
-using namespace android::base;
-using ::testing::Test;
-
class FdBufferTest : public Test {
public:
virtual void SetUp() override {
diff --git a/cmds/incidentd/tests/PrivacyBuffer_test.cpp b/cmds/incidentd/tests/PrivacyBuffer_test.cpp
index 10c2981..685759f 100644
--- a/cmds/incidentd/tests/PrivacyBuffer_test.cpp
+++ b/cmds/incidentd/tests/PrivacyBuffer_test.cpp
@@ -27,7 +27,7 @@
using namespace android;
using namespace android::base;
using namespace android::os;
-using namespace std;
+using namespace android::os::incidentd;
using ::testing::StrEq;
using ::testing::Test;
using ::testing::internal::CaptureStdout;
@@ -36,12 +36,12 @@
const uint8_t OTHER_TYPE = 1;
const uint8_t STRING_TYPE = 9;
const uint8_t MESSAGE_TYPE = 11;
-const string STRING_FIELD_0 = "\x02\viamtestdata";
-const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
-const string STRING_FIELD_2 = "\x12\vandroidwins";
-const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
-const string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
-const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
+const std::string STRING_FIELD_0 = "\x02\viamtestdata";
+const std::string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
+const std::string STRING_FIELD_2 = "\x12\vandroidwins";
+const std::string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
+const std::string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
+const std::string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
class PrivacyBufferTest : public Test {
public:
@@ -56,20 +56,20 @@
virtual void SetUp() override { ASSERT_NE(tf.fd, -1); }
- void writeToFdBuffer(string str) {
+ void writeToFdBuffer(std::string str) {
ASSERT_TRUE(WriteStringToFile(str, tf.path));
ASSERT_EQ(NO_ERROR, buffer.read(tf.fd, 10000));
ASSERT_EQ(str.size(), buffer.size());
}
- void assertBuffer(PrivacyBuffer& buf, string expected) {
+ void assertBuffer(PrivacyBuffer& buf, std::string expected) {
ASSERT_EQ(buf.size(), expected.size());
CaptureStdout();
ASSERT_EQ(buf.flush(STDOUT_FILENO), NO_ERROR);
ASSERT_THAT(GetCapturedStdout(), StrEq(expected));
}
- void assertStrip(uint8_t dest, string expected, Privacy* policy) {
+ void assertStrip(uint8_t dest, std::string expected, Privacy* policy) {
PrivacySpec spec = PrivacySpec::new_spec(dest);
EncodedBuffer::iterator bufData = buffer.data();
PrivacyBuffer privacyBuf(policy, bufData);
@@ -77,7 +77,7 @@
assertBuffer(privacyBuf, expected);
}
- void assertStripByFields(uint8_t dest, string expected, int size, Privacy* privacy, ...) {
+ void assertStripByFields(uint8_t dest, std::string expected, int size, Privacy* privacy, ...) {
Privacy* list[size + 1];
list[0] = privacy;
va_list args;
@@ -194,7 +194,7 @@
TEST_F(PrivacyBufferTest, StripVarintAndString) {
writeToFdBuffer(STRING_FIELD_0 + VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3 +
FIX32_FIELD_4);
- string expected = STRING_FIELD_0 + FIX64_FIELD_3 + FIX32_FIELD_4;
+ std::string expected = STRING_FIELD_0 + FIX64_FIELD_3 + FIX32_FIELD_4;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(1, OTHER_TYPE, DEST_LOCAL),
create_privacy(2, STRING_TYPE, DEST_LOCAL));
}
@@ -202,7 +202,7 @@
TEST_F(PrivacyBufferTest, StripVarintAndFixed64) {
writeToFdBuffer(STRING_FIELD_0 + VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3 +
FIX32_FIELD_4);
- string expected = STRING_FIELD_0 + STRING_FIELD_2 + FIX32_FIELD_4;
+ std::string expected = STRING_FIELD_0 + STRING_FIELD_2 + FIX32_FIELD_4;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(1, OTHER_TYPE, DEST_LOCAL),
create_privacy(3, OTHER_TYPE, DEST_LOCAL));
}
@@ -210,14 +210,14 @@
TEST_F(PrivacyBufferTest, StripVarintInNestedMessage) {
writeToFdBuffer(STRING_FIELD_0 + MESSAGE_FIELD_5);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
- string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_EXPLICIT, expected, 1, create_message_privacy(5, list));
}
TEST_F(PrivacyBufferTest, StripFix64AndVarintInNestedMessage) {
writeToFdBuffer(STRING_FIELD_0 + FIX64_FIELD_3 + MESSAGE_FIELD_5);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
- string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(3, OTHER_TYPE, DEST_LOCAL),
create_message_privacy(5, list));
}
@@ -262,7 +262,7 @@
Privacy* field5 = create_message_privacy(5, NULL);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), field5, NULL};
field5->children = list;
- string expected = "\x2a\x1c" + STRING_FIELD_2 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = "\x2a\x1c" + STRING_FIELD_2 + "\x2a\xd" + STRING_FIELD_2;
assertStrip(DEST_EXPLICIT, expected, field5);
}
@@ -271,6 +271,6 @@
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
Privacy* autoMsg = create_privacy(5, MESSAGE_TYPE, DEST_AUTOMATIC);
autoMsg->children = list;
- string expected = "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_AUTOMATIC, expected, 1, autoMsg);
}
diff --git a/cmds/incidentd/tests/Reporter_test.cpp b/cmds/incidentd/tests/Reporter_test.cpp
index 42d94f0..cf107c8 100644
--- a/cmds/incidentd/tests/Reporter_test.cpp
+++ b/cmds/incidentd/tests/Reporter_test.cpp
@@ -30,6 +30,7 @@
using namespace android::base;
using namespace android::binder;
using namespace android::os;
+using namespace android::os::incidentd;
using namespace std;
using ::testing::StrEq;
using ::testing::Test;
diff --git a/cmds/incidentd/tests/Section_test.cpp b/cmds/incidentd/tests/Section_test.cpp
index 2f6698b..9f92353 100644
--- a/cmds/incidentd/tests/Section_test.cpp
+++ b/cmds/incidentd/tests/Section_test.cpp
@@ -25,25 +25,26 @@
#include <gtest/gtest.h>
#include <string.h>
+using namespace android;
+using namespace android::base;
+using namespace android::binder;
+using namespace android::os;
+using namespace android::os::incidentd;
+using namespace android::util;
+using ::testing::StrEq;
+using ::testing::Test;
+using ::testing::internal::CaptureStdout;
+using ::testing::internal::GetCapturedStdout;
+
const int TIMEOUT_PARSER = -1;
const int NOOP_PARSER = 0;
const int REVERSE_PARSER = 1;
const int QUICK_TIMEOUT_MS = 100;
-const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
-const string STRING_FIELD_2 = "\x12\vandroidwins";
-const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
-
-using namespace android::base;
-using namespace android::binder;
-using namespace android::os;
-using namespace android::util;
-using namespace std;
-using ::testing::StrEq;
-using ::testing::Test;
-using ::testing::internal::CaptureStdout;
-using ::testing::internal::GetCapturedStdout;
+const std::string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
+const std::string STRING_FIELD_2 = "\x12\vandroidwins";
+const std::string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
// NOTICE: this test requires /system/bin/incident_helper is installed.
class SectionTest : public Test {
@@ -101,7 +102,7 @@
requests.add(new ReportRequest(args2, new SimpleListener(), tf.fd));
requests.setMainFd(STDOUT_FILENO);
- string content;
+ std::string content;
CaptureStdout();
ASSERT_EQ(NO_ERROR, hs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\n\x5"
@@ -163,9 +164,9 @@
size_t fileLen = testFile.size();
size_t totalLen = 1 + get_varint_size(fileLen) + fileLen + 3 + gzFile.size();
uint8_t header[20];
- header[0] = '\x2'; // header 0 << 3 + 2
+ header[0] = '\x2'; // header 0 << 3 + 2
uint8_t* ptr = write_raw_varint(header + 1, totalLen);
- *ptr = '\n'; // header 1 << 3 + 2
+ *ptr = '\n'; // header 1 << 3 + 2
ptr = write_raw_varint(++ptr, fileLen);
expected.assign((const char*)header, ptr - header);
expected += testFile + "\x12\x9F\x6" + gzFile;
@@ -227,7 +228,7 @@
requests.setMainFd(STDOUT_FILENO);
CaptureStdout();
ASSERT_EQ(NO_ERROR, ls.Execute(&requests));
- string results = GetCapturedStdout();
+ std::string results = GetCapturedStdout();
EXPECT_FALSE(results.empty());
}
@@ -236,7 +237,7 @@
requests.setMainFd(STDOUT_FILENO);
CaptureStdout();
ASSERT_EQ(NO_ERROR, ls.Execute(&requests));
- string results = GetCapturedStdout();
+ std::string results = GetCapturedStdout();
EXPECT_FALSE(results.empty());
}
@@ -304,7 +305,7 @@
ASSERT_EQ(NO_ERROR, fs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\x02\r" + STRING_FIELD_2));
- string content, expect;
+ std::string content, expect;
expect = VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3;
char c = (char)expect.size();
EXPECT_TRUE(ReadFileToString(output1.path, &content));
@@ -346,7 +347,7 @@
ASSERT_EQ(NO_ERROR, fs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\x02\r" + STRING_FIELD_2));
- string content, expect;
+ std::string content, expect;
expect = STRING_FIELD_2 + FIX64_FIELD_3;
char c = (char)expect.size();
diff --git a/cmds/incidentd/tests/Throttler_test.cpp b/cmds/incidentd/tests/Throttler_test.cpp
index 213dcef..8488c99 100644
--- a/cmds/incidentd/tests/Throttler_test.cpp
+++ b/cmds/incidentd/tests/Throttler_test.cpp
@@ -20,6 +20,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+using namespace android::os::incidentd;
+
TEST(ThrottlerTest, DataSizeExceeded) {
Throttler t(100, 100000);
EXPECT_FALSE(t.shouldThrottle());
diff --git a/cmds/incidentd/tests/section_list.cpp b/cmds/incidentd/tests/section_list.cpp
index bd2d15c..1d7f2b6 100644
--- a/cmds/incidentd/tests/section_list.cpp
+++ b/cmds/incidentd/tests/section_list.cpp
@@ -1,6 +1,10 @@
// This file is a dummy section_list.cpp used for test only.
#include "section_list.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
const Section* SECTION_LIST[] = {NULL};
Privacy sub_field_1{1, 1, NULL, DEST_LOCAL, NULL};
@@ -16,3 +20,7 @@
const Privacy** PRIVACY_POLICY_LIST = const_cast<const Privacy**>(final_list);
const int PRIVACY_POLICY_COUNT = 2;
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file
diff --git a/libs/protoutil/include/android/util/EncodedBuffer.h b/libs/protoutil/include/android/util/EncodedBuffer.h
index bf698d4..c84de4c 100644
--- a/libs/protoutil/include/android/util/EncodedBuffer.h
+++ b/libs/protoutil/include/android/util/EncodedBuffer.h
@@ -23,8 +23,6 @@
namespace android {
namespace util {
-using namespace std;
-
/**
* A stream of bytes containing a read pointer and a write pointer,
* backed by a set of fixed-size buffers. There are write functions for the
@@ -217,7 +215,7 @@
private:
size_t mChunkSize;
- vector<uint8_t*> mBuffers;
+ std::vector<uint8_t*> mBuffers;
Pointer mWp;
Pointer mEp;
diff --git a/libs/protoutil/include/android/util/protobuf.h b/libs/protoutil/include/android/util/protobuf.h
index ca45e26..4b49ced 100644
--- a/libs/protoutil/include/android/util/protobuf.h
+++ b/libs/protoutil/include/android/util/protobuf.h
@@ -22,8 +22,6 @@
namespace android {
namespace util {
-using namespace std;
-
const int FIELD_ID_SHIFT = 3;
const uint8_t WIRE_TYPE_MASK = (1 << FIELD_ID_SHIFT) - 1;
diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp
index a040bd2..015727a 100644
--- a/libs/protoutil/src/ProtoOutputStream.cpp
+++ b/libs/protoutil/src/ProtoOutputStream.cpp
@@ -173,7 +173,7 @@
}
bool
-ProtoOutputStream::write(uint64_t fieldId, string val)
+ProtoOutputStream::write(uint64_t fieldId, std::string val)
{
if (mCompact) return false;
const uint32_t id = (uint32_t)fieldId;
diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp
index 7e922e6..a274a8c 100644
--- a/tools/incident_section_gen/main.cpp
+++ b/tools/incident_section_gen/main.cpp
@@ -393,6 +393,11 @@
static bool generateSectionListCpp(Descriptor const* descriptor) {
generateHead("section_list");
+ // generate namespaces
+ printf("namespace android {\n");
+ printf("namespace os {\n");
+ printf("namespace incidentd {\n");
+
// generates SECTION_LIST
printf("// Generate SECTION_LIST.\n\n");
@@ -502,6 +507,10 @@
printf("const Privacy** PRIVACY_POLICY_LIST = createList();\n\n");
printf("const int PRIVACY_POLICY_COUNT = %d;\n", policyCount);
}
+
+ printf("} // incidentd\n");
+ printf("} // os\n");
+ printf("} // android\n");
return true;
}