Joe Onorato | de5b027d | 2016-11-23 16:16:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _ANDROID_OS_DROPBOXMANAGER_H |
| 18 | #define _ANDROID_OS_DROPBOXMANAGER_H |
| 19 | |
| 20 | #include <android-base/unique_fd.h> |
| 21 | #include <binder/Parcel.h> |
| 22 | #include <binder/Parcelable.h> |
| 23 | #include <binder/Status.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace android { |
| 29 | namespace os { |
| 30 | |
| 31 | using namespace android; |
| 32 | using namespace android::base; |
| 33 | using namespace android::binder; |
| 34 | using namespace std; |
| 35 | |
| 36 | class DropBoxManager : public virtual RefBase |
| 37 | { |
| 38 | public: |
| 39 | enum { |
| 40 | IS_EMPTY = 1, |
| 41 | IS_TEXT = 2, |
| 42 | IS_GZIPPED = 4 |
| 43 | }; |
| 44 | |
| 45 | DropBoxManager(); |
| 46 | virtual ~DropBoxManager(); |
| 47 | |
| 48 | static sp<DropBoxManager> create(); |
| 49 | |
| 50 | // Create a new entry with plain text contents. |
| 51 | Status addText(const String16& tag, const string& text); |
| 52 | |
| 53 | // Create a new Entry with byte array contents. Makes a copy of the data. |
| 54 | Status addData(const String16& tag, uint8_t const* data, size_t size, int flags); |
| 55 | |
| 56 | // Create a new Entry from a file. The file will be opened in this process |
| 57 | // and a handle will be passed to the system process, so no additional permissions |
| 58 | // are required from the system process. Returns NULL if the file can't be opened. |
| 59 | Status addFile(const String16& tag, const string& filename, int flags); |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 60 | |
Joe Onorato | de5b027d | 2016-11-23 16:16:12 -0800 | [diff] [blame] | 61 | class Entry : public virtual RefBase, public Parcelable { |
| 62 | public: |
| 63 | Entry(); |
| 64 | virtual ~Entry(); |
| 65 | |
| 66 | virtual status_t writeToParcel(Parcel* out) const; |
| 67 | virtual status_t readFromParcel(const Parcel* in); |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 68 | |
| 69 | const vector<uint8_t>& getData() const; |
| 70 | const unique_fd& getFd() const; |
| 71 | int32_t getFlags() const; |
| 72 | int64_t getTimestamp() const; |
| 73 | |
Joe Onorato | de5b027d | 2016-11-23 16:16:12 -0800 | [diff] [blame] | 74 | private: |
| 75 | Entry(const String16& tag, int32_t flags); |
| 76 | Entry(const String16& tag, int32_t flags, int fd); |
| 77 | |
| 78 | String16 mTag; |
| 79 | int64_t mTimeMillis; |
| 80 | int32_t mFlags; |
| 81 | |
| 82 | vector<uint8_t> mData; |
| 83 | unique_fd mFd; |
| 84 | |
| 85 | friend class DropBoxManager; |
| 86 | }; |
| 87 | |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 88 | // Get the next entry from the drop box after the specified time. |
| 89 | Status getNextEntry(const String16& tag, long msec, Entry* entry); |
| 90 | |
Joe Onorato | de5b027d | 2016-11-23 16:16:12 -0800 | [diff] [blame] | 91 | private: |
| 92 | enum { |
| 93 | HAS_BYTE_ARRAY = 8 |
| 94 | }; |
| 95 | |
| 96 | Status add(const Entry& entry); |
| 97 | }; |
| 98 | |
| 99 | }} // namespace android::os |
| 100 | |
| 101 | #endif // _ANDROID_OS_DROPBOXMANAGER_H |
| 102 | |