Merge "Fix clang-tidy performance warnings in syste/core."
diff --git a/base/file.cpp b/base/file.cpp
index da1adba..4e7ac82 100644
--- a/base/file.cpp
+++ b/base/file.cpp
@@ -24,9 +24,8 @@
#include <string>
#include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin.
+#include "android-base/logging.h"
#include "android-base/utf8.h"
-#define LOG_TAG "base.file"
-#include "cutils/log.h"
#include "utils/Compat.h"
namespace android {
@@ -86,22 +85,22 @@
int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY;
int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
if (fd == -1) {
- ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
+ PLOG(ERROR) << "android::WriteStringToFile open failed";
return false;
}
// We do an explicit fchmod here because we assume that the caller really
// meant what they said and doesn't want the umask-influenced mode.
if (fchmod(fd, mode) == -1) {
- ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
+ PLOG(ERROR) << "android::WriteStringToFile fchmod failed";
return CleanUpAfterFailedWrite(path);
}
if (fchown(fd, owner, group) == -1) {
- ALOGE("android::WriteStringToFile fchown failed: %s", strerror(errno));
+ PLOG(ERROR) << "android::WriteStringToFile fchown failed";
return CleanUpAfterFailedWrite(path);
}
if (!WriteStringToFd(content, fd)) {
- ALOGE("android::WriteStringToFile write failed: %s", strerror(errno));
+ PLOG(ERROR) << "android::WriteStringToFile write failed";
return CleanUpAfterFailedWrite(path);
}
close(fd);
diff --git a/base/logging.cpp b/base/logging.cpp
index 769c266..959bb8b 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -43,12 +43,11 @@
#include "android-base/macros.h"
#include "android-base/strings.h"
-#include "cutils/threads.h"
// Headers for LogMessage::LogLine.
#ifdef __ANDROID__
#include <android/set_abort_message.h>
-#include "cutils/log.h"
+#include "log/log.h"
#else
#include <sys/types.h>
#include <unistd.h>
diff --git a/debuggerd/test/BacktraceMock.h b/debuggerd/test/BacktraceMock.h
index f75534e..6104f7e 100644
--- a/debuggerd/test/BacktraceMock.h
+++ b/debuggerd/test/BacktraceMock.h
@@ -41,7 +41,7 @@
class BacktraceMock : public Backtrace {
public:
- BacktraceMock(BacktraceMapMock* map) : Backtrace(0, 0, map) {
+ explicit BacktraceMock(BacktraceMapMock* map) : Backtrace(0, 0, map) {
if (map_ == nullptr) {
abort();
}
diff --git a/fastboot/socket.h b/fastboot/socket.h
index de543db..7eaa0ab 100644
--- a/fastboot/socket.h
+++ b/fastboot/socket.h
@@ -104,7 +104,7 @@
protected:
// Protected constructor to force factory function use.
- Socket(cutils_socket_t sock);
+ explicit Socket(cutils_socket_t sock);
// Blocks up to |timeout_ms| until a read is possible on |sock_|, and sets |receive_timed_out_|
// as appropriate to help distinguish between normal timeouts and fatal errors. Returns true if
diff --git a/init/action.h b/init/action.h
index 6dee2d0..0bae9f0 100644
--- a/init/action.h
+++ b/init/action.h
@@ -44,7 +44,7 @@
class Action {
public:
- Action(bool oneshot = false);
+ explicit Action(bool oneshot = false);
bool AddCommand(const std::vector<std::string>& args,
const std::string& filename, int line, std::string* err);
diff --git a/init/devices.cpp b/init/devices.cpp
index 5e12f25..373177e 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -181,7 +181,7 @@
}
if (access(path.c_str(), F_OK) == 0) {
- LOG(INFO) << "restorecon_recursive: " << path;
+ LOG(VERBOSE) << "restorecon_recursive: " << path;
restorecon_recursive(path.c_str());
}
}
diff --git a/init/keychords.cpp b/init/keychords.cpp
index 1cfdd80..3dbb2f0 100644
--- a/init/keychords.cpp
+++ b/init/keychords.cpp
@@ -78,11 +78,13 @@
if (adb_enabled == "running") {
Service* svc = ServiceManager::GetInstance().FindServiceByKeychord(id);
if (svc) {
- LOG(INFO) << "Starting service " << svc->name() << " from keychord...";
+ LOG(INFO) << "Starting service " << svc->name() << " from keychord " << id;
svc->Start();
} else {
- LOG(ERROR) << "service for keychord " << id << " not found";
+ LOG(ERROR) << "Service for keychord " << id << " not found";
}
+ } else {
+ LOG(WARNING) << "Not starting service for keychord " << id << " because ADB is disabled";
}
}
diff --git a/init/parser/tokenizer.h b/init/parser/tokenizer.h
index 8312a08..ade8f73 100644
--- a/init/parser/tokenizer.h
+++ b/init/parser/tokenizer.h
@@ -36,7 +36,7 @@
// a TOK_NEWLINE will not be generated for that line.
class Tokenizer {
public:
- Tokenizer(const std::string& data);
+ explicit Tokenizer(const std::string& data);
~Tokenizer();
enum TokenType { TOK_START, TOK_END, TOK_NEWLINE, TOK_TEXT };
diff --git a/libbacktrace/UnwindMap.h b/libbacktrace/UnwindMap.h
index f85b54a..d5bec06 100644
--- a/libbacktrace/UnwindMap.h
+++ b/libbacktrace/UnwindMap.h
@@ -29,7 +29,7 @@
class UnwindMap : public BacktraceMap {
public:
- UnwindMap(pid_t pid);
+ explicit UnwindMap(pid_t pid);
unw_map_cursor_t* GetMapCursor() { return &map_cursor_; }
@@ -39,7 +39,7 @@
class UnwindMapRemote : public UnwindMap {
public:
- UnwindMapRemote(pid_t pid);
+ explicit UnwindMapRemote(pid_t pid);
virtual ~UnwindMapRemote();
bool Build() override;
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 6e6a9eb..26f908f 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -171,7 +171,7 @@
FILE *fp;
snprintf(pathBuf, sizeof(pathBuf), "/proc/%d/cgroup", tid);
- if (!(fp = fopen(pathBuf, "r"))) {
+ if (!(fp = fopen(pathBuf, "re"))) {
return -1;
}
@@ -329,6 +329,27 @@
#endif
}
+static void set_timerslack_ns(int tid, unsigned long long slack) {
+ char buf[64];
+
+ /* v4.6+ kernels support the /proc/<tid>/timerslack_ns interface. */
+ snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
+ int fd = open(buf, O_WRONLY | O_CLOEXEC);
+ if (fd != -1) {
+ int len = snprintf(buf, sizeof(buf), "%llu", slack);
+ if (write(fd, buf, len) != len) {
+ SLOGE("set_timerslack_ns write failed: %s\n", strerror(errno));
+ }
+ close(fd);
+ return;
+ }
+
+ /* If the above fails, try the old common.git PR_SET_TIMERSLACK_PID. */
+ if (prctl(PR_SET_TIMERSLACK_PID, slack, tid) == -1) {
+ SLOGE("set_timerslack_ns prctl failed: %s\n", strerror(errno));
+ }
+}
+
int set_sched_policy(int tid, SchedPolicy policy)
{
if (tid == 0) {
@@ -341,12 +362,11 @@
char statfile[64];
char statline[1024];
char thread_name[255];
- int fd;
snprintf(statfile, sizeof(statfile), "/proc/%d/stat", tid);
memset(thread_name, 0, sizeof(thread_name));
- fd = open(statfile, O_RDONLY);
+ int fd = open(statfile, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
int rc = read(fd, statline, 1023);
close(fd);
@@ -425,8 +445,8 @@
¶m);
}
- prctl(PR_SET_TIMERSLACK_PID,
- policy == SP_BACKGROUND ? TIMER_SLACK_BG : TIMER_SLACK_FG, tid);
+ set_timerslack_ns(tid, policy == SP_BACKGROUND ?
+ TIMER_SLACK_BG : TIMER_SLACK_FG);
return 0;
}
diff --git a/liblog/tests/benchmark.h b/liblog/tests/benchmark.h
index 57b3748..e9280f6 100644
--- a/liblog/tests/benchmark.h
+++ b/liblog/tests/benchmark.h
@@ -38,7 +38,7 @@
Benchmark(const char* name, void (*fn)(int)) : name_(strdup(name)), fn_(fn) {
BenchmarkRegister(this);
}
- Benchmark(const char* name) : name_(strdup(name)), fn_(NULL) {}
+ explicit Benchmark(const char* name) : name_(strdup(name)), fn_(NULL) {}
virtual ~Benchmark() {
free(name_);
diff --git a/libmemunreachable/Allocator.h b/libmemunreachable/Allocator.h
index a8f579e..5390739 100644
--- a/libmemunreachable/Allocator.h
+++ b/libmemunreachable/Allocator.h
@@ -109,13 +109,13 @@
}
// Construct an STLAllocator on top of a Heap
- STLAllocator(const Heap& heap) :
+ STLAllocator(const Heap& heap) : // NOLINT, implicit
heap_(heap) {
}
// Rebind an STLAllocator from an another STLAllocator
template<typename U>
- STLAllocator(const STLAllocator<U>& other) :
+ STLAllocator(const STLAllocator<U>& other) : // NOLINT, implicit
heap_(other.heap_) {
}
@@ -155,12 +155,12 @@
public:
~Allocator() {}
- Allocator(const Heap& other) :
+ Allocator(const Heap& other) : // NOLINT, implicit
STLAllocator<T>(other) {
}
template<typename U>
- Allocator(const STLAllocator<U>& other) :
+ Allocator(const STLAllocator<U>& other) : // NOLINT, implicit
STLAllocator<T>(other) {
}
diff --git a/libmemunreachable/HeapWalker.h b/libmemunreachable/HeapWalker.h
index 3c1b513..b25696f 100644
--- a/libmemunreachable/HeapWalker.h
+++ b/libmemunreachable/HeapWalker.h
@@ -48,7 +48,7 @@
class HeapWalker {
public:
- HeapWalker(Allocator<HeapWalker> allocator) : allocator_(allocator),
+ explicit HeapWalker(Allocator<HeapWalker> allocator) : allocator_(allocator),
allocations_(allocator), allocation_bytes_(0),
roots_(allocator), root_vals_(allocator),
segv_handler_(allocator), walking_ptr_(0) {
diff --git a/libmemunreachable/LeakFolding.h b/libmemunreachable/LeakFolding.h
index 732d3f2..9c6a525 100644
--- a/libmemunreachable/LeakFolding.h
+++ b/libmemunreachable/LeakFolding.h
@@ -54,7 +54,7 @@
bool dominator;
SCCInfo* accumulator;
- SCCInfo(Allocator<SCCInfo> allocator) : node(this, allocator),
+ explicit SCCInfo(Allocator<SCCInfo> allocator) : node(this, allocator),
count(0), size(0), cuumulative_count(0), cuumulative_size(0),
dominator(false), accumulator(nullptr) {}
private:
diff --git a/libmemunreachable/LinkedList.h b/libmemunreachable/LinkedList.h
index 3e44035..132842d 100644
--- a/libmemunreachable/LinkedList.h
+++ b/libmemunreachable/LinkedList.h
@@ -21,7 +21,7 @@
class LinkedList {
public:
LinkedList() : next_(this), prev_(this), data_() {}
- LinkedList(T data) : LinkedList() {
+ explicit LinkedList(T data) : LinkedList() {
data_ = data;
}
~LinkedList() {}
diff --git a/libmemunreachable/PtracerThread.h b/libmemunreachable/PtracerThread.h
index 4d6ca9a..f88b599 100644
--- a/libmemunreachable/PtracerThread.h
+++ b/libmemunreachable/PtracerThread.h
@@ -32,7 +32,7 @@
// the parent.
class PtracerThread {
public:
- PtracerThread(const std::function<int()>& func);
+ explicit PtracerThread(const std::function<int()>& func);
~PtracerThread();
bool Start();
int Join();
diff --git a/libmemunreachable/ScopedDisableMalloc.h b/libmemunreachable/ScopedDisableMalloc.h
index 4f96376..758d317 100644
--- a/libmemunreachable/ScopedDisableMalloc.h
+++ b/libmemunreachable/ScopedDisableMalloc.h
@@ -74,7 +74,7 @@
class ScopedDisableMallocTimeout {
public:
- ScopedDisableMallocTimeout(std::chrono::milliseconds timeout = std::chrono::milliseconds(2000)) :
+ explicit ScopedDisableMallocTimeout(std::chrono::milliseconds timeout = std::chrono::milliseconds(2000)) :
timeout_(timeout), timed_out_(false), disable_malloc_() {
Disable();
}
diff --git a/libmemunreachable/ScopedSignalHandler.h b/libmemunreachable/ScopedSignalHandler.h
index e006d43..1fd9d4d 100644
--- a/libmemunreachable/ScopedSignalHandler.h
+++ b/libmemunreachable/ScopedSignalHandler.h
@@ -30,7 +30,7 @@
public:
using Fn = std::function<void(ScopedSignalHandler&, int, siginfo_t*, void*)>;
- ScopedSignalHandler(Allocator<Fn> allocator) : allocator_(allocator), signal_(-1) {}
+ explicit ScopedSignalHandler(Allocator<Fn> allocator) : allocator_(allocator), signal_(-1) {}
~ScopedSignalHandler() {
reset();
}
diff --git a/libmemunreachable/Semaphore.h b/libmemunreachable/Semaphore.h
index 45e8c81..6bcf4ea 100644
--- a/libmemunreachable/Semaphore.h
+++ b/libmemunreachable/Semaphore.h
@@ -24,7 +24,7 @@
class Semaphore {
public:
- Semaphore(int count = 0) : count_(count) {}
+ explicit Semaphore(int count = 0) : count_(count) {}
~Semaphore() = default;
void Wait(std::chrono::milliseconds ms) {
diff --git a/libmemunreachable/Tarjan.h b/libmemunreachable/Tarjan.h
index d7ecdb9..dcd139a 100644
--- a/libmemunreachable/Tarjan.h
+++ b/libmemunreachable/Tarjan.h
@@ -62,7 +62,7 @@
template<class T>
class TarjanAlgorithm {
public:
- TarjanAlgorithm(Allocator<void> allocator) : index_(0),
+ explicit TarjanAlgorithm(Allocator<void> allocator) : index_(0),
stack_(allocator), components_(allocator) {}
void Execute(Graph<T>& graph, SCCList<T>& out);
diff --git a/libmemunreachable/tests/MemUnreachable_test.cpp b/libmemunreachable/tests/MemUnreachable_test.cpp
index 0747b12..2ae3db8 100644
--- a/libmemunreachable/tests/MemUnreachable_test.cpp
+++ b/libmemunreachable/tests/MemUnreachable_test.cpp
@@ -27,7 +27,7 @@
class HiddenPointer {
public:
- HiddenPointer(size_t size = 256) {
+ explicit HiddenPointer(size_t size = 256) {
Set(malloc(size));
}
~HiddenPointer() {
diff --git a/libpixelflinger/codeflinger/ARMAssembler.h b/libpixelflinger/codeflinger/ARMAssembler.h
index 7178c65..76acf7e 100644
--- a/libpixelflinger/codeflinger/ARMAssembler.h
+++ b/libpixelflinger/codeflinger/ARMAssembler.h
@@ -35,7 +35,7 @@
class ARMAssembler : public ARMAssemblerInterface
{
public:
- ARMAssembler(const sp<Assembly>& assembly);
+ explicit ARMAssembler(const sp<Assembly>& assembly);
virtual ~ARMAssembler();
uint32_t* base() const;
diff --git a/libpixelflinger/codeflinger/ARMAssemblerProxy.h b/libpixelflinger/codeflinger/ARMAssemblerProxy.h
index b852794..10d0390 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerProxy.h
+++ b/libpixelflinger/codeflinger/ARMAssemblerProxy.h
@@ -34,7 +34,7 @@
// ARMAssemblerProxy take ownership of the target
ARMAssemblerProxy();
- ARMAssemblerProxy(ARMAssemblerInterface* target);
+ explicit ARMAssemblerProxy(ARMAssemblerInterface* target);
virtual ~ARMAssemblerProxy();
void setTarget(ARMAssemblerInterface* target);
diff --git a/libpixelflinger/codeflinger/Arm64Assembler.h b/libpixelflinger/codeflinger/Arm64Assembler.h
index c9be116..527c757 100644
--- a/libpixelflinger/codeflinger/Arm64Assembler.h
+++ b/libpixelflinger/codeflinger/Arm64Assembler.h
@@ -47,8 +47,8 @@
class ArmToArm64Assembler : public ARMAssemblerInterface
{
public:
- ArmToArm64Assembler(const sp<Assembly>& assembly);
- ArmToArm64Assembler(void *base);
+ explicit ArmToArm64Assembler(const sp<Assembly>& assembly);
+ explicit ArmToArm64Assembler(void *base);
virtual ~ArmToArm64Assembler();
uint32_t* base() const;
diff --git a/libpixelflinger/codeflinger/CodeCache.h b/libpixelflinger/codeflinger/CodeCache.h
index 0fb6fd5..c0e0684 100644
--- a/libpixelflinger/codeflinger/CodeCache.h
+++ b/libpixelflinger/codeflinger/CodeCache.h
@@ -42,7 +42,7 @@
class AssemblyKey : public AssemblyKeyBase
{
public:
- AssemblyKey(const T& rhs) : mKey(rhs) { }
+ explicit AssemblyKey(const T& rhs) : mKey(rhs) { }
virtual int compare_type(const AssemblyKeyBase& key) const {
const T& rhs = static_cast<const AssemblyKey&>(key).mKey;
return android::compare_type(mKey, rhs);
@@ -56,7 +56,7 @@
class Assembly
{
public:
- Assembly(size_t size);
+ explicit Assembly(size_t size);
virtual ~Assembly();
ssize_t size() const;
@@ -80,13 +80,13 @@
{
public:
// pretty simple cache API...
- CodeCache(size_t size);
- ~CodeCache();
-
- sp<Assembly> lookup(const AssemblyKeyBase& key) const;
+ explicit CodeCache(size_t size);
+ ~CodeCache();
- int cache( const AssemblyKeyBase& key,
- const sp<Assembly>& assembly);
+ sp<Assembly> lookup(const AssemblyKeyBase& key) const;
+
+ int cache(const AssemblyKeyBase& key,
+ const sp<Assembly>& assembly);
private:
// nothing to see here...
@@ -105,7 +105,7 @@
const AssemblyKeyBase* mKey;
public:
key_t() { };
- key_t(const AssemblyKeyBase& k) : mKey(&k) { }
+ explicit key_t(const AssemblyKeyBase& k) : mKey(&k) { }
};
mutable pthread_mutex_t mLock;
diff --git a/libpixelflinger/codeflinger/GGLAssembler.h b/libpixelflinger/codeflinger/GGLAssembler.h
index ecc242a..47dbf3a 100644
--- a/libpixelflinger/codeflinger/GGLAssembler.h
+++ b/libpixelflinger/codeflinger/GGLAssembler.h
@@ -49,7 +49,7 @@
public:
class RegisterFile;
- RegisterAllocator(int arch);
+ RegisterAllocator(int arch); // NOLINT, implicit
RegisterFile& registerFile();
int reserveReg(int reg);
int obtainReg();
@@ -59,7 +59,7 @@
class RegisterFile
{
public:
- RegisterFile(int arch);
+ RegisterFile(int arch); // NOLINT, implicit
RegisterFile(const RegisterFile& rhs, int arch);
~RegisterFile();
@@ -101,7 +101,7 @@
class Scratch
{
public:
- Scratch(RegisterFile& regFile)
+ explicit Scratch(RegisterFile& regFile)
: mRegFile(regFile), mScratch(0) {
}
~Scratch() {
@@ -177,8 +177,8 @@
{
public:
- GGLAssembler(ARMAssemblerInterface* target);
- virtual ~GGLAssembler();
+ explicit GGLAssembler(ARMAssemblerInterface* target);
+ virtual ~GGLAssembler();
uint32_t* base() const { return 0; } // XXX
uint32_t* pc() const { return 0; } // XXX
@@ -206,7 +206,7 @@
struct reg_t {
reg_t() : reg(-1), flags(0) {
}
- reg_t(int r, int f=0)
+ reg_t(int r, int f=0) // NOLINT, implicit
: reg(r), flags(f) {
}
void setTo(int r, int f=0) {
@@ -219,7 +219,7 @@
struct integer_t : public reg_t {
integer_t() : reg_t(), s(0) {
}
- integer_t(int r, int sz=32, int f=0)
+ integer_t(int r, int sz=32, int f=0) // NOLINT, implicit
: reg_t(r, f), s(sz) {
}
void setTo(int r, int sz=32, int f=0) {
@@ -251,7 +251,7 @@
struct component_t : public reg_t {
component_t() : reg_t(), h(0), l(0) {
}
- component_t(int r, int f=0)
+ component_t(int r, int f=0) // NOLINT, implicit
: reg_t(r, f), h(0), l(0) {
}
component_t(int r, int lo, int hi, int f=0)
diff --git a/libpixelflinger/codeflinger/tinyutils/smartpointer.h b/libpixelflinger/codeflinger/tinyutils/smartpointer.h
index 9d0a16e..23a5f7e 100644
--- a/libpixelflinger/codeflinger/tinyutils/smartpointer.h
+++ b/libpixelflinger/codeflinger/tinyutils/smartpointer.h
@@ -51,10 +51,10 @@
public:
inline sp() : m_ptr(0) { }
- sp(T* other);
+ sp(T* other); // NOLINT, implicit
sp(const sp<T>& other);
- template<typename U> sp(U* other);
- template<typename U> sp(const sp<U>& other);
+ template<typename U> sp(U* other); // NOLINT, implicit
+ template<typename U> sp(const sp<U>& other); // NOLINT, implicit
~sp();
diff --git a/libutils/tests/Looper_test.cpp b/libutils/tests/Looper_test.cpp
index 17319e0..8ebcfaf 100644
--- a/libutils/tests/Looper_test.cpp
+++ b/libutils/tests/Looper_test.cpp
@@ -76,7 +76,7 @@
int fd;
int events;
- StubCallbackHandler(int nextResult) : nextResult(nextResult),
+ explicit StubCallbackHandler(int nextResult) : nextResult(nextResult),
callbackCount(0), fd(-1), events(-1) {
}
diff --git a/libutils/tests/StrongPointer_test.cpp b/libutils/tests/StrongPointer_test.cpp
index f46d6d1..323a6f2 100644
--- a/libutils/tests/StrongPointer_test.cpp
+++ b/libutils/tests/StrongPointer_test.cpp
@@ -23,7 +23,7 @@
class Foo : public LightRefBase<Foo> {
public:
- Foo(bool* deleted_check) : mDeleted(deleted_check) {
+ explicit Foo(bool* deleted_check) : mDeleted(deleted_check) {
*mDeleted = false;
}
diff --git a/libutils/tests/TestHelpers.h b/libutils/tests/TestHelpers.h
index d8e985e..6801cd7 100644
--- a/libutils/tests/TestHelpers.h
+++ b/libutils/tests/TestHelpers.h
@@ -60,7 +60,7 @@
int mDelayMillis;
public:
- DelayedTask(int delayMillis) : mDelayMillis(delayMillis) { }
+ explicit DelayedTask(int delayMillis) : mDelayMillis(delayMillis) { }
protected:
virtual ~DelayedTask() { }
diff --git a/logd/FlushCommand.h b/logd/FlushCommand.h
index 9224773..7172d5f 100644
--- a/logd/FlushCommand.h
+++ b/logd/FlushCommand.h
@@ -35,7 +35,7 @@
uint64_t mTimeout;
public:
- FlushCommand(LogReader &mReader,
+ explicit FlushCommand(LogReader &mReader,
bool nonBlock = false,
unsigned long tail = -1,
unsigned int logMask = -1,
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index b390a0c..162c189 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -103,7 +103,7 @@
public:
LastLogTimes &mTimes;
- LogBuffer(LastLogTimes *times);
+ explicit LogBuffer(LastLogTimes *times);
void init();
bool isMonotonic() { return monotonic; }
diff --git a/logd/LogCommand.h b/logd/LogCommand.h
index c944478..0adc2a1 100644
--- a/logd/LogCommand.h
+++ b/logd/LogCommand.h
@@ -22,7 +22,7 @@
class LogCommand : public FrameworkCommand {
public:
- LogCommand(const char *cmd);
+ explicit LogCommand(const char *cmd);
virtual ~LogCommand() {}
};
diff --git a/logd/LogReader.h b/logd/LogReader.h
index 98674b8..fdcedf1 100644
--- a/logd/LogReader.h
+++ b/logd/LogReader.h
@@ -27,7 +27,7 @@
LogBuffer &mLogbuf;
public:
- LogReader(LogBuffer *logbuf);
+ explicit LogReader(LogBuffer *logbuf);
void notifyNewLog();
LogBuffer &logbuf(void) const { return mLogbuf; }
diff --git a/metricsd/collectors/cpu_usage_collector.h b/metricsd/collectors/cpu_usage_collector.h
index f81dfcb..9f92cf3 100644
--- a/metricsd/collectors/cpu_usage_collector.h
+++ b/metricsd/collectors/cpu_usage_collector.h
@@ -23,7 +23,7 @@
class CpuUsageCollector {
public:
- CpuUsageCollector(MetricsLibraryInterface* metrics_library);
+ explicit CpuUsageCollector(MetricsLibraryInterface* metrics_library);
// Initialize this collector's state.
void Init();
diff --git a/metricsd/collectors/disk_usage_collector.h b/metricsd/collectors/disk_usage_collector.h
index c1d4546..288b34b 100644
--- a/metricsd/collectors/disk_usage_collector.h
+++ b/metricsd/collectors/disk_usage_collector.h
@@ -23,7 +23,7 @@
class DiskUsageCollector {
public:
- DiskUsageCollector(MetricsLibraryInterface* metrics_library);
+ explicit DiskUsageCollector(MetricsLibraryInterface* metrics_library);
// Schedule the next collection.
void Schedule();
diff --git a/metricsd/uploader/metricsd_service_runner.h b/metricsd/uploader/metricsd_service_runner.h
index f5dad21..b36d4a5 100644
--- a/metricsd/uploader/metricsd_service_runner.h
+++ b/metricsd/uploader/metricsd_service_runner.h
@@ -27,7 +27,7 @@
class MetricsdServiceRunner {
public:
- MetricsdServiceRunner(std::shared_ptr<CrashCounters> counters);
+ explicit MetricsdServiceRunner(std::shared_ptr<CrashCounters> counters);
// Start the Metricsd Binder service in a new thread.
void Start();
diff --git a/rootdir/init.usb.configfs.rc b/rootdir/init.usb.configfs.rc
index e19b058..dc875b4 100644
--- a/rootdir/init.usb.configfs.rc
+++ b/rootdir/init.usb.configfs.rc
@@ -5,6 +5,10 @@
write /config/usb_gadget/g1/bDeviceClass 0
write /config/usb_gadget/g1/bDeviceSubClass 0
write /config/usb_gadget/g1/bDeviceProtocol 0
+ rm /config/usb_gadget/g1/configs/b.1/f1
+ rm /config/usb_gadget/g1/configs/b.1/f2
+ rm /config/usb_gadget/g1/configs/b.1/f3
+ rmdir /config/usb_gadget/g1/functions/rndis.gs4
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=adb && property:sys.usb.configfs=1
@@ -12,18 +16,12 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=mtp && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -33,9 +31,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -43,9 +38,6 @@
on property:sys.usb.config=ptp && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ptp"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ptp.gs1 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -55,9 +47,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ptp,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ptp_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ptp.gs1 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -65,9 +54,6 @@
on property:sys.usb.config=accessory && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -77,9 +63,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -87,9 +70,6 @@
on property:sys.usb.config=audio_source && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "audiosource"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/audio_source.gs2 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -99,9 +79,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=audio_source,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "audiosource_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/audio_source.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -109,9 +86,6 @@
on property:sys.usb.config=accessory,audio_source && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_audiosource"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/audio_source.gs3 /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -122,9 +96,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_audiosource_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/audio_source.gs3 /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f3
@@ -133,9 +104,6 @@
on property:sys.usb.config=midi && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -145,19 +113,14 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=midi,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=rndis && property:sys.usb.configfs=1
+ mkdir /config/usb_gadget/g1/functions/rndis.gs4
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/rndis.gs4 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -166,10 +129,8 @@
start adbd
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,adb && property:sys.usb.configfs=1
+ mkdir /config/usb_gadget/g1/functions/rndis.gs4
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/rndis.gs4 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
diff --git a/trusty/gatekeeper/trusty_gatekeeper.h b/trusty/gatekeeper/trusty_gatekeeper.h
index 82108dc..2becc49 100644
--- a/trusty/gatekeeper/trusty_gatekeeper.h
+++ b/trusty/gatekeeper/trusty_gatekeeper.h
@@ -27,7 +27,7 @@
class TrustyGateKeeperDevice {
public:
- TrustyGateKeeperDevice(const hw_module_t* module);
+ explicit TrustyGateKeeperDevice(const hw_module_t* module);
~TrustyGateKeeperDevice();
hw_device_t* hw_device();
diff --git a/trusty/keymaster/trusty_keymaster_device.h b/trusty/keymaster/trusty_keymaster_device.h
index cb74386..68cf40c 100644
--- a/trusty/keymaster/trusty_keymaster_device.h
+++ b/trusty/keymaster/trusty_keymaster_device.h
@@ -39,7 +39,7 @@
* These are the only symbols that will be exported by libtrustykeymaster. All functionality
* can be reached via the function pointers in device_.
*/
- __attribute__((visibility("default"))) TrustyKeymasterDevice(const hw_module_t* module);
+ __attribute__((visibility("default"))) explicit TrustyKeymasterDevice(const hw_module_t* module);
__attribute__((visibility("default"))) hw_device_t* hw_device();
~TrustyKeymasterDevice();
diff --git a/trusty/nvram/Android.mk b/trusty/nvram/Android.mk
index 18c54d5..44e2212 100644
--- a/trusty/nvram/Android.mk
+++ b/trusty/nvram/Android.mk
@@ -22,9 +22,22 @@
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
module.c \
+ trusty_nvram_device.cpp \
trusty_nvram_implementation.cpp
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall -Werror -Wextra -fvisibility=hidden
LOCAL_STATIC_LIBRARIES := libnvram-hal
LOCAL_SHARED_LIBRARIES := libtrusty libnvram-messages liblog
include $(BUILD_SHARED_LIBRARY)
+
+# nvram-wipe is a helper tool for clearing NVRAM state.
+include $(CLEAR_VARS)
+LOCAL_MODULE := nvram-wipe
+LOCAL_SRC_FILES := \
+ nvram_wipe.cpp \
+ trusty_nvram_implementation.cpp
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wall -Werror -Wextra -fvisibility=hidden
+LOCAL_STATIC_LIBRARIES := libnvram-hal
+LOCAL_SHARED_LIBRARIES := libtrusty libnvram-messages liblog
+include $(BUILD_EXECUTABLE)
diff --git a/trusty/nvram/module.c b/trusty/nvram/module.c
index 06819c0..a2e64d3 100644
--- a/trusty/nvram/module.c
+++ b/trusty/nvram/module.c
@@ -16,7 +16,7 @@
#include <hardware/nvram.h>
-// This function is defined in trusty_nvram_implementation.cpp.
+// This function is defined in trusty_nvram_device.cpp.
int trusty_nvram_open(const hw_module_t* module,
const char* device_id,
hw_device_t** device_ptr);
diff --git a/trusty/nvram/nvram_wipe.cpp b/trusty/nvram/nvram_wipe.cpp
new file mode 100644
index 0000000..d0f4fad
--- /dev/null
+++ b/trusty/nvram/nvram_wipe.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <nvram/messages/nvram_messages.h>
+
+#include "trusty_nvram_implementation.h"
+
+void usage(const char* program_name) {
+ fprintf(stderr, "Usage: %s [status|disable|wipe]\n", program_name);
+ exit(-1);
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 2) {
+ usage(argv[0]);
+ }
+
+ nvram::TrustyNvramImplementation nvram_proxy;
+ nvram::Request request;
+ nvram::Response response;
+
+ if (!strcmp(argv[1], "status")) {
+ request.payload.Activate<nvram::COMMAND_GET_INFO>();
+ nvram_proxy.Execute(request, &response);
+ const nvram::GetInfoResponse* get_info_response =
+ response.payload.get<nvram::COMMAND_GET_INFO>();
+ if (response.result == NV_RESULT_SUCCESS) {
+ int status = get_info_response && get_info_response->wipe_disabled;
+ printf("Wiping disabled: %d\n", status);
+ return status;
+ }
+ } else if (!strcmp(argv[1], "disable")) {
+ request.payload.Activate<nvram::COMMAND_DISABLE_WIPE>();
+ nvram_proxy.Execute(request, &response);
+ } else if (!strcmp(argv[1], "wipe")) {
+ request.payload.Activate<nvram::COMMAND_WIPE_STORAGE>();
+ nvram_proxy.Execute(request, &response);
+ } else {
+ usage(argv[0]);
+ }
+
+ if (response.result != NV_RESULT_SUCCESS) {
+ fprintf(stderr, "Command execution failure: %u\n", response.result);
+ return -1;
+ }
+
+ return 0;
+}
+
diff --git a/trusty/nvram/trusty_nvram_device.cpp b/trusty/nvram/trusty_nvram_device.cpp
new file mode 100644
index 0000000..2c50915
--- /dev/null
+++ b/trusty/nvram/trusty_nvram_device.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <nvram/hal/nvram_device_adapter.h>
+
+#include "trusty_nvram_implementation.h"
+
+extern "C" int trusty_nvram_open(const hw_module_t* module,
+ const char* device_id,
+ hw_device_t** device_ptr) {
+ if (strcmp(NVRAM_HARDWARE_DEVICE_ID, device_id) != 0) {
+ return -EINVAL;
+ }
+
+ nvram::NvramDeviceAdapter* adapter = new nvram::NvramDeviceAdapter(
+ module, new nvram::TrustyNvramImplementation);
+ *device_ptr = adapter->as_device();
+ return 0;
+}
diff --git a/trusty/nvram/trusty_nvram_implementation.cpp b/trusty/nvram/trusty_nvram_implementation.cpp
index 39496b4..041c1bd 100644
--- a/trusty/nvram/trusty_nvram_implementation.cpp
+++ b/trusty/nvram/trusty_nvram_implementation.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "trusty_nvram_implementation.h"
+
#include <errno.h>
#include <string.h>
@@ -23,10 +25,9 @@
#define LOG_TAG "TrustyNVRAM"
#include <log/log.h>
-#include <nvram/hal/nvram_device_adapter.h>
#include <nvram/messages/blob.h>
-#include <nvram/messages/nvram_messages.h>
+namespace nvram {
namespace {
// Character device to open for Trusty IPC connections.
@@ -35,35 +36,7 @@
// App identifier of the NVRAM app.
const char kTrustyNvramAppId[] = "com.android.trusty.nvram";
-// |TrustyNvramImplementation| proxies requests to the Trusty NVRAM app. It
-// serializes the request objects, sends it to the Trusty app and finally reads
-// back the result and decodes it.
-class TrustyNvramImplementation : public nvram::NvramImplementation {
- public:
- ~TrustyNvramImplementation() override;
-
- void Execute(const nvram::Request& request,
- nvram::Response* response) override;
-
- private:
- // Connects the IPC channel to the Trusty app if it is not already open.
- // Returns true if the channel is open, false on errors.
- bool Connect();
-
- // Dispatches a command to the trust app. Returns true if successful (note
- // that the response may still indicate an error on the Trusty side), false if
- // there are any I/O or encoding/decoding errors.
- bool SendRequest(const nvram::Request& request,
- nvram::Response* response);
-
- // The file descriptor for the IPC connection to the Trusty app.
- int tipc_nvram_fd_ = -1;
-
- // Response buffer. This puts a hard size limit on the responses from the
- // Trusty app. 4096 matches the maximum IPC message size currently supported
- // by Trusty.
- uint8_t response_buffer_[4096];
-};
+} // namespace
TrustyNvramImplementation::~TrustyNvramImplementation() {
if (tipc_nvram_fd_ != -1) {
@@ -136,17 +109,4 @@
return true;
}
-} // namespace
-
-extern "C" int trusty_nvram_open(const hw_module_t* module,
- const char* device_id,
- hw_device_t** device_ptr) {
- if (strcmp(NVRAM_HARDWARE_DEVICE_ID, device_id) != 0) {
- return -EINVAL;
- }
-
- nvram::NvramDeviceAdapter* adapter =
- new nvram::NvramDeviceAdapter(module, new TrustyNvramImplementation);
- *device_ptr = adapter->as_device();
- return 0;
-}
+} // namespace nvram
diff --git a/trusty/nvram/trusty_nvram_implementation.h b/trusty/nvram/trusty_nvram_implementation.h
new file mode 100644
index 0000000..60758f7
--- /dev/null
+++ b/trusty/nvram/trusty_nvram_implementation.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_
+#define TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_
+
+#include <stdint.h>
+
+#include <nvram/hal/nvram_device_adapter.h>
+#include <nvram/messages/nvram_messages.h>
+
+namespace nvram {
+
+// |TrustyNvramImplementation| proxies requests to the Trusty NVRAM app. It
+// serializes the request objects, sends it to the Trusty app and finally reads
+// back the result and decodes it.
+class TrustyNvramImplementation : public nvram::NvramImplementation {
+ public:
+ ~TrustyNvramImplementation() override;
+
+ void Execute(const nvram::Request& request,
+ nvram::Response* response) override;
+
+ private:
+ // Connects the IPC channel to the Trusty app if it is not already open.
+ // Returns true if the channel is open, false on errors.
+ bool Connect();
+
+ // Dispatches a command to the trust app. Returns true if successful (note
+ // that the response may still indicate an error on the Trusty side), false if
+ // there are any I/O or encoding/decoding errors.
+ bool SendRequest(const nvram::Request& request,
+ nvram::Response* response);
+
+ // The file descriptor for the IPC connection to the Trusty app.
+ int tipc_nvram_fd_ = -1;
+
+ // Response buffer. This puts a hard size limit on the responses from the
+ // Trusty app. 4096 matches the maximum IPC message size currently supported
+ // by Trusty.
+ uint8_t response_buffer_[4096];
+};
+
+} // namespace nvram
+
+#endif // TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_