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/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