From 5490b610b3545c96d48de2e01c758e061b2aeed9 Mon Sep 17 00:00:00 2001 From: Primiano Tucci Date: Fri, 26 Jan 2018 14:25:18 +0000 Subject: DropBoxManager: Allow adding a file using an fd This patch adds an overload to DropBoxManager::addFile() which accepts an already-opened file as a file descriptor. This avoids the need for clients to create a filesystem-visible file when uploading data to DropBox. Test: Tested with perfetto using https://android-review.googlesource.com/c/platform/external/perfetto/+/587674 Change-Id: I076bfd3180fb9b4baff7e1bae2e611419061b2a7 Merged-In: I076bfd3180fb9b4baff7e1bae2e611419061b2a7 --- libs/services/include/android/os/DropBoxManager.h | 6 +++++- libs/services/src/os/DropBoxManager.cpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/services/include/android/os/DropBoxManager.h b/libs/services/include/android/os/DropBoxManager.h index 8717178bb7d6..3449a7b72283 100644 --- a/libs/services/include/android/os/DropBoxManager.h +++ b/libs/services/include/android/os/DropBoxManager.h @@ -57,7 +57,11 @@ public: // and a handle will be passed to the system process, so no additional permissions // are required from the system process. Returns NULL if the file can't be opened. Status addFile(const String16& tag, const string& filename, int flags); - + + // Create a new Entry from an already opened file. Takes ownership of the + // file descriptor. + Status addFile(const String16& tag, int fd, int flags); + class Entry : public virtual RefBase, public Parcelable { public: Entry(); diff --git a/libs/services/src/os/DropBoxManager.cpp b/libs/services/src/os/DropBoxManager.cpp index bbb45f022a87..e8e34d7c4cb3 100644 --- a/libs/services/src/os/DropBoxManager.cpp +++ b/libs/services/src/os/DropBoxManager.cpp @@ -179,7 +179,12 @@ DropBoxManager::addFile(const String16& tag, const string& filename, int flags) ALOGW("DropboxManager: %s", message.c_str()); return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, message.c_str()); } + return addFile(tag, fd, flags); +} +Status +DropBoxManager::addFile(const String16& tag, int fd, int flags) +{ Entry entry(tag, flags, fd); return add(entry); } -- cgit v1.2.3-59-g8ed1b