Loading cmds/incident/main.cpp +18 −3 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <binder/IServiceManager.h> #include <utils/Looper.h> #include <cstring> #include <fcntl.h> #include <getopt.h> #include <stdio.h> Loading Loading @@ -143,6 +144,16 @@ find_section(const char* name) return NULL; } // ================================================================================ static int get_dest(const char* arg) { if (strcmp(arg, "LOCAL") == 0) return 0; if (strcmp(arg, "EXPLICIT") == 0) return 1; if (strcmp(arg, "AUTOMATIC") == 0) return 2; return -1; // return the default value } // ================================================================================ static void usage(FILE* out) Loading @@ -155,6 +166,7 @@ usage(FILE* out) fprintf(out, " -b (default) print the report to stdout (in proto format)\n"); fprintf(out, " -d send the report into dropbox\n"); fprintf(out, " -l list available sections\n"); fprintf(out, " -p privacy spec, LOCAL, EXPLICIT or AUTOMATIC\n"); fprintf(out, "\n"); fprintf(out, " SECTION the field numbers of the incident report fields to include\n"); fprintf(out, "\n"); Loading @@ -166,10 +178,11 @@ main(int argc, char** argv) Status status; IncidentReportArgs args; enum { DEST_DROPBOX, DEST_STDOUT } destination = DEST_STDOUT; int dest = -1; // default // Parse the args int opt; while ((opt = getopt(argc, argv, "bhdl")) != -1) { while ((opt = getopt(argc, argv, "bhdlp:")) != -1) { switch (opt) { case 'h': usage(stdout); Loading @@ -183,6 +196,9 @@ main(int argc, char** argv) case 'd': destination = DEST_DROPBOX; break; case 'p': dest = get_dest(optarg); break; default: usage(stderr); return 1; Loading Loading @@ -210,8 +226,7 @@ main(int argc, char** argv) } } } args.setDest(dest); // Start the thread pool. sp<ProcessState> ps(ProcessState::self()); Loading cmds/incidentd/src/EncodedBuffer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,6 @@ write_field_or_skip(FdBuffer::iterator &iterator, vector<uint8_t> &buf, uint8_t if (skip) { iterator += bytesToWrite; } else { buf.reserve(bytesToWrite); for (size_t i=0; i<bytesToWrite; i++) { buf.push_back(*iterator); iterator++; Loading Loading @@ -193,3 +192,4 @@ EncodedBuffer::flush(int fd) } return NO_ERROR; } cmds/incidentd/src/FdBuffer.cpp +59 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,12 @@ FdBuffer::flush(int fd) const return write_all(fd, mBuffers[i], mCurrentWritten); } FdBuffer::iterator FdBuffer::begin() const { return iterator(*this, 0, 0); } FdBuffer::iterator FdBuffer::end() const { Loading @@ -268,6 +274,17 @@ FdBuffer::end() const return FdBuffer::iterator(*this, mBuffers.size() - 1, mCurrentWritten); } // =============================================================================== FdBuffer::iterator::iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset) : mFdBuffer(buffer), mIndex(index), mOffset(offset) { } FdBuffer::iterator& FdBuffer::iterator::operator=(iterator& other) const { return other; } FdBuffer::iterator& FdBuffer::iterator::operator+(size_t offset) { Loading @@ -280,8 +297,50 @@ FdBuffer::iterator::operator+(size_t offset) return *this; } FdBuffer::iterator& FdBuffer::iterator::operator+=(size_t offset) { return *this + offset; } FdBuffer::iterator& FdBuffer::iterator::operator++() { return *this + 1; } FdBuffer::iterator FdBuffer::iterator::operator++(int) { return *this + 1; } bool FdBuffer::iterator::operator==(iterator other) const { return mIndex == other.mIndex && mOffset == other.mOffset; } bool FdBuffer::iterator::operator!=(iterator other) const { return !(*this == other); } int FdBuffer::iterator::operator-(iterator other) const { return (int)bytesRead() - (int)other.bytesRead(); } FdBuffer::iterator::reference FdBuffer::iterator::operator*() const { return mFdBuffer.mBuffers[mIndex][mOffset]; } FdBuffer::iterator FdBuffer::iterator::snapshot() const { return FdBuffer::iterator(mFdBuffer, mIndex, mOffset); } size_t FdBuffer::iterator::bytesRead() const { return mIndex * BUFFER_SIZE + mOffset; } bool FdBuffer::iterator::outOfBound() const { return bytesRead() > mFdBuffer.size(); } cmds/incidentd/src/FdBuffer.h +13 −16 Original line number Diff line number Diff line Loading @@ -87,32 +87,29 @@ public: friend class iterator; class iterator : public std::iterator<std::random_access_iterator_tag, uint8_t> { public: iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset) : mFdBuffer(buffer), mIndex(index), mOffset(offset) {} iterator& operator=(iterator& other) const { return other; } iterator& operator+(size_t offset); // this is implemented in .cpp iterator& operator+=(size_t offset) { return *this + offset; } iterator& operator++() { return *this + 1; } iterator operator++(int) { return *this + 1; } bool operator==(iterator other) const { return mIndex == other.mIndex && mOffset == other.mOffset; } bool operator!=(iterator other) const { return !(*this == other); } int operator-(iterator other) const { return (int)bytesRead() - (int)other.bytesRead(); } reference operator*() const { return mFdBuffer.mBuffers[mIndex][mOffset]; } iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset); iterator& operator=(iterator& other) const; iterator& operator+(size_t offset); iterator& operator+=(size_t offset); iterator& operator++(); iterator operator++(int); bool operator==(iterator other) const; bool operator!=(iterator other) const; int operator-(iterator other) const; reference operator*() const; // return the snapshot of the current iterator iterator snapshot() const { return iterator(mFdBuffer, mIndex, mOffset); } iterator snapshot() const; // how many bytes are read size_t bytesRead() const; // random access could make the iterator out of bound bool outOfBound() const { return bytesRead() > mFdBuffer.size(); } bool outOfBound() const; private: const FdBuffer& mFdBuffer; size_t mIndex; size_t mOffset; }; iterator begin() const { return iterator(*this, 0, 0); } iterator begin() const; iterator end() const; private: Loading cmds/incidentd/src/Privacy.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,12 @@ static bool allowDest(const uint8_t dest, const uint8_t policy) } } bool PrivacySpec::operator<(const PrivacySpec& other) const { return dest < other.dest; } bool PrivacySpec::CheckPremission(const Privacy* privacy) const { Loading @@ -97,4 +103,9 @@ PrivacySpec::CheckPremission(const Privacy* privacy) const bool PrivacySpec::RequireAll() const { return dest == DEST_LOCAL; } PrivacySpec new_spec_from_args(int dest) { if (dest < 0) return PrivacySpec(); return PrivacySpec(dest); } PrivacySpec get_default_dropbox_spec() { return PrivacySpec(DEST_AUTOMATIC); } No newline at end of file Loading
cmds/incident/main.cpp +18 −3 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <binder/IServiceManager.h> #include <utils/Looper.h> #include <cstring> #include <fcntl.h> #include <getopt.h> #include <stdio.h> Loading Loading @@ -143,6 +144,16 @@ find_section(const char* name) return NULL; } // ================================================================================ static int get_dest(const char* arg) { if (strcmp(arg, "LOCAL") == 0) return 0; if (strcmp(arg, "EXPLICIT") == 0) return 1; if (strcmp(arg, "AUTOMATIC") == 0) return 2; return -1; // return the default value } // ================================================================================ static void usage(FILE* out) Loading @@ -155,6 +166,7 @@ usage(FILE* out) fprintf(out, " -b (default) print the report to stdout (in proto format)\n"); fprintf(out, " -d send the report into dropbox\n"); fprintf(out, " -l list available sections\n"); fprintf(out, " -p privacy spec, LOCAL, EXPLICIT or AUTOMATIC\n"); fprintf(out, "\n"); fprintf(out, " SECTION the field numbers of the incident report fields to include\n"); fprintf(out, "\n"); Loading @@ -166,10 +178,11 @@ main(int argc, char** argv) Status status; IncidentReportArgs args; enum { DEST_DROPBOX, DEST_STDOUT } destination = DEST_STDOUT; int dest = -1; // default // Parse the args int opt; while ((opt = getopt(argc, argv, "bhdl")) != -1) { while ((opt = getopt(argc, argv, "bhdlp:")) != -1) { switch (opt) { case 'h': usage(stdout); Loading @@ -183,6 +196,9 @@ main(int argc, char** argv) case 'd': destination = DEST_DROPBOX; break; case 'p': dest = get_dest(optarg); break; default: usage(stderr); return 1; Loading Loading @@ -210,8 +226,7 @@ main(int argc, char** argv) } } } args.setDest(dest); // Start the thread pool. sp<ProcessState> ps(ProcessState::self()); Loading
cmds/incidentd/src/EncodedBuffer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,6 @@ write_field_or_skip(FdBuffer::iterator &iterator, vector<uint8_t> &buf, uint8_t if (skip) { iterator += bytesToWrite; } else { buf.reserve(bytesToWrite); for (size_t i=0; i<bytesToWrite; i++) { buf.push_back(*iterator); iterator++; Loading Loading @@ -193,3 +192,4 @@ EncodedBuffer::flush(int fd) } return NO_ERROR; }
cmds/incidentd/src/FdBuffer.cpp +59 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,12 @@ FdBuffer::flush(int fd) const return write_all(fd, mBuffers[i], mCurrentWritten); } FdBuffer::iterator FdBuffer::begin() const { return iterator(*this, 0, 0); } FdBuffer::iterator FdBuffer::end() const { Loading @@ -268,6 +274,17 @@ FdBuffer::end() const return FdBuffer::iterator(*this, mBuffers.size() - 1, mCurrentWritten); } // =============================================================================== FdBuffer::iterator::iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset) : mFdBuffer(buffer), mIndex(index), mOffset(offset) { } FdBuffer::iterator& FdBuffer::iterator::operator=(iterator& other) const { return other; } FdBuffer::iterator& FdBuffer::iterator::operator+(size_t offset) { Loading @@ -280,8 +297,50 @@ FdBuffer::iterator::operator+(size_t offset) return *this; } FdBuffer::iterator& FdBuffer::iterator::operator+=(size_t offset) { return *this + offset; } FdBuffer::iterator& FdBuffer::iterator::operator++() { return *this + 1; } FdBuffer::iterator FdBuffer::iterator::operator++(int) { return *this + 1; } bool FdBuffer::iterator::operator==(iterator other) const { return mIndex == other.mIndex && mOffset == other.mOffset; } bool FdBuffer::iterator::operator!=(iterator other) const { return !(*this == other); } int FdBuffer::iterator::operator-(iterator other) const { return (int)bytesRead() - (int)other.bytesRead(); } FdBuffer::iterator::reference FdBuffer::iterator::operator*() const { return mFdBuffer.mBuffers[mIndex][mOffset]; } FdBuffer::iterator FdBuffer::iterator::snapshot() const { return FdBuffer::iterator(mFdBuffer, mIndex, mOffset); } size_t FdBuffer::iterator::bytesRead() const { return mIndex * BUFFER_SIZE + mOffset; } bool FdBuffer::iterator::outOfBound() const { return bytesRead() > mFdBuffer.size(); }
cmds/incidentd/src/FdBuffer.h +13 −16 Original line number Diff line number Diff line Loading @@ -87,32 +87,29 @@ public: friend class iterator; class iterator : public std::iterator<std::random_access_iterator_tag, uint8_t> { public: iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset) : mFdBuffer(buffer), mIndex(index), mOffset(offset) {} iterator& operator=(iterator& other) const { return other; } iterator& operator+(size_t offset); // this is implemented in .cpp iterator& operator+=(size_t offset) { return *this + offset; } iterator& operator++() { return *this + 1; } iterator operator++(int) { return *this + 1; } bool operator==(iterator other) const { return mIndex == other.mIndex && mOffset == other.mOffset; } bool operator!=(iterator other) const { return !(*this == other); } int operator-(iterator other) const { return (int)bytesRead() - (int)other.bytesRead(); } reference operator*() const { return mFdBuffer.mBuffers[mIndex][mOffset]; } iterator(const FdBuffer& buffer, ssize_t index, ssize_t offset); iterator& operator=(iterator& other) const; iterator& operator+(size_t offset); iterator& operator+=(size_t offset); iterator& operator++(); iterator operator++(int); bool operator==(iterator other) const; bool operator!=(iterator other) const; int operator-(iterator other) const; reference operator*() const; // return the snapshot of the current iterator iterator snapshot() const { return iterator(mFdBuffer, mIndex, mOffset); } iterator snapshot() const; // how many bytes are read size_t bytesRead() const; // random access could make the iterator out of bound bool outOfBound() const { return bytesRead() > mFdBuffer.size(); } bool outOfBound() const; private: const FdBuffer& mFdBuffer; size_t mIndex; size_t mOffset; }; iterator begin() const { return iterator(*this, 0, 0); } iterator begin() const; iterator end() const; private: Loading
cmds/incidentd/src/Privacy.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,12 @@ static bool allowDest(const uint8_t dest, const uint8_t policy) } } bool PrivacySpec::operator<(const PrivacySpec& other) const { return dest < other.dest; } bool PrivacySpec::CheckPremission(const Privacy* privacy) const { Loading @@ -97,4 +103,9 @@ PrivacySpec::CheckPremission(const Privacy* privacy) const bool PrivacySpec::RequireAll() const { return dest == DEST_LOCAL; } PrivacySpec new_spec_from_args(int dest) { if (dest < 0) return PrivacySpec(); return PrivacySpec(dest); } PrivacySpec get_default_dropbox_spec() { return PrivacySpec(DEST_AUTOMATIC); } No newline at end of file