OSDN Git Service

Use modern c++ code style for incidentd.
authorYi Jin <jinyithu@google.com>
Fri, 30 Mar 2018 21:04:52 +0000 (14:04 -0700)
committerYi Jin <jinyithu@google.com>
Sat, 31 Mar 2018 00:36:49 +0000 (17:36 -0700)
This cl does not contain code logic changes.

Bug: 77333635
Test: manual and incidentd_test
Change-Id: Iea0a402b1051defd45159ca267e6dd705f9ffa49

34 files changed:
cmds/incident_helper/src/TextParserBase.cpp
cmds/incident_helper/src/TextParserBase.h
cmds/incident_helper/src/ih_util.cpp
cmds/incident_helper/src/ih_util.h
cmds/incidentd/src/FdBuffer.cpp
cmds/incidentd/src/FdBuffer.h
cmds/incidentd/src/IncidentService.cpp
cmds/incidentd/src/IncidentService.h
cmds/incidentd/src/Privacy.cpp
cmds/incidentd/src/Privacy.h
cmds/incidentd/src/PrivacyBuffer.cpp
cmds/incidentd/src/PrivacyBuffer.h
cmds/incidentd/src/Reporter.cpp
cmds/incidentd/src/Reporter.h
cmds/incidentd/src/Section.cpp
cmds/incidentd/src/Section.h
cmds/incidentd/src/Throttler.cpp
cmds/incidentd/src/Throttler.h
cmds/incidentd/src/incidentd_util.cpp
cmds/incidentd/src/incidentd_util.h
cmds/incidentd/src/main.cpp
cmds/incidentd/src/report_directory.cpp
cmds/incidentd/src/report_directory.h
cmds/incidentd/src/section_list.h
cmds/incidentd/tests/FdBuffer_test.cpp
cmds/incidentd/tests/PrivacyBuffer_test.cpp
cmds/incidentd/tests/Reporter_test.cpp
cmds/incidentd/tests/Section_test.cpp
cmds/incidentd/tests/Throttler_test.cpp
cmds/incidentd/tests/section_list.cpp
libs/protoutil/include/android/util/EncodedBuffer.h
libs/protoutil/include/android/util/protobuf.h
libs/protoutil/src/ProtoOutputStream.cpp
tools/incident_section_gen/main.cpp

index a8f9968..e9bc70f 100644 (file)
@@ -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
index 1667966..784c181 100644 (file)
@@ -21,6 +21,7 @@
 #include <utils/String8.h>
 
 using namespace android;
+using namespace std;
 
 /**
  * Base class for text parser
index 5b413e9..4c4d1b9 100644 (file)
@@ -98,9 +98,9 @@ bool getColumnIndices(std::vector<int>& indices, const char** headerNames, const
     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 @@ Table::Table(const char* names[], const uint64_t ids[], const int count)
         :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 @@ void
 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 @@ Message::insertField(ProtoOutputStream* proto, const std::string& name, const st
 
     // 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 @@ Message::insertField(ProtoOutputStream* proto, const std::string& name, const st
 }
 
 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);
index c4eda4a..c02a349 100644 (file)
@@ -150,9 +150,9 @@ public:
     // 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 @@ public:
     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
index c6e561f..86c2e20 100644 (file)
 #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 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f
             }
             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 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f
 size_t FdBuffer::size() const { return mBuffer.size(); }
 
 EncodedBuffer::iterator FdBuffer::data() const { return mBuffer.begin(); }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
index f467da8..20deefd 100644 (file)
 #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 @@ private:
     bool mTruncated;
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // FD_BUFFER_H
index d02b4dd..e305b54 100644 (file)
@@ -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 @@ enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 };
 #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 @@ static Status checkIncidentPermissions(const IncidentReportArgs& args) {
     }
     return Status::ok();
 }
+
 // ================================================================================
 ReportRequestQueue::ReportRequestQueue() {}
 
@@ -373,3 +374,7 @@ status_t IncidentService::cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<Str
     }
     return NO_ERROR;
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
index 0ab34ed..e176bfd 100644 (file)
 
 #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 @@ private:
     status_t cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // INCIDENT_SERVICE_H
index c42a87b..6e55f90 100644 (file)
 #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 @@ PrivacySpec PrivacySpec::new_spec(int dest) {
             return PrivacySpec(android::os::DEST_AUTOMATIC);
     }
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
index 6b6de9c..a3df490 100644 (file)
 
 #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 @@ private:
     PrivacySpec(uint8_t dest) : dest(dest) {}
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // PRIVACY_H
index f1f7c58..6cd2fe1 100644 (file)
@@ -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 @@ status_t PrivacyBuffer::flush(int fd) {
     }
     return NO_ERROR;
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
index cd29d8b..eac3862 100644 (file)
 #include <stdint.h>
 #include <utils/Errors.h>
 
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
+
 using namespace android::util;
 
 /**
@@ -69,4 +72,8 @@ private:
     void writeFieldOrSkip(uint32_t fieldTag, bool skip);
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // PRIVACY_BUFFER_H
\ No newline at end of file
index fc8a6db..103004d 100644 (file)
  */
 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 @@ Reporter::run_report_status_t Reporter::upload_backlog() {
 
     return REPORT_FINISHED;
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
index f9a092a..45fd944 100644 (file)
@@ -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 @@ private:
     bool isTest = true;  // default to true for testing
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // REPORTER_H
index 3f693fa..45d6281 100644 (file)
 #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 @@ status_t GZipSection::Execute(ReportRequestSet* requests) const {
     }
     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 @@ status_t TombstoneSection::BlockingCall(int pipeWriteFd) const {
             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 @@ status_t TombstoneSection::BlockingCall(int pipeWriteFd) const {
     proto.flush(pipeWriteFd);
     return err;
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
\ No newline at end of file
index 19ef7ee..34a3613 100644 (file)
@@ -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 @@ private:
     std::string mType;
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // SECTIONS_H
index 1abf267..2b790ca 100644 (file)
 
 #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 @@ void Throttler::dump(FILE* out) {
     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
index c56f753..e8f317d 100644 (file)
 #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 @@ private:
     int64_t mLastRefractoryMs;
 };
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // THROTTLER_H
index 7db1fa7..af685d8 100644 (file)
 
 #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 @@ status_t wait_child(pid_t pid) {
     if (!died) return kill_child(pid);
     return statusCode(status);
 }
+
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
\ No newline at end of file
index b5f6e21..3dac2c4 100644 (file)
 
 #include "Privacy.h"
 
-using namespace android;
+namespace android {
+namespace os {
+namespace incidentd {
+
 using namespace android::base;
 
 /**
@@ -75,4 +78,8 @@ uint64_t Nanotime();
 status_t kill_child(pid_t pid);
 status_t wait_child(pid_t pid);
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // INCIDENTD_UTIL_H
index 38b7449..4948823 100644 (file)
@@ -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 @@ int main(int /*argc*/, char** /*argv*/) {
     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;
index f023ee1..e2883ba 100644 (file)
@@ -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 @@ done:
     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 @@ void clean_directory(const char* directory, off_t maxSize, size_t maxCount) {
     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 @@ void clean_directory(const char* directory, off_t maxSize, size_t maxCount) {
         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 @@ void clean_directory(const char* directory, off_t maxSize, size_t maxCount) {
     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
index 2a3cf4c..a63f8df 100644 (file)
 #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
index 697e66f..1498127 100644 (file)
 #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 Privacy** PRIVACY_POLICY_LIST;
 
 extern const int PRIVACY_POLICY_COUNT;
 
+}  // namespace incidentd
+}  // namespace os
+}  // namespace android
+
 #endif  // SECTION_LIST_H
index 7a05d7e..9d208df 100644 (file)
 #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 {
index 10c2981..685759f 100644 (file)
@@ -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 @@ using ::testing::internal::GetCapturedStdout;
 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 @@ public:
 
     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 @@ public:
         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, NoStripLengthDelimitedField_Message) {
 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, StripVarintAndString) {
 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, StripVarintAndFixed64) {
 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 @@ TEST_F(PrivacyBufferTest, SelfRecursionMessage) {
     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 @@ TEST_F(PrivacyBufferTest, AutoMessage) {
     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);
 }
index 42d94f0..cf107c8 100644 (file)
@@ -30,6 +30,7 @@ using namespace android;
 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;
index 2f6698b..9f92353 100644 (file)
 #include <gtest/gtest.h>
 #include <string.h>
 
-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;
 using namespace android::base;
 using namespace android::binder;
 using namespace android::os;
+using namespace android::os::incidentd;
 using namespace android::util;
-using namespace std;
 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 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 {
 public:
@@ -101,7 +102,7 @@ TEST_F(SectionTest, HeaderSection) {
     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 @@ TEST_F(SectionTest, GZipSection) {
     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 @@ TEST_F(SectionTest, LogSectionBinary) {
     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 @@ TEST_F(SectionTest, LogSectionSystem) {
     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 @@ TEST_F(SectionTest, TestMultipleRequests) {
     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 @@ TEST_F(SectionTest, TestMultipleRequestsBySpec) {
     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();
 
index 213dcef..8488c99 100644 (file)
@@ -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());
index bd2d15c..1d7f2b6 100644 (file)
@@ -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 @@ Privacy* final_list[] = {&field_0, &field_1};
 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
index bf698d4..c84de4c 100644 (file)
@@ -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 @@ public:
 
 private:
     size_t mChunkSize;
-    vector<uint8_t*> mBuffers;
+    std::vector<uint8_t*> mBuffers;
 
     Pointer mWp;
     Pointer mEp;
index ca45e26..4b49ced 100644 (file)
@@ -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;
 
index a040bd2..015727a 100644 (file)
@@ -173,7 +173,7 @@ ProtoOutputStream::write(uint64_t fieldId, bool val)
 }
 
 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;
index 7e922e6..a274a8c 100644 (file)
@@ -393,6 +393,11 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const Destination
 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 @@ static bool generateSectionListCpp(Descriptor const* descriptor) {
         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;
 }